1 16 17 package org.apache.axis2.mtom; 18 21 import javax.activation.DataHandler ; 22 import javax.xml.namespace.QName ; 23 import javax.xml.stream.XMLOutputFactory; 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.OMOutput; 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 EchoRawMTOMToBase64Test extends TestCase { 49 private EndpointReference targetEPR = 50 new EndpointReference(AddressingConstants.WSA_TO, 51 "http://127.0.0.1:" 52 + (UtilServer.TESTING_PORT) 53 + "/axis/services/EchoXMLService/echoMTOMtoBase64"); 54 private Log log = LogFactory.getLog(getClass()); 55 private QName serviceName = new QName ("EchoXMLService"); 56 private QName operationName = new QName ("echoMTOMtoBase64"); 57 private QName transportName = new QName ("http://localhost/my", "NullTransport"); 58 59 private AxisConfiguration engineRegistry; 60 private MessageContext mc; 61 private ServiceContext serviceContext; 64 private ServiceDescription service; 65 66 private boolean finish = false; 67 68 public EchoRawMTOMToBase64Test() { 69 super(EchoRawMTOMToBase64Test.class.getName()); 70 } 71 72 public EchoRawMTOMToBase64Test(String testName) { 73 super(testName); 74 } 75 76 protected void setUp() throws Exception { 77 UtilServer.start(); 78 service = 79 Utils.createSimpleService(serviceName, 80 Echo.class.getName(), 81 operationName); 82 UtilServer.deployService(service); 83 serviceContext = 84 UtilServer.getConfigurationContext().createServiceContext(service.getName()); 85 } 86 87 protected void tearDown() throws Exception { 88 UtilServer.unDeployService(serviceName); 89 UtilServer.stop(); 90 } 91 92 private OMElement createEnvelope() { 93 94 OMFactory fac = OMAbstractFactory.getOMFactory(); 95 OMNamespace omNs = fac.createOMNamespace("http://localhost/my", "my"); 96 OMElement rpcWrapEle = fac.createOMElement("echoMTOMtoBase64",omNs); 97 OMElement data = fac.createOMElement("data", omNs); 98 byte[] byteArray = new byte[] { 13, 56, 65, 32, 12, 12, 7, -3, -2, -1, 99 98 }; 100 DataHandler dataHandler = new DataHandler (new ByteArrayDataSource(byteArray)); 101 OMTextImpl textData = new OMTextImpl(dataHandler, true); 102 data.addChild(textData); 103 rpcWrapEle.addChild(data); 104 return rpcWrapEle; 105 } 106 107 108 public void testEchoXMLSync() throws Exception { 109 for(int i=0; i<10;i++) 110 { 111 SOAPFactory fac = OMAbstractFactory.getSOAP11Factory(); 112 113 OMElement payload = createEnvelope(); 114 115 org.apache.axis2.clientapi.Call call = new org.apache.axis2.clientapi.Call(); 116 117 call.setTo(targetEPR); 118 call.set(Constants.Configuration.ENABLE_MTOM,Constants.VALUE_TRUE); 119 call.setTransportInfo(Constants.TRANSPORT_HTTP, Constants.TRANSPORT_HTTP, false); 120 121 OMElement result = 122 (OMElement) call.invokeBlocking(operationName.getLocalPart(), payload); 123 result.serializeWithCache(new OMOutput(XMLOutputFactory.newInstance().createXMLStreamWriter(System.out))); 124 call.close(); 125 System.out.println(i); 126 } 127 } 128 129 } 130 | Popular Tags |