Skip to content

Commit 072aab6

Browse files
committed
SWS-297 (SWS-84)
1 parent d299c96 commit 072aab6

File tree

12 files changed

+264
-91
lines changed

12 files changed

+264
-91
lines changed

core-tiger/src/main/java/org/springframework/ws/soap/addressing/server/AnnotationActionEndpointMapping.java

Lines changed: 32 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,11 @@
2424
import org.springframework.aop.support.AopUtils;
2525
import org.springframework.beans.BeansException;
2626
import org.springframework.beans.factory.config.BeanPostProcessor;
27-
import org.springframework.core.JdkVersion;
2827
import org.springframework.core.annotation.AnnotationUtils;
29-
import org.springframework.util.Assert;
3028
import org.springframework.util.StringUtils;
3129
import org.springframework.ws.server.endpoint.MethodEndpoint;
3230
import org.springframework.ws.server.endpoint.annotation.Endpoint;
31+
import org.springframework.ws.soap.addressing.core.MessageAddressingProperties;
3332
import org.springframework.ws.soap.addressing.server.annotation.Action;
3433
import org.springframework.ws.soap.addressing.server.annotation.Address;
3534

@@ -58,46 +57,13 @@
5857
* @see Address
5958
* @since 1.5.0
6059
*/
61-
public class AnnotationActionEndpointMapping extends AbstractActionEndpointMapping implements BeanPostProcessor {
60+
public class AnnotationActionEndpointMapping extends AbstractActionMethodEndpointMapping implements BeanPostProcessor {
6261

6362
/** Returns the 'endpoint' annotation type. Default is {@link Endpoint}. */
6463
protected Class<? extends Annotation> getEndpointAnnotationType() {
6564
return Endpoint.class;
6665
}
6766

68-
public final Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
69-
return bean;
70-
}
71-
72-
public final Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
73-
if (AopUtils.getTargetClass(bean).getAnnotation(getEndpointAnnotationType()) != null) {
74-
registerMethods(bean);
75-
}
76-
return bean;
77-
}
78-
79-
/**
80-
* Helper method that registers the methods of the given bean. This method iterates over the methods of the bean,
81-
* and calls {@link #getActionForMethod(java.lang.reflect.Method)} for each. If this returns a URI, the method is
82-
* registered using {@link #registerEndpoint(java.net.URI, Object)}.
83-
*
84-
* @see #getActionForMethod (java.lang.reflect.Method)
85-
*/
86-
protected void registerMethods(Object endpoint) {
87-
Assert.notNull(endpoint, "'endpoint' must not be null");
88-
Method[] methods = AopUtils.getTargetClass(endpoint).getMethods();
89-
for (int i = 0; i < methods.length; i++) {
90-
if (JdkVersion.isAtLeastJava15() && methods[i].isSynthetic() ||
91-
methods[i].getDeclaringClass().equals(Object.class)) {
92-
continue;
93-
}
94-
URI action = getActionForMethod(methods[i]);
95-
if (action != null) {
96-
registerEndpoint(action, new MethodEndpoint(endpoint, methods[i]));
97-
}
98-
}
99-
}
100-
10167
/**
10268
* Returns the action value for the specified method. Default implementation looks for the {@link Action} annotation
10369
* value.
@@ -109,7 +75,8 @@ protected URI getActionForMethod(Method method) {
10975
return new URI(action.value());
11076
}
11177
catch (URISyntaxException e) {
112-
// ignore
78+
throw new IllegalArgumentException(
79+
"Invalid Action annotation [" + action.value() + "] on [" + method + "]");
11380
}
11481
}
11582
return null;
@@ -139,4 +106,32 @@ protected URI getEndpointAddress(Object endpoint) {
139106
}
140107
return null;
141108
}
109+
110+
protected URI getResponseAction(Object endpoint, MessageAddressingProperties map) {
111+
MethodEndpoint methodEndpoint = (MethodEndpoint) endpoint;
112+
Action action = methodEndpoint.getMethod().getAnnotation(Action.class);
113+
if (action != null && StringUtils.hasText(action.output())) {
114+
try {
115+
return new URI(action.output());
116+
}
117+
catch (URISyntaxException e) {
118+
throw new IllegalArgumentException(
119+
"Invalid Action annotation [" + action.value() + "] on [" + methodEndpoint + "]");
120+
}
121+
}
122+
else {
123+
return super.getResponseAction(endpoint, map);
124+
}
125+
}
126+
127+
public final Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
128+
return bean;
129+
}
130+
131+
public final Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
132+
if (AopUtils.getTargetClass(bean).getAnnotation(getEndpointAnnotationType()) != null) {
133+
registerMethods(bean);
134+
}
135+
return bean;
136+
}
142137
}

core-tiger/src/main/java/org/springframework/ws/soap/addressing/server/annotation/Action.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,7 @@
3737
/** Signifies the value for the request WS-Addressing <code>Action</code> header that is handled by the method. */
3838
String value();
3939

