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.dispatchers;
021:
022: import org.apache.axiom.om.OMElement;
023: import org.apache.axiom.om.OMNamespace;
024: import org.apache.axis2.AxisFault;
025: import org.apache.axis2.engine.AbstractDispatcher;
026: import org.apache.axis2.engine.AxisConfiguration;
027: import org.apache.axis2.context.ConfigurationContext;
028: import org.apache.axis2.context.MessageContext;
029: import org.apache.axis2.description.AxisOperation;
030: import org.apache.axis2.description.AxisService;
031: import org.apache.axis2.description.HandlerDescription;
032: import org.apache.axis2.util.LoggingControl;
033: import org.apache.axis2.util.Utils;
034: import org.apache.commons.logging.Log;
035: import org.apache.commons.logging.LogFactory;
036:
037: import javax.xml.namespace.QName;
038:
039: /**
040: * Dispatches based on the namespace URI of the first child of
041: * the body.
042: */
043: public class SOAPMessageBodyBasedDispatcher extends AbstractDispatcher {
044:
045: /**
046: * Field NAME
047: */
048: public static final String NAME = "SOAPMessageBodyBasedDispatcher";
049: private static final Log log = LogFactory
050: .getLog(SOAPMessageBodyBasedDispatcher.class);
051:
052: public AxisOperation findOperation(AxisService service,
053: MessageContext messageContext) throws AxisFault {
054:
055: OMElement bodyFirstChild = messageContext.getEnvelope()
056: .getBody().getFirstElement();
057:
058: AxisOperation axisOperation = null;
059: if (bodyFirstChild != null) {
060: axisOperation = service
061: .getOperationByMessageElementQName(bodyFirstChild
062: .getQName());
063:
064: // this is required for services uses the RPC message receiver
065: if (axisOperation == null) {
066: QName operationName = new QName(bodyFirstChild
067: .getLocalName());
068: axisOperation = service.getOperation(operationName);
069: }
070:
071: }
072: return axisOperation;
073: }
074:
075: /*
076: * (non-Javadoc)
077: * @see org.apache.axis2.engine.AbstractDispatcher#findService(org.apache.axis2.context.MessageContext)
078: */
079: public AxisService findService(MessageContext messageContext)
080: throws AxisFault {
081: String serviceName;
082:
083: OMElement bodyFirstChild = messageContext.getEnvelope()
084: .getBody().getFirstElement();
085:
086: if (bodyFirstChild != null) {
087: OMNamespace ns = bodyFirstChild.getNamespace();
088:
089: if (ns != null) {
090: String filePart = ns.getNamespaceURI();
091:
092: if (LoggingControl.debugLoggingAllowed
093: && log.isDebugEnabled()) {
094: log
095: .debug(messageContext.getLogIDString()
096: + " Checking for Service using SOAP message body's first child's namespace : "
097: + filePart);
098: }
099: ConfigurationContext configurationContext = messageContext
100: .getConfigurationContext();
101: String[] values = Utils
102: .parseRequestURLForServiceAndOperation(
103: filePart, configurationContext
104: .getServiceContextPath());
105:
106: if (values[0] != null) {
107: serviceName = values[0];
108:
109: AxisConfiguration registry = configurationContext
110: .getAxisConfiguration();
111:
112: return registry.getService(serviceName);
113: }
114: }
115: }
116:
117: return null;
118: }
119:
120: public void initDispatcher() {
121: init(new HandlerDescription(NAME));
122: }
123: }
|