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 CommonsHTTPEchoRawXMLTest 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 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 CommonsHTTPEchoRawXMLTest() { 62 super(CommonsHTTPEchoRawXMLTest.class.getName()); 63 } 64 65 public CommonsHTTPEchoRawXMLTest(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 public void testEchoXMLASync() throws Exception { 87 OMElement payload = TestingUtils.createDummyOMElement(); 88 89 org.apache.axis2.clientapi.Call call = new org.apache.axis2.clientapi.Call(Constants.TESTING_PATH+"commons-http-enabledRepository"); 90 91 call.setTo(targetEPR); 92 call.setTransportInfo(Constants.TRANSPORT_COMMONS_HTTP, Constants.TRANSPORT_HTTP, false); 93 94 Callback callback = new Callback() { 95 public void onComplete(AsyncResult result) { 96 TestingUtils.campareWithCreatedOMElement(result.getResponseEnvelope().getBody().getFirstElement()); 97 finish = true; 98 } 99 100 public void reportError(Exception e) { 101 e.printStackTrace(); 102 finish = true; 103 } 104 }; 105 106 call.invokeNonBlocking(operationName.getLocalPart(), payload, callback); 107 int index = 0; 108 while (!finish) { 109 Thread.sleep(1000); 110 index++; 111 if(index > 10 ){ 112 throw new AxisFault("Server is shutdown as the Async response take too longs time"); 113 } 114 } 115 call.close(); 116 117 118 log.info("send the reqest"); 119 } 120 121 public void testEchoXMLSync() throws Exception { 122 SOAPFactory fac = OMAbstractFactory.getSOAP11Factory(); 123 124 OMElement payload = TestingUtils.createDummyOMElement(); 125 126 org.apache.axis2.clientapi.Call call = new org.apache.axis2.clientapi.Call(Constants.TESTING_PATH+"commons-http-enabledRepository"); 127 128 call.setTo(targetEPR); 129 call.setTransportInfo(Constants.TRANSPORT_COMMONS_HTTP, Constants.TRANSPORT_HTTP, false); 130 131 OMElement result = 132 (OMElement) call.invokeBlocking(operationName.getLocalPart(), payload); 133 TestingUtils.campareWithCreatedOMElement(result); 134 call.close(); 135 } 136 137 } 138 | Popular Tags |