java - Jersey application - Error on start up -
i have jersey application fileupload. , during startup or when upload file in application, below errors in websphere trace logs.
error:
the registered message body writers compatible mime media type are: application/octet-stream -> com.sun.jersey.core.impl.provider.entity.bytearrayprovider com.sun.jersey.core.impl.provider.entity.fileprovider com.sun.jersey.core.impl.provider.entity.inputstreamprovider com.sun.jersey.core.impl.provider.entity.datasourceprovider com.sun.jersey.core.impl.provider.entity.streamingoutputprovider */* -> com.sun.jersey.core.impl.provider.entity.formprovider com.sun.jersey.core.impl.provider.entity.mimemultipartprovider com.sun.jersey.server.impl.template.viewablemessagebodywriter com.sun.jersey.core.impl.provider.entity.stringprovider com.sun.jersey.core.impl.provider.entity.bytearrayprovider com.sun.jersey.core.impl.provider.entity.fileprovider com.sun.jersey.core.impl.provider.entity.inputstreamprovider com.sun.jersey.core.impl.provider.entity.datasourceprovider com.sun.jersey.core.impl.provider.entity.xmljaxbelementprovider$general com.sun.jersey.core.impl.provider.entity.readerprovider com.sun.jersey.core.impl.provider.entity.documentprovider com.sun.jersey.core.impl.provider.entity.streamingoutputprovider com.sun.jersey.core.impl.provider.entity.sourceprovider$sourcewriter com.sun.jersey.core.impl.provider.entity.xmlrootelementprovider$general com.sun.jersey.core.impl.provider.entity.xmllistelementprovider$general [7/12/16 13:26:16:263 cest] 0000034e containerresp e mapped exception response: 500 (internal server error) javax.ws.rs.webapplicationexception: com.sun.jersey.api.messageexception: message body writer java class com.sun.proxy.$proxy553, , java type interface javax.servlet.http.httpservletresponse, , mime media type application/octet-stream not found. @ com.sun.jersey.spi.container.containerresponse.write(containerresponse.java:284) @ com.sun.jersey.server.impl.application.webapplicationimpl._handlerequest(webapplicationimpl.java:1510) @ com.sun.jersey.server.impl.application.webapplicationimpl.handlerequest(webapplicationimpl.java:1419) @ com.sun.jersey.server.impl.application.webapplicationimpl.handlerequest(webapplicationimpl.java:1409) @ com.sun.jersey.spi.container.servlet.webcomponent.service(webcomponent.java:409) @ com.sun.jersey.spi.container.servlet.servletcontainer.service(servletcontainer.java:558)
web.xml
<servlet> <servlet-name>my-service</servlet-name> <servlet-class>com.sun.jersey.spi.spring.container.servlet.springservlet</servlet-class> <init-param> <param-name>jersey.config.server.provider.packages</param-name> <param-value>my.app.service</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet>
pom.xml
<dependency> <groupid>com.sun.jersey</groupid> <artifactid>jersey-server</artifactid> <version>1.19</version> </dependency> <dependency> <groupid>com.sun.jersey.contribs</groupid> <artifactid>jersey-spring</artifactid> <version>1.19</version> <exclusions> <exclusion> <artifactid>spring-beans</artifactid> <groupid>org.springframework</groupid> </exclusion> <exclusion> <artifactid>spring-core</artifactid> <groupid>org.springframework</groupid> </exclusion> <exclusion> <artifactid>spring-web</artifactid> <groupid>org.springframework</groupid> </exclusion> <exclusion> <artifactid>spring-context</artifactid> <groupid>org.springframework</groupid> </exclusion> <exclusion> <artifactid>spring-aop</artifactid> <groupid>org.springframework</groupid> </exclusion> </exclusions> </dependency> <dependency> <groupid>com.sun.jersey.contribs</groupid> <artifactid>jersey-multipart</artifactid> <version>1.19</version> </dependency>
i not sure problem here? please help.
edit: 1
import com.fasterxml.jackson.databind.objectmapper; import com.sun.jersey.core.header.formdatacontentdisposition; @autowired private objectmapper objectmapper; @post @path("/upload") @consumes({mediatype.multipart_form_data}) public httpservletresponse attachdocument(@context httpservletrequest request, @context httpservletresponse response, @formdataparam("file") inputstream fileinputstream, @formdataparam("file") formdatacontentdisposition filedata) { string webserviceresponse = //call webservice here store document objectmapper.writevalue(response.getoutputstream(), webserviceresponse); }
you not want return httpservletresponse
jaxrs resource method. in case, that's error log says:
a message body writer java class com.sun.proxy.$proxy553, , java type interface javax.servlet.http.httpservletresponse
the interface javax.servlet.http.httpservletresponse
(injected @context
) implemented proxy class com.sun.proxy.$proxy553
. in jersey, there no messagebodywriter
(unless add one, not want do).
there bunch of messagebodywriters
in jersey default, named in jaxrs specification, section 4.2.4. wanted return javax.ws.rs.core.response
, such as:
return response.ok(entity).build();
Comments
Post a Comment