KickJava   Java API By Example, From Geeks To Geeks.

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


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.engine;
18
19 //todo
20

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 JavaDoc;
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 JavaDoc serviceName = new QName JavaDoc("EchoXMLService");
53     private QName JavaDoc operationName = new QName JavaDoc("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 JavaDoc testName) {
68         super(testName);
69     }
70
71     protected void setUp() throws Exception JavaDoc {
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 JavaDoc {
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 JavaDoc {
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