Author: ay
Date: Fri Feb 10 11:00:24 2012
New Revision: 1242739
URL: http://svn.apache.org/viewvc?rev=1242739&view=rev
Log:
[CXF-4096] a robust in-only processing option for non-decoupled WS-A EP
Modified:
cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/impl/InternalContextUtils.java
cxf/trunk/systests/uncategorized/src/test/java/org/apache/cxf/systest/interceptor/InterceptorFaultTest.java
Modified:
cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/impl/InternalContextUtils.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/impl/InternalContextUtils.java?rev=1242739&r1=1242738&r2=1242739&view=diff
==============================================================================
---
cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/impl/InternalContextUtils.java
(original)
+++
cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/impl/InternalContextUtils.java
Fri Feb 10 11:00:24 2012
@@ -43,6 +43,7 @@ import org.apache.cxf.interceptor.Outgoi
import org.apache.cxf.io.DelegatingInputStream;
import org.apache.cxf.message.Exchange;
import org.apache.cxf.message.Message;
+import org.apache.cxf.message.MessageUtils;
import org.apache.cxf.service.model.BindingFaultInfo;
import org.apache.cxf.service.model.BindingOperationInfo;
import org.apache.cxf.service.model.EndpointInfo;
@@ -119,6 +120,25 @@ final class InternalContextUtils {
reference);
if (backChannel != null) {
+ boolean robust =
+
MessageUtils.isTrue(inMessage.getContextualProperty(Message.ROBUST_ONEWAY));
+
+ if (robust) {
+ // insert the executor in the exchange to fool the
OneWayProcessorInterceptor
+ exchange.put(Executor.class, getExecutor(inMessage));
+ // pause dispatch on current thread and resume...
+ inMessage.getInterceptorChain().pause();
+ inMessage.getInterceptorChain().resume();
+ MessageObserver faultObserver =
inMessage.getInterceptorChain().getFaultObserver();
+ if (null != inMessage.getContent(Exception.class) &&
null != faultObserver) {
+ // return the fault over the response fault channel
+ inMessage.getExchange().setOneWay(false);
+ faultObserver.onMessage(inMessage);
+ return;
+ }
+ }
+
+
// set up interceptor chains and send message
InterceptorChain chain =
fullResponse != null
@@ -153,7 +173,7 @@ final class InternalContextUtils {
exchange.setDestination(destination);
- if
(ContextUtils.retrieveAsyncPostResponseDispatch(inMessage)) {
+ if
(ContextUtils.retrieveAsyncPostResponseDispatch(inMessage) && !robust) {
//need to suck in all the data from the input stream as
//the transport might discard any data on the stream
when this
//thread unwinds or when the empty response is sent
back
Modified:
cxf/trunk/systests/uncategorized/src/test/java/org/apache/cxf/systest/interceptor/InterceptorFaultTest.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/uncategorized/src/test/java/org/apache/cxf/systest/interceptor/InterceptorFaultTest.java?rev=1242739&r1=1242738&r2=1242739&view=diff
==============================================================================
---
cxf/trunk/systests/uncategorized/src/test/java/org/apache/cxf/systest/interceptor/InterceptorFaultTest.java
(original)
+++
cxf/trunk/systests/uncategorized/src/test/java/org/apache/cxf/systest/interceptor/InterceptorFaultTest.java
Fri Feb 10 11:00:24 2012
@@ -22,7 +22,6 @@ package org.apache.cxf.systest.intercept
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.Collections;
-import java.util.Iterator;
import java.util.List;
import java.util.logging.Logger;
@@ -165,22 +164,18 @@ public class InterceptorFaultTest extend
setupGreeter("org/apache/cxf/systest/interceptor/no-addr.xml", false);
+ control.setRobustInOnlyMode(robust);
+
+ // all interceptors pass
+ testInterceptorsPass();
+
// behaviour is identicial for all phases
- Iterator<Phase> it = inPhases.iterator();
- Phase p = null;
FaultLocation location = new
org.apache.cxf.greeter_control.types.ObjectFactory()
.createFaultLocation();
- while (it.hasNext()) {
- p = it.next();
- location.setPhase(p.getName());
- if (Phase.PRE_LOGICAL.equals(p.getName())) {
- continue;
- } else if (Phase.POST_INVOKE.equals(p.getName())) {
- break;
- }
- testFail(location, false, robust);
- }
+ // test failure occuring before and after logical addressing
interceptor
+ // won't get a fault in case of oneways non-robust for the latter
(partial response already sent)
+ testInterceptorFail(inPhases, location, robust);
}
@Test
@@ -188,62 +183,60 @@ public class InterceptorFaultTest extend
testWithAddressingAnonymousReplies(false);
}
+ @Test
+ public void testRobustWithAddressingAnonymousReplies() throws Exception {
+ testWithAddressingAnonymousReplies(true);
+ }
+
private void testWithAddressingAnonymousReplies(boolean robust) throws
Exception {
setupGreeter("org/apache/cxf/systest/interceptor/addr.xml", false);
-
+
+ control.setRobustInOnlyMode(robust);
+
// all interceptors pass
- greeter.greetMeOneWay("one");
- assertEquals("TWO", greeter.greetMe("two"));
- try {
- greeter.pingMe();
- fail("Expected PingMeFault not thrown.");
- } catch (PingMeFault f) {
- assertEquals(20, f.getFaultInfo().getMajor());
- assertEquals(10, f.getFaultInfo().getMinor());
- }
+ testInterceptorsPass();
// test failure in phases before Phase.PRE_LOGICAL
-
- Iterator<Phase> it = inPhases.iterator();
- Phase p = null;
FaultLocation location = new
org.apache.cxf.greeter_control.types.ObjectFactory()
.createFaultLocation();
location.setAfter(MAPAggregator.class.getName());
- // test failure occuring before logical addressing interceptor
-
- while (it.hasNext()) {
- p = it.next();
+ // test failure occuring before and after logical addressing
interceptor
+ // won't get a fault in case of oneways non-robust for the latter
(partial response already sent)
+ testInterceptorFail(inPhases, location, robust);
+ }
+
+
+ private void testInterceptorFail(List<Phase> phases, FaultLocation
location, boolean robust)
+ throws PingMeFault {
+ for (Phase p : phases) {
location.setPhase(p.getName());
if (Phase.PRE_LOGICAL.equals(p.getName())) {
+ continue;
+ } else if (Phase.POST_INVOKE.equals(p.getName())) {
break;
}
testFail(location, true, robust);
}
-
- // test failure occuring after logical addressing interceptor -
- // won't get a fault in case of oneways (partial response already sent)
-
- do {
- location.setPhase(p.getName());
- if (Phase.INVOKE.equals(p.getName())) {
- //faults from the PRE_LOGICAL and later phases won't make
- //it back to the client, the 200/202 response has already
- //been returned. The server has accepted the message
- break;
- }
- testFail(location, true, robust);
- p = it.hasNext() ? it.next() : null;
- } while (null != p);
}
-
-
+
+ private void testInterceptorsPass() {
+ greeter.greetMeOneWay("one");
+ assertEquals("TWO", greeter.greetMe("two"));
+ try {
+ greeter.pingMe();
+ fail("Expected PingMeFault not thrown.");
+ } catch (PingMeFault f) {
+ assertEquals(20, f.getFaultInfo().getMajor());
+ assertEquals(10, f.getFaultInfo().getMinor());
+ }
+ }
+
private void testFail(FaultLocation location, boolean usingAddressing,
boolean robust)
throws PingMeFault {
// System.out.print("Test interceptor failing in phase: " +
location.getPhase());
control.setFaultLocation(location);
- control.setRobustInOnlyMode(robust);
// oneway reports a plain fault (although server sends a soap fault)