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