KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis2 > engine > SOAPversionTest


1 package org.apache.axis2.engine;
2
3 import junit.framework.TestCase;
4 import org.apache.axis2.Constants;
5 import org.apache.axis2.addressing.AddressingConstants;
6 import org.apache.axis2.addressing.EndpointReference;
7 import org.apache.axis2.context.MessageContext;
8 import org.apache.axis2.context.ServiceContext;
9 import org.apache.axis2.description.ServiceDescription;
10 import org.apache.axis2.engine.util.MyInOutMEPClient;
11 import org.apache.axis2.integration.UtilServer;
12 import org.apache.axis2.om.*;
13 import org.apache.axis2.soap.SOAPEnvelope;
14 import org.apache.axis2.soap.SOAPFactory;
15 import org.apache.axis2.soap.impl.llom.soap11.SOAP11Constants;
16 import org.apache.axis2.soap.impl.llom.soap12.SOAP12Constants;
17 import org.apache.axis2.util.Utils;
18 import org.apache.commons.logging.Log;
19 import org.apache.commons.logging.LogFactory;
20
21 import javax.xml.namespace.QName JavaDoc;
22 import javax.xml.stream.XMLStreamException;
23
24 /*
25  * Copyright 2004,2005 The Apache Software Foundation.
26  *
27  * Licensed under the Apache License, Version 2.0 (the "License");
28  * you may not use this file except in compliance with the License.
29  * You may obtain a copy of the License at
30  *
31  * http://www.apache.org/licenses/LICENSE-2.0
32  *
33  * Unless required by applicable law or agreed to in writing, software
34  * distributed under the License is distributed on an "AS IS" BASIS,
35  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
36  * See the License for the specific language governing permissions and
37  * limitations under the License.
38  *
39  * author : Eran Chinthaka (chinthaka@apache.org)
40  */

41
42 public class SOAPversionTest extends TestCase {
43     private EndpointReference targetEPR =
44             new EndpointReference(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 JavaDoc serviceName = new QName JavaDoc("EchoXMLService");
50     private QName JavaDoc operationName = new QName JavaDoc("echoOMElement");
51     private QName JavaDoc transportName = new QName JavaDoc("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     private ServiceDescription service;
59
60     private boolean finish = false;
61
62     protected void setUp() throws Exception JavaDoc {
63         UtilServer.start();
64         service =
65                 Utils.createSimpleService(serviceName,
66         Echo.class.getName(),
67                         operationName);
68         UtilServer.deployService(service);
69         serviceContext =
70                 UtilServer.getConfigurationContext().createServiceContext(service.getName());
71
72     }
73
74     public void testSOAP11() throws AxisFault {
75         SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();
76
77         OMElement payload = createEnvelope();
78         MyInOutMEPClient inOutMEPClient = new MyInOutMEPClient();
79         inOutMEPClient.setSoapVersionURI(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
80         inOutMEPClient.setTo(targetEPR);
81         inOutMEPClient.setTransportInfo(Constants.TRANSPORT_HTTP, Constants.TRANSPORT_HTTP, false);
82
83         SOAPEnvelope result =
84                  inOutMEPClient.invokeBlockingWithEnvelopeOut(operationName.getLocalPart(), payload);
85         assertEquals("SOAP Version received is not compatible", SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI, result.getNamespace().getName());
86         inOutMEPClient.close();
87     }
88
89     public void testSOAP12() throws AxisFault {
90         SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();
91
92         OMElement payload = createEnvelope();
93         MyInOutMEPClient inOutMEPClient = new MyInOutMEPClient();
94         inOutMEPClient.setSoapVersionURI(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
95         inOutMEPClient.setTo(targetEPR);
96         inOutMEPClient.setTransportInfo(Constants.TRANSPORT_HTTP, Constants.TRANSPORT_HTTP, false);
97
98         SOAPEnvelope result =
99                  inOutMEPClient.invokeBlockingWithEnvelopeOut(operationName.getLocalPart(), payload);
100         assertEquals("SOAP Version received is not compatible", SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI, result.getNamespace().getName());
101
102
103         inOutMEPClient.close();
104     }
105
106     public void testSOAPfault() throws AxisFault {
107         SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();
108
109         OMElement payload = createEnvelope();
110         MyInOutMEPClient inOutMEPClient = new MyInOutMEPClient();
111         inOutMEPClient.setSoapVersionURI(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
112
113         inOutMEPClient.setTo(targetEPR);
114         inOutMEPClient.setTransportInfo(Constants.TRANSPORT_HTTP, Constants.TRANSPORT_HTTP, false);
115
116         SOAPEnvelope result =
117                  inOutMEPClient.invokeBlockingWithEnvelopeOut(operationName.getLocalPart(), payload);
118 // assertEquals("SOAP Version received is not compatible", SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI, result.getNamespace().getName());
119
try {
120             OMOutput output = new OMOutput(System.out, false);
121             result.serializeWithCache(output);
122             output.flush();
123         } catch (XMLStreamException e) {
124             e.printStackTrace();
125         }
126
127         inOutMEPClient.close();
128     }
129
130     private OMElement createEnvelope() {
131         OMFactory fac = OMAbstractFactory.getOMFactory();
132         OMNamespace omNs = fac.createOMNamespace("http://localhost/my", "my");
133         OMElement method = fac.createOMElement("echoOMElement", omNs);
134         OMElement value = fac.createOMElement("myValue", omNs);
135         value.addChild(fac.createText(value, "Isaac Assimov, the foundation Sega"));
136         method.addChild(value);
137
138         return method;
139     }
140
141
142 }
143
Popular Tags