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

MultipartRelatedOutput with StreamingOutput parts throws java.lang.ClassCastException: class org.jboss.resteasy.plugins.providers.StreamingOutputProvider cannot be cast to class org.jboss.resteasy.spi.AsyncMessageBodyWriter

    XMLWordPrintable

Details

    • Hide

      Deploy WAR with below Resource at Wildfly 25.0.1.Final (includes RESTEasy 4.7.2.Final):

      @RequestScoped
      @Path("multipart")
      public class MultipartTest {
      
          @GET
          @Path("/withBytes")
          public MultipartRelatedOutput withBytes() {
              MultipartRelatedOutput output = new MultipartRelatedOutput();
              output.addPart(new byte[]{ 'H', 'e', 'l', 'l', 'o'},
                      MediaType.TEXT_PLAIN_TYPE);
              return output;
          }
      
          @GET
          @Path("/withStreamingOutput")
          public MultipartRelatedOutput withStreamingOutput() {
              MultipartRelatedOutput output = new MultipartRelatedOutput();
              output.addPart(
                      (StreamingOutput) out -> out.write(new byte[]{ 'H', 'e', 'l', 'l', 'o'}),
                      MediaType.TEXT_PLAIN_TYPE);
              return output;
          }
      }
      
      $ curl -v http://localhost:8080/multipart/withBytes
      > GET /multipart/withBytes HTTP/1.1
      > Host: localhost:8080
      > User-Agent: curl/7.68.0
      > Accept: */*
      >
      < HTTP/1.1 200 OK
      < Connection: keep-alive
      < Content-Type: multipart/related;start="<87febb36-e39a-422e-ba45-b37979075a83@resteasy-multipart>";type="text/plain"; boundary=170cdeda-b788-4200-93da-58638fc87dd9
      < Content-Length: 186
      < Date: Fri, 17 Dec 2021 14:03:33 GMT
      <
      --170cdeda-b788-4200-93da-58638fc87dd9
      Content-ID: <87febb36-e39a-422e-ba45-b37979075a83@resteasy-multipart>
      Content-Type: text/plain
      
      Hello
      --170cdeda-b788-4200-93da-58638fc87dd9--
      
      $ curl -v http://localhost:8080/multipart/withStreamingOutput
      > GET /multipart/withStreamingOutput HTTP/1.1
      > Host: localhost:8080
      > User-Agent: curl/7.68.0
      > Accept: */*
              >
      < HTTP/1.1 500 Internal Server Error
      < Connection: keep-alive
      < Transfer-Encoding: chunked
      < Content-Type: text/html;charset=UTF-8
      < Date: Fri, 17 Dec 2021 13:59:41 GMT
      <
      <html><head><title>ERROR</title><style>
      body {
      ...
      Show
      Deploy WAR with below Resource at Wildfly 25.0.1.Final (includes RESTEasy 4.7.2.Final): @RequestScoped @Path( "multipart" ) public class MultipartTest { @GET @Path( "/withBytes" ) public MultipartRelatedOutput withBytes() { MultipartRelatedOutput output = new MultipartRelatedOutput(); output.addPart( new byte []{ 'H' , 'e' , 'l' , 'l' , 'o' }, MediaType.TEXT_PLAIN_TYPE); return output; } @GET @Path( "/withStreamingOutput" ) public MultipartRelatedOutput withStreamingOutput() { MultipartRelatedOutput output = new MultipartRelatedOutput(); output.addPart( (StreamingOutput) out -> out.write( new byte []{ 'H' , 'e' , 'l' , 'l' , 'o' }), MediaType.TEXT_PLAIN_TYPE); return output; } } $ curl -v http://localhost:8080/multipart/withBytes > GET /multipart/withBytes HTTP/1.1 > Host: localhost:8080 > User-Agent: curl/7.68.0 > Accept: */* > < HTTP/1.1 200 OK < Connection: keep-alive < Content-Type: multipart/related;start="<87febb36-e39a-422e-ba45-b37979075a83@resteasy-multipart>";type="text/plain"; boundary=170cdeda-b788-4200-93da-58638fc87dd9 < Content-Length: 186 < Date: Fri, 17 Dec 2021 14:03:33 GMT < --170cdeda-b788-4200-93da-58638fc87dd9 Content-ID: <87febb36-e39a-422e-ba45-b37979075a83@resteasy-multipart> Content-Type: text/plain Hello --170cdeda-b788-4200-93da-58638fc87dd9-- $ curl -v http://localhost:8080/multipart/withStreamingOutput > GET /multipart/withStreamingOutput HTTP/1.1 > Host: localhost:8080 > User-Agent: curl/7.68.0 > Accept: */* > < HTTP/1.1 500 Internal Server Error < Connection: keep-alive < Transfer-Encoding: chunked < Content-Type: text/html;charset=UTF-8 < Date: Fri, 17 Dec 2021 13:59:41 GMT < <html><head><title>ERROR</title><style> body { ...

    Description

      MultipartRelatedOutput with StreamingOutput parts throws

      org.jboss.resteasy.spi.UnhandledException: java.lang.ClassCastException: class org.jboss.resteasy.plugins.providers.StreamingOutputProvider cannot be cast to class org.jboss.resteasy.spi.AsyncMessageBodyWriter (org.jboss.resteasy.plugins.providers.StreamingOutputProvider is in unnamed module of loader 'org.jboss.resteasy.resteasy-core@4.7.2.Final' @41f69e84; org.jboss.resteasy.spi.AsyncMessageBodyWriter is in unnamed module of loader 'org.jboss.resteasy.resteasy-core-spi@4.7.2.Final' @45efd90f)
      	at org.jboss.resteasy.resteasy-core@4.7.2.Final//org.jboss.resteasy.core.ExceptionHandler.handleException(ExceptionHandler.java:381)
      	at org.jboss.resteasy.resteasy-core@4.7.2.Final//org.jboss.resteasy.core.SynchronousDispatcher.writeException(SynchronousDispatcher.java:218)
      	at org.jboss.resteasy.resteasy-core@4.7.2.Final//org.jboss.resteasy.core.SynchronousDispatcher.writeResponse(SynchronousDispatcher.java:614)
      	at org.jboss.resteasy.resteasy-core@4.7.2.Final//org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:524)
      	at org.jboss.resteasy.resteasy-core@4.7.2.Final//org.jboss.resteasy.core.SynchronousDispatcher.lambda$invoke$4(SynchronousDispatcher.java:261)
      	at org.jboss.resteasy.resteasy-core@4.7.2.Final//org.jboss.resteasy.core.SynchronousDispatcher.lambda$preprocess$0(SynchronousDispatcher.java:161)
      	at org.jboss.resteasy.resteasy-core@4.7.2.Final//org.jboss.resteasy.core.interception.jaxrs.PreMatchContainerRequestContext.filter(PreMatchContainerRequestContext.java:364)
      	at org.jboss.resteasy.resteasy-core@4.7.2.Final//org.jboss.resteasy.core.SynchronousDispatcher.preprocess(SynchronousDispatcher.java:164)
      	at org.jboss.resteasy.resteasy-core@4.7.2.Final//org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:247)
      	at org.jboss.resteasy.resteasy-core@4.7.2.Final//org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:249)
      	at org.jboss.resteasy.resteasy-core@4.7.2.Final//org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:60)
      	at org.jboss.resteasy.resteasy-core@4.7.2.Final//org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:55)
      	at javax.servlet.api@2.0.0.Final//javax.servlet.http.HttpServlet.service(HttpServlet.java:590)
      	at io.undertow.servlet@2.2.12.Final//io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:74)
      	at io.undertow.servlet@2.2.12.Final//io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:129)
      	at io.undertow.websocket@2.2.12.Final//io.undertow.websockets.jsr.JsrWebSocketFilter.doFilter(JsrWebSocketFilter.java:173)
      	at io.undertow.servlet@2.2.12.Final//io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
      	at io.undertow.servlet@2.2.12.Final//io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
      	at io.opentracing.contrib.opentracing-jaxrs2//io.opentracing.contrib.jaxrs2.server.SpanFinishingFilter.doFilter(SpanFinishingFilter.java:52)
      	at io.undertow.servlet@2.2.12.Final//io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
      	at io.undertow.servlet@2.2.12.Final//io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
      	at io.undertow.servlet@2.2.12.Final//io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84)
      	at io.undertow.servlet@2.2.12.Final//io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
      	at io.undertow.servlet@2.2.12.Final//io.undertow.servlet.handlers.ServletChain$1.handleRequest(ServletChain.java:68)
      	at io.undertow.servlet@2.2.12.Final//io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
      	at org.wildfly.security.elytron-web.undertow-server@1.10.0.Final//org.wildfly.elytron.web.undertow.server.ElytronRunAsHandler.lambda$handleRequest$1(ElytronRunAsHandler.java:68)
      	at org.wildfly.security.elytron-base@1.17.1.Final//org.wildfly.security.auth.server.FlexibleIdentityAssociation.runAsFunctionEx(FlexibleIdentityAssociation.java:103)
      	at org.wildfly.security.elytron-base@1.17.1.Final//org.wildfly.security.auth.server.Scoped.runAsFunctionEx(Scoped.java:161)
      	at org.wildfly.security.elytron-base@1.17.1.Final//org.wildfly.security.auth.server.Scoped.runAs(Scoped.java:73)
      	at org.wildfly.security.elytron-web.undertow-server@1.10.0.Final//org.wildfly.elytron.web.undertow.server.ElytronRunAsHandler.handleRequest(ElytronRunAsHandler.java:67)
      	at io.undertow.servlet@2.2.12.Final//io.undertow.servlet.handlers.RedirectDirHandler.handleRequest(RedirectDirHandler.java:68)
      	at io.undertow.servlet@2.2.12.Final//io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:117)
      	at io.undertow.servlet@2.2.12.Final//io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
      	at io.undertow.core@2.2.12.Final//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
      	at io.undertow.core@2.2.12.Final//io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
      	at io.undertow.servlet@2.2.12.Final//io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
      	at io.undertow.core@2.2.12.Final//io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
      	at org.wildfly.security.elytron-web.undertow-server-servlet@1.10.0.Final//org.wildfly.elytron.web.undertow.server.servlet.CleanUpHandler.handleRequest(CleanUpHandler.java:38)
      	at io.undertow.core@2.2.12.Final//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
      	at org.wildfly.extension.undertow@25.0.1.Final//org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
      	at io.undertow.core@2.2.12.Final//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
      	at org.wildfly.extension.undertow@25.0.1.Final//org.wildfly.extension.undertow.deployment.GlobalRequestControllerHandler.handleRequest(GlobalRequestControllerHandler.java:68)
      	at io.undertow.servlet@2.2.12.Final//io.undertow.servlet.handlers.SendErrorPageHandler.handleRequest(SendErrorPageHandler.java:52)
      	at io.undertow.core@2.2.12.Final//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
      	at io.undertow.servlet@2.2.12.Final//io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:280)
      	at io.undertow.servlet@2.2.12.Final//io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:79)
      	at io.undertow.servlet@2.2.12.Final//io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:134)
      	at io.undertow.servlet@2.2.12.Final//io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:131)
      	at io.undertow.servlet@2.2.12.Final//io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)
      	at io.undertow.servlet@2.2.12.Final//io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
      	at org.wildfly.extension.undertow@25.0.1.Final//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1544)
      	at org.wildfly.extension.undertow@25.0.1.Final//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1544)
      	at org.wildfly.extension.undertow@25.0.1.Final//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1544)
      	at org.wildfly.extension.undertow@25.0.1.Final//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1544)
      	at org.wildfly.extension.undertow@25.0.1.Final//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1544)
      	at io.undertow.servlet@2.2.12.Final//io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:260)
      	at io.undertow.servlet@2.2.12.Final//io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:79)
      	at io.undertow.servlet@2.2.12.Final//io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:100)
      	at io.undertow.core@2.2.12.Final//io.undertow.server.Connectors.executeRootHandler(Connectors.java:387)
      	at io.undertow.core@2.2.12.Final//io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:852)
      	at org.jboss.threads@2.4.0.Final//org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
      	at org.jboss.threads@2.4.0.Final//org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1990)
      	at org.jboss.threads@2.4.0.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1486)
      	at org.jboss.threads@2.4.0.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1377)
      	at org.jboss.xnio@3.8.4.Final//org.xnio.XnioWorker$WorkerThreadFactory$1$1.run(XnioWorker.java:1280)
      	at java.base/java.lang.Thread.run(Thread.java:829)
      Caused by: java.lang.ClassCastException: class org.jboss.resteasy.plugins.providers.StreamingOutputProvider cannot be cast to class org.jboss.resteasy.spi.AsyncMessageBodyWriter (org.jboss.resteasy.plugins.providers.StreamingOutputProvider is in unnamed module of loader 'org.jboss.resteasy.resteasy-core@4.7.2.Final' @41f69e84; org.jboss.resteasy.spi.AsyncMessageBodyWriter is in unnamed module of loader 'org.jboss.resteasy.resteasy-core-spi@4.7.2.Final' @45efd90f)
      	at org.jboss.resteasy.resteasy-multipart-provider@4.7.2.Final//org.jboss.resteasy.plugins.providers.multipart.AbstractMultipartWriter.asyncWritePart(AbstractMultipartWriter.java:118)
      	at org.jboss.resteasy.resteasy-multipart-provider@4.7.2.Final//org.jboss.resteasy.plugins.providers.multipart.AbstractMultipartWriter.lambda$asyncWriteParts$2(AbstractMultipartWriter.java:104)
      	at java.base/java.util.concurrent.CompletableFuture.uniComposeStage(CompletableFuture.java:1106)
      	at java.base/java.util.concurrent.CompletableFuture.thenCompose(CompletableFuture.java:2235)
      	at java.base/java.util.concurrent.CompletableFuture.thenCompose(CompletableFuture.java:143)
      	at org.jboss.resteasy.resteasy-multipart-provider@4.7.2.Final//org.jboss.resteasy.plugins.providers.multipart.AbstractMultipartWriter.asyncWriteParts(AbstractMultipartWriter.java:104)
      	at org.jboss.resteasy.resteasy-multipart-provider@4.7.2.Final//org.jboss.resteasy.plugins.providers.multipart.AbstractMultipartWriter.asyncWrite(AbstractMultipartWriter.java:93)
      	at org.jboss.resteasy.resteasy-multipart-provider@4.7.2.Final//org.jboss.resteasy.plugins.providers.multipart.AbstractMultipartRelatedWriter.asyncWriteRelated(AbstractMultipartRelatedWriter.java:71)
      	at org.jboss.resteasy.resteasy-multipart-provider@4.7.2.Final//org.jboss.resteasy.plugins.providers.multipart.MultipartRelatedWriter.asyncWriteTo(MultipartRelatedWriter.java:59)
      	at org.jboss.resteasy.resteasy-multipart-provider@4.7.2.Final//org.jboss.resteasy.plugins.providers.multipart.MultipartRelatedWriter.asyncWriteTo(MultipartRelatedWriter.java:26)
      	at org.jboss.resteasy.resteasy-core@4.7.2.Final//org.jboss.resteasy.core.interception.jaxrs.ServerWriterInterceptorContext.writeTo(ServerWriterInterceptorContext.java:87)
      	at org.jboss.resteasy.resteasy-core@4.7.2.Final//org.jboss.resteasy.core.interception.jaxrs.AbstractWriterInterceptorContext.asyncProceed(AbstractWriterInterceptorContext.java:203)
      	at org.jboss.resteasy.resteasy-crypto@4.7.2.Final//org.jboss.resteasy.security.doseta.DigitalSigningInterceptor.asyncAroundWriteTo(DigitalSigningInterceptor.java:169)
      	at org.jboss.resteasy.resteasy-core@4.7.2.Final//org.jboss.resteasy.core.interception.jaxrs.AbstractWriterInterceptorContext.asyncProceed(AbstractWriterInterceptorContext.java:211)
      	at org.jboss.resteasy.resteasy-core@4.7.2.Final//org.jboss.resteasy.core.interception.jaxrs.AbstractWriterInterceptorContext.getStarted(AbstractWriterInterceptorContext.java:166)
      	at org.jboss.resteasy.resteasy-core@4.7.2.Final//org.jboss.resteasy.core.interception.jaxrs.ServerWriterInterceptorContext.lambda$getStarted$0(ServerWriterInterceptorContext.java:73)
      	at org.jboss.resteasy.resteasy-core@4.7.2.Final//org.jboss.resteasy.core.interception.jaxrs.ServerWriterInterceptorContext.aroundWriteTo(ServerWriterInterceptorContext.java:93)
      	at org.jboss.resteasy.resteasy-core@4.7.2.Final//org.jboss.resteasy.core.interception.jaxrs.ServerWriterInterceptorContext.getStarted(ServerWriterInterceptorContext.java:73)
      	at org.jboss.resteasy.resteasy-core@4.7.2.Final//org.jboss.resteasy.core.ServerResponseWriter.lambda$writeNomapResponse$3(ServerResponseWriter.java:163)
      	at org.jboss.resteasy.resteasy-core@4.7.2.Final//org.jboss.resteasy.core.interception.jaxrs.ContainerResponseContextImpl.filter(ContainerResponseContextImpl.java:404)
      	at org.jboss.resteasy.resteasy-core@4.7.2.Final//org.jboss.resteasy.core.ServerResponseWriter.executeFilters(ServerResponseWriter.java:252)
      	at org.jboss.resteasy.resteasy-core@4.7.2.Final//org.jboss.resteasy.core.ServerResponseWriter.writeNomapResponse(ServerResponseWriter.java:101)
      	at org.jboss.resteasy.resteasy-core@4.7.2.Final//org.jboss.resteasy.core.ServerResponseWriter.writeNomapResponse(ServerResponseWriter.java:74)
      	at org.jboss.resteasy.resteasy-core@4.7.2.Final//org.jboss.resteasy.core.SynchronousDispatcher.writeResponse(SynchronousDispatcher.java:594)
      	... 63 more

      Attachments

        Issue Links

          Activity

            People

              jperkins-rhn James Perkins
              gunterze Gunter Zeilinger
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: