You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by he...@apache.org on 2004/12/09 05:40:37 UTC
svn commit: r111349 - in webservices/axis/trunk/java/dev/scratch/prototype2/src: java/org/apache/axis/client test/org/apache/axis/engine
Author: hemapani
Date: Wed Dec 8 20:40:36 2004
New Revision: 111349
URL: http://svn.apache.org/viewcvs?view=rev&rev=111349
Log:
add a test case to test the handler faliure
Added:
webservices/axis/trunk/java/dev/scratch/prototype2/src/test/org/apache/axis/engine/HandlerFaliureTest.java
Modified:
webservices/axis/trunk/java/dev/scratch/prototype2/src/java/org/apache/axis/client/Call.java
webservices/axis/trunk/java/dev/scratch/prototype2/src/test/org/apache/axis/engine/EngineUtils.java
Modified: webservices/axis/trunk/java/dev/scratch/prototype2/src/java/org/apache/axis/client/Call.java
Url: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/dev/scratch/prototype2/src/java/org/apache/axis/client/Call.java?view=diff&rev=111349&p1=webservices/axis/trunk/java/dev/scratch/prototype2/src/java/org/apache/axis/client/Call.java&r1=111348&p2=webservices/axis/trunk/java/dev/scratch/prototype2/src/java/org/apache/axis/client/Call.java&r2=111349
==============================================================================
--- webservices/axis/trunk/java/dev/scratch/prototype2/src/java/org/apache/axis/client/Call.java (original)
+++ webservices/axis/trunk/java/dev/scratch/prototype2/src/java/org/apache/axis/client/Call.java Wed Dec 8 20:40:36 2004
@@ -42,12 +42,15 @@
import org.apache.axis.om.OMFactory;
import org.apache.axis.om.OMNamespace;
import org.apache.axis.om.OMNode;
+import org.apache.axis.om.OMText;
import org.apache.axis.om.SOAPBody;
import org.apache.axis.om.SOAPEnvelope;
import org.apache.axis.om.SOAPFault;
import org.apache.axis.registry.EngineRegistry;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.crimson.tree.TextNode;
+
/**
* This is conveneice API for the User who do not need to see the complexity of the
@@ -99,8 +102,18 @@
OMNamespace ns = element.getNamespace();
if(OMConstants.SOAPFAULT_LOCAL_NAME.equals(element.getLocalName())
&& OMConstants.SOAPFAULT_NAMESPACE_URI.equals(ns.getValue())){
- //TODO handle this better
- throw new AxisFault(element.getValue());
+ Iterator it = element.getChildren();
+ String error = null;
+ while(it.hasNext()){
+ OMNode node = (OMNode)it.next();
+ if(OMNode.TEXT_NODE == node.getType()){
+ error = ((OMText)node).getValue();
+ if(error != null){
+ break;
+ }
+ }
+ }
+ throw new AxisFault(error);
}
return (OMElement)child;
}
Modified: webservices/axis/trunk/java/dev/scratch/prototype2/src/test/org/apache/axis/engine/EngineUtils.java
Url: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/dev/scratch/prototype2/src/test/org/apache/axis/engine/EngineUtils.java?view=diff&rev=111349&p1=webservices/axis/trunk/java/dev/scratch/prototype2/src/test/org/apache/axis/engine/EngineUtils.java&r1=111348&p2=webservices/axis/trunk/java/dev/scratch/prototype2/src/test/org/apache/axis/engine/EngineUtils.java&r2=111349
==============================================================================
--- webservices/axis/trunk/java/dev/scratch/prototype2/src/test/org/apache/axis/engine/EngineUtils.java (original)
+++ webservices/axis/trunk/java/dev/scratch/prototype2/src/test/org/apache/axis/engine/EngineUtils.java Wed Dec 8 20:40:36 2004
@@ -15,12 +15,20 @@
*/
package org.apache.axis.engine;
+import java.io.IOException;
+import java.net.ServerSocket;
+
+import org.apache.axis.impl.transport.http.SimpleAxisServer;
+import org.apache.axis.registry.EngineRegistry;
import org.apache.axis.registry.Flow;
/**
* @author Srinath Perera (hemapani@opensource.lk)
*/
public class EngineUtils {
+ public static final int TESTING_PORT = 7777;
+ public static final String FAILURE_MESSAGE = "Intentional Faliure";
+
public static void addHandlers(Flow flow,ExecutionChain exeChain,String phaseName) throws AxisFault{
if(flow != null){
int handlerCount = flow.getHandlerCount();
@@ -29,4 +37,16 @@
}
}
}
+
+ public static SimpleAxisServer startServer(EngineRegistry engineRegistry) throws IOException{
+ AxisEngine engine = new AxisEngine(engineRegistry);
+ ServerSocket serverSoc = new ServerSocket(TESTING_PORT);
+ SimpleAxisServer sas = new SimpleAxisServer(engine);
+ sas.setServerSocket(serverSoc);
+ Thread thisThread = new Thread(sas);
+ thisThread.setDaemon(true);
+ thisThread.start();
+ return sas;
+ }
+
}
Added: webservices/axis/trunk/java/dev/scratch/prototype2/src/test/org/apache/axis/engine/HandlerFaliureTest.java
Url: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/dev/scratch/prototype2/src/test/org/apache/axis/engine/HandlerFaliureTest.java?view=auto&rev=111349
==============================================================================
--- (empty file)
+++ webservices/axis/trunk/java/dev/scratch/prototype2/src/test/org/apache/axis/engine/HandlerFaliureTest.java Wed Dec 8 20:40:36 2004
@@ -0,0 +1,201 @@
+/*
+ * Copyright 2003,2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.axis.engine;
+
+//todo
+import java.net.URL;
+
+import javax.xml.namespace.QName;
+
+import org.apache.axis.AbstractTestCase;
+import org.apache.axis.client.Call;
+import org.apache.axis.context.MessageContext;
+import org.apache.axis.impl.engine.OperationImpl;
+import org.apache.axis.impl.engine.ServiceImpl;
+import org.apache.axis.impl.handlers.AbstractHandler;
+import org.apache.axis.impl.providers.RawXMLProvider;
+import org.apache.axis.impl.registry.FlowImpl;
+import org.apache.axis.impl.registry.ParameterImpl;
+import org.apache.axis.impl.transport.http.SimpleAxisServer;
+import org.apache.axis.om.OMElement;
+import org.apache.axis.om.OMFactory;
+import org.apache.axis.om.OMNamespace;
+import org.apache.axis.registry.EngineRegistry;
+import org.apache.axis.registry.Flow;
+import org.apache.axis.registry.Operation;
+import org.apache.axis.registry.Parameter;
+import org.apache.axis.registry.Service;
+import org.apache.axis.registry.SpeakingHandler;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * @author Srinath Perera(hemapani@opensource.lk)
+ */
+public class HandlerFaliureTest extends AbstractTestCase{
+ private Log log = LogFactory.getLog(getClass());
+ private QName serviceName = new QName("","EchoXMLService");
+ private QName operationName = new QName("http://localhost/my","echoOMElement");
+ private QName transportName = new QName("http://localhost/my","NullTransport");
+
+ private EngineRegistry engineRegistry;
+ private MessageContext mc;
+ private Thread thisThread = null;
+ private SimpleAxisServer sas;
+ private int testingPort = 7777;
+ private int testCount = 0;
+
+ public HandlerFaliureTest(){
+ super(HandlerFaliureTest.class.getName());
+ }
+
+ public HandlerFaliureTest(String testName) {
+ super(testName);
+ }
+
+ protected void setUp() throws Exception {
+ engineRegistry = Utils.createMockRegistry(serviceName,operationName,transportName);
+ }
+
+
+ public void testFailureAtServerRequestFlow() throws Exception{
+ Service service = new ServiceImpl(serviceName);
+
+ Flow flow = new FlowImpl();
+ flow.addHandler(new SpeakingHandler());
+ flow.addHandler(new SpeakingHandler());
+ flow.addHandler(new SpeakingHandler());
+ flow.addHandler(new SpeakingHandler());
+ flow.addHandler(culprit);
+ flow.addHandler(new SpeakingHandler());
+ service.setInFlow(flow);
+
+ service.setClassLoader(Thread.currentThread().getContextClassLoader());
+ Parameter classParam = new ParameterImpl("className",EchoXML.class.getName());
+ service.addParameter(classParam);
+ service.setProvider(new RawXMLProvider());
+ Operation operation = new OperationImpl(operationName,service);
+
+ service.addOperation(operation);
+
+ ExecutionChain inchain = new ExecutionChain();
+ inchain.addPhase(new Phase(Constants.PHASE_SERVICE));
+ EngineUtils.addHandlers(service.getInFlow(),inchain,Constants.PHASE_SERVICE);
+ service.setInputExecutionChain(inchain);
+
+ ExecutionChain outchain = new ExecutionChain();
+ outchain.addPhase(new Phase(Constants.PHASE_SERVICE));
+ EngineUtils.addHandlers(service.getOutFlow(),outchain,Constants.PHASE_SERVICE);
+ service.setOutExecutionChain(outchain);
+
+ ExecutionChain faultchain = new ExecutionChain();
+
+ faultchain.addPhase(new Phase(Constants.PHASE_SERVICE));
+
+ EngineUtils.addHandlers(service.getFaultFlow(),faultchain,Constants.PHASE_SERVICE);
+ service.setFaultExecutionChain(outchain);
+ engineRegistry.addService(service);
+ sas = EngineUtils.startServer(engineRegistry);
+ callTheService();
+ }
+
+ public void testFailureAtServerResponseFlow() throws Exception{
+ Service service = new ServiceImpl(serviceName);
+
+ Flow flow = new FlowImpl();
+ flow.addHandler(new SpeakingHandler());
+ flow.addHandler(new SpeakingHandler());
+ flow.addHandler(new SpeakingHandler());
+ flow.addHandler(new SpeakingHandler());
+ flow.addHandler(new SpeakingHandler());
+ service.setInFlow(flow);
+
+
+ flow = new FlowImpl();
+ flow.addHandler(new SpeakingHandler());
+ flow.addHandler(new SpeakingHandler());
+ flow.addHandler(new SpeakingHandler());
+ flow.addHandler(new SpeakingHandler());
+ flow.addHandler(culprit);
+ flow.addHandler(new SpeakingHandler());
+ service.setInFlow(flow);
+
+ service.setClassLoader(Thread.currentThread().getContextClassLoader());
+ Parameter classParam = new ParameterImpl("className",EchoXML.class.getName());
+ service.addParameter(classParam);
+ service.setProvider(new RawXMLProvider());
+ Operation operation = new OperationImpl(operationName,service);
+
+ service.addOperation(operation);
+
+ ExecutionChain inchain = new ExecutionChain();
+ inchain.addPhase(new Phase(Constants.PHASE_SERVICE));
+ EngineUtils.addHandlers(service.getInFlow(),inchain,Constants.PHASE_SERVICE);
+ service.setInputExecutionChain(inchain);
+
+ ExecutionChain outchain = new ExecutionChain();
+ outchain.addPhase(new Phase(Constants.PHASE_SERVICE));
+ EngineUtils.addHandlers(service.getOutFlow(),outchain,Constants.PHASE_SERVICE);
+ service.setOutExecutionChain(outchain);
+
+ ExecutionChain faultchain = new ExecutionChain();
+
+ faultchain.addPhase(new Phase(Constants.PHASE_SERVICE));
+
+ EngineUtils.addHandlers(service.getFaultFlow(),faultchain,Constants.PHASE_SERVICE);
+ service.setFaultExecutionChain(outchain);
+ engineRegistry.addService(service);
+ sas = EngineUtils.startServer(engineRegistry);
+ callTheService();
+ }
+
+
+
+ protected void tearDown() throws Exception {
+ sas.stop();
+ Thread.sleep(1000);
+ }
+
+
+ public void callTheService() throws Exception{
+ try{
+ OMFactory fac = OMFactory.newInstance();
+
+ OMNamespace omNs = fac.createOMNamespace("http://localhost/my","my");
+ OMElement method = fac.createOMElement("echoOMElement",omNs) ;
+ OMElement value = fac.createOMElement("myValue",omNs) ;
+ value.setValue("Isaac Assimov, the foundation Sega");
+ method.addChild(value);
+
+ Call call = new Call();
+ URL url = new URL("http","127.0.0.1",EngineUtils.TESTING_PORT,"/axis/services/EchoXMLService");
+ OMElement omele = call.syncCall(method,url);
+ assertNotNull(omele);
+ }catch(AxisFault e){
+ assertEquals(e.getMessage(),EngineUtils.FAILURE_MESSAGE);
+ tearDown();
+ return;
+ }
+ fail("the test must fail due to bad service Name");
+ }
+
+ private Handler culprit = new AbstractHandler() {
+ public void invoke(MessageContext msgContext) throws AxisFault {
+ throw new AxisFault(EngineUtils.FAILURE_MESSAGE);
+ }
+ };
+}
+