1 16 17 package org.apache.axis2.engine; 18 19 21 import junit.framework.TestCase; 22 import org.apache.axis2.Constants; 23 import org.apache.axis2.addressing.AddressingConstants; 24 import org.apache.axis2.addressing.EndpointReference; 25 import org.apache.axis2.context.MessageContext; 26 import org.apache.axis2.description.Flow; 27 import org.apache.axis2.description.FlowImpl; 28 import org.apache.axis2.description.ServiceDescription; 29 import org.apache.axis2.handlers.AbstractHandler; 30 import org.apache.axis2.integration.UtilServer; 31 import org.apache.axis2.om.OMAbstractFactory; 32 import org.apache.axis2.om.OMElement; 33 import org.apache.axis2.om.OMNamespace; 34 import org.apache.axis2.om.OMOutput; 35 import org.apache.axis2.phaseresolver.PhaseMetadata; 36 import org.apache.axis2.soap.SOAPFactory; 37 import org.apache.axis2.transport.http.SimpleHTTPServer; 38 import org.apache.axis2.util.Utils; 39 import org.apache.commons.logging.Log; 40 import org.apache.commons.logging.LogFactory; 41 42 import javax.xml.namespace.QName ; 43 import javax.xml.stream.XMLOutputFactory; 44 45 46 public class HandlerFailureTest extends TestCase { 47 private Log log = LogFactory.getLog(getClass()); 48 private static final String SERVICE_NAME = "EchoXMLService"; 49 private static final String OPERATION_NAME = "echoOMElement"; 50 51 52 private static final String ADDRESS = "http://127.0.0.1:" + (UtilServer.TESTING_PORT) + 53 "/axis/services/" + SERVICE_NAME + "/" +OPERATION_NAME; 54 private EndpointReference targetEPR = new EndpointReference(AddressingConstants.WSA_TO, ADDRESS); 56 private QName serviceName = new QName ("", SERVICE_NAME); 57 59 private QName operationName = new QName (OPERATION_NAME); 60 61 62 private MessageContext mc; 63 private Thread thisThread; 64 private SimpleHTTPServer sas; 65 66 public HandlerFailureTest() { 67 super(HandlerFailureTest.class.getName()); 68 } 69 70 public HandlerFailureTest(String testName) { 71 super(testName); 72 } 73 74 protected void setUp() throws Exception { 75 } 76 77 78 public void testFailureAtServerRequestFlow() throws Exception { 79 Flow flow = new FlowImpl(); 80 Utils.addHandler(flow, new SpeakingHandler(),PhaseMetadata.PHASE_POLICY_DETERMINATION); 81 Utils.addHandler(flow, new SpeakingHandler(),PhaseMetadata.PHASE_POLICY_DETERMINATION); 82 Utils.addHandler(flow, new SpeakingHandler(),PhaseMetadata.PHASE_POLICY_DETERMINATION); 83 Utils.addHandler(flow, new SpeakingHandler(),PhaseMetadata.PHASE_POLICY_DETERMINATION); 84 Utils.addHandler(flow, culprit,PhaseMetadata.PHASE_POLICY_DETERMINATION); 85 Utils.addHandler(flow, new SpeakingHandler(),PhaseMetadata.PHASE_POLICY_DETERMINATION); 86 87 ServiceDescription service = Utils.createSimpleService(serviceName,Echo.class.getName(),operationName); 88 service.setInFlow(flow); 89 90 UtilServer.start(); 91 UtilServer.deployService(service); 92 try { 93 callTheService(); 94 } finally { 95 UtilServer.unDeployService(serviceName); 96 UtilServer.stop(); 97 } 98 } 99 100 135 136 protected void tearDown() throws Exception { 137 138 } 139 140 141 private void callTheService() throws Exception { 142 try { 143 SOAPFactory fac = OMAbstractFactory.getSOAP11Factory(); 144 145 OMNamespace omNs = fac.createOMNamespace("http://localhost/my", "my"); 146 OMElement method = fac.createOMElement("echoOMElement", omNs); 147 OMElement value = fac.createOMElement("myValue", omNs); 148 value.setText("Isaac Assimov, the foundation Sega"); 149 method.addChild(value); 150 151 org.apache.axis2.clientapi.Call call = new org.apache.axis2.clientapi.Call(); 152 154 call.setTransportInfo(Constants.TRANSPORT_HTTP,Constants.TRANSPORT_HTTP,false); 155 call.setTo(targetEPR); 156 OMElement result = call.invokeBlocking(operationName.getLocalPart(),method); 157 OMOutput omOutput = new OMOutput(XMLOutputFactory.newInstance().createXMLStreamWriter(System.out)); 158 result.serialize(omOutput); 159 omOutput.flush(); 160 fail("the test must fail due to bad service Name"); 161 } catch (AxisFault e) { 162 e.printStackTrace(); 163 assertTrue((e.getMessage().indexOf(UtilServer.FAILURE_MESSAGE)) > 0); 164 return; 165 } 166 167 } 168 169 private Handler culprit = new AbstractHandler() { 170 public void invoke(MessageContext msgContext) throws AxisFault { 171 throw new AxisFault(UtilServer.FAILURE_MESSAGE); 172 } 173 }; 174 } 175 176 | Popular Tags |