Skip to content

Commit

Permalink
[RESTEASY-1932]
Browse files Browse the repository at this point in the history
ClientInvoker.invoke() catches ResponseProcessingException and closes
connection.

[RESTEASY-1932]

Added integration test.

[RESTEASY-1932]

Cleaned up test.
  • Loading branch information
ronsigal authored and asoldano committed Jun 27, 2018
1 parent 3670785 commit 766ccf5
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 1 deletion.
Expand Up @@ -16,6 +16,7 @@
import org.jboss.resteasy.util.MediaTypeHelper;

import javax.ws.rs.Path;
import javax.ws.rs.client.ResponseProcessingException;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.container.DynamicFeature;
import javax.ws.rs.container.ResourceInfo;
Expand Down Expand Up @@ -99,7 +100,19 @@ public Class<?> getDeclaring()
public Object invoke(Object[] args)
{
ClientInvocation request = createRequest(args);
ClientResponse response = (ClientResponse)request.invoke();
ClientResponse response = null;
try
{
response = (ClientResponse)request.invoke();
}
catch (ResponseProcessingException e)
{
if (e.getResponse() != null)
{
e.getResponse().close();
}
throw e;
}
ClientContext context = new ClientContext(request, response, entityExtractorFactory);
return extractor.extractEntity(context);
}
Expand Down
@@ -0,0 +1,90 @@
package org.jboss.resteasy.test.core.interceptors;

import javax.ws.rs.InternalServerErrorException;
import javax.ws.rs.client.ResponseProcessingException;

import org.apache.http.client.config.RequestConfig;
import org.apache.http.impl.client.HttpClientBuilder;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.resteasy.client.jaxrs.ClientHttpEngine;
import org.jboss.resteasy.client.jaxrs.ResteasyClient;
import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder;
import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget;
import org.jboss.resteasy.client.jaxrs.engines.factory.ApacheHttpClient4EngineFactory;
import org.jboss.resteasy.test.core.interceptors.resource.ClientResponseFilterExceptionFilter;
import org.jboss.resteasy.test.core.interceptors.resource.ClientResponseFilterExceptionResource;
import org.jboss.resteasy.test.core.interceptors.resource.ClientResponseFilterExceptionResourceImpl;
import org.jboss.resteasy.utils.PortProviderUtil;
import org.jboss.resteasy.utils.TestUtil;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;

/**
* @tpSubChapter Interceptors
* @tpChapter Integration tests
* @tpTestCaseDetails Regression test for RESTEASY-1932
* @tpSince RESTEasy 3.0.26
*/
@RunWith(Arquillian.class)
@RunAsClient
public class ClientResponseFilterExceptionTest {

@Deployment
public static Archive<?> deploySimpleResource() {
WebArchive war = TestUtil.prepareArchive(ClientResponseFilterExceptionTest.class.getSimpleName());
war.addClass(ClientResponseFilterExceptionResource.class);
war.addClass(ClientResponseFilterExceptionFilter.class);
return TestUtil.finishContainerPrepare(war, null, ClientResponseFilterExceptionResourceImpl.class);
}

private String generateURL(String path) {
return PortProviderUtil.generateURL(path, ClientResponseFilterExceptionTest.class.getSimpleName());
}

/**
* @tpTestDetails Generate PreProcessorExceptionMapperCandlepinUnauthorizedException
* @tpPassCrit SC_PRECONDITION_FAILED (412) HTTP code is excepted
* @tpSince RESTEasy 3.0.26
*/
@Test
public void testMapper() throws Exception {
RequestConfig requestConfig = RequestConfig.custom()
.setConnectionRequestTimeout(1000)
.setSocketTimeout(1000)
.setConnectTimeout(1000)
.build();

HttpClientBuilder httpClientBuilder = HttpClientBuilder.create()
.setDefaultRequestConfig(requestConfig)
.setMaxConnPerRoute(2)
.setMaxConnTotal(2);

ClientHttpEngine engine = ApacheHttpClient4EngineFactory.create(httpClientBuilder.build(), true);

ResteasyClientBuilder clientBuilder = new ResteasyClientBuilder().httpEngine(engine)
.register(ClientResponseFilterExceptionFilter.class)
;

ResteasyClient client = clientBuilder.build();

ResteasyWebTarget target = client.target(generateURL(""));
ClientResponseFilterExceptionResource service = target.proxy(ClientResponseFilterExceptionResource.class);

int i = 0;
for (; i < 10; i++) {
try {
service.dummy();
} catch (InternalServerErrorException e) {
//do nothing
} catch (ResponseProcessingException e) {
//do nothing
}
}
Assert.assertEquals(10, i);
}
}
@@ -0,0 +1,15 @@
package org.jboss.resteasy.test.core.interceptors.resource;

import javax.ws.rs.client.ClientRequestContext;
import javax.ws.rs.client.ClientResponseContext;
import javax.ws.rs.client.ClientResponseFilter;
import javax.ws.rs.ext.Provider;

@Provider
public class ClientResponseFilterExceptionFilter implements ClientResponseFilter {

@Override
public void filter(ClientRequestContext requestContext, ClientResponseContext responseContext) {
throw new RuntimeException();
}
}
@@ -0,0 +1,12 @@
package org.jboss.resteasy.test.core.interceptors.resource;

import javax.ws.rs.GET;
import javax.ws.rs.Path;

@Path("dummyservice")
public interface ClientResponseFilterExceptionResource {

@Path("dummy")
@GET
public String dummy();
}
@@ -0,0 +1,14 @@
package org.jboss.resteasy.test.core.interceptors.resource;

import javax.ws.rs.GET;
import javax.ws.rs.Path;

@Path("dummyservice")
public class ClientResponseFilterExceptionResourceImpl {

@Path("dummy")
@GET
public String dummy() {
return "dummy";
}
}

0 comments on commit 766ccf5

Please sign in to comment.