Rest Service URI mapping to Java Inner Classes -


i have model rest service operations trying create uri hit java inner classes. let me know if can achieved using rest web service? using rest easy services.

edit: (using code provided answer peeskillet)

javax.ws.rs.processingexception: unable invoke request @  org.jboss.resteasy.client.jaxrs.engines.apachehttpclient4engine.invoke(apachehttpclient4engine.java:287) @ org.jboss.resteasy.client.jaxrs.internal.clientinvocation.invoke(clientinvocation.java:407)  caused by: org.apache.http.conn.httphostconnectexception: connection http://localhost:8081 refused @ org.apache.http.impl.conn.defaultclientconnectionoperator.openconnection(defaultclientconnectionoperator.java:190) @ org.apache.http.impl.conn.managedclientconnectionimpl.open(managedclientconnectionimpl.java:294) @ org.apache.http.impl.client.defaultrequestdirector.tryconnect(defaultrequestdirector.java:643) @ org.apache.http.impl.client.defaultrequestdirector.execute(defaultrequestdirector.java:479) @ org.apache.http.impl.client.abstracthttpclient.execute(abstracthttpclient.java:906) @ org.apache.http.impl.client.abstracthttpclient.execute(abstracthttpclient.java:805) @ org.jboss.resteasy.client.jaxrs.engines.apachehttpclient4engine.invoke(apachehttpclient4engine.java:283) ... 26 more caused by: java.net.connectexception: connection refused 

please advise if resource class can made inner class other class

yes possible, cannot annotate inner class path @path , expect call there. need use "sub-resource locators". basically, can method annotated @path, return instance of inner resource class. like

@path("/messages") public class messageresource {      @get     @path("/{id}")     public response getmessage(@pathparam("id") int id) {         return response.ok("messages, id: " + id).build();     }      @path("/{id}/comments")     public commentsresource getcomments() {         return new commentsresource();     }      public class commentsresource {          @get         @path("/{id}")         public response getcomment(@pathparam("id") int id) {             return response.ok("hello sub-resource locators").build();         }     } } 

we can test it

@test public void testresteasy() {     webtarget target = client.target(testportprovider.generateurl(base_uri))             .path("messages").path("1234").path("comments").path("5678");     response response = target.request().get();     system.out.println("status:" + response.getstatus());     system.out.println("response: " + response.readentity(string.class));     response.close(); } 

and we'll response hello sub-resource locators


further reading


edit:

base on error you've provided, testportprovider use port 8081, , start off uri http://localhost:8081. pass gererateurl appended. use embedded server tests. if running actual server, on port 8080. suggest passing string base url instead, like:

webtarget target = client.target("http://localhost:8080/myapp/rest")         .path("messages").path("1234").path("comments").path("5678"); 

Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -