001: /*
002: * Copyright 2005 the original author or authors.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.springframework.ws.soap.server.endpoint.mapping;
018:
019: import org.springframework.util.Assert;
020: import org.springframework.util.StringUtils;
021: import org.springframework.ws.context.MessageContext;
022: import org.springframework.ws.server.EndpointInterceptor;
023: import org.springframework.ws.server.EndpointInvocationChain;
024: import org.springframework.ws.server.endpoint.mapping.AbstractMapBasedEndpointMapping;
025: import org.springframework.ws.soap.SoapMessage;
026: import org.springframework.ws.soap.axiom.AxiomSoapMessageFactory;
027: import org.springframework.ws.soap.server.SoapEndpointInvocationChain;
028: import org.springframework.ws.soap.server.SoapEndpointMapping;
029:
030: /**
031: * Implementation of the <code>EndpointMapping</code> interface to map from <code>SOAPAction</code> headers to endpoint
032: * beans. Supports both mapping to bean instances and mapping to bean names: the latter is required for prototype
033: * handlers.
034: * <p/>
035: * The <code>endpointMap</code> property is suitable for populating the endpoint map with bean references, e.g. via the
036: * map element in XML bean definitions.
037: * <p/>
038: * Mappings to bean names can be set via the <code>mappings</code> property, in a form accepted by the
039: * <code>java.util.Properties</code> class, like as follows:
040: * <pre>
041: * http://www.springframework.org/spring-ws/samples/airline/BookFlight=bookFlightEndpoint
042: * http://www.springframework.org/spring-ws/samples/airline/GetFlights=getFlightsEndpoint
043: * </pre>
044: * The syntax is SOAP_ACTION=ENDPOINT_BEAN_NAME.
045: * <p/>
046: * This endpoint mapping does not read from the request message, and therefore is more suitable for message factories
047: * which directly read from the transport request (such as the {@link AxiomSoapMessageFactory} with the
048: * <code>payloadCaching</code> disabled).
049: *
050: * @author Arjen Poutsma
051: * @since 1.0.0
052: */
053: public class SoapActionEndpointMapping extends
054: AbstractMapBasedEndpointMapping implements SoapEndpointMapping {
055:
056: private String[] actorsOrRoles;
057:
058: private boolean isUltimateReceiver = true;
059:
060: public final void setActorOrRole(String actorOrRole) {
061: Assert.notNull(actorOrRole, "actorOrRole must not be null");
062: actorsOrRoles = new String[] { actorOrRole };
063: }
064:
065: public final void setActorsOrRoles(String[] actorsOrRoles) {
066: Assert.notEmpty(actorsOrRoles,
067: "actorsOrRoles must not be empty");
068: this .actorsOrRoles = actorsOrRoles;
069: }
070:
071: public final void setUltimateReceiver(boolean ultimateReceiver) {
072: isUltimateReceiver = ultimateReceiver;
073: }
074:
075: /**
076: * Creates a new <code>SoapEndpointInvocationChain</code> based on the given endpoint, and the set interceptors, and
077: * actors/roles.
078: *
079: * @param endpoint the endpoint
080: * @param interceptors the endpoint interceptors
081: * @return the created invocation chain
082: * @see #setInterceptors(org.springframework.ws.server.EndpointInterceptor[])
083: * @see #setActorsOrRoles(String[])
084: */
085: protected final EndpointInvocationChain createEndpointInvocationChain(
086: MessageContext messageContext, Object endpoint,
087: EndpointInterceptor[] interceptors) {
088: return new SoapEndpointInvocationChain(endpoint, interceptors,
089: actorsOrRoles, isUltimateReceiver);
090: }
091:
092: protected String getLookupKeyForMessage(
093: MessageContext messageContext) throws Exception {
094: if (messageContext.getRequest() instanceof SoapMessage) {
095: SoapMessage request = (SoapMessage) messageContext
096: .getRequest();
097: String soapAction = request.getSoapAction();
098: if (StringUtils.hasLength(soapAction)
099: && soapAction.charAt(0) == '"'
100: && soapAction.charAt(soapAction.length() - 1) == '"') {
101: return soapAction.substring(1, soapAction.length() - 1);
102: } else {
103: return soapAction;
104: }
105: } else {
106: return null;
107: }
108: }
109:
110: protected boolean validateLookupKey(String key) {
111: return StringUtils.hasLength(key);
112: }
113: }
|