You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by gd...@apache.org on 2002/09/25 23:29:00 UTC
cvs commit: xml-axis/java/test/soap TestFaultHandler.java TestOnFaultHeaders.java PackageTests.java TestHandler.java TestHeaderAttrs.java TestService.java
gdaniels 2002/09/25 14:29:00
Modified: java/src/org/apache/axis SimpleChain.java
java/src/org/apache/axis/providers/java JavaProvider.java
java/src/org/apache/axis/transport/http AxisServlet.java
java/test/soap PackageTests.java TestHandler.java
TestHeaderAttrs.java TestService.java
Added: java/test/soap TestFaultHandler.java TestOnFaultHeaders.java
Log:
Fix for http://nagoya.apache.org/bugzilla/show_bug.cgi?id=10944
We now take pains to preserve the response message once it has been
set to a fault. This allows onFault() methods to change things, add
headers, etc. and have them propagated back to the client.
Revision Changes Path
1.55 +15 -4 xml-axis/java/src/org/apache/axis/SimpleChain.java
Index: SimpleChain.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/SimpleChain.java,v
retrieving revision 1.54
retrieving revision 1.55
diff -u -r1.54 -r1.55
--- SimpleChain.java 18 Sep 2002 16:10:31 -0000 1.54
+++ SimpleChain.java 25 Sep 2002 21:28:59 -0000 1.55
@@ -92,6 +92,9 @@
protected Vector handlers = new Vector();
protected boolean invoked = false;
+
+ private String CAUGHTFAULT_PROPERTY =
+ "org.apache.axis.SimpleChain.caughtFaultInResponse";
public void init() {
for ( int i = 0 ; i < handlers.size() ; i++ )
@@ -154,10 +157,18 @@
i++;
}
} catch( AxisFault f ) {
- // Attach the fault to the response message; enabling access to the
- // fault details while inside the handler onFault methods.
- Message respMsg = new Message(f);
- msgContext.setResponseMessage(respMsg);
+ // Something went wrong. If we haven't already put this fault
+ // into the MessageContext's response message, do so and make sure
+ // we only do it once. This allows onFault() methods to safely
+ // set headers and such in the response message without them
+ // getting stomped.
+ if (!msgContext.isPropertyTrue(CAUGHTFAULT_PROPERTY)) {
+ // Attach the fault to the response message; enabling access to the
+ // fault details while inside the handler onFault methods.
+ Message respMsg = new Message(f);
+ msgContext.setResponseMessage(respMsg);
+ msgContext.setProperty(CAUGHTFAULT_PROPERTY, Boolean.TRUE);
+ }
while( --i >= 0 )
((Handler) handlers.elementAt( i )).onFault( msgContext );
throw f;
1.82 +0 -1 xml-axis/java/src/org/apache/axis/providers/java/JavaProvider.java
Index: JavaProvider.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/providers/java/JavaProvider.java,v
retrieving revision 1.81
retrieving revision 1.82
diff -u -r1.81 -r1.82
--- JavaProvider.java 25 Sep 2002 20:16:05 -0000 1.81
+++ JavaProvider.java 25 Sep 2002 21:28:59 -0000 1.82
@@ -70,7 +70,6 @@
import org.apache.axis.message.SOAPEnvelope;
import org.apache.axis.providers.BasicProvider;
import org.apache.axis.utils.ClassUtils;
-import org.apache.axis.utils.JavaUtils;
import org.apache.axis.utils.Messages;
import org.apache.axis.utils.cache.ClassCache;
import org.apache.axis.utils.cache.JavaClass;
1.146 +9 -3 xml-axis/java/src/org/apache/axis/transport/http/AxisServlet.java
Index: AxisServlet.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/transport/http/AxisServlet.java,v
retrieving revision 1.145
retrieving revision 1.146
diff -u -r1.145 -r1.146
--- AxisServlet.java 25 Sep 2002 20:54:36 -0000 1.145
+++ AxisServlet.java 25 Sep 2002 21:28:59 -0000 1.146
@@ -705,17 +705,23 @@
res.setHeader("WWW-Authenticate","Basic realm=\"AXIS\"");
// TODO: less generic realm choice?
res.setStatus(status);
- responseMsg = new Message(e);
+ responseMsg = msgContext.getResponseMessage();
+ if (responseMsg == null)
+ responseMsg = new Message(e);
contentType = responseMsg.getContentType(msgContext.getSOAPConstants());
} catch (Exception e) {
log.error(Messages.getMessage("exception00"), e);
res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
- responseMsg = new Message(AxisFault.makeFault(e));
+ responseMsg = msgContext.getResponseMessage();
+ if (responseMsg == null)
+ responseMsg = new Message(AxisFault.makeFault(e));
contentType = responseMsg.getContentType(msgContext.getSOAPConstants());
}
} catch (AxisFault fault) {
log.error(Messages.getMessage("axisFault00"), fault);
- responseMsg = new Message(fault);
+ responseMsg = msgContext.getResponseMessage();
+ if (responseMsg == null)
+ responseMsg = new Message(fault);
contentType = responseMsg.getContentType(msgContext.getSOAPConstants());
}
if( tlog.isDebugEnabled() ) {
1.3 +55 -0 xml-axis/java/test/soap/PackageTests.java
Index: PackageTests.java
===================================================================
RCS file: /home/cvs/xml-axis/java/test/soap/PackageTests.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- PackageTests.java 2 Apr 2002 22:05:19 -0000 1.2
+++ PackageTests.java 25 Sep 2002 21:28:59 -0000 1.3
@@ -1,3 +1,57 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Axis" and "Apache Software Foundation" must
+ * not be used to endorse or promote products derived from this
+ * software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * nor may "Apache" appear in their name, without prior written
+ * permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
package test.soap;
import junit.framework.Test;
@@ -16,6 +70,7 @@
TestSuite suite = new TestSuite("All axis.soap tests");
suite.addTest(TestHeaderAttrs.suite());
+ suite.addTestSuite(TestOnFaultHeaders.class);
return suite;
}
1.2 +69 -6 xml-axis/java/test/soap/TestHandler.java
Index: TestHandler.java
===================================================================
RCS file: /home/cvs/xml-axis/java/test/soap/TestHandler.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TestHandler.java 14 Jan 2002 21:17:47 -0000 1.1
+++ TestHandler.java 25 Sep 2002 21:28:59 -0000 1.2
@@ -1,10 +1,56 @@
/*
- * Created by IntelliJ IDEA.
- * User: gdaniels
- * Date: Jan 14, 2002
- * Time: 2:13:08 PM
- * To change template for new class use
- * Code Style | Class Templates options (Tools | IDE Options).
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Axis" and "Apache Software Foundation" must
+ * not be used to endorse or promote products derived from this
+ * software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * nor may "Apache" appear in their name, without prior written
+ * permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
*/
package test.soap;
@@ -12,6 +58,7 @@
import org.apache.axis.MessageContext;
import org.apache.axis.AxisFault;
import org.apache.axis.message.SOAPEnvelope;
+import org.apache.axis.message.SOAPHeaderElement;
/**
* This is a test Handler which interacts with the TestService below in
@@ -28,6 +75,22 @@
// Just the header's presence is enough - mark the property
// so it can be picked up by the service (see below)
msgContext.setProperty(TestHeaderAttrs.PROP_DOUBLEIT, Boolean.TRUE);
+ }
+
+ if (env.getHeaderByName(TestOnFaultHeaders.TRIGGER_NS,
+ TestOnFaultHeaders.TRIGGER_NAME) != null) {
+ // Fault trigger header is there, so throw an Exception
+ throw new AxisFault("triggered exception");
+ }
+ }
+
+ public void onFault(MessageContext msgContext) {
+ try {
+ SOAPEnvelope env = msgContext.getResponseMessage().getSOAPEnvelope();
+ SOAPHeaderElement header = new SOAPHeaderElement("ns", "local", "val");
+ env.addHeader(header);
+ } catch (Exception e) {
+ throw new RuntimeException("Exception during onFault processing");
}
}
}
1.7 +55 -0 xml-axis/java/test/soap/TestHeaderAttrs.java
Index: TestHeaderAttrs.java
===================================================================
RCS file: /home/cvs/xml-axis/java/test/soap/TestHeaderAttrs.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- TestHeaderAttrs.java 10 Jul 2002 19:32:13 -0000 1.6
+++ TestHeaderAttrs.java 25 Sep 2002 21:28:59 -0000 1.7
@@ -1,3 +1,58 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Axis" and "Apache Software Foundation" must
+ * not be used to endorse or promote products derived from this
+ * software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * nor may "Apache" appear in their name, without prior written
+ * permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+
package test.soap;
import junit.framework.TestCase;
1.2 +52 -6 xml-axis/java/test/soap/TestService.java
Index: TestService.java
===================================================================
RCS file: /home/cvs/xml-axis/java/test/soap/TestService.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TestService.java 14 Jan 2002 21:17:47 -0000 1.1
+++ TestService.java 25 Sep 2002 21:28:59 -0000 1.2
@@ -1,10 +1,56 @@
/*
- * Created by IntelliJ IDEA.
- * User: gdaniels
- * Date: Jan 14, 2002
- * Time: 2:12:43 PM
- * To change template for new class use
- * Code Style | Class Templates options (Tools | IDE Options).
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Axis" and "Apache Software Foundation" must
+ * not be used to endorse or promote products derived from this
+ * software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * nor may "Apache" appear in their name, without prior written
+ * permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
*/
package test.soap;
1.1 xml-axis/java/test/soap/TestFaultHandler.java
Index: TestFaultHandler.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Axis" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package test.soap;
import org.apache.axis.handlers.BasicHandler;
import org.apache.axis.MessageContext;
import org.apache.axis.AxisFault;
import org.apache.axis.message.SOAPEnvelope;
import org.apache.axis.message.SOAPHeaderElement;
/**
* This is a test Handler which interacts with the TestService below in
* order to test header processing. This one runs before the TestHandler,
* so when the TestHandler throws an Exception (triggered by a particular
* header being sent from TestOnFaultHeaders), the onFault() method gets
* called. In there, we get the response message and add a header to it.
* This header gets picked up by the client, who checks that it looks right
* and has successfully propagated from here to the top of the call stack.
*
* @author Glen Daniels (gdaniels@apache.org)
*/
public class TestFaultHandler extends BasicHandler {
public void invoke(MessageContext msgContext) throws AxisFault {
}
public void onFault(MessageContext msgContext) {
try {
SOAPEnvelope env = msgContext.getResponseMessage().getSOAPEnvelope();
SOAPHeaderElement header = new SOAPHeaderElement(
TestOnFaultHeaders.TRIGGER_NS,
TestOnFaultHeaders.RESP_NAME,
"here's the value"
);
env.addHeader(header);
} catch (Exception e) {
throw new RuntimeException("Exception during onFault processing");
}
}
}
1.1 xml-axis/java/test/soap/TestOnFaultHeaders.java
Index: TestOnFaultHeaders.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Axis" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package test.soap;
import org.apache.axis.handlers.soap.SOAPService;
import org.apache.axis.providers.java.RPCProvider;
import org.apache.axis.configuration.SimpleProvider;
import org.apache.axis.server.AxisServer;
import org.apache.axis.transport.local.LocalTransport;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.message.SOAPHeaderElement;
import org.apache.axis.message.SOAPEnvelope;
import org.apache.axis.SimpleChain;
import junit.framework.TestCase;
import java.util.Vector;
/**
* Confirm OnFault() header processing + additions work right.
*
* @author Glen Daniels (gdaniels@apache.org)
*/
public class TestOnFaultHeaders extends TestCase {
public static String TRIGGER_NS = "http://trigger-fault";
public static String TRIGGER_NAME = "faultPlease";
public static String RESP_NAME = "okHeresYourFault";
private SimpleProvider provider = new SimpleProvider();
private AxisServer engine = new AxisServer(provider);
private LocalTransport localTransport = new LocalTransport(engine);
static final String localURL = "local:///testService";
public TestOnFaultHeaders(String s) {
super(s);
}
public void setUp() throws Exception {
engine.init();
localTransport.setUrl(localURL);
SimpleChain chain = new SimpleChain();
chain.addHandler(new TestFaultHandler());
chain.addHandler(new TestHandler());
SOAPService service = new SOAPService(chain,
new RPCProvider(),
null);
service.setOption("className", TestService.class.getName());
service.setOption("allowedMethods", "*");
provider.deployService("testService", service);
}
/**
* Add a header which will trigger a fault in the TestHandler, and
* therefore trigger the onFault() in the TestFaultHandler. That should
* put a header in the outgoing message, which we check for when we get
* the fault.
*
* @throws Exception
*/
public void testOnFaultHeaders() throws Exception {
Call call = new Call(new Service());
call.setTransport(localTransport);
SOAPHeaderElement header = new SOAPHeaderElement(TRIGGER_NS,
TRIGGER_NAME,
"do it");
call.addHeader(header);
try {
call.invoke("countChars", new Object [] { "foo" });
} catch (Exception e) {
SOAPEnvelope env = call.getResponseMessage().getSOAPEnvelope();
Vector headers = env.getHeaders();
assertEquals("Wrong # of headers in fault!", 1, headers.size());
SOAPHeaderElement respHeader = (SOAPHeaderElement)headers.get(0);
assertEquals("Wrong namespace for header", TRIGGER_NS,
respHeader.getNamespaceURI());
assertEquals("Wrong localName for response header", RESP_NAME,
respHeader.getName());
return;
}
fail("We should have gotten a fault!");
}
}