Modified: incubator/cxf/branches/headerwork/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerInvocationTest.java URL: http://svn.apache.org/viewvc/incubator/cxf/branches/headerwork/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerInvocationTest.java?view=diff&rev=538192&r1=538191&r2=538192 ============================================================================== --- incubator/cxf/branches/headerwork/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerInvocationTest.java (original) +++ incubator/cxf/branches/headerwork/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerInvocationTest.java Tue May 15 07:49:20 2007 @@ -18,6 +18,7 @@ */ package org.apache.cxf.systest.handlers; + import java.io.InputStream; import java.net.URL; import java.util.ArrayList; @@ -33,6 +34,7 @@ import javax.xml.ws.LogicalMessage; import javax.xml.ws.ProtocolException; import javax.xml.ws.Service; +import javax.xml.ws.WebServiceException; import javax.xml.ws.handler.Handler; import javax.xml.ws.handler.HandlerResolver; import javax.xml.ws.handler.LogicalMessageContext; @@ -127,7 +129,7 @@ } @Test - public void testSOAPHandlerHandleMessageReturnTrueClientSide() throws Exception { + public void testSOAPHandlerHandleMessageReturnTrueClient() throws Exception { TestHandler<LogicalMessageContext> handler1 = new TestHandler<LogicalMessageContext>(false); TestHandler<LogicalMessageContext> handler2 = new TestHandler<LogicalMessageContext>(false); TestSOAPHandler soapHandler1 = new TestSOAPHandler(false); @@ -163,7 +165,7 @@ } @Test - public void testLogicalHandlerHandleMessageReturnFalseClientSide() throws Exception { + public void testLogicalHandlerHandleMessageReturnFalseClientOutBound() throws Exception { final String clientHandlerMessage = "handler2 client side"; TestHandler<LogicalMessageContext> handler1 = new TestHandler<LogicalMessageContext>(false); @@ -203,10 +205,55 @@ //assertTrue("close must be called", handler1.isCloseInvoked()); //assertTrue("close must be called", handler2.isCloseInvoked()); } + + @Test + public void testSOAPHandlerHandleMessageReturnFalseClientOutbound() throws Exception { + final String clientHandlerMessage = "client side"; + TestHandler<LogicalMessageContext> handler1 = new TestHandler<LogicalMessageContext>(false); + TestHandler<LogicalMessageContext> handler2 = new TestHandler<LogicalMessageContext>(false) { + public boolean handleMessage(LogicalMessageContext ctx) { + super.handleMessage(ctx); + try { + Boolean outbound = (Boolean)ctx.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY); + if (outbound) { + LogicalMessage msg = ctx.getMessage(); + assertNotNull("logical message is null", msg); + JAXBContext jaxbCtx = JAXBContext.newInstance(PackageUtils + .getPackageName(PingOneWay.class)); + PingResponse resp = new PingResponse(); + resp.getHandlersInfo().add(clientHandlerMessage); + + msg.setPayload(resp, jaxbCtx); + } + + } catch (Exception e) { + e.printStackTrace(); + fail(e.toString()); + } + return true; + } + }; + TestSOAPHandler soapHandler1 = new TestSOAPHandler(false); + TestSOAPHandler soapHandler2 = new TestSOAPHandler<SOAPMessageContext>(false) { + public boolean handleMessage(SOAPMessageContext ctx) { + super.handleMessage(ctx); + + return false; + } + }; + addHandlersToChain((BindingProvider)handlerTest, handler1, handler2, soapHandler1, soapHandler2); + List<String> resp = handlerTest.ping(); + assertEquals(clientHandlerMessage, resp.get(0)); + + assertEquals(2, handler1.getHandleMessageInvoked()); + assertEquals(2, handler2.getHandleMessageInvoked()); + assertEquals(1, soapHandler1.getHandleMessageInvoked()); + assertEquals(1, soapHandler2.getHandleMessageInvoked()); + } @Test - public void testLogicalHandlerHandleMessageReturnsFalseInboundServerSide() throws PingException { + public void testLogicalHandlerHandleMessageReturnsFalseServerInbound() throws PingException { String[] expectedHandlers = {"soapHandler4", "soapHandler3", "handler2", "handler2", "soapHandler3", "soapHandler4"}; @@ -221,7 +268,7 @@ } @Test - public void testSOAPHandlerHandleMessageReturnsFalseInboundServerSide() throws PingException { + public void testSOAPHandlerHandleMessageReturnsFalseServerInbound() throws PingException { String[] expectedHandlers = {"soapHandler4", "soapHandler3", "soapHandler3", "soapHandler4"}; List<String> resp = handlerTest.pingWithArgs("soapHandler3 inbound stop"); @@ -231,10 +278,9 @@ assertEquals(expected, resp.get(i++)); } } - @Test - public void testSOAPHandlerHandleMessageReturnsFalseOutboundServerSide() throws PingException { + public void testSOAPHandlerHandleMessageReturnsFalseServerOutbound() throws PingException { String[] expectedHandlers = {"soapHandler3 outbound stop", "soapHandler4", "soapHandler3", "handler2", "handler1", "handler1", "handler2", "soapHandler3"}; List<String> resp = handlerTest.pingWithArgs("soapHandler3 outbound stop"); @@ -245,10 +291,9 @@ assertEquals(expected, resp.get(i++)); } } - - @Test - public void testLogicalHandlerHandleMessageThrowsProtocolExceptionClientSide() throws Exception { + @Test + public void testLogicalHandlerHandleMessageThrowsProtocolExceptionClientOutbound() throws Exception { final String clientHandlerMessage = "handler1 client side"; TestHandler<LogicalMessageContext> handler1 = new TestHandler<LogicalMessageContext>(false); @@ -275,20 +320,8 @@ assertEquals(1, handler2.getCloseInvoked()); } - // TODO: commented out due to CXF-333 - @Test - @Ignore - public void testLogicalHandlerThrowsProtocolExceptionServerSide() throws PingException { - try { - handlerTest.pingWithArgs("handler2 inbound throw javax.xml.ws.ProtocolException"); - fail("did not get expected exception"); - } catch (ProtocolException e) { - // happy now - } - } - @Test - public void testLogicalHandlerHandleMessageThrowsRuntimeExceptionClientSide() throws Exception { + public void testLogicalHandlerHandleMessageThrowsRuntimeExceptionClientOutbound() throws Exception { final String clientHandlerMessage = "handler1 client side"; TestHandler<LogicalMessageContext> handler1 = new TestHandler<LogicalMessageContext>(false); @@ -314,57 +347,52 @@ assertEquals(1, handler1.getCloseInvoked()); assertEquals(1, handler2.getCloseInvoked()); } - + @Test - public void testSOAPHandlerHandleMessageReturnFalseOutboundClientSide() throws Exception { - final String clientHandlerMessage = "client side"; - TestHandler<LogicalMessageContext> handler1 = new TestHandler<LogicalMessageContext>(false); - TestHandler<LogicalMessageContext> handler2 = new TestHandler<LogicalMessageContext>(false) { - public boolean handleMessage(LogicalMessageContext ctx) { - super.handleMessage(ctx); - try { - Boolean outbound = (Boolean)ctx.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY); - if (outbound) { - LogicalMessage msg = ctx.getMessage(); - assertNotNull("logical message is null", msg); - JAXBContext jaxbCtx = JAXBContext.newInstance(PackageUtils - .getPackageName(PingOneWay.class)); - PingResponse resp = new PingResponse(); - resp.getHandlersInfo().add(clientHandlerMessage); - - msg.setPayload(resp, jaxbCtx); - } - - } catch (Exception e) { - e.printStackTrace(); - fail(e.toString()); - } - return true; - } - }; - TestSOAPHandler soapHandler1 = new TestSOAPHandler(false); - TestSOAPHandler soapHandler2 = new TestSOAPHandler<SOAPMessageContext>(false) { - public boolean handleMessage(SOAPMessageContext ctx) { - super.handleMessage(ctx); - - return false; - } - }; - addHandlersToChain((BindingProvider)handlerTest, handler1, handler2, soapHandler1, soapHandler2); - - List<String> resp = handlerTest.ping(); - assertEquals(clientHandlerMessage, resp.get(0)); - - assertEquals(2, handler1.getHandleMessageInvoked()); - assertEquals(2, handler2.getHandleMessageInvoked()); - assertEquals(1, soapHandler1.getHandleMessageInvoked()); - assertEquals(1, soapHandler2.getHandleMessageInvoked()); + public void testSOAPHandlerHandleMessageThrowsRuntimeExceptionServerInbound() throws PingException { + try { + handlerTest.pingWithArgs("soapHandler3 inbound throw RuntimeException"); + fail("did not get expected exception"); + } catch (RuntimeException e) { + //FIXME + //e.printStackTrace(); +/* assertTrue("Did not get expected exception message", e.getMessage() + .indexOf("HandleMessage throws runtime exception") > -1);*/ + } + } + + @Test + public void testSOAPHandlerHandleMessageThrowsProtocolExceptionServerInbound() throws PingException { + try { + handlerTest.pingWithArgs("soapHandler3 inbound throw ProtocolException"); + fail("did not get expected WebServiceException"); + } catch (WebServiceException e) { + //FIXME +/* ByteArrayOutputStream baos = new ByteArrayOutputStream(); + PrintStream ps = new PrintStream(baos, true); + e.printStackTrace(ps); + assertTrue("Did not get expected exception message", baos.toString() + .indexOf("HandleMessage throws runtime exception") > -1); + assertTrue("Did not get expected javax.xml.ws.soap.SOAPFaultException", baos.toString() + .indexOf("javax.xml.ws.soap.SOAPFaultException") > -1);*/ + } } @Test @Ignore + public void testLogicalHandlerHandleMessageThrowsProtocolExceptionServerInbound() + throws PingException { + try { + handlerTest.pingWithArgs("handler2 inbound throw ProtocolException"); + fail("did not get expected exception"); + } catch (WebServiceException e) { + assertTrue(e.getMessage().indexOf("HandleMessage throws ProtocolException exception") >= 0); + } + } + + @Test + @Ignore public void testLogicalHandlerHandlerFaultServerSide() { - TestHandler<LogicalMessageContext> handler1 = new TestHandler<LogicalMessageContext>(false); TestHandler<LogicalMessageContext> handler2 = new TestHandler<LogicalMessageContext>(false); addHandlersToChain((BindingProvider)handlerTest, handler1, handler2);
Modified: incubator/cxf/branches/headerwork/systests/src/test/java/org/apache/cxf/systest/handlers/TestHandler.java URL: http://svn.apache.org/viewvc/incubator/cxf/branches/headerwork/systests/src/test/java/org/apache/cxf/systest/handlers/TestHandler.java?view=diff&rev=538192&r1=538191&r2=538192 ============================================================================== --- incubator/cxf/branches/headerwork/systests/src/test/java/org/apache/cxf/systest/handlers/TestHandler.java (original) +++ incubator/cxf/branches/headerwork/systests/src/test/java/org/apache/cxf/systest/handlers/TestHandler.java Tue May 15 07:49:20 2007 @@ -103,35 +103,51 @@ String arg = ((PingWithArgs)payload).getHandlersCommand(); 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 (outbound) { - return ret; + if (!getHandlerId().equals(hid)) { + return true; } - - if (getHandlerId().equals(hid) - && "inbound".equals(direction)) { - - if ("stop".equals(command)) { + + if ("stop".equals(command)) { + if (!outbound && "inbound".equals(direction)) { PingResponse resp = new PingResponse(); resp.getHandlersInfo().addAll(getHandlerInfoList(ctx)); msg.setPayload(resp, jaxbCtx); ret = false; - } else if ("throw".equals(command)) { - throwException(strtok.nextToken()); + } else if (outbound && "outbound".equals(direction)) { + ret = false; + } + } else if ("throw".equals(command)) { + String exceptionType = null; + if (strtok.hasMoreTokens()) { + exceptionType = strtok.nextToken(); } + if (exceptionType != null && !outbound && "inbound".equals(direction)) { + if ("RuntimeException".equals(exceptionType)) { + throw new RuntimeException("HandleMessage throws runtime exception"); + } else if ("ProtocolException".equals(exceptionType)) { + throw new ProtocolException("HandleMessage throws ProtocolException exception"); + } + } else if (exceptionType != null && outbound && "outbound".equals(direction)) { + if ("RuntimeException".equals(exceptionType)) { + throw new RuntimeException("HandleMessage throws RuntimeException exception"); + } else if ("ProtocolException".equals(exceptionType)) { + throw new ProtocolException("HandleMessage throws ProtocolException exception"); + } + } + } } - return ret; - } - - private void throwException(String exType) { - if (exType.contains("ProtocolException")) { - throw new ProtocolException("from server handler"); - } + return ret; } private boolean handlePingMessage(boolean outbound, T ctx) { Modified: incubator/cxf/branches/headerwork/systests/src/test/java/org/apache/cxf/systest/handlers/TestSOAPHandler.java URL: http://svn.apache.org/viewvc/incubator/cxf/branches/headerwork/systests/src/test/java/org/apache/cxf/systest/handlers/TestSOAPHandler.java?view=diff&rev=538192&r1=538191&r2=538192 ============================================================================== --- incubator/cxf/branches/headerwork/systests/src/test/java/org/apache/cxf/systest/handlers/TestSOAPHandler.java (original) +++ incubator/cxf/branches/headerwork/systests/src/test/java/org/apache/cxf/systest/handlers/TestSOAPHandler.java Tue May 15 07:49:20 2007 @@ -25,7 +25,9 @@ import javax.xml.namespace.QName; import javax.xml.soap.SOAPBody; +import javax.xml.soap.SOAPException; import javax.xml.soap.SOAPMessage; +import javax.xml.ws.ProtocolException; import javax.xml.ws.handler.MessageContext; import javax.xml.ws.handler.soap.SOAPHandler; import javax.xml.ws.handler.soap.SOAPMessageContext; @@ -108,7 +110,7 @@ getHandlerInfoList(ctx).add(getHandlerId()); } } - } catch (Exception e) { + } catch (SOAPException e) { e.printStackTrace(); } return continueProcessing; @@ -151,13 +153,17 @@ String hid = ""; String direction = ""; String command = ""; - if (strtok.countTokens() == 3) { + if (strtok.countTokens() >= 3) { hid = strtok.nextToken(); direction = strtok.nextToken(); command = strtok.nextToken(); } - if (getHandlerId().equals(hid) && "stop".equals(command)) { + if (!getHandlerId().equals(hid)) { + return true; + } + + if ("stop".equals(command)) { if (!outbound && "inbound".equals(direction)) { // remove the incoming request body. Document doc = body.getOwnerDocument(); @@ -183,9 +189,28 @@ } else if (outbound && "outbound".equals(direction)) { ret = false; } - } + } else if ("throw".equals(command)) { + String exceptionType = null; + if (strtok.hasMoreTokens()) { + exceptionType = strtok.nextToken(); + } + if (exceptionType != null && !outbound && "inbound".equals(direction)) { + if ("RuntimeException".equals(exceptionType)) { + throw new RuntimeException("HandleMessage throws runtime exception"); + } else if ("ProtocolException".equals(exceptionType)) { + throw new ProtocolException("HandleMessage throws runtime exception"); + } + } else if (exceptionType != null && outbound && "outbound".equals(direction)) { + if ("RuntimeException".equals(exceptionType)) { + throw new RuntimeException("HandleMessage throws ProtocolException exception"); + } else if ("ProtocolException".equals(exceptionType)) { + throw new ProtocolException("HandleMessage throws ProtocolException exception"); + } + } + + } - } catch (Exception e) { + } catch (SOAPException e) { e.printStackTrace(); } Modified: incubator/cxf/branches/headerwork/systests/src/test/java/org/apache/cxf/systest/interceptor/InterceptorFaultTest.java URL: http://svn.apache.org/viewvc/incubator/cxf/branches/headerwork/systests/src/test/java/org/apache/cxf/systest/interceptor/InterceptorFaultTest.java?view=diff&rev=538192&r1=538191&r2=538192 ============================================================================== --- incubator/cxf/branches/headerwork/systests/src/test/java/org/apache/cxf/systest/interceptor/InterceptorFaultTest.java (original) +++ incubator/cxf/branches/headerwork/systests/src/test/java/org/apache/cxf/systest/interceptor/InterceptorFaultTest.java Tue May 15 07:49:20 2007 @@ -267,7 +267,6 @@ SoapFault sf = (SoapFault)cause; assertEquals(expectedMsg, sf.getReason()); assertEquals(SOAP_FAULT_CODE, sf.getFaultCode()); - assertNull(sf.getDetail()); } try { @@ -278,7 +277,6 @@ SoapFault sf = (SoapFault)cause; assertEquals(expectedMsg, sf.getReason()); assertEquals(SOAP_FAULT_CODE, sf.getFaultCode()); - assertNull(sf.getDetail()); } } Modified: incubator/cxf/branches/headerwork/testutils/pom.xml URL: http://svn.apache.org/viewvc/incubator/cxf/branches/headerwork/testutils/pom.xml?view=diff&rev=538192&r1=538191&r2=538192 ============================================================================== --- incubator/cxf/branches/headerwork/testutils/pom.xml (original) +++ incubator/cxf/branches/headerwork/testutils/pom.xml Tue May 15 07:49:20 2007 @@ -328,6 +328,11 @@ <wsdlOption> <wsdl>${basedir}/src/main/resources/wsdl/factory_pattern.wsdl</wsdl> </wsdlOption> + <!-- will be removed--> + <wsdlOption> + <wsdl>${basedir}/src/main/resources/wsdl/test_chars.wsdl</wsdl> + </wsdlOption> + </wsdlOptions> </configuration> <goals> Modified: incubator/cxf/branches/headerwork/tools/javato/src/main/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/FaultBeanGenerator.java URL: http://svn.apache.org/viewvc/incubator/cxf/branches/headerwork/tools/javato/src/main/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/FaultBeanGenerator.java?view=diff&rev=538192&r1=538191&r2=538192 ============================================================================== --- incubator/cxf/branches/headerwork/tools/javato/src/main/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/FaultBeanGenerator.java (original) +++ incubator/cxf/branches/headerwork/tools/javato/src/main/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/FaultBeanGenerator.java Tue May 15 07:49:20 2007 @@ -21,6 +21,7 @@ import java.lang.reflect.Method; import java.rmi.RemoteException; +import java.rmi.ServerException; import java.util.Collection; import java.util.HashSet; import java.util.Set; @@ -68,7 +69,8 @@ || Fault.class.isAssignableFrom(exClazz) || exClazz.equals(RuntimeException.class) || exClazz.equals(Throwable.class) - || exClazz.equals(RemoteException.class)) { + || exClazz.equals(RemoteException.class) + || exClazz.equals(ServerException.class)) { continue; } Modified: incubator/cxf/branches/headerwork/tools/javato/src/main/java/org/apache/cxf/tools/java2wsdl/processor/JavaToProcessor.java URL: http://svn.apache.org/viewvc/incubator/cxf/branches/headerwork/tools/javato/src/main/java/org/apache/cxf/tools/java2wsdl/processor/JavaToProcessor.java?view=diff&rev=538192&r1=538191&r2=538192 ============================================================================== --- incubator/cxf/branches/headerwork/tools/javato/src/main/java/org/apache/cxf/tools/java2wsdl/processor/JavaToProcessor.java (original) +++ incubator/cxf/branches/headerwork/tools/javato/src/main/java/org/apache/cxf/tools/java2wsdl/processor/JavaToProcessor.java Tue May 15 07:49:20 2007 @@ -46,6 +46,7 @@ import org.apache.cxf.tools.common.WSDLConstants; import org.apache.cxf.tools.java2wsdl.generator.AbstractGenerator; import org.apache.cxf.tools.java2wsdl.generator.WSDLGeneratorFactory; +import org.apache.cxf.tools.java2wsdl.generator.wsdl11.FaultBeanGenerator; import org.apache.cxf.tools.java2wsdl.generator.wsdl11.WrapperBeanGenerator; import org.apache.cxf.tools.java2wsdl.processor.internal.ServiceBuilder; import org.apache.cxf.tools.java2wsdl.processor.internal.ServiceBuilderFactory; @@ -84,12 +85,20 @@ generators.add(getWSDLGenerator(wsdlFile)); generators.add(getWrapperBeanGenerator()); + generators.add(getFaultBeanGenerator()); generate(service, outputDir); } private AbstractGenerator getWrapperBeanGenerator() { WrapperBeanGenerator generator = new WrapperBeanGenerator(); + generator.setOutputBase(getSourceDir()); + generator.setCompileToDir(getClassesDir()); + return generator; + } + + private AbstractGenerator getFaultBeanGenerator() { + FaultBeanGenerator generator = new FaultBeanGenerator(); generator.setOutputBase(getSourceDir()); generator.setCompileToDir(getClassesDir()); return generator; Modified: incubator/cxf/branches/headerwork/tools/javato/src/test/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/expected/soap_header.wsdl URL: http://svn.apache.org/viewvc/incubator/cxf/branches/headerwork/tools/javato/src/test/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/expected/soap_header.wsdl?view=diff&rev=538192&r1=538191&r2=538192 ============================================================================== --- incubator/cxf/branches/headerwork/tools/javato/src/test/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/expected/soap_header.wsdl (original) +++ incubator/cxf/branches/headerwork/tools/javato/src/test/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/expected/soap_header.wsdl Tue May 15 07:49:20 2007 @@ -19,7 +19,7 @@ <?xml version="1.0" encoding="UTF-8"?> <wsdl:definitions name="HeaderTesterService" targetNamespace="http://apache.org/samples/headers" xmlns:ns1="http://apache.org/samples/headers" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"> <wsdl:types> -<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://apache.org/samples/headers" attributeFormDefault="unqualified" elementFormDefault="unqualified" targetNamespace="http://apache.org/samples/headers"> +<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://apache.org/samples/headers" targetNamespace="http://apache.org/samples/headers" version="1.0"> <xs:element name="SOAPHeaderInfo" nillable="true" type="tns:SOAPHeaderData"/> <xs:element name="inHeader"> <xs:complexType> @@ -69,12 +69,6 @@ <xs:element name="message" type="xs:string"/> </xs:sequence> </xs:complexType> -<xs:element nillable="true" ref="tns:outHeader"/> -<xs:element nillable="true" ref="tns:outHeaderResponse"/> -<xs:element nillable="true" ref="tns:inHeader"/> -<xs:element nillable="true" ref="tns:inHeaderResponse"/> -<xs:element nillable="true" ref="tns:inoutHeader"/> -<xs:element nillable="true" ref="tns:inoutHeaderResponse"/> </xs:schema> </wsdl:types> <wsdl:message name="inHeaderResponse">
