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

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top