Repository: cxf Updated Branches: refs/heads/2.7.x-fixes 426206197 -> 45adf06d5
[CXF-6657] Making ResponseExceptionMapper work with FailoverFeature, patch from Florian Léger applied with tiny modifications Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/45adf06d Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/45adf06d Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/45adf06d Branch: refs/heads/2.7.x-fixes Commit: 45adf06d56aeb8f670b1b2dc5732f4a7ddf75772 Parents: 4262061 Author: Sergey Beryozkin <[email protected]> Authored: Fri Oct 30 11:55:22 2015 +0000 Committer: Sergey Beryozkin <[email protected]> Committed: Fri Oct 30 11:55:22 2015 +0000 ---------------------------------------------------------------------- .../cxf/clustering/FailoverTargetSelector.java | 21 +++++++++++------- .../apache/cxf/jaxrs/client/AbstractClient.java | 23 +++++++++++++------- .../apache/cxf/transport/http/HTTPConduit.java | 7 +++--- 3 files changed, 31 insertions(+), 20 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/45adf06d/rt/features/clustering/src/main/java/org/apache/cxf/clustering/FailoverTargetSelector.java ---------------------------------------------------------------------- diff --git a/rt/features/clustering/src/main/java/org/apache/cxf/clustering/FailoverTargetSelector.java b/rt/features/clustering/src/main/java/org/apache/cxf/clustering/FailoverTargetSelector.java index 3938831..a2dc8c8 100644 --- a/rt/features/clustering/src/main/java/org/apache/cxf/clustering/FailoverTargetSelector.java +++ b/rt/features/clustering/src/main/java/org/apache/cxf/clustering/FailoverTargetSelector.java @@ -47,8 +47,10 @@ import org.apache.cxf.transport.Conduit; */ public class FailoverTargetSelector extends AbstractConduitSelector { - private static final Logger LOG = - LogUtils.getL7dLogger(FailoverTargetSelector.class); + private static final Logger LOG = LogUtils.getL7dLogger(FailoverTargetSelector.class); + private static final String COMPLETE_IF_SERVICE_NOT_AVAIL_PROPERTY = + "org.apache.cxf.transport.complete_if_service_not_available"; + protected ConcurrentHashMap<InvocationKey, InvocationContext> inProgress = new ConcurrentHashMap<InvocationKey, InvocationContext>();; protected FailoverStrategy failoverStrategy; @@ -99,7 +101,10 @@ public class FailoverTargetSelector extends AbstractConduitSelector { } protected void setupExchangeExceptionProperties(Exchange ex) { - ex.remove("org.apache.cxf.transport.no_io_exceptions"); + if (!isSupportNotAvailableErrorsOnly()) { + ex.remove("org.apache.cxf.transport.no_io_exceptions"); + } + ex.put(COMPLETE_IF_SERVICE_NOT_AVAIL_PROPERTY, true); } /** @@ -169,6 +174,7 @@ public class FailoverTargetSelector extends AbstractConduitSelector { } } } else { + exchange.remove(COMPLETE_IF_SERVICE_NOT_AVAIL_PROPERTY); setEndpoint(invocation.retrieveOriginalEndpoint(endpoint)); } } @@ -249,12 +255,11 @@ public class FailoverTargetSelector extends AbstractConduitSelector { "CHECK_FAILURE_IN_TRANSPORT", new Object[] {ex, failover}); } - if (failover - && isSupportNotAvailableErrorsOnly() - && exchange.get(Message.RESPONSE_CODE) != null - && !PropertyUtils.isTrue(exchange.get("org.apache.cxf.transport.service_not_available"))) { - failover = false; + + if (isSupportNotAvailableErrorsOnly() && exchange.get(Message.RESPONSE_CODE) != null) { + failover = PropertyUtils.isTrue(exchange.get("org.apache.cxf.transport.service_not_available")); } + return failover; } http://git-wip-us.apache.org/repos/asf/cxf/blob/45adf06d/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java ---------------------------------------------------------------------- diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java index f1f7ee3..411fd24 100644 --- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java +++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java @@ -59,6 +59,7 @@ import javax.xml.stream.XMLStreamWriter; import org.apache.cxf.Bus; import org.apache.cxf.common.i18n.BundleUtils; import org.apache.cxf.common.logging.LogUtils; +import org.apache.cxf.common.util.PropertyUtils; import org.apache.cxf.endpoint.ClientLifeCycleManager; import org.apache.cxf.endpoint.ConduitSelector; import org.apache.cxf.endpoint.Endpoint; @@ -105,8 +106,10 @@ public abstract class AbstractClient implements Client, Retryable { protected static final String HTTP_SCHEME = "http"; private static final String PROXY_PROPERTY = "jaxrs.proxy"; - private static final String HEADER_SPLIT_PROPERTY = - "org.apache.cxf.http.header.split"; + private static final String HEADER_SPLIT_PROPERTY = "org.apache.cxf.http.header.split"; + private static final String SERVICE_NOT_AVAIL_PROPERTY = "org.apache.cxf.transport.service_not_available"; + private static final String COMPLETE_IF_SERVICE_NOT_AVAIL_PROPERTY = + "org.apache.cxf.transport.complete_if_service_not_available"; private static final Logger LOG = LogUtils.getL7dLogger(AbstractClient.class); private static final ResourceBundle BUNDLE = BundleUtils.getBundle(AbstractClient.class); @@ -456,8 +459,8 @@ public abstract class AbstractClient implements Client, Retryable { } protected WebApplicationException convertToWebApplicationException(Response r) { - Class<?> exceptionClass = ExceptionUtils.getWebApplicationExceptionClass(r, - WebApplicationException.class); + Class<?> exceptionClass = ExceptionUtils.getWebApplicationExceptionClass(r, + WebApplicationException.class); try { Constructor<?> ctr = exceptionClass.getConstructor(Response.class); return (WebApplicationException)ctr.newInstance(r); @@ -551,15 +554,19 @@ public abstract class AbstractClient implements Client, Retryable { protected Object[] preProcessResult(Message message) throws Exception { Exchange exchange = message.getExchange(); - + Exception ex = message.getContent(Exception.class); - if (ex != null) { + if (ex != null + || PropertyUtils.isTrue(exchange.get(SERVICE_NOT_AVAIL_PROPERTY)) + && PropertyUtils.isTrue(exchange.get(COMPLETE_IF_SERVICE_NOT_AVAIL_PROPERTY))) { getConfiguration().getConduitSelector().complete(exchange); + } + if (ex != null) { checkClientException(message, ex); } - checkClientException(message, message.getExchange().get(Exception.class)); + checkClientException(message, exchange.get(Exception.class)); - List<?> result = message.getExchange().get(List.class); + List<?> result = exchange.get(List.class); return result != null ? result.toArray() : null; } http://git-wip-us.apache.org/repos/asf/cxf/blob/45adf06d/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java ---------------------------------------------------------------------- diff --git a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java index 18beb8f..f7469ed 100644 --- a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java +++ b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java @@ -1553,6 +1553,9 @@ public abstract class HTTPConduit } if (exchange != null) { exchange.put(Message.RESPONSE_CODE, rc); + if (rc == 404 || rc == 503) { + exchange.put("org.apache.cxf.transport.service_not_available", true); + } } // "org.apache.cxf.transport.no_io_exceptions" property should be set in case the exceptions @@ -1566,10 +1569,6 @@ public abstract class HTTPConduit && (rc > 400 || !MessageUtils.isTrue(outMessage .getContextualProperty("org.apache.cxf.transport.process_fault_on_http_400")))) { - if (rc == 404 || rc == 503) { - exchange.put("org.apache.cxf.transport.service_not_available", true); - } - throw new HTTPException(rc, getResponseMessage(), url.toURL()); } return rc;
