- This topic has 9 replies, 4 voices, and was last updated 11 years, 7 months ago by
Gary Holland.
-
AuthorPosts
-
mongonvParticipantI 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-swapnaModeratormongonv,
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.
mongonvParticipantI knew I had to be missing something and that was it.
Thanks much
mongonvParticipantAnother 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-swapnaModeratormongonv,
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.
srmcateeMemberK.
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; }
srmcateeMemberapplication/xml works just fine.
support-swapnaModeratorsrmcatee,
Glad that you got it working.
Do let us know if you have any issues.
srmcateeMemberapplication/xml works.
I’m trying to get application/json to work.
Gary HollandMemberI 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]
-
AuthorPosts