facebook

REST service tutorial results in MIME not found error

  1. MyEclipse Archived
  2.  > 
  3. Web Services
Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #327386 Reply

    mongonv
    Participant

    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

    #327397 Reply

    support-swapna
    Moderator

    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.

    #327407 Reply

    mongonv
    Participant

    I knew I had to be missing something and that was it.

    Thanks much

    #327409 Reply

    mongonv
    Participant

    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.

    #327448 Reply

    support-swapna
    Moderator

    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.

    #330513 Reply

    srmcatee
    Member

    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

    
    @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;
        }
    
    
    #330515 Reply

    srmcatee
    Member

    application/xml works just fine.

    #330541 Reply

    support-swapna
    Moderator

    srmcatee,

    Glad that you got it working.
    Do let us know if you have any issues.

    #330675 Reply

    srmcatee
    Member

    application/xml works.

    I’m trying to get application/json to work.

    #335264 Reply

    Gary Holland
    Member

    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]

Viewing 10 posts - 1 through 10 (of 10 total)
Reply To: REST service tutorial results in MIME not found error

You must be logged in to post in the forum log in