Uploaded image for project: 'RESTEasy'
  1. RESTEasy
  2. RESTEASY-700

IOException when converting octet-stream to application/json format

XMLWordPrintable

    • Hide

      1. Implement a RESTful web service
      2. Define a transfer object class that contains a property of type javax.activation.DataHandler that is annotated by @XmlMimeType("application/octet-stream")
      3. Define an operation in the RESTful service that has the defined above transfer object as return type
      4. Invoke the operation via HTTP and include the "accept: application/json" HTTP header

      Show
      1. Implement a RESTful web service 2. Define a transfer object class that contains a property of type javax.activation.DataHandler that is annotated by @XmlMimeType("application/octet-stream") 3. Define an operation in the RESTful service that has the defined above transfer object as return type 4. Invoke the operation via HTTP and include the "accept: application/json" HTTP header

      RestEasy is unable to convert a transfer object DataHandler property (annotated by @XmlMimeType("application/octet-stream")) into the appropriate JSON format. It is, however, able to convert it into XML format without any problems.

      Sample transfer object class:

      import javax.activation.DataHandler;
      import javax.xml.bind.annotation.XmlAccessType;
      import javax.xml.bind.annotation.XmlAccessorType;
      import javax.xml.bind.annotation.XmlElement;
      import javax.xml.bind.annotation.XmlMimeType;
      import javax.xml.bind.annotation.XmlType;

      @XmlAccessorType(XmlAccessType.FIELD)
      @XmlType(name = "DriverTO", propOrder = {
      "name",
      "metadata"
      })
      public class DriverTO {

      .....

      @XmlElement(required = true)

      protected String name;

      @XmlMimeType("application/octet-stream")

      protected DataHandler metadata;

      .....
      }

      Sample RESTful operation:

      @GET
      @Path("/opePortfolios/

      {portfolioId:[0-9]+}

      /drivers/

      {driverId:[0-9]+}

      ")
      @Produces(

      {MediaType.TEXT_XML, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}

      )
      public DriverTO getDriver(
      @PathParam("portfolioId") Long portfolioId,
      @PathParam("driverId") Long driverId) throws Exception

      { //retrieve driver and convert to transfer object DriverTO driver = ..... return driver; }

      Exception stacktrace:

      12:02:53,387 SEVERE [org.jboss.resteasy.core.SynchronousDispatcher] (http--127.0.0.1-8080-1) Failed executing GET /opePortfolioWS/opePortfolios/1/drivers/2: org.jboss.resteasy.spi.WriterException:
      java.io.IOException: cannot do this
      at org.jboss.resteasy.core.ServerResponse.writeTo(ServerResponse.java:262) [resteasy-jaxrs-2.3.1.GA.jar:]
      at org.jboss.resteasy.core.SynchronousDispatcher.writeJaxrsResponse(SynchronousDispatcher.java:585) [resteasy-jaxrs-2.3.1.GA.jar:]
      at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:506) [resteasy-jaxrs-2.3.1.GA.jar:]
      at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:119) [resteasy-jaxrs-2.3.1.GA.jar:]
      at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:208) [resteasy-jaxrs-2.3.1.GA.jar:]
      at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:55) [resteasy-jaxrs-2.3.1.GA.jar:]
      at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:50) [resteasy-jaxrs-2.3.1.GA.jar:]
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.10.Final.jar:]
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.10.Final.jar:]
      at org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:62) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.10.Final.jar:]
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.10.Final.jar:]
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.10.Final.jar:]
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.10.Final.jar:]
      at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.1.0.Final.jar:7.1.0.Final]
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:489) [jbossweb-7.0.10.Final.jar:]
      at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:154) [jboss-as-web-7.1.0.Final.jar:7.1.0.Final]
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.10.Final.jar:]
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.10.Final.jar:]
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.10.Final.jar:]
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.10.Final.jar:]
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.10.Final.jar:]
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.10.Final.jar:]
      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.10.Final.jar:]
      at java.lang.Thread.run(Thread.java:662) [rt.jar:1.6.0_27]
      Caused by: java.io.IOException: cannot do this
      at javax.mail.util.ByteArrayDataSource.getOutputStream(ByteArrayDataSource.java:169) [mail-1.4.4.jar:1.4.4]
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.6.0_27]
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [rt.jar:1.6.0_27]
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [rt.jar:1.6.0_27]
      at java.lang.reflect.Method.invoke(Method.java:597) [rt.jar:1.6.0_27]
      at org.codehaus.jackson.map.ser.BeanPropertyWriter.get(BeanPropertyWriter.java:483)
      at org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:418)
      at org.codehaus.jackson.map.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:150)
      at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:112)
      at org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:446)
      at org.codehaus.jackson.map.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:150)
      at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:112)
      at org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:446)
      at org.codehaus.jackson.map.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:150)
      at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:112)
      at org.codehaus.jackson.map.ser.StdSerializerProvider._serializeValue(StdSerializerProvider.java:610)
      at org.codehaus.jackson.map.ser.StdSerializerProvider.serializeValue(StdSerializerProvider.java:256)
      at org.codehaus.jackson.map.ObjectMapper.writeValue(ObjectMapper.java:1604)
      at org.codehaus.jackson.jaxrs.JacksonJsonProvider.writeTo(JacksonJsonProvider.java:558)
      at org.jboss.resteasy.core.interception.MessageBodyWriterContextImpl.proceed(MessageBodyWriterContextImpl.java:117) [resteasy-jaxrs-2.3.1.GA.jar:]
      at org.jboss.resteasy.plugins.interceptors.encoding.GZIPEncodingInterceptor.write(GZIPEncodingInterceptor.java:98) [resteasy-jaxrs-2.3.1.GA.jar:]
      at org.jboss.resteasy.core.interception.MessageBodyWriterContextImpl.proceed(MessageBodyWriterContextImpl.java:123) [resteasy-jaxrs-2.3.1.GA.jar:]
      at org.jboss.resteasy.core.ServerResponse.writeTo(ServerResponse.java:250) [resteasy-jaxrs-2.3.1.GA.jar:]
      ... 25 more

              patriot1burke@gmail.com Bill Burke (Inactive)
              softlinqs Krasimir Georgiev (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved: