Author: jliu
Date: Wed May 9 04:30:07 2007
New Revision: 536490
URL: http://svn.apache.org/viewvc?view=rev&rev=536490
Log:
Support for soap handler handleMessage returns false on server side outbound
and client side inbound. In this case, normal handler message processing stops
(i.e next handler is not getting called), but the interceptor chain still
continues, the message is dispatched.
Modified:
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/soap/SOAPHandlerInterceptor.java
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerInvocationTest.java
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerTestImpl.java
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/TestHandler.java
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/TestSOAPHandler.java
Modified:
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/soap/SOAPHandlerInterceptor.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/soap/SOAPHandlerInterceptor.java?view=diff&rev=536490&r1=536489&r2=536490
==============================================================================
---
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/soap/SOAPHandlerInterceptor.java
(original)
+++
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/soap/SOAPHandlerInterceptor.java
Wed May 9 04:30:07 2007
@@ -126,41 +126,71 @@
invoker.setProtocolMessageContext(context);
if (!invoker.invokeProtocolHandlers(isRequestor(message), context)) {
- message.getInterceptorChain().abort();
- Endpoint e = message.getExchange().get(Endpoint.class);
- Message responseMsg = e.getBinding().createMessage();
-
- MessageObserver observer =
(MessageObserver)message.getExchange().get(MessageObserver.class);
- if (observer != null) {
- //client side outbound, the request message becomes the
response message
- message.getExchange().setInMessage(responseMsg);
- SOAPMessage soapMessage =
((SOAPMessageContext)context).getMessage();
+ handleAbort(message, context);
+ }
+
+ onCompletion(message);
+ }
+
+ private void handleAbort(SoapMessage message, MessageContext context) {
+ if (isRequestor(message)) {
+ // client side outbound
+ if (getInvoker(message).isOutbound()) {
+ message.getInterceptorChain().abort();
+ Endpoint e = message.getExchange().get(Endpoint.class);
+ Message responseMsg = e.getBinding().createMessage();
+
+ MessageObserver observer =
(MessageObserver)message.getExchange().get(MessageObserver.class);
+ if (observer != null) {
+ // the request message becomes the response message
+ message.getExchange().setInMessage(responseMsg);
+ SOAPMessage soapMessage =
((SOAPMessageContext)context).getMessage();
+
+ if (soapMessage != null) {
+ responseMsg.setContent(SOAPMessage.class, soapMessage);
+ XMLStreamReader xmlReader =
createXMLStreamReaderFromSOAPMessage(soapMessage);
+ responseMsg.setContent(XMLStreamReader.class,
xmlReader);
+ }
+
responseMsg.put(PhaseInterceptorChain.STARTING_AFTER_INTERCEPTOR_ID,
+ SOAPHandlerInterceptor.class.getName());
+ observer.onMessage(responseMsg);
+ }
+ } else {
+ // client side inbound - Normal handler message processing
+ // stops,, but still continue the outbound interceptor chain,
dispatch the message
+ System.out.println("SOAP Handler handleMessage returns false
on client inbound, aborting");
+ }
+ } else {
+ if (!getInvoker(message).isOutbound()) {
+
+ // server side outbound
+ message.getInterceptorChain().abort();
+ Endpoint e = message.getExchange().get(Endpoint.class);
+ Message responseMsg = e.getBinding().createMessage();
+ if (!message.getExchange().isOneWay()) {
+ // server side inbound
+ message.getExchange().setOutMessage(responseMsg);
+ SOAPMessage soapMessage =
((SOAPMessageContext)context).getMessage();
- if (soapMessage != null) {
responseMsg.setContent(SOAPMessage.class, soapMessage);
- XMLStreamReader xmlReader =
createXMLStreamReaderFromSOAPMessage(soapMessage);
- responseMsg.setContent(XMLStreamReader.class, xmlReader);
+
+ InterceptorChain chain =
OutgoingChainInterceptor.getOutInterceptorChain(message
+ .getExchange());
+ responseMsg.setInterceptorChain(chain);
+ // so the idea of starting interceptor chain from any
+ // specified point does not work
+ // well for outbound case, as many outbound interceptors
+ // have their ending interceptors.
+ // For example, we can not skip MessageSenderInterceptor.
+ chain.doInterceptStartingAfter(responseMsg,
SoapActionInterceptor.class.getName());
}
-
responseMsg.put(PhaseInterceptorChain.STARTING_AFTER_INTERCEPTOR_ID,
- SOAPHandlerInterceptor.class.getName());
- observer.onMessage(responseMsg);
- } else if (!message.getExchange().isOneWay()) {
- //server side inbound
- message.getExchange().setOutMessage(responseMsg);
- SOAPMessage soapMessage =
((SOAPMessageContext)context).getMessage();
-
- responseMsg.setContent(SOAPMessage.class, soapMessage);
-
- InterceptorChain chain =
OutgoingChainInterceptor.getOutInterceptorChain(message
- .getExchange());
- responseMsg.setInterceptorChain(chain);
- //so the idea of starting interceptor chain from any specified
point does not work
- //well for outbound case, as many outbound interceptors have
their ending interceptors.
- //For example, we can not skip MessageSenderInterceptor.
- chain.doInterceptStartingAfter(responseMsg,
SoapActionInterceptor.class.getName());
- }
- }
- onCompletion(message);
+
+ } else {
+ // server side inbound - Normal handler message processing
+ // stops, but still continue the inbound interceptor chain,
dispatch the message
+ System.out.println("SOAP Handler handleMessage returns false
on server inbound, aborting");
+ }
+ }
}
@Override
Modified:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerInvocationTest.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerInvocationTest.java?view=diff&rev=536490&r1=536489&r2=536490
==============================================================================
---
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerInvocationTest.java
(original)
+++
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerInvocationTest.java
Wed May 9 04:30:07 2007
@@ -206,11 +206,11 @@
@Test
- public void testLogicalHandlerHandleMessageReturnsFalseServerSide() throws
PingException {
+ public void testLogicalHandlerHandleMessageReturnsFalseInboundServerSide()
throws PingException {
String[] expectedHandlers = {"soapHandler4", "soapHandler3",
"handler2",
"handler2", "soapHandler3",
"soapHandler4"};
- List<String> resp = handlerTest.pingWithArgs("handler2 inbound stop");
+ List<String> resp = handlerTest.pingWithArgs("handler2 inbound stop");
assertEquals(expectedHandlers.length, resp.size());
@@ -221,7 +221,7 @@
}
@Test
- public void testSOAPHandlerHandleMessageReturnsFalseServerSide() throws
PingException {
+ public void testSOAPHandlerHandleMessageReturnsFalseInboundServerSide()
throws PingException {
String[] expectedHandlers = {"soapHandler4", "soapHandler3",
"soapHandler3", "soapHandler4"};
List<String> resp = handlerTest.pingWithArgs("soapHandler3 inbound
stop");
@@ -232,6 +232,20 @@
}
}
+
+ @Test
+ public void testSOAPHandlerHandleMessageReturnsFalseOutboundServerSide()
throws PingException {
+ String[] expectedHandlers = {"soapHandler3 outbound stop",
"soapHandler4", "soapHandler3", "handler2",
+ "handler1", "handler1", "handler2",
"soapHandler3"};
+ List<String> resp = handlerTest.pingWithArgs("soapHandler3 outbound
stop");
+
+ assertEquals(expectedHandlers.length, resp.size());
+ int i = 0;
+ for (String expected : expectedHandlers) {
+ assertEquals(expected, resp.get(i++));
+ }
+ }
+
@Test
public void
testLogicalHandlerHandleMessageThrowsProtocolExceptionClientSide() throws
Exception {
@@ -302,7 +316,7 @@
}
@Test
- public void testSOAPHandlerHandleMessageReturnFalseClientSide() throws
Exception {
+ public void testSOAPHandlerHandleMessageReturnFalseOutboundClientSide()
throws Exception {
final String clientHandlerMessage = "client side";
TestHandler<LogicalMessageContext> handler1 = new
TestHandler<LogicalMessageContext>(false);
TestHandler<LogicalMessageContext> handler2 = new
TestHandler<LogicalMessageContext>(false) {
Modified:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerTestImpl.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerTestImpl.java?view=diff&rev=536490&r1=536489&r2=536490
==============================================================================
---
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerTestImpl.java
(original)
+++
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerTestImpl.java
Wed May 9 04:30:07 2007
@@ -66,7 +66,7 @@
List<String> ret = new ArrayList<String>();
ret.add(handlerCommand);
- //ret.addAll(getHandlersInfo(context.getMessageContext()));
+ ret.addAll(getHandlersInfo(context.getMessageContext()));
if (handlerCommand.contains("throw exception")) {
PingFaultDetails details = new PingFaultDetails();
Modified:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/TestHandler.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/TestHandler.java?view=diff&rev=536490&r1=536489&r2=536490
==============================================================================
---
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/TestHandler.java
(original)
+++
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/TestHandler.java
Wed May 9 04:30:07 2007
@@ -116,7 +116,6 @@
if ("stop".equals(command)) {
PingResponse resp = new PingResponse();
- getHandlerInfoList(ctx).add(getHandlerId());
resp.getHandlersInfo().addAll(getHandlerInfoList(ctx));
msg.setPayload(resp, jaxbCtx);
ret = false;
@@ -151,7 +150,7 @@
newResp.getHandlersInfo().addAll(origResp.getHandlersInfo());
newResp.getHandlersInfo().add(getHandlerId());
msg.setPayload(newResp, jaxbCtx);
- } else if (obj instanceof Ping) {
+ } else if (obj instanceof Ping || obj instanceof PingWithArgs) {
getHandlerInfoList(ctx).add(getHandlerId());
}
}
Modified:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/TestSOAPHandler.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/TestSOAPHandler.java?view=diff&rev=536490&r1=536489&r2=536490
==============================================================================
---
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/TestSOAPHandler.java
(original)
+++
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/TestSOAPHandler.java
Wed May 9 04:30:07 2007
@@ -78,7 +78,7 @@
if (isServerSideHandler()) {
if (outbound) {
- continueProcessing = true;
+ continueProcessing = getReturnValue(outbound, ctx);
} else {
continueProcessing = getReturnValue(outbound, ctx);
if (!continueProcessing) {
@@ -134,11 +134,6 @@
}
private boolean getReturnValue(boolean outbound, T ctx) {
-
- if (outbound) {
- return true;
- }
-
boolean ret = true;
try {
SOAPMessage msg = ctx.getMessage();
@@ -153,15 +148,18 @@
String namespace =
body.getFirstChild().getFirstChild().getNamespaceURI();
StringTokenizer strtok = new StringTokenizer(arg, " ");
- String hid = strtok.nextToken();
- String direction = strtok.nextToken();
- String command = strtok.nextToken();
+ String hid = "";
+ String direction = "";
+ String command = "";
+ if (strtok.countTokens() == 3) {
+ hid = strtok.nextToken();
+ direction = strtok.nextToken();
+ command = strtok.nextToken();
+ }
- if (getHandlerId().equals(hid)
- && "inbound".equals(direction)) {
- if ("stop".equals(command)) {
-
- // remove the incoming request body.
+ if (getHandlerId().equals(hid) && "stop".equals(command)) {
+ if (!outbound && "inbound".equals(direction)) {
+ // remove the incoming request body.
Document doc = body.getOwnerDocument();
// build the SOAP response for this message
//
@@ -182,10 +180,10 @@
}
}
ret = false;
- } else if ("throw".equals(command)) {
- //throwException(strtok.nextToken());
+ } else if (outbound && "outbound".equals(direction)) {
+ ret = false;
}
- }
+ }
} catch (Exception e) {
e.printStackTrace();