MyEclipse Forums
This thread has been locked & this forum has been archived.
Please post new topics to Java EE Development (EJB, JSP, Struts, XDoclet, etc.)
View previous topic Printable version Log in to check your private messages View next topic
Author Message
mongonv
Post subject: REST service tutorial results in MIME not found error  PostPosted: Jun 21, 2012 - 01:40 AM
Registered Member
Registered Member


Joined: Nov 12, 2008
Posts: 76

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
 
 View user's profile Send private message  
Reply with quote Back to top
support-swapna
Post subject:   PostPosted: Jun 21, 2012 - 10:41 AM



Joined: Nov 11, 2010
Posts: 2491

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.

_________________
Swapna
MyEclipse Support
 
 View user's profile Send private message  
Reply with quote Back to top
mongonv
Post subject:   PostPosted: Jun 21, 2012 - 12:51 PM
Registered Member
Registered Member


Joined: Nov 12, 2008
Posts: 76

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

Thanks much
 
 View user's profile Send private message  
Reply with quote Back to top
mongonv
Post subject:   PostPosted: Jun 21, 2012 - 01:13 PM
Registered Member
Registered Member


Joined: Nov 12, 2008
Posts: 76

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.
 
 View user's profile Send private message  
Reply with quote Back to top
support-swapna
Post subject:   PostPosted: Jun 22, 2012 - 05:44 AM



Joined: Nov 11, 2010
Posts: 2491

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.

_________________
Swapna
MyEclipse Support
 
 View user's profile Send private message  
Reply with quote Back to top
srmcatee
Post subject: REST returning JSON in Myeclipse Not working  PostPosted: Sep 26, 2012 - 03:21 PM
Registered Member
Registered Member


Joined: Aug 18, 2012
Posts: 3

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;
   }

 
 View user's profile Send private message  
Reply with quote Back to top
srmcatee
Post subject: Followup to prior post  PostPosted: Sep 26, 2012 - 03:23 PM
Registered Member
Registered Member


Joined: Aug 18, 2012
Posts: 3

application/xml works just fine.
 
 View user's profile Send private message  
Reply with quote Back to top
support-swapna
Post subject:   PostPosted: Sep 27, 2012 - 05:53 AM



Joined: Nov 11, 2010
Posts: 2491

srmcatee,

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

_________________
Swapna
MyEclipse Support
 
 View user's profile Send private message  
Reply with quote Back to top
srmcatee
Post subject: Didn't fix it.  PostPosted: Oct 01, 2012 - 08:14 PM
Registered Member
Registered Member


Joined: Aug 18, 2012
Posts: 3

application/xml works.

I'm trying to get application/json to work.
 
 View user's profile Send private message  
Reply with quote Back to top
drgaryholland
Post subject: JSON vs XML  PostPosted: Feb 11, 2013 - 02:05 PM
Registered Member
Registered Member


Joined: Jun 18, 2012
Posts: 6

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]
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT - 6 Hours
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2004 The PNphpBB Group
Credits