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 ; 22 import javax.xml.stream.XMLStreamException; 23 24 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 serviceName = new QName ("EchoXMLService"); 50 private QName operationName = new QName ("echoOMElement"); 51 private QName transportName = new QName ("http://localhost/my", "NullTransport"); 52 53 private AxisConfiguration engineRegistry; 54 private MessageContext mc; 55 private ServiceContext serviceContext; 58 private ServiceDescription service; 59 60 private boolean finish = false; 61 62 protected void setUp() throws Exception { 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 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 |