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.clientapi.AsyncResult; 26 import org.apache.axis2.clientapi.Callback; 27 import org.apache.axis2.context.MessageContext; 28 import org.apache.axis2.context.ServiceContext; 29 import org.apache.axis2.description.ServiceDescription; 30 import org.apache.axis2.integration.TestingUtils; 31 import org.apache.axis2.integration.UtilServer; 32 import org.apache.axis2.om.OMAbstractFactory; 33 import org.apache.axis2.om.OMElement; 34 import org.apache.axis2.soap.SOAPFactory; 35 import org.apache.axis2.util.Utils; 36 import org.apache.commons.logging.Log; 37 import org.apache.commons.logging.LogFactory; 38 39 import javax.xml.namespace.QName ; 40 41 public class EchoRawXMLTest extends TestCase { 42 private EndpointReference targetEPR = 43 new EndpointReference(AddressingConstants.WSA_TO, 44 "http://127.0.0.1:" 45 + (UtilServer.TESTING_PORT) 46 + "/axis/services/EchoXMLService/echoOMElement"); 47 private Log log = LogFactory.getLog(getClass()); 48 private QName serviceName = new QName ("EchoXMLService"); 49 private QName operationName = new QName ("echoOMElement"); 50 private QName transportName = new QName ("http://localhost/my", "NullTransport"); 51 52 private AxisConfiguration engineRegistry; 53 private MessageContext mc; 54 private ServiceContext serviceContext; 57 private ServiceDescription service; 58 59 private boolean finish = false; 60 61 public EchoRawXMLTest() { 62 super(EchoRawXMLTest.class.getName()); 63 } 64 65 public EchoRawXMLTest(String testName) { 66 super(testName); 67 } 68 69 protected void setUp() throws Exception { 70 UtilServer.start(); 71 service = 72 Utils.createSimpleService(serviceName, 73 Echo.class.getName(), 74 operationName); 75 UtilServer.deployService(service); 76 serviceContext = 77 UtilServer.getConfigurationContext().createServiceContext(service.getName()); 78 79 } 80 81 protected void tearDown() throws Exception { 82 UtilServer.unDeployService(serviceName); 83 UtilServer.stop(); 84 } 85 86 87 public void testEchoXMLASync() throws Exception { 88 OMElement payload = TestingUtils.createDummyOMElement(); 89 90 org.apache.axis2.clientapi.Call call = new org.apache.axis2.clientapi.Call(); 91 92 call.setTo(targetEPR); 93 call.setTransportInfo(Constants.TRANSPORT_HTTP, Constants.TRANSPORT_HTTP, false); 94 95 Callback callback = new Callback() { 96 public void onComplete(AsyncResult result) { 97 TestingUtils.campareWithCreatedOMElement(result.getResponseEnvelope().getBody().getFirstElement()); 98 finish = true; 99 } 100 101 public void reportError(Exception e) { 102 e.printStackTrace(); 103 finish = true; 104 } 105 }; 106 107 call.invokeNonBlocking(operationName.getLocalPart(), payload, callback); 108 int index = 0; 109 while (!finish) { 110 Thread.sleep(1000); 111 index++; 112 if(index > 10 ){ 113 throw new AxisFault("Server is shutdown as the Async response take too longs time"); 114 } 115 } 116 call.close(); 117 118 119 log.info("send the reqest"); 120 } 121 122 public void testEchoXMLSync() throws Exception { 123 SOAPFactory fac = OMAbstractFactory.getSOAP11Factory(); 124 125 OMElement payload = TestingUtils.createDummyOMElement(); 126 127 org.apache.axis2.clientapi.Call call = new org.apache.axis2.clientapi.Call(); 128 129 call.setTo(targetEPR); 130 call.setTransportInfo(Constants.TRANSPORT_HTTP, Constants.TRANSPORT_HTTP, false); 131 132 OMElement result = 133 (OMElement) call.invokeBlocking(operationName.getLocalPart(), payload); 134 TestingUtils.campareWithCreatedOMElement(result); 135 call.close(); 136 } 137 138 public void testCorrectSOAPEnvelope() throws Exception { 139 140 OMElement payload = TestingUtils.createDummyOMElement(); 141 142 org.apache.axis2.clientapi.Call call = new org.apache.axis2.clientapi.Call(); 143 144 call.setTo(targetEPR); 145 call.setTransportInfo(Constants.TRANSPORT_HTTP, Constants.TRANSPORT_HTTP, false); 146 147 OMElement result = (OMElement) call.invokeBlocking(operationName.getLocalPart(), payload); 148 TestingUtils.campareWithCreatedOMElement(result); 149 call.close(); 150 } 151 152 153 } 154 | Popular Tags |