1 /*
2 * Copyright 2005-2010 the original author or authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package org.springframework.ws.soap.server.endpoint.mapping;
18
19 import org.springframework.util.Assert;
20 import org.springframework.util.StringUtils;
21 import org.springframework.ws.context.MessageContext;
22 import org.springframework.ws.server.EndpointInterceptor;
23 import org.springframework.ws.server.EndpointInvocationChain;
24 import org.springframework.ws.server.endpoint.mapping.AbstractMapBasedEndpointMapping;
25 import org.springframework.ws.soap.SoapMessage;
26 import org.springframework.ws.soap.axiom.AxiomSoapMessageFactory;
27 import org.springframework.ws.soap.server.SoapEndpointInvocationChain;
28 import org.springframework.ws.soap.server.SoapEndpointMapping;
29
30 /**
31 * Implementation of the <code>EndpointMapping</code> interface to map from <code>SOAPAction</code> headers to endpoint
32 * beans. Supports both mapping to bean instances and mapping to bean names: the latter is required for prototype
33 * handlers.
34 * <p/>
35 * The <code>endpointMap</code> property is suitable for populating the endpoint map with bean references, e.g. via the
36 * map element in XML bean definitions.
37 * <p/>
38 * Mappings to bean names can be set via the <code>mappings</code> property, in a form accepted by the
39 * <code>java.util.Properties</code> class, like as follows:
40 * <pre>
41 * http://www.springframework.org/spring-ws/samples/airline/BookFlight=bookFlightEndpoint
42 * http://www.springframework.org/spring-ws/samples/airline/GetFlights=getFlightsEndpoint
43 * </pre>
44 * The syntax is SOAP_ACTION=ENDPOINT_BEAN_NAME.
45 * <p/>
46 * This endpoint mapping does not read from the request message, and therefore is more suitable for message factories
47 * which directly read from the transport request (such as the {@link AxiomSoapMessageFactory} with the
48 * <code>payloadCaching</code> disabled).
49 *
50 * @author Arjen Poutsma
51 * @since 1.0.0
52 * @deprecated as of Spring Web Services 2.0, in favor of {@link SoapActionAnnotationMethodEndpointMapping}.
53 */
54 @Deprecated
55 public class SoapActionEndpointMapping extends AbstractMapBasedEndpointMapping implements SoapEndpointMapping {
56
57 private String[] actorsOrRoles;
58
59 private boolean isUltimateReceiver = true;
60
61 public final void setActorOrRole(String actorOrRole) {
62 Assert.notNull(actorOrRole, "actorOrRole must not be null");
63 actorsOrRoles = new String[]{actorOrRole};
64 }
65
66 public final void setActorsOrRoles(String[] actorsOrRoles) {
67 Assert.notEmpty(actorsOrRoles, "actorsOrRoles must not be empty");
68 this.actorsOrRoles = actorsOrRoles;
69 }
70
71 public final void setUltimateReceiver(boolean ultimateReceiver) {
72 isUltimateReceiver = ultimateReceiver;
73 }
74
75 /**
76 * Creates a new <code>SoapEndpointInvocationChain</code> based on the given endpoint, and the set interceptors, and
77 * actors/roles.
78 *
79 * @param endpoint the endpoint
80 * @param interceptors the endpoint interceptors
81 * @return the created invocation chain
82 * @see #setInterceptors(org.springframework.ws.server.EndpointInterceptor[])
83 * @see #setActorsOrRoles(String[])
84 */
85 @Override
86 protected final EndpointInvocationChain createEndpointInvocationChain(MessageContext messageContext,
87 Object endpoint,
88 EndpointInterceptor[] interceptors) {
89 return new SoapEndpointInvocationChain(endpoint, interceptors, actorsOrRoles, isUltimateReceiver);
90 }
91
92 @Override
93 protected String getLookupKeyForMessage(MessageContext messageContext) throws Exception {
94 if (messageContext.getRequest() instanceof SoapMessage) {
95 SoapMessage request = (SoapMessage) messageContext.getRequest();
96 String soapAction = request.getSoapAction();
97 if (StringUtils.hasLength(soapAction) && soapAction.charAt(0) == '"' &&
98 soapAction.charAt(soapAction.length() - 1) == '"') {
99 return soapAction.substring(1, soapAction.length() - 1);
100 }
101 else {
102 return soapAction;
103 }
104 }
105 else {
106 return null;
107 }
108 }
109
110 @Override
111 protected boolean validateLookupKey(String key) {
112 return StringUtils.hasLength(key);
113 }
114 }