title: REST Webservice - Sample Code - Gives HTTP 302 response
body: <p>I am just trying REST webservice; Standard Sample; 
  While I am able to create the war and load it into WSO2 AS, when I try to connect it with client I get a response of HTTP 302; I was wondering where the mistake could be; 
  Following are my file listings.</p>
  
  <pre><code>package com.indu.rs.test;
  
  import javax.ws.rs.GET;
  import javax.ws.rs.Path;
  import javax.ws.rs.Produces;
  import javax.ws.rs.core.MediaType;
  
  // POJO, no interface no extends
  
  // The class registers its methods for the HTTP GET request using the @GET annotation. 
  // Using the @Produces annotation, it defines that it can deliver several MIME types,
  // text, XML and HTML. 
  
  // The browser requests per default the HTML MIME type.
  
  //Sets the path to base URL + /hello
  @Path("/hello")
  public class Hello {
  
      // This method is called if TEXT_PLAIN is request
      @GET
      @Produces(MediaType.TEXT_PLAIN)
      public String sayPlainTextHello() {
          return "Hello Jersey";
      }
  
      // This method is called if XML is request
      @GET
      @Produces(MediaType.TEXT_XML)
      public String sayXMLHello() {
          return "&lt;?xml version=\"1.0\"?&gt;" + "&lt;hello&gt; Hello Jersey" + "&lt;/hello&gt;";
      }
  
      // This method is called if HTML is request
      @GET
      @Produces(MediaType.TEXT_HTML)
      public String sayHtmlHello() {
          return "&lt;html&gt; " + "&lt;title&gt;" + "Hello Jersey" + "&lt;/title&gt;"
                  + "&lt;body&gt;&lt;h1&gt;" + "Hello Jersey" + "&lt;/h1&gt;&lt;/body&gt;" + "&lt;/html&gt; ";
      }
  
  } // class
  </code></pre>
  
  <p><strong>web.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
              xmlns="http://java.sun.com/xml/ns/javaee" 
              xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
              xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
              id="WebApp_ID" version="2.5"&gt;
  
    &lt;display-name&gt;com.indu.rs.test&lt;/display-name&gt;
  
    &lt;servlet&gt;
      &lt;servlet-name&gt;Jersey1&lt;/servlet-name&gt;
      &lt;servlet-class&gt;com.sun.jersey.spi.container.servlet.ServletContainer&lt;/servlet-class&gt;
      &lt;init-param&gt;
        &lt;param-name&gt;com.sun.jersey.config.property.packages&lt;/param-name&gt;
        &lt;param-value&gt;com.indu.rs.test&lt;/param-value&gt;
      &lt;/init-param&gt;
      &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
    &lt;/servlet&gt;
  
    &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;Jersey1&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/rest&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p><strong>client</strong></p>
  
  <pre><code>package com.indu.rs.test.client;
  
  import java.net.URI;
  
  import javax.ws.rs.core.MediaType;
  import javax.ws.rs.core.UriBuilder;
  
  import com.sun.jersey.api.client.Client;
  import com.sun.jersey.api.client.ClientResponse;
  import com.sun.jersey.api.client.WebResource;
  import com.sun.jersey.api.client.config.ClientConfig;
  import com.sun.jersey.api.client.config.DefaultClientConfig;
  
  public class RsTest {
      public static void main(String[] args) {
          ClientConfig config = new DefaultClientConfig();
          Client client = Client.create(config);
          WebResource service = client.resource(getBaseURI());
  
          // Fluent interfaces
          System.out.println(service.path("rest").path("hello").accept(
                  MediaType.TEXT_PLAIN).get(ClientResponse.class).toString());
  
          // Get plain text
          System.out.println(service.path("rest").path("hello").accept(
                  MediaType.TEXT_PLAIN).get(String.class));
  
          // Get XML
          System.out.println(service.path("rest").path("hello").accept(
                  MediaType.TEXT_XML).get(String.class));
  
          // The HTML
          System.out.println(service.path("rest").path("hello").accept(
                  MediaType.TEXT_HTML).get(String.class));
  
  
      }
  
      private static URI getBaseURI() {
          return UriBuilder.fromUri(
                  "http://localhost:9100/com.indu.rs.test").build();
      }
  
  }
  </code></pre>