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:
020: package org.apache.axis2.receivers;
021:
022: import org.apache.axiom.om.OMElement;
023: import org.apache.axis2.AxisFault;
024: import org.apache.axis2.context.MessageContext;
025: import org.apache.axis2.description.AxisOperation;
026: import org.apache.axis2.engine.MessageReceiver;
027: import org.apache.axis2.i18n.Messages;
028:
029: import java.lang.reflect.Method;
030:
031: /**
032: * The RawXMLINOnlyMessageReceiver MessageReceiver hands over the raw request received to
033: * the service implementation class as an OMElement. The implementation class is NOT
034: * expected to return any value, but may do so and it would be ignored. This is a
035: * synchronous MessageReceiver, and finds the service implementation class to invoke by
036: * referring to the "ServiceClass" parameter value specified in the service.xml and
037: * looking at the methods of the form void <<methodName>>(OMElement request)
038: *
039: * @see RawXMLINOutMessageReceiver
040: * @see RawXMLINOutAsyncMessageReceiver
041: */
042: public class RawXMLINOnlyMessageReceiver extends
043: AbstractInMessageReceiver implements MessageReceiver {
044:
045: private Method findOperation(AxisOperation op, Class implClass) {
046: Method method = (Method) (op.getParameterValue("myMethod"));
047: if (method != null)
048: return method;
049:
050: String methodName = op.getName().getLocalPart();
051: try {
052: // Looking for a method of the form "void method(OMElement)"
053: method = implClass.getMethod(methodName,
054: new Class[] { OMElement.class });
055: if (method.getReturnType().equals(void.class)) {
056: try {
057: op.addParameter("myMethod", method);
058: } catch (AxisFault axisFault) {
059: // Do nothing here
060: }
061: return method;
062: }
063: } catch (NoSuchMethodException e) {
064: // Fall through
065: }
066:
067: return null;
068: }
069:
070: /**
071: * Invokes the business logic invocation on the service implementation class
072: *
073: * @param msgContext the incoming message context
074: * @throws AxisFault on invalid method (wrong signature)
075: */
076: public void invokeBusinessLogic(MessageContext msgContext)
077: throws AxisFault {
078: try {
079: // get the implementation class for the Web Service
080: Object obj = getTheImplementationObject(msgContext);
081:
082: // find the WebService method
083: Class implClass = obj.getClass();
084:
085: AxisOperation op = msgContext.getAxisOperation();
086: Method method = findOperation(op, implClass);
087:
088: if (method == null) {
089: throw new AxisFault(Messages
090: .getMessage("methodDoesNotExistInOnly"));
091: }
092:
093: method.invoke(obj, new Object[] { msgContext.getEnvelope()
094: .getBody().getFirstElement() });
095:
096: } catch (Exception e) {
097: throw AxisFault.makeFault(e);
098: }
099: }
100: }
|