001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019: package org.apache.axis2.rpc.receivers;
020:
021: import org.apache.axiom.om.OMElement;
022: import org.apache.axiom.om.OMNamespace;
023: import org.apache.axiom.soap.SOAPEnvelope;
024: import org.apache.axiom.soap.SOAPFactory;
025: import org.apache.axis2.AxisFault;
026: import org.apache.axis2.context.MessageContext;
027: import org.apache.axis2.description.*;
028: import org.apache.axis2.description.java2wsdl.Java2WSDLConstants;
029: import org.apache.axis2.receivers.AbstractInOutAsyncMessageReceiver;
030: import org.apache.axis2.wsdl.WSDLConstants;
031: import org.apache.commons.logging.Log;
032: import org.apache.commons.logging.LogFactory;
033:
034: import java.lang.reflect.InvocationTargetException;
035: import java.lang.reflect.Method;
036:
037: public class RPCInOutAsyncMessageReceiver extends
038: AbstractInOutAsyncMessageReceiver {
039:
040: private static Log log = LogFactory
041: .getLog(RPCInOnlyMessageReceiver.class);
042:
043: /**
044: * reflect and get the Java method - for each i'th param in the java method - get the first
045: * child's i'th child -if the elem has an xsi:type attr then find the deserializer for it - if
046: * not found, lookup deser for th i'th param (java type) - error if not found - deserialize &
047: * save in an object array - end for
048: * <p/>
049: * - invoke method and get the return value
050: * <p/>
051: * - look up serializer for return value based on the value and type
052: * <p/>
053: * - create response msg and add return value as grand child of <soap:body>
054: *
055: * @param inMessage
056: * @param outMessage
057: * @throws AxisFault
058: */
059:
060: public void invokeBusinessLogic(MessageContext inMessage,
061: MessageContext outMessage) throws AxisFault {
062: Method method = null;
063: try {
064: // get the implementation class for the Web Service
065: Object obj = getTheImplementationObject(inMessage);
066:
067: Class ImplClass = obj.getClass();
068:
069: AxisOperation op = inMessage.getOperationContext()
070: .getAxisOperation();
071: AxisService service = inMessage.getAxisService();
072: OMElement methodElement = inMessage.getEnvelope().getBody()
073: .getFirstElement();
074:
075: AxisMessage inaxisMessage = op
076: .getMessage(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
077: String messageNameSpace = null;
078: String methodName = op.getName().getLocalPart();
079: Method[] methods = ImplClass.getMethods();
080: for (int i = 0; i < methods.length; i++) {
081: if (methods[i].getName().equals(methodName)) {
082: method = methods[i];
083: break;
084: }
085: }
086: Object resObject = null;
087: if (inaxisMessage != null) {
088: resObject = RPCUtil.invokeServiceClass(inaxisMessage,
089: method, obj, messageNameSpace, methodElement,
090: inMessage);
091: }
092:
093: SOAPFactory fac = getSOAPFactory(inMessage);
094:
095: // Handling the response
096:
097: AxisMessage outaxisMessage = op
098: .getMessage(WSDLConstants.MESSAGE_LABEL_OUT_VALUE);
099: if (outaxisMessage != null
100: && outaxisMessage.getElementQName() != null) {
101: messageNameSpace = outaxisMessage.getElementQName()
102: .getNamespaceURI();
103: } else {
104: messageNameSpace = service.getTargetNamespace();
105: }
106:
107: OMNamespace ns = fac.createOMNamespace(messageNameSpace,
108: service.getSchemaTargetNamespacePrefix());
109: SOAPEnvelope envelope = fac.getDefaultEnvelope();
110: OMElement bodyContent = null;
111:
112: if (WSDL2Constants.MEP_URI_ROBUST_IN_ONLY.equals(op
113: .getMessageExchangePattern())) {
114: OMElement bodyChild = fac.createOMElement(outMessage
115: .getAxisMessage().getName(), ns);
116: envelope.getBody().addChild(bodyChild);
117: outMessage.setEnvelope(envelope);
118: return;
119: }
120: Parameter generateBare = service
121: .getParameter(Java2WSDLConstants.DOC_LIT_BARE_PARAMETER);
122: if (generateBare != null
123: && "true".equals(generateBare.getValue())) {
124: RPCUtil.processResonseAsDocLitBare(resObject, service,
125: envelope, fac, ns, bodyContent, outMessage);
126: } else {
127: RPCUtil.processResponseAsDocLitWrapped(resObject,
128: service, method, envelope, fac, ns,
129: bodyContent, outMessage);
130: }
131: outMessage.setEnvelope(envelope);
132: } catch (InvocationTargetException e) {
133: String msg = null;
134: Throwable cause = e.getCause();
135: if (cause != null) {
136: msg = cause.getMessage();
137: }
138: if (msg == null) {
139: msg = "Exception occurred while trying to invoke service method "
140: + method.getName();
141: }
142: log.error(msg, e);
143: if (cause instanceof AxisFault) {
144: throw (AxisFault) cause;
145: }
146: throw new AxisFault(msg);
147: } catch (Exception e) {
148: String msg = "Exception occurred while trying to invoke service method "
149: + method.getName();
150: log.error(msg, e);
151: throw new AxisFault(msg, e);
152: }
153: }
154: }
|