1 16 17 package org.apache.axis2.mtom; 18 19 22 import javax.activation.DataHandler ; 23 import javax.xml.namespace.QName ; 24 25 import junit.framework.TestCase; 26 27 import org.apache.axis2.Constants; 28 import org.apache.axis2.addressing.AddressingConstants; 29 import org.apache.axis2.addressing.EndpointReference; 30 import org.apache.axis2.attachments.ByteArrayDataSource; 31 import org.apache.axis2.context.MessageContext; 32 import org.apache.axis2.context.ServiceContext; 33 import org.apache.axis2.description.ServiceDescription; 34 import org.apache.axis2.engine.AxisConfiguration; 35 import org.apache.axis2.engine.Echo; 36 import org.apache.axis2.integration.UtilServer; 37 import org.apache.axis2.om.OMAbstractFactory; 38 import org.apache.axis2.om.OMElement; 39 import org.apache.axis2.om.OMFactory; 40 import org.apache.axis2.om.OMNamespace; 41 import org.apache.axis2.om.OMText; 42 import org.apache.axis2.om.impl.llom.OMTextImpl; 43 import org.apache.axis2.soap.SOAPFactory; 44 import org.apache.axis2.util.Utils; 45 import org.apache.commons.logging.Log; 46 import org.apache.commons.logging.LogFactory; 47 48 public class EchoRawMTOMLoadTest extends TestCase { 49 private EndpointReference targetEPR = new EndpointReference( 50 AddressingConstants.WSA_TO, "http://127.0.0.1:" 51 + (UtilServer.TESTING_PORT) 52 + "/axis/services/EchoXMLService/echoOMElement"); 53 54 private Log log = LogFactory.getLog(getClass()); 55 56 private QName serviceName = new QName ("EchoXMLService"); 57 58 private QName operationName = new QName ("echoOMElement"); 59 60 private QName transportName = new QName ("http://localhost/my", 61 "NullTransport"); 62 63 private AxisConfiguration engineRegistry; 64 65 private MessageContext mc; 66 67 private ServiceContext serviceContext; 68 69 private ServiceDescription service; 70 71 private boolean finish = false; 72 73 public EchoRawMTOMLoadTest() { 74 super(EchoRawMTOMLoadTest.class.getName()); 75 } 76 77 public EchoRawMTOMLoadTest(String testName) { 78 super(testName); 79 } 80 81 protected void setUp() throws Exception { 82 UtilServer.start(Constants.TESTING_PATH + "MTOM-enabledRepository"); 83 service = Utils.createSimpleService(serviceName, Echo.class.getName(), 84 operationName); 85 UtilServer.deployService(service); 86 serviceContext = UtilServer.getConfigurationContext() 87 .createServiceContext(service.getName()); 88 } 89 90 protected void tearDown() throws Exception { 91 UtilServer.unDeployService(serviceName); 92 UtilServer.stop(); 93 } 94 95 private OMElement createEnvelope() { 96 97 OMFactory fac = OMAbstractFactory.getOMFactory(); 98 OMNamespace omNs = fac.createOMNamespace("http://localhost/my", "my"); 99 OMElement rpcWrapEle = fac.createOMElement("echoOMElement", omNs); 100 OMElement data = fac.createOMElement("data", omNs); 101 byte[] byteArray = new byte[] { 13, 56, 65, 32, 12, 12, 7, -3, -2, -1, 102 98 }; 103 for (int i = 0; i <4; i++) { 104 OMElement subData = fac.createOMElement("subData", omNs); 105 DataHandler dataHandler = new DataHandler (new ByteArrayDataSource( 106 byteArray)); 107 OMText textData = new OMTextImpl(dataHandler, true); 108 subData.addChild(textData); 110 data.addChild(subData); 111 } 113 114 rpcWrapEle.addChild(data); 115 return rpcWrapEle; 116 } 117 118 public void testEchoXMLSync() throws Exception { 119 for (int i = 0; i < 10; i++) { 120 SOAPFactory fac = OMAbstractFactory.getSOAP11Factory(); 121 122 OMElement payload = createEnvelope(); 123 124 org.apache.axis2.clientapi.Call call = new org.apache.axis2.clientapi.Call(); 125 call.setTo(targetEPR); 126 call.set(Constants.Configuration.ENABLE_MTOM, Constants.VALUE_TRUE); 127 call.setTransportInfo(Constants.TRANSPORT_HTTP, 128 Constants.TRANSPORT_HTTP, false); 129 130 OMElement result = (OMElement) call.invokeBlocking(operationName 131 .getLocalPart(), payload); 132 OMElement ele = (OMElement) result.getFirstChild(); 133 OMElement ele1 = (OMElement)ele.getFirstChild(); 134 OMText binaryNode = (OMText) ele1.getFirstChild(); 135 System.out.println(i); 136 } 137 } 138 139 } | Popular Tags |