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