0

I am trying to use Firefox poster to test a Jersey restful webservice running on Glassfish 4.0. I am getting a HTTP Server 500 error returned to the Poster output when I return a java class as xml. I do not get an error when I return a String as xml. This makes me wonder if I need to include any of the JAX-RS jars or Jersey jars in my ear on Glassfish. I was thinking these were included in the Glassfish modules so I am not including them in my WEB-INF lib.

Here is an example of what works, returns xml to firefox poster:

 @GET
@Produces( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, "application/x-javascript", MediaType.APPLICATION_OCTET_STREAM } )
@Path( "/getTest/" )
public String getXml()
{
    return "<?xml version=\"1.0\"?>" + "<hello> Hello Jersey" + "</hello>";

}

Here is an example of what throws the Internal server error 500:

 @GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path( "/getTodo/" )
public Todo getXML() {
  Todo todo = new Todo();
  todo.setSummary("This is my first todo");
  todo.setDescription("This is my first todo");
  return todo;
}

 @XmlRootElement
 // JAX-RS supports an automatic mapping from JAXB annotated class to XML and JSON    
 // Isn't that cool?
 public class Todo {
   private String summary;
   private String description;
   public String getSummary() {
     return summary;
   }
   public void setSummary(String summary) {
     this.summary = summary;
   }
   public String getDescription() {
     return description;
    }
   public void setDescription(String description) {
     this.description = description;
   }
}

FYI - I am loosely following the blog here - restBlog

spartikus
  • 2,852
  • 4
  • 33
  • 38
  • I have truned up the loggin in my glassfish and found that I am getting a couple log messages but they are not errors. Trying to locate com/myPath/web/rest/jaxb.properties – spartikus Jul 11 '13 at 23:59
  • Ok the answer here had to do with packaging of the TODO class. I was including this class an an inner class. The inner class lived in the class that was defined as the context class. When I moved the TODO class into an entity folder in the ejb.jar it started to work. Hopefully this helps someone else in the future. You do not need the jersey jars so I am marking that answer as correct, sorry for the red herring. – spartikus Jul 15 '13 at 20:47

1 Answers1

0

You definitely don't need to include any of the standard jersey files in your war or ear file for them to be accessible at runtime. I've certainly had exactly the kind of thing you're doing working fine, either using maven or native netbeans 7.3.1 projects.

I suggest you look at the glassfish server.log file to see precisely what the detailed error you are getting is. If you are missing needed jars, that should tell you.

bilkusg
  • 126
  • 1
  • 7
  • Thanks for the help. I have checked the glassfish server.log and there is no activity there. The error in firefox poster comes back with this response in xml format- HTTP Status 500 - Internal Server Error. The server encountered an internal error that prevented it from fulfilling this request. – spartikus Jul 11 '13 at 18:14
  • What happens if you just open a browser window to the URL? I just recreated your project in NetBeans 7.3.1, and was able to deploy it and open a Firefox window to the resource URL and display the correct XML. – Ian Evans Jul 11 '13 at 20:02
  • @IanEvens when I hit this from the web browser I get the same 500 error. – spartikus Jul 11 '13 at 23:57
  • Here's my [recreated project that works with GlassFish 4/NetBeans 7.3.1](https://docs.google.com/file/d/0B1-Md939r5NeVDdlcnBCLWktd28/edit?usp=sharing). – Ian Evans Jul 12 '13 at 17:17
  • @IanEvans This link did not work for me but I was able to figure out my problem. Please see above thanks for your help – spartikus Jul 15 '13 at 20:46