Documentation

Trace:

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
jvx:communication:rest_customservice [2022/11/17 13:17]
admin
jvx:communication:rest_customservice [2022/11/18 09:06]
admin
Line 88: Line 88:
 } }
 </​file>​ </​file>​
-If you won't define the context listener as @WebListener,​ simply add:+If you won't define the context listener as ''​@WebListener''​, simply add:
  
 <file xml> <file xml>
Line 96: Line 96:
 </​file>​ </​file>​
 to your deployment descriptor (web.xml). to your deployment descriptor (web.xml).
 +
 +To use your services, simply send ''​GET''​ or ''​POST''​ requests, e.g.
 +
 +<file java>
 +@Test
 +public void testGet() throws Exception
 +{
 +    ClientResource cres = new ClientResource(getBaseURL() + "​_user/​healthCheck"​); ​   ​
 +    cres.get();
 +    ​
 +    HashMap<​String,​ Object> hmpResult = (HashMap<​String,​ Object>​)JSONUtil.getObject(cres.getResponse().getEntity());​
 +
 +    Assert.assertEquals(200,​ cres.getStatus().getCode());​
 +    Assert.assertEquals("​SUCCESS",​ hmpResult.get("​code"​));​
 +    Assert.assertEquals("​GET is working!",​ hmpResult.get("​message"​));​
 +    Assert.assertEquals(2,​ hmpResult.size());​
 +}
 +
 +@Test
 +public void testPost() throws Exception
 +{
 +    IBean bean = new Bean();
 +    bean.put("​username",​ "​@john.doe"​);​
 +    bean.put("​firstName",​ "​John"​);​
 +    bean.put("​lastName",​ "​Doe"​);​
 +
 +    ClientResource cres = new ClientResource(getBaseURL() + "​_user/​healthCheck"​); ​   ​
 +    cres.post(bean);​
 +    ​
 +    HashMap<​String,​ Object> hmpResult = (HashMap<​String,​ Object>​)JSONUtil.getObject(cres.getResponse().getEntity());​
 +
 +    Assert.assertEquals(200,​ cres.getStatus().getCode());​
 +    Assert.assertEquals("​SUCCESS",​ hmpResult.get("​code"​));​
 +    Assert.assertEquals("​POST is working!",​ hmpResult.get("​message"​));​
 +    Assert.assertEquals(5,​ hmpResult.size());​
 +    Assert.assertEquals(bean.get("​username"​),​ hmpResult.get("​username"​));​
 +}
 +</​file>​
 +
 +The user-zone is per default ''​_zone''​ (e.g. **http://​localhost/​AppContext/​services/​rest/​_user/​healthCheck**). If you want another zone name, simply add a parameter to the servlet mapping in deployment descriptor (web.xml):
 +
 +<file xml>
 +<​servlet>  ​
 +  <​servlet-name>​RestletServlet</​servlet-name>  ​
 +  <​servlet-class>​com.sibvisions.rad.server.http.rest.RESTServlet</​servlet-class>​
 +
 +  <​init-param>​
 +    <​param-name>​zone.user</​param-name>​
 +    <​param-value>​uzone</​param-value>​
 +  </​init-param>​
 +</​servlet>​
 +</​file>​
 +
 +The zone name is now ''​uzone''​ (e.g. **http://​localhost/​AppContext/​services/​rest/​uzone/​healthCheck**).
 +
 +The complete source code is available [[https://​sourceforge.net/​p/​jvx/​code/​HEAD/​tree/​trunk/​java/​server/​tomcat/​|here]].
 +
 +In this document, we registered User services. It's also possible to register custom services as [[jvx:​common:​util:​rest#​administration|Admin services]]. The difference is that it's possible to [[jvx:​server:​security:​rest_services_disable|en/​disable admin services]] by name.
This website uses cookies for visitor traffic analysis. By using the website, you agree with storing the cookies on your computer.More information