KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > axis > client > AxisClient


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 2001-2003 The Apache Software Foundation. All rights
6  * reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Apache Software Foundation (http://www.apache.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "Axis" and "Apache Software Foundation" must
28  * not be used to endorse or promote products derived from this
29  * software without prior written permission. For written
30  * permission, please contact apache@apache.org.
31  *
32  * 5. Products derived from this software may not be called "Apache",
33  * nor may "Apache" appear in their name, without prior written
34  * permission of the Apache Software Foundation.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
40  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47  * SUCH DAMAGE.
48  * ====================================================================
49  *
50  * This software consists of voluntary contributions made by many
51  * individuals on behalf of the Apache Software Foundation. For more
52  * information on the Apache Software Foundation, please see
53  * <http://www.apache.org/>.
54  */

55
56 package org.jboss.axis.client;
57
58 import org.jboss.axis.AxisEngine;
59 import org.jboss.axis.AxisFault;
60 import org.jboss.axis.Constants;
61 import org.jboss.axis.EngineConfiguration;
62 import org.jboss.axis.Handler;
63 import org.jboss.axis.MessageContext;
64 import org.jboss.axis.configuration.EngineConfigurationFactoryFinder;
65 import org.jboss.axis.handlers.HandlerChainImpl;
66 import org.jboss.axis.handlers.HandlerInfoChainFactory;
67 import org.jboss.axis.handlers.soap.SOAPService;
68 import org.jboss.axis.utils.Messages;
69 import org.jboss.logging.Logger;
70
71 import javax.xml.namespace.QName JavaDoc;
72
73 /**
74  * Provides the equivalent of an "Axis engine" on the client side.
75  * Subclasses hardcode initialization & setup logic for particular
76  * client-side transports.
77  *
78  * @author Rob Jellinghaus (robj@unrealities.com)
79  * @author Doug Davis (dug@us.ibm.com)
80  * @author Glen Daniels (gdaniels@allaire.com)
81  */

82 public class AxisClient extends AxisEngine
83 {
84    private static Logger log = Logger.getLogger(AxisClient.class.getName());
85
86    public AxisClient(EngineConfiguration config)
87    {
88       super(config);
89    }
90
91    public AxisClient()
92    {
93       this(EngineConfigurationFactoryFinder.newFactory().getClientEngineConfig());
94    }
95
96    /**
97     * this *is* the client engine!
98     */

99    public AxisEngine getClientEngine()
100    {
101       return this;
102    }
103
104    /**
105     * Main routine of the AXIS engine. In short we locate the appropriate
106     * handler for the desired service and invoke() it.
107     */

108    public void invoke(MessageContext msgContext) throws AxisFault
109    {
110       if (log.isDebugEnabled())
111       {
112          log.debug("Enter: AxisClient::invoke");
113       }
114
115       String JavaDoc hName = null;
116       Handler h = null;
117
118       // save previous context
119
MessageContext previousContext = getCurrentMessageContext();
120
121       try
122       {
123          // set active context
124
setCurrentMessageContext(msgContext);
125
126          hName = msgContext.getStrProp(MessageContext.ENGINE_HANDLER);
127          if (log.isDebugEnabled())
128          {
129             log.debug("EngineHandler: " + hName);
130          }
131
132          if (hName != null)
133          {
134             h = getHandler(hName);
135             if (h != null)
136                h.invoke(msgContext);
137             else
138                throw new AxisFault("Client.error",
139                        Messages.getMessage("noHandler00", hName),
140                        null, null);
141          }
142          else
143          {
144             // This really should be in a handler - but we need to discuss it
145
// first - to make sure that's what we want.
146

147             /* Now we do the 'real' work. The flow is basically: */
148             /* */
149             /* Service Specific Request Chain */
150             /* Global Request Chain */
151             /* Transport Request Chain - must have a send at the end */
152             /* Transport Response Chain */
153             /* Global Response Chain */
154             /* Service Specific Response Chain */
155             /* Protocol Specific-Handler/Checker */
156             /**************************************************************/
157
158             // When do we call init/cleanup??
159

160             SOAPService service = null;
161             msgContext.setPastPivot(false);
162
163             /* Process the Service Specific Request Chain */
164             /**********************************************/
165             service = msgContext.getService();
166             if (service != null)
167             {
168                h = service.getRequestHandler();
169                if (h != null)
170                   h.invoke(msgContext);
171             }
172
173             /* Process the Global Request Chain */
174             /**********************************/
175             if ((h = getGlobalRequest()) != null)
176                h.invoke(msgContext);
177
178             /* Process the JAXRPC Handlers */
179             invokeJAXRPCHandlers(msgContext);
180
181             /** Process the Transport Specific stuff
182              *
183              * NOTE: Somewhere in here there is a handler which actually
184              * sends the message and receives a response. Generally
185              * this is the pivot point in the Transport chain.
186              */

187             hName = msgContext.getTransportName();
188             if (hName != null && (h = getTransport(hName)) != null)
189             {
190                h.invoke(msgContext);
191             }
192             else
193             {
194                throw new AxisFault(Messages.getMessage("noTransport00", hName));
195             }
196
197             /* Process the JAXRPC Handlers */
198             invokeJAXRPCHandlers(msgContext);
199
200             /* Process the Global Response Chain */
201             /***********************************/
202             if ((h = getGlobalResponse()) != null)
203             {
204                h.invoke(msgContext);
205             }
206
207             if (service != null)
208             {
209                h = service.getResponseHandler();
210                if (h != null)
211                {
212                   h.invoke(msgContext);
213                }
214             }
215
216             // Do SOAP Semantics checks here - this needs to be a call to
217
// a pluggable object/handler/something
218
}
219
220       }
221       catch (Exception JavaDoc e)
222       {
223          // Should we even bother catching it ?
224
log.debug(Messages.getMessage("exception00"), e);
225          throw AxisFault.makeFault(e);
226
227       }
228       finally
229       {
230          // restore previous state
231
setCurrentMessageContext(previousContext);
232       }
233
234       if (log.isDebugEnabled())
235       {
236          log.debug("Exit: AxisClient::invoke");
237       }
238    }
239
240    protected void invokeJAXRPCHandlers(MessageContext context)
241    {
242       java.util.List JavaDoc chain = null;
243       HandlerInfoChainFactory hiChainFactory = null;
244       boolean clientSpecified = false;
245
246       Service service
247               = (Service)context.getProperty(Call.WSDL_SERVICE);
248       if (service == null)
249       {
250          return;
251       }
252
253       QName JavaDoc portName = (QName JavaDoc)context.getProperty(Call.WSDL_PORT_NAME);
254       if (portName == null)
255       {
256          return;
257       }
258
259       javax.xml.rpc.handler.HandlerRegistry JavaDoc registry;
260       registry = service.getHandlerRegistry();
261       if (registry != null)
262       {
263          chain = registry.getHandlerChain(portName);
264          if ((chain != null) && (!chain.isEmpty()))
265          {
266             hiChainFactory = new HandlerInfoChainFactory(chain);
267             clientSpecified = true;
268          }
269       }
270
271       // Otherwise, use the container support
272
if (!clientSpecified)
273       {
274          SOAPService soapService = context.getService();
275          if (soapService != null)
276          {
277             // A client configuration exists for this service. Check
278
// to see if there is a HandlerInfoChain configured on it.
279
hiChainFactory = (HandlerInfoChainFactory)
280                     soapService.getOption(Constants.ATTR_HANDLERINFOCHAIN);
281          }
282       }
283
284       if (hiChainFactory == null)
285       {
286          return;
287       }
288       HandlerChainImpl impl = (HandlerChainImpl)hiChainFactory.createHandlerChain();
289
290       if (!context.getPastPivot())
291       {
292          impl.handleRequest(context);
293       }
294       else
295       {
296          impl.handleResponse(context);
297       }
298       impl.destroy();
299    }
300 }
301
302
Popular Tags