40+
/** Signifies the value for the response WS-Addressing <code>Action</code> header that is provided by the method. */
41+
String output() default "";
42+
4043
}

core/src/main/java/org/springframework/ws/soap/addressing/WsAddressingException.java renamed to core/src/main/java/org/springframework/ws/soap/addressing/AddressingException.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@
2424
* @author Arjen Poutsma
2525
* @since 1.5.0
2626
*/
27-
public class WsAddressingException extends WebServiceException {
27+
public class AddressingException extends WebServiceException {
2828

29-
public WsAddressingException(String msg) {
29+
public AddressingException(String msg) {
3030
super(msg);
3131
}
3232

33-
public WsAddressingException(String msg, Throwable ex) {
33+
public AddressingException(String msg, Throwable ex) {
3434
super(msg, ex);
3535
}
3636
}

core/src/main/java/org/springframework/ws/soap/addressing/server/AbstractActionEndpointMapping.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,36 @@
2929
/**
3030
* Abstract base class for WS-Addressing <code>Action</code>-mapped {@link org.springframework.ws.server.EndpointMapping}
3131
* implementations. Provides infrastructure for mapping endpoints to actions.
32+
* <p/>
33+
* By default, this mapping creates a <code>Action</code> for reply messages based on the request message, plus the
34+
* extra {@link #setOutputActionSuffix(String) suffix}.
3235
*
3336
* @author Arjen Poutsma
3437
* @since 1.5.0
3538
*/
3639
public abstract class AbstractActionEndpointMapping extends AbstractAddressingEndpointMapping
3740
implements ApplicationContextAware {
3841

42+
/** The defaults suffix to add to request <code>Action</code> for reply messages. */
43+
public static final String DEFAULT_OUTPUT_ACTION_SUFFIX = "Response";
44+
3945
// keys are action URIs, values are endpoints
4046
private final Map endpointMap = new HashMap();
4147

48+
private String outputActionSuffix = DEFAULT_OUTPUT_ACTION_SUFFIX;
49+
4250
private ApplicationContext applicationContext;
4351

52+
/**
53+
* Sets the suffix to add to request <code>Action</code>s for reply messages.
54+
*
55+
* @see #DEFAULT_OUTPUT_ACTION_SUFFIX
56+
*/
57+
public void setOutputActionSuffix(String outputActionSuffix) {
58+
Assert.hasText(outputActionSuffix, "'replyActionSuffix' must not be empty");
59+
this.outputActionSuffix = outputActionSuffix;
60+
}
61+
4462
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
4563
this.applicationContext = applicationContext;
4664
}
@@ -116,5 +134,13 @@ protected void registerEndpoint(URI action, Object endpoint) throws BeansExcepti
116134
}
117135
}
118136

119-
137+
protected URI getResponseAction(Object endpoint, MessageAddressingProperties requestMap) {
138+
URI requestAction = requestMap.getAction();
139+
if (requestAction != null) {
140+
return URI.create(requestAction.toString() + outputActionSuffix);
141+
}
142+
else {
143+
return null;
144+
}
145+
}
120146
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* Copyright 2008 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.addressing.server;
18+
19+
import java.lang.reflect.Method;
20+
import java.net.URI;
21+
22+
import org.springframework.aop.support.AopUtils;
23+
import org.springframework.core.JdkVersion;
24+
import org.springframework.util.Assert;
25+
import org.springframework.ws.server.endpoint.MethodEndpoint;
26+
27+
/**
28+
* Abstract base class for WS-Addressing <code>Action</code>-mapped {@link org.springframework.ws.server.EndpointMapping}
29+
* implementations that map to {@link MethodEndpoint}s. Provides infrastructure for mapping endpoint methods to
30+
* actions.
31+
*
32+
* @author Arjen Poutsma
33+
* @since 1.5.0
34+
*/
35+
public abstract class AbstractActionMethodEndpointMapping extends AbstractActionEndpointMapping {
36+
37+
/**
38+
* Helper method that registers the methods of the given bean. This method iterates over the methods of the bean,
39+
* and calls {@link #getActionForMethod(java.lang.reflect.Method)} for each. If this returns a URI, the method is
40+
* registered using {@link #registerEndpoint(java.net.URI, Object)}.
41+
*
42+
* @see #getActionForMethod (java.lang.reflect.Method)
43+
*/
44+
protected void registerMethods(Object endpoint) {
45+
Assert.notNull(endpoint, "'endpoint' must not be null");
46+
Method[] methods = AopUtils.getTargetClass(endpoint).getMethods();
47+
for (int i = 0; i < methods.length; i++) {
48+
if (JdkVersion.isAtLeastJava15() && methods[i].isSynthetic() ||
49+
methods[i].getDeclaringClass().equals(Object.class)) {
50+
continue;
51+
}
52+
URI action = getActionForMethod(methods[i]);
53+
if (action != null) {
54+
registerEndpoint(action, new MethodEndpoint(endpoint, methods[i]));
55+
}
56+
}
57+
}
58+
59+
/** Returns the action value for the specified method. */
60+
protected abstract URI getActionForMethod(Method method);
61+
62+
/**
63+
* Return the class or interface to use for method reflection.
64+
* <p/>
65+
* Default implementation delegates to {@link AopUtils#getTargetClass(Object)}.
66+
*
67+
* @param endpoint the bean instance (might be an AOP proxy)
68+
* @return the bean class to expose
69+
*/
70+
protected Class getEndpointClass(Object endpoint) {
71+
return AopUtils.getTargetClass(endpoint);
72+
}
73+
74+
}

core/src/main/java/org/springframework/ws/soap/addressing/server/AbstractAddressingEndpointMapping.java

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public final EndpointInvocationChain getEndpoint(MessageContext messageContext)
184184
if (endpoint == null) {
185185
return null;
186186
}
187-
return getEndpointInvocationChain(endpoint, versions[i]);
187+
return getEndpointInvocationChain(endpoint, versions[i], requestMap);
188188
}
189189
}
190190
return null;
@@ -194,14 +194,15 @@ public final EndpointInvocationChain getEndpoint(MessageContext messageContext)
194194
* Creates a {@link SoapEndpointInvocationChain} based on the given endpoint and {@link
195195
* org.springframework.ws.soap.addressing.version.AddressingVersion}.
196196
*/
197-
private EndpointInvocationChain getEndpointInvocationChain(Object endpoint, AddressingVersion version) {
198-
URI responseAction = getResponseAction(endpoint);
199-
URI faultAction = getFaultAction(endpoint);
197+
private EndpointInvocationChain getEndpointInvocationChain(Object endpoint,
198+
AddressingVersion version,
199+
MessageAddressingProperties requestMap) {
200+
URI responseAction = getResponseAction(endpoint, requestMap);
200201
EndpointInterceptor[] interceptors =
201202
new EndpointInterceptor[preInterceptors.length + postInterceptors.length + 1];
202203
System.arraycopy(preInterceptors, 0, interceptors, 0, preInterceptors.length);
203-
AddressingEndpointInterceptor interceptor = new AddressingEndpointInterceptor(version, messageIdStrategy,
204-
messageSenders, responseAction, faultAction);
204+
AddressingEndpointInterceptor interceptor =
205+
new AddressingEndpointInterceptor(version, messageIdStrategy, messageSenders, responseAction, null);
205206
interceptors[preInterceptors.length] = interceptor;
206207
System.arraycopy(postInterceptors, 0, interceptors, preInterceptors.length + 1, postInterceptors.length);
207208
return new SoapEndpointInvocationChain(endpoint, interceptors, actorsOrRoles, isUltimateReceiver);
@@ -229,12 +230,6 @@ private boolean supports(AddressingVersion version, SoapMessage request) {
229230
*/
230231
protected abstract Object getEndpointInternal(MessageAddressingProperties map);
231232

232-
protected URI getResponseAction(Object endpoint) {
233-
return null;
234-
}
235-
236-
protected URI getFaultAction(Object endpoint) {
237-
return null;
238-
}
233+
protected abstract URI getResponseAction(Object endpoint, MessageAddressingProperties requestMap);
239234

240235
}

0 commit comments

Comments
 (0)