KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis2 > clientapi > MEPClient


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  * Runtime state of the engine
17  */

18 package org.apache.axis2.clientapi;
19
20 import org.apache.axis2.addressing.EndpointReference;
21 import org.apache.axis2.context.MessageContext;
22 import org.apache.axis2.context.ServiceContext;
23 import org.apache.axis2.description.OperationDescription;
24 import org.apache.axis2.description.TransportOutDescription;
25 import org.apache.axis2.engine.AxisFault;
26 import org.apache.axis2.om.OMAbstractFactory;
27 import org.apache.axis2.om.OMElement;
28 import org.apache.axis2.soap.SOAPEnvelope;
29 import org.apache.axis2.soap.SOAPFactory;
30 import org.apache.axis2.soap.impl.llom.soap11.SOAP11Constants;
31 import org.apache.axis2.soap.impl.llom.soap12.SOAP12Constants;
32
33 import javax.xml.namespace.QName JavaDoc;
34
35 /**
36  * This is the Super Class for all the MEPClients, All the MEPClient will extend this.
37  */

38 public abstract class MEPClient {
39     protected ServiceContext serviceContext;
40     protected final String JavaDoc mep;
41     protected String JavaDoc soapVersionURI = SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI;
42     protected String JavaDoc soapAction = "";
43     protected boolean doREST = false;
44     protected String JavaDoc wsaAction;
45
46     public void setDoREST(boolean b) {
47        doREST = b;
48    }
49
50
51     public String JavaDoc getSoapAction() {
52         return soapAction;
53     }
54
55     public MEPClient(ServiceContext service, String JavaDoc mep) {
56         this.serviceContext = service;
57         this.mep = mep;
58     }
59
60     protected void verifyInvocation(OperationDescription axisop,MessageContext msgCtx) throws AxisFault {
61         if (axisop == null) {
62             throw new AxisFault("OperationDescription can not be null");
63         }
64
65         if (mep.equals(axisop.getMessageExchangePattern())) {
66             throw new AxisFault("This mepClient supports only "
67                     + mep
68                     + " And the Axis Operations suppiled supports "
69                     + axisop.getMessageExchangePattern());
70         }
71
72         if (serviceContext.getServiceConfig().getOperation(axisop.getName()) == null) {
73             serviceContext.getServiceConfig().addOperation(axisop);
74         }
75         msgCtx.setDoingREST(doREST);
76         if(wsaAction != null){
77             msgCtx.setWSAAction(wsaAction);
78         }
79     }
80
81     protected MessageContext prepareTheSystem(OMElement toSend) throws AxisFault {
82         MessageContext msgctx = new MessageContext(serviceContext.getEngineContext());
83
84         SOAPEnvelope envelope = createDefaultSOAPEnvelope();
85         envelope.getBody().addChild(toSend);
86         msgctx.setEnvelope(envelope);
87         return msgctx;
88     }
89
90     public TransportOutDescription inferTransport(EndpointReference epr) throws AxisFault {
91         String JavaDoc transport = null;
92         if (epr != null) {
93             String JavaDoc toURL = epr.getAddress();
94             int index = toURL.indexOf(':');
95             if (index > 0) {
96                 transport = toURL.substring(0, index);
97             }
98         }
99
100         if (transport != null) {
101             return serviceContext.getEngineContext().getAxisConfiguration().getTransportOut(new QName JavaDoc(transport));
102
103         } else {
104             throw new AxisFault("Cannot Infer transport from the URL");
105         }
106
107     }
108
109     public SOAPEnvelope createDefaultSOAPEnvelope() throws AxisFault{
110         SOAPFactory fac = null;
111         if (SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(soapVersionURI)) {
112             fac = OMAbstractFactory.getSOAP12Factory();
113         } else if (SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(soapVersionURI)) {
114             fac = OMAbstractFactory.getSOAP11Factory();
115         } else {
116              throw new AxisFault("Invalid SOAP URI. Axis2 only supports SOAP 1.1 and 1.2");
117         }
118         return fac.getDefaultEnvelope();
119     }
120
121     /**
122      * @param string
123      */

124     public void setSoapVersionURI(String JavaDoc string) {
125         soapVersionURI = string;
126     }
127
128     /**
129      * @param string
130      */

131     public void setSoapAction(String JavaDoc string) {
132         soapAction = string;
133     }
134
135     /**
136      * @param string
137      */

138     public void setWsaAction(String JavaDoc string) {
139         wsaAction = string;
140     }
141
142 }
143
Popular Tags