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 protected URI getActionForMethod(Method method) {
72 Action action = method.getAnnotation(Action.class);
73 if (action != null && StringUtils.hasText(action.value())) {
74 try {
75 return new URI(action.value());
76 }
77 catch (URISyntaxException e) {
78 throw new IllegalArgumentException(
79 "Invalid Action annotation [" + action.value() + "] on [" + method + "]");
80 }
81 }
82 return null;
83 }
84
85
86
87
88
89
90
91
92
93
94 protected URI getEndpointAddress(Object endpoint) {
95 MethodEndpoint methodEndpoint = (MethodEndpoint) endpoint;
96 Class endpointClass = methodEndpoint.getMethod().getDeclaringClass();
97 Address address = AnnotationUtils.findAnnotation(endpointClass, Address.class);
98 if (address != null && StringUtils.hasText(address.value())) {
99 return getActionUri(address.value(), methodEndpoint);
100 }
101 else {
102 return null;
103 }
104 }
105
106 protected URI getResponseAction(Object endpoint, MessageAddressingProperties map) {
107 MethodEndpoint methodEndpoint = (MethodEndpoint) endpoint;
108 Action action = methodEndpoint.getMethod().getAnnotation(Action.class);
109 if (action != null && StringUtils.hasText(action.output())) {
110 return getActionUri(action.output(), methodEndpoint);
111 }
112 else {
113 return super.getResponseAction(endpoint, map);
114 }
115 }
116
117 protected URI getFaultAction(Object endpoint, MessageAddressingProperties map) {
118 MethodEndpoint methodEndpoint = (MethodEndpoint) endpoint;
119 Action action = methodEndpoint.getMethod().getAnnotation(Action.class);
120 if (action != null && StringUtils.hasText(action.fault())) {
121 return getActionUri(action.fault(), methodEndpoint);
122 }
123 else {
124 return super.getResponseAction(endpoint, map);
125 }
126 }
127
128 private URI getActionUri(String action, MethodEndpoint methodEndpoint) {
129 try {
130 return new URI(action);
131 }
132 catch (URISyntaxException e) {
133 throw new IllegalArgumentException(
134 "Invalid Action annotation [" + action + "] on [" + methodEndpoint + "]");
135 }
136 }
137
138 public final Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
139 return bean;
140 }
141
142 public final Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
143 if (AopUtils.getTargetClass(bean).getAnnotation(getEndpointAnnotationType()) != null) {
144 registerMethods(bean);
145 }
146 return bean;
147 }
148 }