01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */
19: package org.apache.axis2.rpc.receivers;
20:
21: import org.apache.axiom.om.OMElement;
22: import org.apache.axis2.AxisFault;
23: import org.apache.axis2.context.MessageContext;
24: import org.apache.axis2.description.AxisMessage;
25: import org.apache.axis2.description.AxisOperation;
26: import org.apache.axis2.receivers.AbstractInMessageReceiver;
27: import org.apache.axis2.wsdl.WSDLConstants;
28: import org.apache.commons.logging.Log;
29: import org.apache.commons.logging.LogFactory;
30:
31: import java.lang.reflect.InvocationTargetException;
32: import java.lang.reflect.Method;
33:
34: public class RPCInOnlyMessageReceiver extends AbstractInMessageReceiver {
35:
36: private static Log log = LogFactory
37: .getLog(RPCInOnlyMessageReceiver.class);
38:
39: public void invokeBusinessLogic(MessageContext inMessage)
40: throws AxisFault {
41: Method method = null;
42: try {
43: // get the implementation class for the Web Service
44: Object obj = getTheImplementationObject(inMessage);
45:
46: Class ImplClass = obj.getClass();
47:
48: AxisOperation op = inMessage.getOperationContext()
49: .getAxisOperation();
50:
51: OMElement methodElement = inMessage.getEnvelope().getBody()
52: .getFirstElement();
53:
54: AxisMessage inAxisMessage = op
55: .getMessage(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
56: String messageNameSpace = null;
57: String methodName = op.getName().getLocalPart();
58: Method[] methods = ImplClass.getMethods();
59: for (int i = 0; i < methods.length; i++) {
60: if (methods[i].getName().equals(methodName)) {
61: method = methods[i];
62: break;
63: }
64: }
65: if (inAxisMessage != null) {
66: RPCUtil.invokeServiceClass(inAxisMessage, method, obj,
67: messageNameSpace, methodElement, inMessage);
68:
69: }
70: } catch (InvocationTargetException e) {
71: Throwable cause = e.getCause();
72: if (cause != null) {
73: String msg = cause.getMessage();
74: if (msg == null) {
75: msg = "Exception occurred while trying to invoke service method "
76: + method.getName();
77: }
78: log.error(msg, cause);
79: } else {
80: cause = e;
81: }
82: throw AxisFault.makeFault(cause);
83: } catch (Exception e) {
84: String msg = "Exception occurred while trying to invoke service method "
85: + method.getName();
86: log.error(msg, e);
87: throw new AxisFault(msg, e);
88: }
89: }
90: }
|