1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.ws.soap.addressing.client;
18
19 import java.io.IOException;
20 import java.net.URI;
21 import java.net.URISyntaxException;
22 import javax.xml.transform.TransformerException;
23
24 import org.springframework.core.JdkVersion;
25 import org.springframework.util.Assert;
26 import org.springframework.ws.WebServiceMessage;
27 import org.springframework.ws.client.core.WebServiceMessageCallback;
28 import org.springframework.ws.soap.SoapMessage;
29 import org.springframework.ws.soap.addressing.core.EndpointReference;
30 import org.springframework.ws.soap.addressing.core.MessageAddressingProperties;
31 import org.springframework.ws.soap.addressing.messageid.MessageIdStrategy;
32 import org.springframework.ws.soap.addressing.messageid.RandomGuidMessageIdStrategy;
33 import org.springframework.ws.soap.addressing.messageid.UuidMessageIdStrategy;
34 import org.springframework.ws.soap.addressing.version.Addressing10;
35 import org.springframework.ws.soap.addressing.version.AddressingVersion;
36 import org.springframework.ws.transport.context.TransportContext;
37 import org.springframework.ws.transport.context.TransportContextHolder;
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56 public class ActionCallback implements WebServiceMessageCallback {
57
58 private final AddressingVersion version;
59
60 private final URI action;
61
62 private final URI to;
63
64 private MessageIdStrategy messageIdStrategy;
65
66 private EndpointReference from;
67
68 private EndpointReference replyTo;
69
70 private EndpointReference faultTo;
71
72
73
74
75
76
77
78
79
80
81
82 public ActionCallback(String action) throws URISyntaxException {
83 this(new URI(action), new Addressing10(), null);
84 }
85
86
87
88
89
90
91
92
93
94
95
96 public ActionCallback(URI action) {
97 this(action, new Addressing10(), null);
98 }
99
100
101
102
103
104
105
106
107
108
109 public ActionCallback(URI action, AddressingVersion version) {
110 this(action, version, null);
111 }
112
113
114
115
116
117
118
119
120
121 public ActionCallback(URI action, AddressingVersion version, URI to) {
122 Assert.notNull(action, "'action' must not be null");
123 Assert.notNull(version, "'version' must not be null");
124 this.action = action;
125 this.version = version;
126 this.to = to;
127 if (JdkVersion.isAtLeastJava15()) {
128 messageIdStrategy = new UuidMessageIdStrategy();
129 }
130 else {
131 messageIdStrategy = new RandomGuidMessageIdStrategy();
132 }
133 }
134
135
136
137
138
139 public AddressingVersion getVersion() {
140 return version;
141 }
142
143
144
145
146
147
148
149 public MessageIdStrategy getMessageIdStrategy() {
150 return messageIdStrategy;
151 }
152
153
154
155
156
157
158
159 public void setMessageIdStrategy(MessageIdStrategy messageIdStrategy) {
160 Assert.notNull(messageIdStrategy, "'messageIdStrategy' must not be null");
161 this.messageIdStrategy = messageIdStrategy;
162 }
163
164
165
166
167
168 public URI getAction() {
169 return action;
170 }
171
172
173
174
175
176 public EndpointReference getFrom() {
177 return from;
178 }
179
180
181
182
183
184 public void setFrom(EndpointReference from) {
185 this.from = from;
186 }
187
188
189
190
191
192 public EndpointReference getReplyTo() {
193 return replyTo;
194 }
195
196
197
198
199
200 public void setReplyTo(EndpointReference replyTo) {
201 this.replyTo = replyTo;
202 }
203
204
205
206
207
208 public EndpointReference getFaultTo() {
209 return faultTo;
210 }
211
212
213
214
215
216 public void setFaultTo(EndpointReference faultTo) {
217 this.faultTo = faultTo;
218 }
219
220
221
222
223
224
225
226
227
228 protected URI getTo() {
229 if (to == null) {
230 TransportContext transportContext = TransportContextHolder.getTransportContext();
231 if (transportContext != null && transportContext.getConnection() != null) {
232 try {
233 return transportContext.getConnection().getUri();
234 }
235 catch (URISyntaxException ex) {
236
237 }
238 }
239 throw new IllegalStateException("Could not obtain connection URI from Transport Context");
240 }
241 else {
242 return to;
243 }
244 }
245
246 public void doWithMessage(WebServiceMessage message) throws IOException, TransformerException {
247 Assert.isInstanceOf(SoapMessage.class, message);
248 SoapMessage soapMessage = (SoapMessage) message;
249 URI messageId = getMessageIdStrategy().newMessageId(soapMessage);
250 MessageAddressingProperties map =
251 new MessageAddressingProperties(getTo(), getFrom(), getReplyTo(), getFaultTo(), getAction(), messageId);
252 version.addAddressingHeaders(soapMessage, map);
253 }
254
255
256 }