Return-Path: Delivered-To: apmail-incubator-cxf-commits-archive@locus.apache.org Received: (qmail 15379 invoked from network); 18 May 2007 06:42:16 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 18 May 2007 06:42:16 -0000 Received: (qmail 73806 invoked by uid 500); 18 May 2007 06:42:12 -0000 Delivered-To: apmail-incubator-cxf-commits-archive@incubator.apache.org Received: (qmail 73758 invoked by uid 500); 18 May 2007 06:42:12 -0000 Mailing-List: contact cxf-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: cxf-dev@incubator.apache.org Delivered-To: mailing list cxf-commits@incubator.apache.org Received: (qmail 73733 invoked by uid 99); 18 May 2007 06:42:11 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 17 May 2007 23:42:11 -0700 X-ASF-Spam-Status: No, hits=-99.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 17 May 2007 23:42:04 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id B959C1A981A; Thu, 17 May 2007 23:41:44 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r539286 - in /incubator/cxf/trunk: rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/ rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/logical/ rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/soap/ systes... Date: Fri, 18 May 2007 06:41:44 -0000 To: cxf-commits@incubator.apache.org From: jliu@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070518064144.B959C1A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: jliu Date: Thu May 17 23:41:43 2007 New Revision: 539286 URL: http://svn.apache.org/viewvc?view=rev&rev=539286 Log: Fixed a problem in handler chain to make sure handleFault is properly invoked when server side servant throws exception to outbound fault chain. The logic of current implementation is if the exception is thrown from previous handlers, we only invoke handleFault if it is a ProtocolException (per spec), if the exception is thrown from other places other than handlers, we always invoke handleFault. Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/HandlerChainInvoker.java incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/logical/LogicalHandlerFaultOutInterceptor.java incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/soap/SOAPHandlerFaultOutInterceptor.java incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerInvocationTest.java Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/HandlerChainInvoker.java URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/HandlerChainInvoker.java?view=diff&rev=539286&r1=539285&r2=539286 ============================================================================== --- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/HandlerChainInvoker.java (original) +++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/HandlerChainInvoker.java Thu May 17 23:41:43 2007 @@ -262,7 +262,14 @@ } } }*/ - + + //REVISIT + /* + * the logic of current implemetation is if the exception is thrown from + * previous handlers, we only invoke handleFault if it is ProtocolException + * (per spec), if the exception is thrown from other places other than + * handlers, we always invoke handleFault. + */ private boolean invokeHandlerChainHandleFault(List handlerChain, MessageContext ctx) { if (handlerChain.isEmpty()) { LOG.log(Level.FINEST, "no handlers registered"); @@ -272,6 +279,12 @@ if (isClosed()) { return false; } + + //The fault is raised from previous handlers, in this case, we only invoke handleFault + //if the fault is a ProtocolException + if (fault != null && !(fault instanceof ProtocolException)) { + return true; + } if (LOG.isLoggable(Level.FINE)) { LOG.log(Level.FINE, "invoking handlers, direction: " + (outbound ? "outbound" : "inbound")); @@ -527,7 +540,7 @@ int index = invokedHandlers.size() - 1; while (index >= 0) { Handler handler = invokedHandlers.get(index); - //System.out.println("===========invokeReversedClose " + invokeReversedClose.toString()); + //System.out.println("===========invokeReversedClose " + handler.toString()); if (handler instanceof LogicalHandler) { handler.close(logicalMessageContext); } else { Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/logical/LogicalHandlerFaultOutInterceptor.java URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/logical/LogicalHandlerFaultOutInterceptor.java?view=diff&rev=539286&r1=539285&r2=539286 ============================================================================== --- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/logical/LogicalHandlerFaultOutInterceptor.java (original) +++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/logical/LogicalHandlerFaultOutInterceptor.java Thu May 17 23:41:43 2007 @@ -27,7 +27,6 @@ import javax.xml.transform.Source; import javax.xml.transform.dom.DOMSource; import javax.xml.ws.Binding; -import javax.xml.ws.ProtocolException; import org.apache.cxf.helpers.XMLUtils; import org.apache.cxf.interceptor.Fault; @@ -108,18 +107,9 @@ StaxUtils.createXMLStreamReader(domWriter.getDocument())); } - Fault f = (Fault)message.getContent(Exception.class); - - Throwable cause = f.getCause(); - if (cause instanceof ProtocolException) { - - if (!invoker.invokeLogicalHandlersHandleFault(requestor, lctx)) { - //do nothing - } - } else { - // do nothing - } - + if (!invoker.invokeLogicalHandlersHandleFault(requestor, lctx)) { + //do nothing + } if (origMessage != null) { message.setContent(SOAPMessage.class, origMessage); Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/soap/SOAPHandlerFaultOutInterceptor.java URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/soap/SOAPHandlerFaultOutInterceptor.java?view=diff&rev=539286&r1=539285&r2=539286 ============================================================================== --- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/soap/SOAPHandlerFaultOutInterceptor.java (original) +++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/soap/SOAPHandlerFaultOutInterceptor.java Thu May 17 23:41:43 2007 @@ -29,7 +29,6 @@ import javax.xml.soap.SOAPFault; import javax.xml.soap.SOAPMessage; import javax.xml.ws.Binding; -import javax.xml.ws.ProtocolException; import javax.xml.ws.handler.Handler; import javax.xml.ws.handler.MessageContext; import javax.xml.ws.handler.soap.SOAPHandler; @@ -116,58 +115,53 @@ private void handleMessageInternal(SoapMessage message) { MessageContext context = createProtocolMessageContext(message); HandlerChainInvoker invoker = getInvoker(message); - invoker.setProtocolMessageContext(context); - - Fault f = (Fault)message.getContent(Exception.class); + invoker.setProtocolMessageContext(context); - Throwable cause = f.getCause(); - if (cause instanceof ProtocolException) { + try { + if (!invoker.invokeProtocolHandlersHandleFault(isRequestor(message), context)) { + // handleAbort(message, context); + } + } catch (RuntimeException exception) { + /* + * handleFault throws exception, in this case we need to replace + * SOAPFault with the exception thrown from HandleFault so that the + * exception can be dispatched. + */ try { - - if (!invoker.invokeProtocolHandlersHandleFault(isRequestor(message), context)) { - // handleAbort(message, context); - } - } catch (RuntimeException exception) { - //Replace SOAPFault with the exception thrown from HandleFault - - try { - SOAPMessage originalMsg = message.getContent(SOAPMessage.class); - SOAPBody body = originalMsg.getSOAPBody(); - body.removeContents(); - - SOAPFault soapFault = body.addFault(); - - if (exception instanceof SOAPFaultException) { - SOAPFaultException sf = (SOAPFaultException)exception; - soapFault.setFaultString(sf.getFault().getFaultString()); - soapFault.setFaultCode(sf.getFault().getFaultCodeAsQName()); - soapFault.setFaultActor(sf.getFault().getFaultActor()); - if (sf.getFault().hasDetail()) { - Node nd = originalMsg.getSOAPPart().importNode( - sf.getFault().getDetail() - .getFirstChild(), true); - soapFault.addDetail().appendChild(nd); - } - } else if (exception instanceof Fault) { - SoapFault sf = SoapFault.createFault((Fault)exception, ((SoapMessage)message) - .getVersion()); - soapFault.setFaultString(sf.getReason()); - soapFault.setFaultCode(sf.getFaultCode()); - Node nd = originalMsg.getSOAPPart().importNode(sf.getOrCreateDetail(), true); + SOAPMessage originalMsg = message.getContent(SOAPMessage.class); + SOAPBody body = originalMsg.getSOAPBody(); + body.removeContents(); + + SOAPFault soapFault = body.addFault(); + + if (exception instanceof SOAPFaultException) { + SOAPFaultException sf = (SOAPFaultException)exception; + soapFault.setFaultString(sf.getFault().getFaultString()); + soapFault.setFaultCode(sf.getFault().getFaultCodeAsQName()); + soapFault.setFaultActor(sf.getFault().getFaultActor()); + if (sf.getFault().hasDetail()) { + Node nd = originalMsg.getSOAPPart().importNode( + sf.getFault().getDetail() + .getFirstChild(), true); soapFault.addDetail().appendChild(nd); - } else { - soapFault.setFaultString(exception.getMessage()); - soapFault.setFaultCode(new QName("http://cxf.apache.org/faultcode", "HandleFault")); - } - } catch (SOAPException e) { - //do nothing - e.printStackTrace(); - } + } + } else if (exception instanceof Fault) { + SoapFault sf = SoapFault.createFault((Fault)exception, ((SoapMessage)message) + .getVersion()); + soapFault.setFaultString(sf.getReason()); + soapFault.setFaultCode(sf.getFaultCode()); + Node nd = originalMsg.getSOAPPart().importNode(sf.getOrCreateDetail(), true); + soapFault.addDetail().appendChild(nd); + } else { + soapFault.setFaultString(exception.getMessage()); + soapFault.setFaultCode(new QName("http://cxf.apache.org/faultcode", "HandleFault")); + } + } catch (SOAPException e) { + // do nothing + e.printStackTrace(); } - } else { - // do nothing } - + onCompletion(message); } 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=539286&r1=539285&r2=539286 ============================================================================== --- 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 Thu May 17 23:41:43 2007 @@ -742,8 +742,8 @@ handlerTest.pingWithArgs("soapHandler3 outbound throw RuntimeException"); fail("did not get expected exception"); } catch (RuntimeException e) { - //e.printStackTrace(); -/* ByteArrayOutputStream baos = new ByteArrayOutputStream(); +/* //e.printStackTrace(); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos, true); e.printStackTrace(ps); assertTrue("Did not get expected exception message", baos.toString() @@ -788,8 +788,8 @@ + "soapHandler4HandleFaultThrowsRunException"); fail("did not get expected WebServiceException"); } catch (WebServiceException e) { - //e.printStackTrace(); -/* ByteArrayOutputStream baos = new ByteArrayOutputStream(); +/* //e.printStackTrace(); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos, true); e.printStackTrace(ps); assertTrue("Did not get expected exception message", baos.toString() @@ -828,7 +828,7 @@ PrintStream ps = new PrintStream(baos, true); e.printStackTrace(ps); assertTrue("Did not get expected exception message", baos.toString() - .indexOf("HandleMessage throws ProtocolException exception") > -1); + .indexOf("HandleMessage throws exception") > -1); assertTrue("Did not get expected javax.xml.ws.soap.SOAPFaultException", baos.toString() .indexOf("javax.xml.ws.soap.SOAPFaultException") > -1);*/ } @@ -847,13 +847,12 @@ handlerTest.pingWithArgs("soapHandler3 inbound throw SOAPFaultException"); fail("did not get expected SOAPFaultException"); } catch (SOAPFaultException e) { - //e.printStackTrace(); - /* +/* //e.printStackTrace(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos, true); e.printStackTrace(ps); assertTrue("Did not get expected exception message", baos.toString() - .indexOf("soapHandler3 HandleFault throws SOAPFaultException") > -1); + .indexOf("HandleMessage throws exception") > -1); assertTrue("Did not get expected javax.xml.ws.soap.SOAPFaultException", baos.toString() .indexOf("javax.xml.ws.soap.SOAPFaultException") > -1);*/ @@ -879,19 +878,26 @@ assertTrue(soapHandler1.getInvokeOrderOfClose() < handler2.getInvokeOrderOfClose()); assertTrue(handler2.getInvokeOrderOfClose() - < handler1.getInvokeOrderOfClose()); */ + < handler1.getInvokeOrderOfClose()); */ } /*------------------------------------------------------- * This is the expected order *------------------------------------------------------- - * soapHandler3.handleMessage().doInbound() * soapHandler4.handleMessage().doInbound() + * soapHandler3.handleMessage().doInbound() + * handler2.handleMessage().doInbound() + * handler1.handleMessage().doInbound() + * servant throws RuntimeException + * handler1.handleFault() + * handler2.handleFault() * soapHandler3.handleFault() * soapHandler4.handleFault() + * handler1.close() + * handler2.close() * soapHandler3.close() * soapHandler4.close() - */ + * */ @Test public void testServerEndpointRemoteRuntimeException() throws PingException { try { @@ -903,9 +909,7 @@ PrintStream ps = new PrintStream(baos, true); e.printStackTrace(ps); assertTrue("Did not get expected exception message", baos.toString() - .indexOf("servant throw RuntimeException") > -1); - assertTrue("Did not get expected javax.xml.ws.soap.SOAPFaultException", baos.toString() - .indexOf("javax.xml.ws.soap.SOAPFaultException") > -1);*/ + .indexOf("RemoteException with nested RuntimeException") > -1);*/ } }