I am using Jersey version 1.12 and i am facing the error that is
A message body writer for Java class java.lang.Boolean, and Java type boolean, and MIME media type application/octet-stream was not found
at com.sun.jersey.spi.container.ContainerResponse.write(ContainerResponse.java:285)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1451)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1363)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1353)
at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:414)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:708)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
my code is
@POST
@Path("/save/{Name}/{data}")
@Consumes("application/x-www-form-urlencoded")
public String saveDataMap(@QueryParam("number") String number,
@PathParam("data") String data,
@PathParam("Name") String appName
MultivaluedMap<String, String> formParam) throws Exception{
boolean response =false'
try{
// some business logic
response =true
}
return response;
}
After Googling this error i found that this is due to you are not specifying the content type of the data you are sending - so Jersey is not able to locate the right MessageBodyWritter to serialize
after this i added produces anotation to the method with the MediaType.TEXT_PLAIN
but it doesn't work ,but when i changed return type of method to String
it started working.
I simply wants to know whats problem with boolean ,why it is not working with boolean ? and how to solve this problem without changing boolean to String ?
any help will be greatly appreciated.
I usually code these methods like this:
@POST
@Path("/save/{Name}/{data}")
@Consumes("application/x-www-form-urlencoded")
@Produces(MediaType.TEXT_PLAIN)
public Response saveDataMap(@QueryParam("number") String number,
@PathParam("data") String data,
@PathParam("Name") String appName
MultivaluedMap<String, String> formParam) throws Exception{
boolean response =false
try{
// some business logic
response =true
}
return Response.ok().entity(String.valueOf(response)).build();
}
The only changes is that it returns a jersey HTTP response building it from a string from a boolean.
I hope it helps.
Regards, Cris.