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

Client Proxy/MP-Rest-Client fails when sending an empty ByteArrayInputStream

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 3.7.0.Final
    • 3.6.2.Final
    • None
    • None
    • Hide

      Server side:

      @Path("/")
      public interface Proxy {
          @PUT
          @Consumes(MediaType.APPLICATION_OCTET_STREAM)
          Response upload(InputStream data);
      }
      public class TestResource implements Proxy {
          public Response upload(InputStream data) {
              java.util.Scanner s = new java.util.Scanner(data).useDelimiter("\\A");
              return Response.ok(s.hasNext() ? s.next() : "").build();
          }
      }
      

      Proxy client side:

      Proxy class from server side
      
      public class App {
          public static void main(String[] args) throws Exception {
              ResteasyClient client = new ResteasyClientBuilder().build();
              Proxy apiService = client.target("http://localhost:8080/jaxrs-wf").proxy(Proxy.class);
              System.out.println(apiService.upload(new ByteArrayInputStream(new byte[0])));
          }
      }
      

      Output:

      Exception in thread "main" javax.ws.rs.ProcessingException: RESTEASY004655: Unable to invoke request
      	at org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.invoke(ApacheHttpClient4Engine.java:321)
      	at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.invoke(ClientInvocation.java:439)
      	at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.invokeSync(ClientInvoker.java:148)
      	at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.invoke(ClientInvoker.java:112)
      	at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientProxy.invoke(ClientProxy.java:76)
      	at com.sun.proxy.$Proxy14.upload(Unknown Source)
      	at com.resteasy.test.App.main(App.java:30)
      Caused by: org.apache.http.client.ClientProtocolException
      	at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:187)
      	at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83)
      	at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56)
      	at org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.invoke(ApacheHttpClient4Engine.java:317)
      	... 6 more
      Caused by: org.apache.http.ProtocolException: Content-Length header already present
      	at org.apache.http.protocol.RequestContent.process(RequestContent.java:97)
      	at org.apache.http.protocol.ImmutableHttpProcessor.process(ImmutableHttpProcessor.java:133)
      	at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:183)
      	at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)
      	at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:111)
      	at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
      	... 9 more
      

      MP REST Client - Client side:

              RestClientBuilder builder = RestClientBuilder.newBuilder();
              Proxy apiService = builder.baseUrl(new URL("http://localhost:8080/jaxrs-wf/")).build(Proxy.class);
              System.out.println(apiService.upload(new ByteArrayInputStream(new byte[0])));
      

      Output:

      Exception in thread "main" java.lang.reflect.UndeclaredThrowableException
      	at com.sun.proxy.$Proxy16.upload(Unknown Source)
      	at com.resteasy.test.App.main(App.java:38)
      Caused by: java.lang.reflect.InvocationTargetException
      	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
      	at org.jboss.resteasy.client.microprofile.ProxyInvocationHandler.invoke(ProxyInvocationHandler.java:92)
      	... 2 more
      Caused by: javax.ws.rs.ProcessingException: RESTEASY004655: Unable to invoke request
      	at org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.invoke(ApacheHttpClient4Engine.java:321)
      	at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.invoke(ClientInvocation.java:439)
      	at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.invokeSync(ClientInvoker.java:148)
      	at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.invoke(ClientInvoker.java:112)
      	at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientProxy.invoke(ClientProxy.java:76)
      	at com.sun.proxy.$Proxy15.upload(Unknown Source)
      	... 7 more
      Caused by: org.apache.http.client.ClientProtocolException
      	at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:187)
      	at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83)
      	at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56)
      	at org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.invoke(ApacheHttpClient4Engine.java:317)
      	... 12 more
      Caused by: org.apache.http.ProtocolException: Content-Length header already present
      	at org.apache.http.protocol.RequestContent.process(RequestContent.java:97)
      	at org.apache.http.protocol.ImmutableHttpProcessor.process(ImmutableHttpProcessor.java:133)
      	at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:183)
      	at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)
      	at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:111)
      	at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
      	... 15 more
      
      Show
      Server side: @Path( "/" ) public interface Proxy { @PUT @Consumes(MediaType.APPLICATION_OCTET_STREAM) Response upload(InputStream data); } public class TestResource implements Proxy { public Response upload(InputStream data) { java.util.Scanner s = new java.util.Scanner(data).useDelimiter( "\\A" ); return Response.ok(s.hasNext() ? s.next() : "").build(); } } Proxy client side: Proxy class from server side public class App { public static void main( String [] args) throws Exception { ResteasyClient client = new ResteasyClientBuilder().build(); Proxy apiService = client.target( "http: //localhost:8080/jaxrs-wf" ).proxy(Proxy.class); System .out.println(apiService.upload( new ByteArrayInputStream( new byte [0]))); } } Output: Exception in thread "main" javax.ws.rs.ProcessingException: RESTEASY004655: Unable to invoke request at org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.invoke(ApacheHttpClient4Engine.java:321) at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.invoke(ClientInvocation.java:439) at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.invokeSync(ClientInvoker.java:148) at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.invoke(ClientInvoker.java:112) at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientProxy.invoke(ClientProxy.java:76) at com.sun.proxy.$Proxy14.upload(Unknown Source) at com.resteasy.test.App.main(App.java:30) Caused by: org.apache.http.client.ClientProtocolException at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:187) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56) at org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.invoke(ApacheHttpClient4Engine.java:317) ... 6 more Caused by: org.apache.http.ProtocolException: Content-Length header already present at org.apache.http.protocol.RequestContent.process(RequestContent.java:97) at org.apache.http.protocol.ImmutableHttpProcessor.process(ImmutableHttpProcessor.java:133) at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:183) at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89) at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:111) at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185) ... 9 more MP REST Client - Client side: RestClientBuilder builder = RestClientBuilder.newBuilder(); Proxy apiService = builder.baseUrl( new URL( "http: //localhost:8080/jaxrs-wf/" )).build(Proxy.class); System .out.println(apiService.upload( new ByteArrayInputStream( new byte [0]))); Output: Exception in thread "main" java.lang.reflect.UndeclaredThrowableException at com.sun.proxy.$Proxy16.upload(Unknown Source) at com.resteasy.test.App.main(App.java:38) Caused by: java.lang.reflect.InvocationTargetException at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at org.jboss.resteasy.client.microprofile.ProxyInvocationHandler.invoke(ProxyInvocationHandler.java:92) ... 2 more Caused by: javax.ws.rs.ProcessingException: RESTEASY004655: Unable to invoke request at org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.invoke(ApacheHttpClient4Engine.java:321) at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.invoke(ClientInvocation.java:439) at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.invokeSync(ClientInvoker.java:148) at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.invoke(ClientInvoker.java:112) at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientProxy.invoke(ClientProxy.java:76) at com.sun.proxy.$Proxy15.upload(Unknown Source) ... 7 more Caused by: org.apache.http.client.ClientProtocolException at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:187) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56) at org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.invoke(ApacheHttpClient4Engine.java:317) ... 12 more Caused by: org.apache.http.ProtocolException: Content-Length header already present at org.apache.http.protocol.RequestContent.process(RequestContent.java:97) at org.apache.http.protocol.ImmutableHttpProcessor.process(ImmutableHttpProcessor.java:133) at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:183) at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89) at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:111) at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185) ... 15 more

      My services have an endpoint which receives an input stream to retrieve the request's data. When I'm using the client api, through a service proxy, with an empty byte array input stream, I get the "org.apache.http.ProtocolException: Content-Length header already present" exception.

      For some reason, the Content-Length seems to already exist in that specific case. If I back the input stream with an array of length 1 (or any other length), the problem disappear.

      This issue is valid for proxy and for MP Rest Client (cc rhn-support-asoldano)

              rsigal@redhat.com Ronald Sigal
              sturcotte06_jira Simon Turcotte-Langevin (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Created:
                Updated:
                Resolved: