1 16 17 package org.apache.axis2.engine; 18 19 import junit.framework.TestCase; 20 import org.apache.axis2.Constants; 21 import org.apache.axis2.addressing.AddressingConstants; 22 import org.apache.axis2.addressing.EndpointReference; 23 import org.apache.axis2.clientapi.AsyncResult; 24 import org.apache.axis2.clientapi.Callback; 25 import org.apache.axis2.context.MessageContext; 26 import org.apache.axis2.context.ServiceContext; 27 import org.apache.axis2.description.ServiceDescription; 28 import org.apache.axis2.integration.TestingUtils; 29 import org.apache.axis2.integration.UtilServer; 30 import org.apache.axis2.om.OMAbstractFactory; 31 import org.apache.axis2.om.OMElement; 32 import org.apache.axis2.om.OMFactory; 33 import org.apache.axis2.om.OMNamespace; 34 import org.apache.axis2.transport.http.SimpleHTTPServer; 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 EchoRawXMLOnTwoChannelsTest extends TestCase { 42 private EndpointReference targetEPR = 43 new EndpointReference( 44 AddressingConstants.WSA_TO, 45 "http://127.0.0.1:" 46 + (UtilServer.TESTING_PORT) 47 + "/axis/services/EchoXMLService/echoOMElement"); 48 private Log log = LogFactory.getLog(getClass()); 49 private QName serviceName = new QName ("EchoXMLService"); 50 private QName operationName = new QName ("echoOMElement"); 51 private QName transportName = new QName ("http://localhost/my", "NullTransport"); 52 53 private AxisConfiguration engineRegistry; 54 private MessageContext mc; 55 private Thread thisThread; 56 private SimpleHTTPServer sas; 57 private ServiceContext serviceContext; 58 59 private boolean finish = false; 60 61 public EchoRawXMLOnTwoChannelsTest() { 62 super(EchoRawXMLOnTwoChannelsTest.class.getName()); 63 } 64 65 public EchoRawXMLOnTwoChannelsTest(String testName) { 66 super(testName); 67 } 68 69 protected void setUp() throws Exception { 70 UtilServer.start(); 71 UtilServer.getConfigurationContext().getAxisConfiguration().engageModule( 72 new QName ("addressing")); 73 74 ServiceDescription service = 75 Utils.createSimpleService( 76 serviceName, 77 Echo.class.getName(), 78 operationName); 79 UtilServer.deployService(service); 80 serviceContext = 81 UtilServer.getConfigurationContext().createServiceContext(service.getName()); 82 83 } 84 85 protected void tearDown() throws Exception { 86 UtilServer.unDeployService(serviceName); 87 UtilServer.stop(); 88 } 89 90 91 92 public void testEchoXMLCompleteASync() throws Exception { 93 ServiceDescription service = 94 Utils.createSimpleService( 95 serviceName, 96 Echo.class.getName(), 97 operationName); 98 99 ServiceContext serviceContext = UtilServer.createAdressedEnabledClientSide(service); 100 101 OMFactory fac = OMAbstractFactory.getOMFactory(); 102 103 OMNamespace omNs = fac.createOMNamespace("http://localhost/my", "my"); 104 OMElement method = fac.createOMElement("echoOMElement", omNs); 105 OMElement value = fac.createOMElement("myValue", omNs); 106 value.setText("Isaac Assimov, the foundation Sega"); 107 method.addChild(value); 108 109 org.apache.axis2.clientapi.Call call = new org.apache.axis2.clientapi.Call(serviceContext); 110 call.engageModule(new QName (Constants.MODULE_ADDRESSING)); 111 112 try { 113 call.setTo(targetEPR); 114 call.setTransportInfo(Constants.TRANSPORT_HTTP, Constants.TRANSPORT_HTTP, true); 115 Callback callback = new Callback() { 116 public void onComplete(AsyncResult result) { 117 TestingUtils.campareWithCreatedOMElement(result.getResponseEnvelope().getBody().getFirstElement()); 118 finish = true; 119 } 120 121 public void reportError(Exception e) { 122 e.printStackTrace(); 123 finish = true; 124 } 125 }; 126 127 call.invokeNonBlocking(operationName.getLocalPart(), method, callback); 128 int index = 0; 129 while (!finish) { 130 Thread.sleep(1000); 131 index++; 132 if (index > 10) { 133 throw new AxisFault("Server is shutdown as the Async response take too longs time"); 134 } 135 } 136 log.info("send the reqest"); 137 call.close(); 138 } finally { 139 call.close(); 140 } 141 142 } 143 } 144 | Popular Tags |