1
16
17 package org.springframework.ws.soap.server.endpoint.mapping;
18
19 import java.lang.reflect.Method;
20 import java.util.ArrayList;
21 import java.util.List;
22
23 import org.springframework.core.annotation.AnnotationUtils;
24 import org.springframework.util.Assert;
25 import org.springframework.util.StringUtils;
26 import org.springframework.ws.context.MessageContext;
27 import org.springframework.ws.server.EndpointInterceptor;
28 import org.springframework.ws.server.EndpointInvocationChain;
29 import org.springframework.ws.server.endpoint.mapping.AbstractAnnotationMethodEndpointMapping;
30 import org.springframework.ws.soap.SoapMessage;
31 import org.springframework.ws.soap.server.SoapEndpointInvocationChain;
32 import org.springframework.ws.soap.server.SoapEndpointMapping;
33 import org.springframework.ws.soap.server.endpoint.annotation.SoapAction;
34 import org.springframework.ws.soap.server.endpoint.annotation.SoapActions;
35
36
54 public class SoapActionAnnotationMethodEndpointMapping extends AbstractAnnotationMethodEndpointMapping<String>
55 implements SoapEndpointMapping {
56
57 private String[] actorsOrRoles;
58
59 private boolean isUltimateReceiver = true;
60
61 @Override
62 public final void setActorOrRole(String actorOrRole) {
63 Assert.notNull(actorOrRole, "actorOrRole must not be null");
64 actorsOrRoles = new String[]{actorOrRole};
65 }
66
67 @Override
68 public final void setActorsOrRoles(String[] actorsOrRoles) {
69 Assert.notEmpty(actorsOrRoles, "actorsOrRoles must not be empty");
70 this.actorsOrRoles = actorsOrRoles;
71 }
72
73 @Override
74 public final void setUltimateReceiver(boolean ultimateReceiver) {
75 isUltimateReceiver = ultimateReceiver;
76 }
77
78
88 @Override
89 protected final EndpointInvocationChain createEndpointInvocationChain(MessageContext messageContext,
90 Object endpoint,
91 EndpointInterceptor[] interceptors) {
92 return new SoapEndpointInvocationChain(endpoint, interceptors, actorsOrRoles, isUltimateReceiver);
93 }
94
95 @Override
96 protected String getLookupKeyForMessage(MessageContext messageContext) throws Exception {
97 if (messageContext.getRequest() instanceof SoapMessage) {
98 SoapMessage request = (SoapMessage) messageContext.getRequest();
99 String soapAction = request.getSoapAction();
100 if (StringUtils.hasLength(soapAction) && soapAction.charAt(0) == '"' &&
101 soapAction.charAt(soapAction.length() - 1) == '"') {
102 return soapAction.substring(1, soapAction.length() - 1);
103 }
104 else {
105 return soapAction;
106 }
107 }
108 else {
109 return null;
110 }
111 }
112
113 @Override
114 protected String getLookupKeyForMethod(Method method) {
115 SoapAction soapAction = AnnotationUtils.findAnnotation(method, SoapAction.class);
116 return soapAction != null ? soapAction.value() : null;
117 }
118
119 @Override
120 protected List<String> getLookupKeysForMethod(Method method) {
121 List<String> result = new ArrayList<String>();
122
123 SoapActions soapActions = AnnotationUtils.findAnnotation(method,
124 SoapActions.class);
125 if (soapActions != null) {
126 for (SoapAction soapAction : soapActions.value()) {
127 result.add(soapAction.value());
128 }
129 }
130 else {
131 SoapAction soapAction = AnnotationUtils.findAnnotation(method, SoapAction.class);
132 if (soapAction != null) {
133 result.add(soapAction.value());
134 }
135 }
136 return result;
137 }
138 }
139