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.net.URI;
20 import java.util.HashMap;
21 import java.util.Map;
22
23 import org.springframework.beans.BeansException;
24 import org.springframework.context.ApplicationContext;
25 import org.springframework.context.ApplicationContextAware;
26 import org.springframework.util.Assert;
27 import org.springframework.ws.soap.addressing.core.MessageAddressingProperties;
28
29
30
31
32
33
34
35
36
37
38
39
40 public abstract class AbstractActionEndpointMapping extends AbstractAddressingEndpointMapping
41 implements ApplicationContextAware {
42
43
44 public static final String DEFAULT_OUTPUT_ACTION_SUFFIX = "Response";
45
46
47 public static final String DEFAULT_FAULT_ACTION_SUFFIX = "Fault";
48
49
50 private final Map<URI, Object> endpointMap = new HashMap<URI, Object>();
51
52 private String outputActionSuffix = DEFAULT_OUTPUT_ACTION_SUFFIX;
53
54 private String faultActionSuffix = DEFAULT_OUTPUT_ACTION_SUFFIX;
55
56 private ApplicationContext applicationContext;
57
58
59 public String getOutputActionSuffix() {
60 return outputActionSuffix;
61 }
62
63
64
65
66
67
68 public void setOutputActionSuffix(String outputActionSuffix) {
69 Assert.hasText(outputActionSuffix, "'outputActionSuffix' must not be empty");
70 this.outputActionSuffix = outputActionSuffix;
71 }
72
73
74 public String getFaultActionSuffix() {
75 return faultActionSuffix;
76 }
77
78
79
80
81
82
83 public void setFaultActionSuffix(String faultActionSuffix) {
84 Assert.hasText(faultActionSuffix, "'faultActionSuffix' must not be empty");
85 this.faultActionSuffix = faultActionSuffix;
86 }
87
88 public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
89 this.applicationContext = applicationContext;
90 }
91
92 @Override
93 protected final Object getEndpointInternal(MessageAddressingProperties map) {
94 URI action = map.getAction();
95 if (logger.isDebugEnabled()) {
96 logger.debug("Looking up endpoint for action [" + action + "]");
97 }
98 Object endpoint = lookupEndpoint(action);
99 if (endpoint != null) {
100 URI endpointAddress = getEndpointAddress(endpoint);
101 if (endpointAddress == null || endpointAddress.equals(map.getTo())) {
102 return endpoint;
103 }
104 }
105 return null;
106 }
107
108
109
110
111
112
113
114
115
116 protected abstract URI getEndpointAddress(Object endpoint);
117
118
119
120
121
122
123
124 protected Object lookupEndpoint(URI action) {
125 return endpointMap.get(action);
126 }
127
128
129
130
131
132
133
134
135
136
137
138 protected void registerEndpoint(URI action, Object endpoint) throws BeansException, IllegalStateException {
139 Assert.notNull(action, "Action must not be null");
140 Assert.notNull(endpoint, "Endpoint object must not be null");
141 Object resolvedEndpoint = endpoint;
142
143 if (endpoint instanceof String) {
144 String endpointName = (String) endpoint;
145 if (applicationContext.isSingleton(endpointName)) {
146 resolvedEndpoint = applicationContext.getBean(endpointName);
147 }
148 }
149 Object mappedEndpoint = this.endpointMap.get(action);
150 if (mappedEndpoint != null) {
151 if (mappedEndpoint != resolvedEndpoint) {
152 throw new IllegalStateException("Cannot map endpoint [" + endpoint + "] to action [" + action +
153 "]: There is already endpoint [" + resolvedEndpoint + "] mapped.");
154 }
155 }
156 else {
157 this.endpointMap.put(action, resolvedEndpoint);
158 if (logger.isDebugEnabled()) {
159 logger.debug("Mapped Action [" + action + "] onto endpoint [" + resolvedEndpoint + "]");
160 }
161 }
162 }
163
164 @Override
165 protected URI getResponseAction(Object endpoint, MessageAddressingProperties requestMap) {
166 URI requestAction = requestMap.getAction();
167 if (requestAction != null) {
168 return URI.create(requestAction.toString() + getOutputActionSuffix());
169 }
170 else {
171 return null;
172 }
173 }
174
175 @Override
176 protected URI getFaultAction(Object endpoint, MessageAddressingProperties requestMap) {
177 URI requestAction = requestMap.getAction();
178 if (requestAction != null) {
179 return URI.create(requestAction.toString() + getFaultActionSuffix());
180 }
181 else {
182 return null;
183 }
184 }
185
186 }