KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > axis > providers > java > RPCProvider


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.providers.java;
57
58 import org.jboss.axis.AxisFault;
59 import org.jboss.axis.MessageContext;
60 import org.jboss.axis.description.OperationDesc;
61 import org.jboss.axis.message.SOAPEnvelopeAxisImpl;
62 import org.jboss.axis.utils.Messages;
63 import org.jboss.logging.Logger;
64
65 import java.lang.reflect.InvocationTargetException JavaDoc;
66 import java.lang.reflect.Method JavaDoc;
67
68 /**
69  * Implement message processing by walking over RPCElements of the
70  * envelope body, invoking the appropriate methods on the service object.
71  *
72  * @author Doug Davis (dug@us.ibm.com)
73  */

74 public class RPCProvider extends JavaProvider
75 {
76
77    private static Logger log = Logger.getLogger(RPCProvider.class.getName());
78
79    /**
80     * The key for the invocation object in the MessageContext
81     */

82    public final static String JavaDoc RPC_INVOCATION = "axis.provider.java.rpc-invocation";
83
84    /**
85     * Process the current message.
86     * Result in resEnv.
87     *
88     * @param msgContext self-explanatory
89     * @param reqEnv the request envelope
90     * @param resEnv the response envelope
91     * @param obj the service object itself
92     */

93    public void processMessage(MessageContext msgContext, SOAPEnvelopeAxisImpl reqEnv, SOAPEnvelopeAxisImpl resEnv, Object JavaDoc obj)
94            throws Exception JavaDoc
95    {
96
97       if (log.isDebugEnabled())
98       {
99          log.debug("Enter: RPCProvider.processMessage()");
100       }
101
102       RPCInvocation invocation = createRPCInvocation(msgContext, reqEnv, resEnv, obj);
103       invocation.prepareFromRequestEnvelope();
104
105       OperationDesc operation = invocation.getOperation();
106       Object JavaDoc[] argValues = invocation.getArgValues();
107
108       // store it in the messsage context, so that ws4ee handlers
109
// can pick it up and modify the invocation if neccessary
110
msgContext.setProperty(RPC_INVOCATION, invocation);
111
112       // This is a hack that disables AsString representation of the SOAPPart
113
// for as long as we are processing the message. WS4EE need access to the SOAPEnvelope's DOM model.
114
// TDI 15-June-2004
115
reqEnv.setProcessingRPCInvocation(true);
116       resEnv.setProcessingRPCInvocation(true);
117
118       // OK! Now we can invoke the method
119
try
120       {
121          Object JavaDoc resObj = invokeTarget(invocation);
122          invocation.prepareResponseEnvelope(resObj);
123       }
124       catch (IllegalArgumentException JavaDoc e)
125       {
126          String JavaDoc methodSig = operation.toString();
127          String JavaDoc argClasses = "";
128          for (int i = 0; i < argValues.length; i++)
129          {
130             if (argValues[i] == null)
131             {
132                argClasses += "null";
133             }
134             else
135             {
136                argClasses += argValues[i].getClass().getName();
137             }
138             if (i + 1 < argValues.length)
139             {
140                argClasses += ",";
141             }
142          }
143          log.info(Messages.getMessage("dispatchIAE00", new String JavaDoc[]{methodSig, argClasses}), e);
144          throw new AxisFault(Messages.getMessage("dispatchIAE00", new String JavaDoc[]{methodSig, argClasses}), e);
145       }
146       finally
147       {
148          reqEnv.setProcessingRPCInvocation(false);
149          resEnv.setProcessingRPCInvocation(false);
150       }
151    }
152
153    public RPCInvocation createRPCInvocation(MessageContext msgContext, SOAPEnvelopeAxisImpl reqEnv, SOAPEnvelopeAxisImpl resEnv, Object JavaDoc obj)
154    {
155       RPCInvocation invocation = new RPCInvocation(this, msgContext, reqEnv, resEnv, obj);
156       return invocation;
157    }
158
159    /**
160     * Unwraps the invocation and calls invokeMethod
161     *
162     * @param invocation The invocation
163     * @return Return value from invokeMethod
164     * @throws Exception Any client Exception
165     */

166    protected Object JavaDoc invokeTarget(RPCInvocation invocation) throws Exception JavaDoc
167    {
168
169       MessageContext msgContext = invocation.getMessageContext();
170       Object JavaDoc targetObject = invocation.getTargetObject();
171       Method JavaDoc method = invocation.getOperation().getMethod();
172       Object JavaDoc[] argValues = invocation.getArgValues();
173
174       try
175       {
176          Object JavaDoc objRes = invokeMethod(msgContext, method, targetObject, argValues);
177          return objRes;
178       }
179       catch (InvocationTargetException JavaDoc e)
180       {
181          if (e.getTargetException() instanceof Exception JavaDoc)
182             throw (Exception JavaDoc)e.getTargetException();
183          else
184             throw e;
185       }
186       finally
187       {
188          msgContext.setPastPivot(true);
189       }
190    }
191
192    /**
193     * This method encapsulates the method invocation.
194     *
195     * @param msgContext MessageContext
196     * @param method the target method.
197     * @param obj the target object
198     * @param argValues the method arguments
199     */

200    protected Object JavaDoc invokeMethod(MessageContext msgContext, Method JavaDoc method, Object JavaDoc obj, Object JavaDoc[] argValues)
201            throws Exception JavaDoc
202    {
203
204       return (method.invoke(obj, argValues));
205    }
206
207    /**
208     * Throw an AxisFault if the requested method is not allowed.
209     *
210     * @param msgContext MessageContext
211     * @param allowedMethods list of allowed methods
212     * @param methodName name of target method
213     */

214    protected void checkMethodName(MessageContext msgContext, String JavaDoc allowedMethods, String JavaDoc methodName)
215            throws Exception JavaDoc
216    {
217
218       // Our version doesn't need to do anything, though inherited ones might.
219
}
220 }
221
Popular Tags