1

I use jersey in my project to implement RESTful service. After I type the url my browser displays only the characters 'GET'. I dont know where it is wrong.

Here is the web.xml:

<servlet>
  <servlet-name>Jersey REST Service</servlet-name>
<servlet-class>
  com.sun.jersey.spi.container.servlet.ServletContainer
</servlet-class>
  <init-param>
    <param-name>com.sun.jersey.config.property.packages</param-name>
    <param-value>com.bcom.restful.server.sequence</param-value>
  </init-param>
  <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
  <servlet-name>Jersey REST Service</servlet-name>
  <url-pattern>/restfulService/*</url-pattern>
</servlet-mapping>  

Here is the resource class:

@Path("/tenant/{tId}/seqContinue/{sName}")
@Produces(MediaType.APPLICATION_JSON)
public class SequenceContinueService {

    private ISequenceGenerator sequenceGenerator;

    @GET
    public Sequence getSequenceContinue(@PathParam("tId") String tenantId,
            @PathParam("sName") String seqName) {

        if (!hasParams()) {

            try {
                Sequence seq = new Sequence();
                  seq.setSeqenceStr(Convert
                        .toString(sequenceGenerator.nextSequence(seqName))) ;
                  return seq;
            } catch (ApplicationException e) {
                ResponseBuilder builder = Response
                        .status(Status.INTERNAL_SERVER_ERROR);
                builder.type("application/json");
                builder.entity(e.getMessage());
                throw new WebApplicationException(builder.build());

            }

        }
        return null;
    }

}

Browser just displays the characters 'GET' on the screen.

Daniel Szalay
  • 4,041
  • 12
  • 57
  • 103
Mr.Sky
  • 91
  • 6
  • What URL to you try in the browser? Can `Sequence` be formated as JSON? –  Feb 21 '14 at 07:52
  • Did you try to debug the service, to know at least that the right web service method is actually called? You could also extend your question with the environment details (API versions, application server). – Daniel Szalay Feb 21 '14 at 08:27

1 Answers1

0

If you want JSON support with Jersey 1.*, you have to add this init-param to your servlet configuration:

<init-param>
    <param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
    <param-value>true</param-value>
</init-param>

You might have to extend the following too, to get Jersey detect JSON provider classes:

<init-param>
    <param-name>com.sun.jersey.config.property.packages</param-name>
    <param-value>com.bcom.restful.server.sequence;org.codehaus.jackson.jaxrs</param-value>
</init-param>

Other material on the same topic:

Community
  • 1
  • 1
Daniel Szalay
  • 4,041
  • 12
  • 57
  • 103