KickJava   Java API By Example, From Geeks To Geeks.

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


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  * @author <a HREF="mailto:thilina@opensource.lk">Thilina Gunarathne </a>
20  */

21 import javax.activation.DataHandler JavaDoc;
22 import javax.xml.namespace.QName JavaDoc;
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 JavaDoc serviceName = new QName JavaDoc("EchoXMLService");
56     private QName JavaDoc operationName = new QName JavaDoc("echoMTOMtoBase64");
57     private QName JavaDoc transportName = new QName JavaDoc("http://localhost/my", "NullTransport");
58
59     private AxisConfiguration engineRegistry;
60     private MessageContext mc;
61     //private Thread thisThread;
62
// private SimpleHTTPServer sas;
63
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 JavaDoc testName) {
73         super(testName);
74     }
75
76     protected void setUp() throws Exception JavaDoc {
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 JavaDoc {
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 JavaDoc dataHandler = new DataHandler JavaDoc(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 JavaDoc {
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