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.engine;
021:
022: import org.apache.axis2.AxisFault;
023: import org.apache.axis2.Constants;
024: import org.apache.axis2.context.MessageContext;
025: import org.apache.axis2.description.AxisBindingOperation;
026: import org.apache.axis2.description.AxisEndpoint;
027: import org.apache.axis2.description.AxisOperation;
028: import org.apache.axis2.description.AxisService;
029: import org.apache.axis2.description.HandlerDescription;
030: import org.apache.axis2.description.WSDL2Constants;
031: import org.apache.axis2.handlers.AbstractHandler;
032: import org.apache.axis2.i18n.Messages;
033: import org.apache.axis2.util.LoggingControl;
034: import org.apache.axis2.wsdl.WSDLConstants;
035: import org.apache.commons.logging.Log;
036: import org.apache.commons.logging.LogFactory;
037:
038: /**
039: * This the base class for all dispatchers. A dispatcher's task is
040: * to find the service for an incoming SOAP message.
041: * <p/>
042: * In Axis2, a chain of dispatchers is setup. Each tries to
043: * dispatch and return without throwing an exception, in case it fails
044: * to find the service or operation. Dispatchers look for services, operations,
045: * or both.
046: *
047: */
048: public abstract class AbstractDispatcher extends AbstractHandler {
049:
050: /**
051: * Field NAME
052: */
053: public static final String NAME = "AbstractDispatcher";
054: private static final Log log = LogFactory
055: .getLog(AbstractDispatcher.class);
056:
057: public AbstractDispatcher() {
058: init(new HandlerDescription(NAME));
059: }
060:
061: /**
062: * Called by Axis Engine to find the operation.
063: *
064: * @param service
065: * @param messageContext
066: * @return Returns AxisOperation.
067: * @throws AxisFault
068: */
069: public abstract AxisOperation findOperation(AxisService service,
070: MessageContext messageContext) throws AxisFault;
071:
072: /**
073: * Called by Axis Engine to find the service.
074: *
075: * @param messageContext
076: * @return Returns AxisService.
077: * @throws AxisFault
078: */
079: public abstract AxisService findService(
080: MessageContext messageContext) throws AxisFault;
081:
082: public abstract void initDispatcher();
083:
084: /**
085: * @param msgctx
086: * @throws org.apache.axis2.AxisFault
087: */
088: public InvocationResponse invoke(MessageContext msgctx)
089: throws AxisFault {
090: AxisService axisService = msgctx.getAxisService();
091:
092: if (axisService == null) {
093: axisService = findService(msgctx);
094:
095: if (axisService != null) {
096: if (LoggingControl.debugLoggingAllowed
097: && log.isDebugEnabled()) {
098: log.debug(msgctx.getLogIDString()
099: + " "
100: + Messages.getMessage("servicefound",
101: axisService.getName()));
102: }
103: msgctx.setAxisService(axisService);
104: }
105: }
106:
107: if ((axisService != null)
108: && (msgctx.getAxisOperation() == null)) {
109: AxisOperation axisOperation = findOperation(axisService,
110: msgctx);
111:
112: if (axisOperation != null) {
113: if (LoggingControl.debugLoggingAllowed
114: && log.isDebugEnabled()) {
115: log.debug(msgctx.getLogIDString()
116: + " "
117: + Messages.getMessage("operationfound",
118: axisOperation.getName()
119: .getLocalPart()));
120: }
121:
122: msgctx.setAxisOperation(axisOperation);
123: //setting axisMessage into messageContext
124: msgctx
125: .setAxisMessage(axisOperation
126: .getMessage(WSDLConstants.MESSAGE_LABEL_IN_VALUE));
127: AxisEndpoint axisEndpoint = (AxisEndpoint) msgctx
128: .getProperty(WSDL2Constants.ENDPOINT_LOCAL_NAME);
129: if (axisEndpoint != null) {
130: AxisBindingOperation axisBindingOperation = (AxisBindingOperation) axisEndpoint
131: .getBinding().getChild(
132: axisOperation.getName());
133: msgctx.setProperty(
134: Constants.AXIS_BINDING_OPERATION,
135: axisBindingOperation);
136: }
137:
138: }
139: }
140: return InvocationResponse.CONTINUE;
141: }
142: }
|