title: Getting REST Service data in my REST client
body: <p>Using NetBeans and GlassFish,
  I'm developing a simple standalone application that gets a list of <code>Tweet</code>'s from a REST service. Those objects contain, amongst others, a variable called <code>tweet</code>, wich is the String-value I'd like to see in the other application.</p>
  
  <p>I've built the website application and created a new class in this:</p>
  
  <p>RESTService.java:</p>
  
  <pre><code>package service;
  
  import domain.Tweet;
  import domain.User;
  import java.util.Collection;
  import java.util.Date;
  import javax.inject.Inject;
  import javax.ws.rs.*;
  import javax.ws.rs.core.MediaType;
  
  @Path("/rest")
  public class RESTService {
  
      @Inject
      KwetterService service;
  
      @GET
      @Path("/{user}")
      public User getUser(@PathParam("user") String userName)
      {
          return service.findByName(userName);
      }
  
      @GET
      @Path("/{user}/tweets")
      @Produces(MediaType.TEXT_XML)
      public Collection&lt;Tweet&gt; getTweets(@PathParam("user") String userName)
      {
          User user = service.findByName(userName);
          return user.getTweets();
      }
  }
  </code></pre>
  
  <p>In the standalone application, I've created a small form with a button. With a press on that button, I'd like to grab those tweets. </p>
  
  <p>When using NetBeans to add a REST client class, I linked it to the service of the website. It generated a class I called RestClient.java:</p>
  
  <pre><code>package service;
  
  import com.sun.jersey.api.client.Client;
  import com.sun.jersey.api.client.UniformInterfaceException;
  import com.sun.jersey.api.client.WebResource;
  
  public class RestClient {
      private WebResource webResource;
      private Client client;
  
      public RestClient() {
      }
  
      public &lt;T&gt; T getUser(Class&lt;T&gt; responseType, String user) throws UniformInterfaceException {
          WebResource resource = webResource;
          resource = resource.path(java.text.MessageFormat.format("{0}", new Object[]{user}));
          return resource.get(responseType);
      }
  
      public &lt;T&gt; T getTweets(Class&lt;T&gt; responseType, String user) throws UniformInterfaceException {
          WebResource resource = webResource;
          resource = resource.path(java.text.MessageFormat.format("{0}/tweets", new Object[]{user}));
          return resource.accept(javax.ws.rs.core.MediaType.TEXT_XML).get(responseType);
      }
  }
  </code></pre>
  
  <p>In the actionbutton performed method, I'm trying to use that class to gain tweets. When doing so, it asks for a <code>Class&lt;T&gt; responseType</code> next to the username on which it should get tweets on.</p>
  
  <p>The code of the form looks like this:</p>
  
  <pre><code>private void btnZoekFollowersActionPerformed(java.awt.event.ActionEvent evt) {                                              
          String userName = txtZoekTweets.getText(); //de naam van de user
          RestClient client = new RestClient();
          Collection&lt;Tweet&gt; tweets = client.getTweets(MediaType.TEXT_XML, userName);
          //What to insert for mediatype? Above gives an error since it requires Class&lt;T&gt; responseType
          System.out.println("Datasize: " + data.size());
  }
  </code></pre>
  
  <p>So, in short, my question is as follows: I need to insert a <code>Class&lt;T&gt; responseType</code> as parameter, why? And what should I use as parameter or, better, how can I avoid having to do this and instead only insert the username as parameter? </p>
  
  <p>And next to this, do I need to type code myself somewhere where I specify which URL to approach? Or is this all set and working through generating the client-class?</p>