1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.ws.server.endpoint;
18
19 import java.io.IOException;
20
21 import org.springframework.beans.factory.InitializingBean;
22 import org.springframework.oxm.Marshaller;
23 import org.springframework.oxm.Unmarshaller;
24 import org.springframework.util.Assert;
25 import org.springframework.ws.WebServiceMessage;
26 import org.springframework.ws.context.MessageContext;
27 import org.springframework.ws.support.MarshallingUtils;
28
29 import org.apache.commons.logging.Log;
30 import org.apache.commons.logging.LogFactory;
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46 @Deprecated
47 public abstract class AbstractMarshallingPayloadEndpoint implements MessageEndpoint, InitializingBean {
48
49
50 protected final Log logger = LogFactory.getLog(getClass());
51
52 private Marshaller marshaller;
53
54 private Unmarshaller unmarshaller;
55
56
57
58
59
60
61
62
63 protected AbstractMarshallingPayloadEndpoint() {
64 }
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79 protected AbstractMarshallingPayloadEndpoint(Marshaller marshaller) {
80 Assert.notNull(marshaller, "marshaller must not be null");
81 if (!(marshaller instanceof Unmarshaller)) {
82 throw new IllegalArgumentException("Marshaller [" + marshaller + "] does not implement the Unmarshaller " +
83 "interface. Please set an Unmarshaller explicitly by using the " +
84 "AbstractMarshallingPayloadEndpoint(Marshaller, Unmarshaller) constructor.");
85 }
86 else {
87 setMarshaller(marshaller);
88 setUnmarshaller((Unmarshaller) marshaller);
89 }
90 }
91
92
93
94
95
96
97
98 protected AbstractMarshallingPayloadEndpoint(Marshaller marshaller, Unmarshaller unmarshaller) {
99 Assert.notNull(marshaller, "marshaller must not be null");
100 Assert.notNull(unmarshaller, "unmarshaller must not be null");
101 setMarshaller(marshaller);
102 setUnmarshaller(unmarshaller);
103 }
104
105
106 public Marshaller getMarshaller() {
107 return marshaller;
108 }
109
110
111 public final void setMarshaller(Marshaller marshaller) {
112 this.marshaller = marshaller;
113 }
114
115
116 public Unmarshaller getUnmarshaller() {
117 return unmarshaller;
118 }
119
120
121 public final void setUnmarshaller(Unmarshaller unmarshaller) {
122 this.unmarshaller = unmarshaller;
123 }
124
125 public void afterPropertiesSet() throws Exception {
126 afterMarshallerSet();
127 }
128
129 public final void invoke(MessageContext messageContext) throws Exception {
130 WebServiceMessage request = messageContext.getRequest();
131 Object requestObject = unmarshalRequest(request);
132 if (onUnmarshalRequest(messageContext, requestObject)) {
133 Object responseObject = invokeInternal(requestObject);
134 if (responseObject != null) {
135 WebServiceMessage response = messageContext.getResponse();
136 marshalResponse(responseObject, response);
137 onMarshalResponse(messageContext, requestObject, responseObject);
138 }
139 }
140 }
141
142 private Object unmarshalRequest(WebServiceMessage request) throws IOException {
143 Unmarshaller unmarshaller = getUnmarshaller();
144 Assert.notNull(unmarshaller, "No unmarshaller registered. Check configuration of endpoint.");
145 Object requestObject = MarshallingUtils.unmarshal(unmarshaller, request);
146 if (logger.isDebugEnabled()) {
147 logger.debug("Unmarshalled payload request to [" + requestObject + "]");
148 }
149 return requestObject;
150 }
151
152
153
154
155
156
157
158
159
160
161
162 protected boolean onUnmarshalRequest(MessageContext messageContext, Object requestObject) throws Exception {
163 return true;
164 }
165
166 private void marshalResponse(Object responseObject, WebServiceMessage response) throws IOException {
167 Marshaller marshaller = getMarshaller();
168 Assert.notNull(marshaller, "No marshaller registered. Check configuration of endpoint.");
169 if (logger.isDebugEnabled()) {
170 logger.debug("Marshalling [" + responseObject + "] to response payload");
171 }
172 MarshallingUtils.marshal(marshaller, responseObject, response);
173 }
174
175
176
177
178
179
180
181
182
183
184
185 protected void onMarshalResponse(MessageContext messageContext, Object requestObject, Object responseObject) {
186 }
187
188
189
190
191
192
193
194
195
196 @Deprecated
197 public void afterMarshallerSet() throws Exception {
198 }
199
200
201
202
203
204
205
206
207
208
209 protected abstract Object invokeInternal(Object requestObject) throws Exception;
210 }