1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.ws.server.endpoint.adapter.method;
18
19 import org.springframework.core.MethodParameter;
20 import org.springframework.oxm.GenericMarshaller;
21 import org.springframework.oxm.GenericUnmarshaller;
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
30
31
32
33
34
35
36 public class MarshallingPayloadMethodProcessor extends AbstractPayloadMethodProcessor {
37
38 private Marshaller marshaller;
39
40 private Unmarshaller unmarshaller;
41
42
43
44
45
46
47
48
49 public MarshallingPayloadMethodProcessor() {
50 }
51
52
53
54
55
56
57
58
59
60
61
62
63 public MarshallingPayloadMethodProcessor(Marshaller marshaller) {
64 Assert.notNull(marshaller, "marshaller must not be null");
65 Assert.isInstanceOf(Unmarshaller.class, marshaller);
66 setMarshaller(marshaller);
67 setUnmarshaller((Unmarshaller) marshaller);
68 }
69
70
71
72
73
74
75
76 public MarshallingPayloadMethodProcessor(Marshaller marshaller, Unmarshaller unmarshaller) {
77 Assert.notNull(marshaller, "marshaller must not be null");
78 Assert.notNull(unmarshaller, "unmarshaller must not be null");
79 setMarshaller(marshaller);
80 setUnmarshaller(unmarshaller);
81 }
82
83
84
85
86 public Marshaller getMarshaller() {
87 return marshaller;
88 }
89
90
91
92
93 public void setMarshaller(Marshaller marshaller) {
94 this.marshaller = marshaller;
95 }
96
97
98
99
100 public Unmarshaller getUnmarshaller() {
101 return unmarshaller;
102 }
103
104
105
106
107 public void setUnmarshaller(Unmarshaller unmarshaller) {
108 this.unmarshaller = unmarshaller;
109 }
110
111 @Override
112 protected boolean supportsRequestPayloadParameter(MethodParameter parameter) {
113 Unmarshaller unmarshaller = getUnmarshaller();
114 if (unmarshaller == null) {
115 return false;
116 }
117 else if (unmarshaller instanceof GenericUnmarshaller) {
118 return ((GenericUnmarshaller) unmarshaller).supports(parameter.getGenericParameterType());
119 }
120 else {
121 return unmarshaller.supports(parameter.getParameterType());
122 }
123 }
124
125 public Object resolveArgument(MessageContext messageContext, MethodParameter parameter) throws Exception {
126 Unmarshaller unmarshaller = getUnmarshaller();
127 Assert.state(unmarshaller != null, "unmarshaller must not be null");
128
129 WebServiceMessage request = messageContext.getRequest();
130 Object argument = MarshallingUtils.unmarshal(unmarshaller, request);
131 if (logger.isDebugEnabled()) {
132 logger.debug("Unmarshalled payload request to [" + argument + "]");
133 }
134 return argument;
135 }
136
137 @Override
138 protected boolean supportsResponsePayloadReturnType(MethodParameter returnType) {
139 Marshaller marshaller = getMarshaller();
140 if (marshaller == null) {
141 return false;
142 }
143 else if (marshaller instanceof GenericMarshaller) {
144 GenericMarshaller genericMarshaller = (GenericMarshaller) marshaller;
145 return genericMarshaller.supports(returnType.getGenericParameterType());
146 }
147 else {
148 return marshaller.supports(returnType.getParameterType());
149 }
150 }
151
152 public void handleReturnValue(MessageContext messageContext, MethodParameter returnType, Object returnValue)
153 throws Exception {
154 Marshaller marshaller = getMarshaller();
155 Assert.state(marshaller != null, "marshaller must not be null");
156
157 if (logger.isDebugEnabled()) {
158 logger.debug("Marshalling [" + returnValue + "] to response payload");
159 }
160 WebServiceMessage response = messageContext.getResponse();
161 MarshallingUtils.marshal(marshaller, returnValue, response);
162 }
163
164 }