KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis2 > mtom > EchoRawMTOMLoadTest


1 /*
2  * Copyright 2004,2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.axis2.mtom;
18
19 /**
20  * @author <a HREF="mailto:thilina@opensource.lk">Thilina Gunarathne </a>
21  */

22 import javax.activation.DataHandler JavaDoc;
23 import javax.xml.namespace.QName JavaDoc;
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 JavaDoc serviceName = new QName JavaDoc("EchoXMLService");
57
58     private QName JavaDoc operationName = new QName JavaDoc("echoOMElement");
59
60     private QName JavaDoc transportName = new QName JavaDoc("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 JavaDoc testName) {
78         super(testName);
79     }
80
81     protected void setUp() throws Exception JavaDoc {
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 JavaDoc {
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 JavaDoc dataHandler = new DataHandler JavaDoc(new ByteArrayDataSource(
106                     byteArray));
107             OMText textData = new OMTextImpl(dataHandler, true);
108             //OMText textData = new OMTextImpl("Thilina Gunarathne");
109
subData.addChild(textData);
110             data.addChild(subData);
111             //System.out.println("Creating blobs "+i);
112
}
113         
114         rpcWrapEle.addChild(data);
115         return rpcWrapEle;
116     }
117
118     public void testEchoXMLSync() throws Exception JavaDoc {
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