1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.ws.soap.addressing.server;
18
19 import java.lang.annotation.Annotation;
20 import java.lang.reflect.Method;
21 import java.net.URI;
22 import java.net.URISyntaxException;
23
24 import org.springframework.aop.support.AopUtils;
25 import org.springframework.beans.BeansException;
26 import org.springframework.beans.factory.config.BeanPostProcessor;
27 import org.springframework.core.annotation.AnnotationUtils;
28 import org.springframework.util.StringUtils;
29 import org.springframework.ws.server.endpoint.MethodEndpoint;
30 import org.springframework.ws.server.endpoint.annotation.Endpoint;
31 import org.springframework.ws.soap.addressing.core.MessageAddressingProperties;
32 import org.springframework.ws.soap.addressing.server.annotation.Action;
33 import org.springframework.ws.soap.addressing.server.annotation.Address;
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60 public class AnnotationActionEndpointMapping extends AbstractActionMethodEndpointMapping implements BeanPostProcessor {
61
62
63 protected Class<? extends Annotation> getEndpointAnnotationType() {
64 return Endpoint.class;
65 }
66
67
68
69
70
71 @Override
72 protected URI getActionForMethod(Method method) {
73 Action action = method.getAnnotation(Action.class);
74 if (action != null && StringUtils.hasText(action.value())) {
75 try {
76 return new URI(action.value());
77 }
78 catch (URISyntaxException e) {
79 throw new IllegalArgumentException(
80 "Invalid Action annotation [" + action.value() + "] on [" + method + "]");
81 }
82 }
83 return null;
84 }
85
86
87
88
89
90
91
92
93
94
95 @Override
96 protected URI getEndpointAddress(Object endpoint) {
97 MethodEndpoint methodEndpoint = (MethodEndpoint) endpoint;
98 Class<?> endpointClass = methodEndpoint.getMethod().getDeclaringClass();
99 Address address = AnnotationUtils.findAnnotation(endpointClass, Address.class);
100 if (address != null && StringUtils.hasText(address.value())) {
101 return getActionUri(address.value(), methodEndpoint);
102 }
103 else {
104 return null;
105 }
106 }
107
108 @Override
109 protected URI getResponseAction(Object endpoint, MessageAddressingProperties map) {
110 MethodEndpoint methodEndpoint = (MethodEndpoint) endpoint;
111 Action action = methodEndpoint.getMethod().getAnnotation(Action.class);
112 if (action != null && StringUtils.hasText(action.output())) {
113 return getActionUri(action.output(), methodEndpoint);
114 }
115 else {
116 return super.getResponseAction(endpoint, map);
117 }
118 }
119
120 @Override
121 protected URI getFaultAction(Object endpoint, MessageAddressingProperties map) {
122 MethodEndpoint methodEndpoint = (MethodEndpoint) endpoint;
123 Action action = methodEndpoint.getMethod().getAnnotation(Action.class);
124 if (action != null && StringUtils.hasText(action.fault())) {
125 return getActionUri(action.fault(), methodEndpoint);
126 }
127 else {
128 return super.getResponseAction(endpoint, map);
129 }
130 }
131
132 private URI getActionUri(String action, MethodEndpoint methodEndpoint) {
133 try {
134 return new URI(action);
135 }
136 catch (URISyntaxException e) {
137 throw new IllegalArgumentException(
138 "Invalid Action annotation [" + action + "] on [" + methodEndpoint + "]");
139 }
140 }
141
142 public final Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
143 return bean;
144 }
145
146 public final Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
147 if (AopUtils.getTargetClass(bean).getAnnotation(getEndpointAnnotationType()) != null) {
148 registerMethods(bean);
149 }
150 return bean;
151 }
152 }