MyEclipse: REST service tutorial results in MIME not found error

mongonv - Jun 21, 2012 - 01:40 AM
Post subject: REST service tutorial results in MIME not found error
I am trying to use the tutorial for creating a REST service in ME 8.6 and when I run the service and try to test it from the REST Web Services Explorer it always produces the following error:

Jun 20, 2012 5:30:26 PM com.sun.jersey.spi.container.ContainerResponse write
SEVERE: A message body writer for Java type, class com.myeclipseide.ws.Customer, and MIME media type, application/xml, was not found
Jun 20, 2012 5:30:26 PM com.sun.jersey.server.impl.application.WebApplicationImpl onException
SEVERE: Internal server error
javax.ws.rs.WebApplicationException
at com.sun.jersey.spi.container.ContainerResponse.write(ContainerResponse.java:241)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:724)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:647)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:638)
at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:309)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:425)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:590)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)

I have deleted and recreated the project multiple times, verifying that everything is the same as the tutorial entries and have not been able to get past this error.

Can anyone shed some light on what might be wrong?

Thanks
support-swapna - Jun 21, 2012 - 10:41 AM
Post subject:
mongonv,

Did you add the @XmlRootElement annotation to your Customer class?

For an explanation, please see Customer class code in section 4.1 in the REST tutorial :
http://www.myeclipseide.com/documentation/quickstarts/webservices_rest/

Let us know how it works for you.
mongonv - Jun 21, 2012 - 12:51 PM
Post subject:
I knew I had to be missing something and that was it.

Thanks much
mongonv - Jun 21, 2012 - 01:13 PM
Post subject:
Another related question, where can I find info on setting up JSON REST services?

Cause when I try to change the produces to application/json I get the same type of error and could not find any examples of what to change to produce or consume json rather than xml.

Thanks for any pointers.
support-swapna - Jun 22, 2012 - 05:44 AM
Post subject:
mongonv,

Glad that the issue is resolved.

Regarding setting up JSON, our tutorials will only give you an initial start with the MyEclipse. You will have to check the related development forums for development specific questions.

I suggest you cross post to webservices forums for this issue.

Hope it helps.
srmcatee - Sep 26, 2012 - 03:21 PM
Post subject: REST returning JSON in Myeclipse Not working
K.

I've tried all the demo's and everything else. I'm still getting the same error.

SEVERE: A message body writer for Java type, class java.util.ArrayList, and MIME media type, application/json, was not found

Code:

@Produces("application/json")
@XmlRootElement   
public class Nastytask  {
   
   private String name;
   private int id;
   
   public String getName(){
      return name;
         }
   
   public int  getId(){ return id;}
   
   public void setId(int id) { this.id=id; }
   
   public void setName(String name) { this.name = name; }
}

//In my resource class

List<Nastytask> nastytasks=new ArrayList<Nastytask>();

@GET 
    @Produces("application/json")
   public List<Nastytask> getNastytasks() throws Exception{
      
      Nastytask ni=new Nastytask();
      ni.setName("Item 1");
      
      nastytasks.add(ni);
      
      ni=new Nastytask();
      ni.setName("Item 2");
      
      nastytasks.add(ni);
      
      return nastytasks;
   }


srmcatee - Sep 26, 2012 - 03:23 PM
Post subject: Followup to prior post
application/xml works just fine.
support-swapna - Sep 27, 2012 - 05:53 AM
Post subject:
srmcatee,

Glad that you got it working.
Do let us know if you have any issues.
srmcatee - Oct 01, 2012 - 08:14 PM
Post subject: Didn't fix it.
application/xml works.

I'm trying to get application/json to work.
drgaryholland - Feb 11, 2013 - 02:05 PM
Post subject: JSON vs XML
I too noticed that XML is the flavor of choice in your tutorial.
XML appears from what I have been reading is being superceded with JSON among the industry. At lest you could have done was addressed his question , either answer you don't know or "here is a hint on how you would go about returning JSON" or even a link.



quote="support-swapna"]mongonv,

Glad that the issue is resolved.

Regarding setting up JSON, our tutorials will only give you an initial start with the MyEclipse. You will have to check the related development forums for development specific questions.

I suggest you cross post to webservices forums for this issue.

Hope it helps.[/quote]
All times are GMT - 6 Hours
Powered by PNphpBB2 © 2003-2004 The PNphpBB Group
Credits