From: Gregor J. <gr...@ja...> - 2013-06-21 15:51:46
|
I am just routing it through without reading the Entity explicitly. Remote { @GET Response getInputStream(){ return Response.ok(<InputStream>).type(<MediaType>).build(); } } Proxy { @GET Response getInputStream() { //create client api instance ... return remote.getInputStream(); } } ----- Original Message ----- From: "Bill Burke" <bb...@re...> To: "Gregor Jarisch" <gr...@ja...> Cc: res...@li... Sent: Friday, June 21, 2013 5:43:57 PM Subject: Re: [Resteasy-developers] Unable to fetch StreamingOutput via Client Api How are you using the response? InputStream is = response.readEntity(InputStream.class); On 6/21/2013 10:56 AM, Gregor Jarisch wrote: > I have changed my return type to InputStream to make it work for the moment. > > I have encountered something else that could be consider as a bug or of course an enhancement for a future version: > If the return type is explicitly set to InputStream it works as you said - the stream won't get closed. > If the return type is wrapped in a Response though and an InputStream is set as its Entity it doesn't work (Stream gets closed). > > Would be also nice if this would work in a future release.. > > ----- Original Message ----- > From: "Bill Burke" <bb...@re...> > To: "Gregor Jarisch" <gr...@ja...> > Cc: res...@li... > Sent: Thursday, June 20, 2013 7:00:54 PM > Subject: Re: [Resteasy-developers] Unable to fetch StreamingOutput via Client Api > > StreamingOutput is a server-side callback interface implemented by the > application. But, Yeah, you're right, apologies. I guess the framework > could implement this and you pass in your output stream or let the > runtime do the callback as you've shown. > > You can't just plug in a MessageBodyReader for StreamingOutput because > Response.readEntity() closes the InputStream automatically if the return > type isn't a InputSTream or Reader. > > Log a jira and we can get it implemented sometime. > > On 6/20/2013 11:35 AM, Gregor Jarisch wrote: >> Although this might appear to you like a stupid question, it is not meant to waste anyone's time - so why are you bother answering if you don't include any helpful information? >> I might misuse the concept of OutputStream here - if so, I'd be happy to learn more about it. >> >> IMO, fetching a stream from one resource and routing it through to serve another one is a legitimate use case. >> >> ----- Original Message ----- >> From: "Bill Burke" <bb...@re...> >> To: res...@li... >> Sent: Thursday, June 20, 2013 4:10:09 PM >> Subject: Re: [Resteasy-developers] Unable to fetch StreamingOutput via Client Api >> >> Of course you can't obtain a StreamingOutput from the client api.... >> >> On 6/20/2013 7:14 AM, Gregor Jarisch wrote: >>> Hi, >>> >>> I have to proxy a request from one Jax-RS resource to another (secured) one. >>> >>> RestInterface { >>> >>> @GET >>> @Path("/{id}") >>> @Produces({"image/jpeg"}) >>> public StreamingOutput getImage(@PathParam("id") String id); >>> >>> } >>> >>> RestProxyInterface { >>> >>> @GET >>> @Path("/{id}") >>> @Produces({"image/jpeg"}) >>> public StreamingOutput getImage(@PathParam("id") String id){ >>> // create client proxy ... --> remoteRestInterface >>> StreamingOutput image = remoteRestInterface.getImage(id); >>> return image; >>> } >>> } >>> >>> Client api causes following exception: >>> Caused by: javax.ws.rs.ProcessingException: Unable to find a MessageBodyReader of content-type image/jpeg and type interface javax.ws.rs.core.StreamingOutput >>> at org.jboss.resteasy.core.interception.ClientReaderInterceptorContext.throwReaderNotFound(ClientReaderInterceptorContext.java:39) >>> at org.jboss.resteasy.core.interception.AbstractReaderInterceptorContext.getReader(AbstractReaderInterceptorContext.java:73) >>> at org.jboss.resteasy.core.interception.AbstractReaderInterceptorContext.proceed(AbstractReaderInterceptorContext.java:50) >>> at org.jboss.resteasy.plugins.interceptors.encoding.GZIPDecodingInterceptor.aroundReadFrom(GZIPDecodingInterceptor.java:59) >>> at org.jboss.resteasy.core.interception.AbstractReaderInterceptorContext.proceed(AbstractReaderInterceptorContext.java:53) >>> at org.jboss.resteasy.client.jaxrs.internal.ClientResponse.readFrom(ClientResponse.java:244) >>> at org.jboss.resteasy.client.jaxrs.internal.ClientResponse.readEntity(ClientResponse.java:178) >>> at org.jboss.resteasy.specimpl.BuiltResponse.readEntity(BuiltResponse.java:211) >>> at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.extractResult(ClientInvocation.java:104) >>> ... 35 more >>> >>> So, obviously there is no reader for StreamingOutput. >>> Creating on: >>> >>> @Provider >>> @Consumes("image/jpeg") >>> public class StreamingOutputReader implements MessageBodyReader<StreamingOutput> { >>> @Override >>> public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) { >>> return StreamingOutput.class.isAssignableFrom(type); >>> } >>> >>> @Override >>> public StreamingOutput readFrom(Class<StreamingOutput> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, final InputStream entityStream) throws IOException, WebApplicationException { >>> return new StreamingOutput() { >>> @Override >>> public void write(OutputStream output) throws IOException, WebApplicationException { >>> byte[] buffer = new byte[1024]; >>> int bytesRead; >>> while ((bytesRead = entityStream.read(buffer)) != -1) { >>> output.write(buffer, 0, bytesRead); >>> } >>> } >>> }; >>> } >>> } >>> >>> Unfortunately I cannot get it to be invoked by the Client Api. Scanning providers is on and according to the logs it is recognized by resteasy.. Debugging through the code, indeed the providerFactory of ClientReaderInterceptorContext doesn't have my StreamingOutputReader... >>> >>> What am I doing wrong here? >>> >>> Thanks, >>> >>> Gregor >>> >>> >>> >>> >>> ------------------------------------------------------------------------------ >>> This SF.net email is sponsored by Windows: >>> >>> Build for Windows Store. >>> >>> http://p.sf.net/sfu/windows-dev2dev >>> _______________________________________________ >>> Resteasy-developers mailing list >>> Res...@li... >>> https://lists.sourceforge.net/lists/listinfo/resteasy-developers >>> >> > -- Bill Burke JBoss, a division of Red Hat http://bill.burkecentral.com |