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
140
141 public void setMessageIdStrategy(MessageIdStrategy messageIdStrategy) {
142 Assert.notNull(messageIdStrategy, "'messageIdStrategy' must not be null");
143 this.messageIdStrategy = messageIdStrategy;
144 }
145
146 public void setFrom(EndpointReference from) {
147 this.from = from;
148 }
149
150 public void setReplyTo(EndpointReference replyTo) {
151 this.replyTo = replyTo;
152 }
153
154 public void setFaultTo(EndpointReference faultTo) {
155 this.faultTo = faultTo;
156 }
157
158
159
160
161
162
163
164 protected URI getTo() {
165 if (to == null) {
166 TransportContext transportContext = TransportContextHolder.getTransportContext();
167 if (transportContext != null && transportContext.getConnection() != null) {
168 try {
169 return transportContext.getConnection().getUri();
170 }
171 catch (URISyntaxException ex) {
172
173 }
174 }
175 throw new IllegalStateException("Could not obtain connection URI from Transport Context");
176 }
177 else {
178 return to;
179 }
180 }
181
182 public void doWithMessage(WebServiceMessage message) throws IOException, TransformerException {
183 Assert.isInstanceOf(SoapMessage.class, message);
184 SoapMessage soapMessage = (SoapMessage) message;
185 URI to = getTo();
186 URI messageId = messageIdStrategy.newMessageId(soapMessage);
187 MessageAddressingProperties map =
188 new MessageAddressingProperties(to, from, replyTo, faultTo, action, messageId);
189 version.addAddressingHeaders(soapMessage, map);
190 }
191
192
193 }