001: /*
002: * Copyright 2007 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 java.lang.reflect.Method;
020:
021: import org.springframework.util.Assert;
022: import org.springframework.util.StringUtils;
023: import org.springframework.ws.context.MessageContext;
024: import org.springframework.ws.server.EndpointInterceptor;
025: import org.springframework.ws.server.EndpointInvocationChain;
026: import org.springframework.ws.server.endpoint.mapping.AbstractAnnotationMethodEndpointMapping;
027: import org.springframework.ws.soap.SoapMessage;
028: import org.springframework.ws.soap.server.SoapEndpointInvocationChain;
029: import org.springframework.ws.soap.server.SoapEndpointMapping;
030: import org.springframework.ws.soap.server.endpoint.annotation.SoapAction;
031:
032: /**
033: * Implementation of the {@link org.springframework.ws.server.EndpointMapping} interface that uses the {@link
034: * SoapAction} annotation to map methods to the request SOAPAction header.
035: * <p/>
036: * Endpoints typically have the following form:
037: * <pre>
038: * @Endpoint
039: * public class MyEndpoint{
040: * @SoapAction("http://springframework.org/spring-ws/SoapAction")
041: * public Source doSomethingWithRequest() {
042: * ...
043: * }
044: * }
045: * </pre>
046: *
047: * @author Arjen Poutsma
048: * @since 1.0.0
049: */
050: public class SoapActionAnnotationMethodEndpointMapping extends
051: AbstractAnnotationMethodEndpointMapping implements
052: SoapEndpointMapping {
053:
054: private String[] actorsOrRoles;
055:
056: private boolean isUltimateReceiver = true;
057:
058: public final void setActorOrRole(String actorOrRole) {
059: Assert.notNull(actorOrRole, "actorOrRole must not be null");
060: actorsOrRoles = new String[] { actorOrRole };
061: }
062:
063: public final void setActorsOrRoles(String[] actorsOrRoles) {
064: Assert.notEmpty(actorsOrRoles,
065: "actorsOrRoles must not be empty");
066: this .actorsOrRoles = actorsOrRoles;
067: }
068:
069: public final void setUltimateReceiver(boolean ultimateReceiver) {
070: isUltimateReceiver = ultimateReceiver;
071: }
072:
073: /**
074: * Creates a new <code>SoapEndpointInvocationChain</code> based on the given endpoint, and the set interceptors, and
075: * actors/roles.
076: *
077: * @param endpoint the endpoint
078: * @param interceptors the endpoint interceptors
079: * @return the created invocation chain
080: * @see #setInterceptors(org.springframework.ws.server.EndpointInterceptor[])
081: * @see #setActorsOrRoles(String[])
082: */
083: protected final EndpointInvocationChain createEndpointInvocationChain(
084: MessageContext messageContext, Object endpoint,
085: EndpointInterceptor[] interceptors) {
086: return new SoapEndpointInvocationChain(endpoint, interceptors,
087: actorsOrRoles, isUltimateReceiver);
088: }
089:
090: protected String getLookupKeyForMessage(
091: MessageContext messageContext) throws Exception {
092: if (messageContext.getRequest() instanceof SoapMessage) {
093: SoapMessage request = (SoapMessage) messageContext
094: .getRequest();
095: String soapAction = request.getSoapAction();
096: if (StringUtils.hasLength(soapAction)
097: && soapAction.charAt(0) == '"'
098: && soapAction.charAt(soapAction.length() - 1) == '"') {
099: return soapAction.substring(1, soapAction.length() - 1);
100: } else {
101: return soapAction;
102: }
103: } else {
104: return null;
105: }
106: }
107:
108: protected String getLookupKeyForMethod(Method method) {
109: SoapAction soapAction = method.getAnnotation(SoapAction.class);
110: return soapAction != null ? soapAction.value() : null;
111: }
112: }
|