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 java.util.Map;
023:
024: import org.apache.axis2.AxisFault;
025: import org.apache.axis2.addressing.EndpointReference;
026: import org.apache.axis2.context.ConfigurationContext;
027: import org.apache.axis2.context.MessageContext;
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.engine.AxisConfiguration;
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: public class RequestURIBasedServiceDispatcher extends
038: AbstractServiceDispatcher {
039:
040: public static final String NAME = "RequestURIBasedServiceDispatcher";
041: private static final Log log = LogFactory
042: .getLog(RequestURIBasedServiceDispatcher.class);
043:
044: /*
045: * (non-Javadoc)
046: * @see org.apache.axis2.engine.AbstractDispatcher#findService(org.apache.axis2.context.MessageContext)
047: */
048: public AxisService findService(MessageContext messageContext)
049: throws AxisFault {
050: EndpointReference toEPR = messageContext.getTo();
051: if (toEPR != null) {
052: if (LoggingControl.debugLoggingAllowed
053: && log.isDebugEnabled()) {
054: log
055: .debug(messageContext.getLogIDString()
056: + " Checking for Service using target endpoint address : "
057: + toEPR.getAddress());
058: }
059: String filePart = toEPR.getAddress();
060: //REVIEW: (nagy) Parsing the RequestURI will also give us the operationName if present, so we could conceivably store it in the MessageContext, but doing so and retrieving it is probably no faster than simply reparsing the URI
061: ConfigurationContext configurationContext = messageContext
062: .getConfigurationContext();
063: String[] values = Utils
064: .parseRequestURLForServiceAndOperation(filePart,
065: messageContext.getConfigurationContext()
066: .getServiceContextPath());
067:
068: if ((values.length >= 1) && (values[0] != null)) {
069:
070: AxisConfiguration registry = configurationContext
071: .getAxisConfiguration();
072:
073: AxisService axisService = registry
074: .getService(values[0]);
075:
076: // If the axisService is not null we get the binding that the request came to add
077: // add it as a property to the messageContext
078: if (axisService != null) {
079: Map endpoints = axisService.getEndpoints();
080: if (endpoints != null) {
081: if (endpoints.size() == 1) {
082: messageContext.setProperty(
083: WSDL2Constants.ENDPOINT_LOCAL_NAME,
084: endpoints.get(axisService
085: .getEndpointName()));
086: } else {
087: String endpointName = values[0]
088: .substring(values[0].indexOf(".") + 1);
089: messageContext.setProperty(
090: WSDL2Constants.ENDPOINT_LOCAL_NAME,
091: endpoints.get(endpointName));
092: }
093: }
094: }
095:
096: return axisService;
097: } else {
098: if (LoggingControl.debugLoggingAllowed
099: && log.isDebugEnabled()) {
100: log
101: .debug(messageContext.getLogIDString()
102: + " Attempted to check for Service using target endpoint URI, but the service fragment was missing");
103: }
104: return null;
105: }
106: } else {
107: if (LoggingControl.debugLoggingAllowed
108: && log.isDebugEnabled()) {
109: log
110: .debug(messageContext.getLogIDString()
111: + " Attempted to check for Service using null target endpoint URI");
112: }
113: return null;
114: }
115: }
116:
117: public void initDispatcher() {
118: init(new HandlerDescription(NAME));
119: }
120: }
|