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

Accept header not correctly parsed by org.jboss.resteasy.client.jaxrs.cache.CacheInterceptor

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 4.2.0.Final, 3.9.0.Final
    • 4.1.1.Final
    • None
    • None
    • Hide

      Execute the following test:

          @Test
          public void testAcceptHeader() {
              ResteasyClientBuilder builder = new ResteasyClientBuilderImpl();
              BrowserCacheFeature browserCacheFeature = new BrowserCacheFeature();
              browserCacheFeature.setCache(new MapCache());
              builder.register(browserCacheFeature);
      
              TestInterface test = builder.build()
                  .target("https://jsonplaceholder.typicode.com/posts/")
                  .proxyBuilder(TestInterface.class)           
                  .build();
              String load = test.load("42");
              log.info("{}", load);
      
          }
      
          @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
          interface TestInterface {
                @GET
                @Path("/{id:.*}")
                String load(@Encoded @PathParam("id") String id);
          }
      
      

      Which will result the following exception:

      javax.ws.rs.client.ResponseProcessingException: java.lang.IllegalArgumentException: RESTEASY003340: Failure parsing MediaType string: application/json, application/xml
      
      	at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.filterResponse(ClientInvocation.java:730)
      	at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.invoke(ClientInvocation.java:489)
      	at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.invokeSync(ClientInvoker.java:150)
      	at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.invoke(ClientInvoker.java:113)
      	at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientProxy.invoke(ClientProxy.java:76)
      	at nl.vpro.api.client.frontend.$Proxy18.load(Unknown Source)
      	at nl.vpro.api.client.frontend.ResteasyTest.testAcceptHeader(ResteasyTest.java:35)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at java.lang.reflect.Method.invoke(Method.java:498)
      	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
      	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
      	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
      	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
      	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
      	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
      	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
      	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
      	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
      	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
      	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
      	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
      	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
      	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
      	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
      	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
      	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
      	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
      Caused by: java.lang.IllegalArgumentException: RESTEASY003340: Failure parsing MediaType string: application/json, application/xml
      	at org.jboss.resteasy.plugins.delegates.MediaTypeHeaderDelegate.internalParse(MediaTypeHeaderDelegate.java:113)
      	at org.jboss.resteasy.plugins.delegates.MediaTypeHeaderDelegate.parse(MediaTypeHeaderDelegate.java:64)
      	at org.jboss.resteasy.plugins.delegates.MediaTypeHeaderDelegate.fromString(MediaTypeHeaderDelegate.java:29)
      	at javax.ws.rs.core.MediaType.valueOf(MediaType.java:172)
      	at org.jboss.resteasy.client.jaxrs.cache.CacheInterceptor.cacheIfPossible(CacheInterceptor.java:209)
      	at org.jboss.resteasy.client.jaxrs.cache.CacheInterceptor.cache(CacheInterceptor.java:121)
      	at org.jboss.resteasy.client.jaxrs.cache.CacheInterceptor.filter(CacheInterceptor.java:98)
      	at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.filterResponse(ClientInvocation.java:722)
      	... 28 more
      
      
      Show
      Execute the following test: @Test public void testAcceptHeader() { ResteasyClientBuilder builder = new ResteasyClientBuilderImpl(); BrowserCacheFeature browserCacheFeature = new BrowserCacheFeature(); browserCacheFeature.setCache( new MapCache()); builder.register(browserCacheFeature); TestInterface test = builder.build() .target( "https: //jsonplaceholder.typicode.com/posts/" ) .proxyBuilder(TestInterface.class) .build(); String load = test.load( "42" ); log.info( "{}" , load); } @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) interface TestInterface { @GET @Path( "/{id:.*}" ) String load(@Encoded @PathParam( "id" ) String id); } Which will result the following exception: javax.ws.rs.client.ResponseProcessingException: java.lang.IllegalArgumentException: RESTEASY003340: Failure parsing MediaType string: application/json, application/xml at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.filterResponse(ClientInvocation.java:730) at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.invoke(ClientInvocation.java:489) at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.invokeSync(ClientInvoker.java:150) at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.invoke(ClientInvoker.java:113) at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientProxy.invoke(ClientProxy.java:76) at nl.vpro.api.client.frontend.$Proxy18.load(Unknown Source) at nl.vpro.api.client.frontend.ResteasyTest.testAcceptHeader(ResteasyTest.java:35) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68) at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70) Caused by: java.lang.IllegalArgumentException: RESTEASY003340: Failure parsing MediaType string: application/json, application/xml at org.jboss.resteasy.plugins.delegates.MediaTypeHeaderDelegate.internalParse(MediaTypeHeaderDelegate.java:113) at org.jboss.resteasy.plugins.delegates.MediaTypeHeaderDelegate.parse(MediaTypeHeaderDelegate.java:64) at org.jboss.resteasy.plugins.delegates.MediaTypeHeaderDelegate.fromString(MediaTypeHeaderDelegate.java:29) at javax.ws.rs.core.MediaType.valueOf(MediaType.java:172) at org.jboss.resteasy.client.jaxrs.cache.CacheInterceptor.cacheIfPossible(CacheInterceptor.java:209) at org.jboss.resteasy.client.jaxrs.cache.CacheInterceptor.cache(CacheInterceptor.java:121) at org.jboss.resteasy.client.jaxrs.cache.CacheInterceptor.filter(CacheInterceptor.java:98) at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.filterResponse(ClientInvocation.java:722) ... 28 more

      If you generate a client for a service that does content negotiation for more then one media-type, then the accept-header will contain two mediatype. The class org.jboss.resteasy.client.jaxrs.cache.CacheInterceptor will interpret as a single media-type, also ignoring possible quality argument, and cause an exception.

              rhn-support-asoldano Alessio Soldano
              mihxil Michiel Meeuwissen (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved: