1

I can't seem to connect and I dont know what is wrong here. I am debugging and all I get is a 404. My class ApiServer is in this directory A.B.C.api.users

<servlet>
    <servlet-name>Jersey REST Service</servlet-name>
    <servlet-class>
        org.glassfish.jersey.servlet.ServletContainer
    </servlet-class>
    <init-param>
        <param-name>com.sun.jersey.config.property.packages</param-name>
        <param-value>A.B.C.api</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>Jersey REST Service</servlet-name>
    <url-pattern>/users/*</url-pattern>
</servlet-mapping>

.........

@Path("/test")
    public class ApiServer {

        @GET
        @Path("/")
        public Response putContainer() {


            System.out.println("Hellooo");

..........

curl -v 192.168.92.128:8080/users/

....

Apr 25, 2014 10:26:19 AM org.glassfish.jersey.server.ApplicationHandler initialize
INFO: Initiating Jersey application, version Jersey: 2.7 2014-03-12 18:11:31...

There is nothing after this, does it mean that its not initialized completly? And How can I debug Jax-rs ?

mike628
  • 45,873
  • 18
  • 40
  • 57
  • Ive changed it to make it simpler , but still nothing – mike628 Apr 25 '14 at 14:31
  • Were you able to get help on this? If you were id love to see the answer if you want to answer your own question. If not I would be happy to help pair on the issue. – AnthonyJClink May 01 '14 at 17:13

2 Answers2

2

You do not seem to have the @Produces annotation on your method

@Produces(MediaType.APPLICATION_JSON)

Without @Produces, the default mimetype returned is "text/html"

Shiraaz.M
  • 3,073
  • 2
  • 24
  • 40
  • I'm just trying to get the breakpoint in my IntelliJ to get hit. I think that would happen even without the @Produces – mike628 Apr 24 '14 at 22:15
  • @mike628 Though hes right about the produces annotation... where do you define the /users/? did you intend your method to be @path(test) @Path(/users/) public Response (you don't have to do a response you can just return a java object) putContainer. seems your url may be wrong – AnthonyJClink Apr 24 '14 at 22:54
  • Oh never mind, just saw your pattern url. Let me write up this example and see if I can find the issue... but before I do, could you try 127.0.0.1 for your url instead of your internal ip? – AnthonyJClink Apr 24 '14 at 22:55
  • @Mike628 another quick look, and I noticed that you are passing content type to your server, but you don't have a method that accepts application/json. Try taking out the header – AnthonyJClink Apr 24 '14 at 22:57
  • @Mike628 is it possible to show more of the web.xml? I tried on my own with an existing project, and it seems to work how you expect. – AnthonyJClink Apr 24 '14 at 23:08
1

If you are deploying a WAR (or EAR) on Glassfish, the URL is going to contain the web application context before your REST path... If your WAR is named myapp.war, the URL would likely be:

http://somehost:8080/myapp/users/
djmorton
  • 616
  • 4
  • 6
  • I think I need to get rid of Glassfish...This is a JSF program with an API embedded in it.I dont think this is going to work. – mike628 Apr 25 '14 at 18:37
  • Automatically prefixing the application url with the application context is pretty standard behavior across all Application Servers, it's not a property unique to Glassfish. JBoss, for example, would do exactly the same thing. You can modify (or remove) the context root an application deploys under if you really need to. See http://stackoverflow.com/questions/16216323/using-the-context-root-from-glassfish-web-xml-in-glassfish-3 for details. – djmorton Apr 26 '14 at 21:13
  • If you are free to choose some technologies on this project, this was very helpful to me @mike628 http://blog.palominolabs.com/2011/08/15/a-simple-java-web-stack-with-guice-jetty-jersey-and-jackson/ – AnthonyJClink Apr 28 '14 at 21:40