Note that there are some explanatory texts on larger screens.

plurals
  1. PORetrieve a list of entities from a Restfull service (inside client app)
    text
    copied!<p>Im new to Rest web services and say Ive created this web service using Netbeans</p> <pre><code>@Path("browse") @Stateless public class ArticleBrowseResource { @EJB private ArticleSearcherLocal ejbRef; @GET @Produces(MediaType.APPLICATION_XML) public List&lt;Article&gt; browse(@DefaultValue("") @QueryParam("username") String username,@QueryParam("sd") String sd) { // convert sd string to date List&lt;Article&gt; articles = ejbRef.search(username, date); return articles; } } </code></pre> <p>where <code>Article</code> is an entity which is anotated with <code>@XmlRootElement</code></p> <p>Now how am I supossed to retreive this list of articles in my <strong>client</strong> which for simplicity lets just say it is a java standard application? In SOAP web services I know that these objects are automatically generated but not in Rest.</p> <p>This is the client class generated for this service by Netbeans</p> <pre><code>public class ArticleBrowseClient { private WebResource webResource; private Client client; private static final String BASE_URI = "http://localhost:8080/cityblog/rest"; public ArticleBrowseClient() { com.sun.jersey.api.client.config.ClientConfig config = new com.sun.jersey.api.client.config.DefaultClientConfig(); client = Client.create(config); webResource = client.resource(BASE_URI).path("browse"); } public &lt;T&gt; T browse(Class&lt;T&gt; responseType, String username, String sd) throws UniformInterfaceException { WebResource resource = webResource; if (username != null) { resource = resource.queryParam("username", username); } if (sd != null) { resource = resource.queryParam("sd", sd); } return resource.accept(javax.ws.rs.core.MediaType.APPLICATION_XML).get(responseType); } public void close() { client.destroy(); } } </code></pre> <p>What is the best and simplest way to resolve this issue?</p> <p>Any help is appreciated and thx in advance</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload