1 16 17 package org.apache.axis2.engine; 18 19 21 import junit.framework.TestCase; 22 import org.apache.axis2.Constants; 23 import org.apache.axis2.addressing.AddressingConstants; 24 import org.apache.axis2.addressing.EndpointReference; 25 import org.apache.axis2.clientapi.MessageSender; 26 import org.apache.axis2.context.ConfigurationContext; 27 import org.apache.axis2.context.MessageContext; 28 import org.apache.axis2.description.OperationDescription; 29 import org.apache.axis2.description.ParameterImpl; 30 import org.apache.axis2.description.ServiceDescription; 31 import org.apache.axis2.om.OMAbstractFactory; 32 import org.apache.axis2.om.OMElement; 33 import org.apache.axis2.om.OMFactory; 34 import org.apache.axis2.om.OMNamespace; 35 import org.apache.axis2.receivers.AbstractMessageReceiver; 36 import org.apache.axis2.receivers.RawXMLINOnlyMessageReceiver; 37 import org.apache.axis2.soap.SOAPEnvelope; 38 import org.apache.axis2.soap.SOAPFactory; 39 import org.apache.axis2.soap.impl.llom.soap11.SOAP11Constants; 40 import org.apache.axis2.transport.local.LocalTransportReceiver; 41 import org.apache.axis2.util.Utils; 42 import org.apache.commons.logging.Log; 43 import org.apache.commons.logging.LogFactory; 44 45 import javax.xml.namespace.QName ; 46 47 public class MessageContextInjectionTest extends TestCase { 48 private EndpointReference targetEPR = 49 new EndpointReference( 50 AddressingConstants.WSA_TO,"/axis/services/EchoXMLService/echoOMElement"); 51 private Log log = LogFactory.getLog(getClass()); 52 private QName serviceName = new QName ("EchoXMLService"); 53 private QName operationName = new QName ("echoOMElement"); 54 55 56 private AxisConfiguration engineRegistry; 57 private MessageContext mc; 58 59 private SOAPEnvelope envelope; 60 61 private boolean finish = false; 62 63 public MessageContextInjectionTest() { 64 super(MessageContextInjectionTest.class.getName()); 65 } 66 67 public MessageContextInjectionTest(String testName) { 68 super(testName); 69 } 70 71 protected void setUp() throws Exception { 72 ConfigurationContext configContext = new ConfigurationContext(new AxisConfigurationImpl()); 73 LocalTransportReceiver.CONFIG_CONTEXT = configContext; 74 75 ServiceDescription service = new ServiceDescription(serviceName); 76 service.addParameter(new ParameterImpl(AbstractMessageReceiver.SERVICE_CLASS, MessageContextEnabledEcho.class.getName())); 77 OperationDescription operation = new OperationDescription(operationName); 78 operation.setMessageReciever(new RawXMLINOnlyMessageReceiver()); 79 service.addOperation(operation); 80 service.setClassLoader(Thread.currentThread().getContextClassLoader()); 81 LocalTransportReceiver.CONFIG_CONTEXT.getAxisConfiguration().addService(service); 82 Utils.resolvePhases(LocalTransportReceiver.CONFIG_CONTEXT.getAxisConfiguration(), service); 83 } 84 85 protected void tearDown() throws Exception { 86 } 87 88 private OMElement createEnvelope() { 89 OMFactory fac = OMAbstractFactory.getOMFactory(); 90 OMNamespace omNs = fac.createOMNamespace("http://localhost/my", "my"); 91 OMElement method = fac.createOMElement("echoOMElement", omNs); 92 OMElement value = fac.createOMElement("myValue", omNs); 93 value.addChild(fac.createText(value, "Isaac Assimov, the foundation Sega")); 94 method.addChild(value); 95 96 return method; 97 } 98 99 public void testEchoXMLSync() throws Exception { 100 SOAPFactory fac = OMAbstractFactory.getSOAP11Factory(); 101 102 OMElement payload = createEnvelope(); 103 104 MessageSender sender = new MessageSender(); 105 106 sender.setTo(targetEPR); 107 sender.setSenderTransport(Constants.TRANSPORT_LOCAL); 108 sender.setSoapVersionURI(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI); 109 sender.send(operationName.getLocalPart(), payload); 110 111 } 112 113 } 114 | Popular Tags |