1 /*
2  * Copyright 2005-2014 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.ws.soap.server.endpoint.adapter.method;
18
19 import org.springframework.core.MethodParameter;
20 import org.springframework.util.Assert;
21 import org.springframework.ws.context.MessageContext;
22 import org.springframework.ws.server.endpoint.adapter.method.MethodArgumentResolver;
23 import org.springframework.ws.soap.SoapBody;
24 import org.springframework.ws.soap.SoapEnvelope;
25 import org.springframework.ws.soap.SoapHeader;
26 import org.springframework.ws.soap.SoapMessage;
27
28 /**
29  * Implementation of {@link MethodArgumentResolver} that supports {@link SoapMessage}, {@link SoapBody}, {@link
30  * SoapEnvelope}, and {@link SoapHeader}.
31  *
32  * @author Arjen Poutsma
33  * @since 2.0
34  */

35 public class SoapMethodArgumentResolver implements MethodArgumentResolver {
36
37     @Override
38     public boolean supportsParameter(MethodParameter parameter) {
39         Class<?> parameterType = parameter.getParameterType();
40         return SoapMessage.class.equals(parameterType) || SoapBody.class.equals(parameterType) ||
41                 SoapEnvelope.class.equals(parameterType) || SoapHeader.class.equals(parameterType);
42     }
43
44     @Override
45     public Object resolveArgument(MessageContext messageContext, MethodParameter parameter) {
46         Assert.isInstanceOf(SoapMessage.class, messageContext.getRequest());
47         SoapMessage request = (SoapMessage) messageContext.getRequest();
48
49         Class<?> parameterType = parameter.getParameterType();
50
51         if (SoapMessage.class.equals(parameterType)) {
52             return request;
53         }
54         else if (SoapBody.class.equals(parameterType)) {
55             return request.getSoapBody();
56         }
57         else if (SoapEnvelope.class.equals(parameterType)) {
58             return request.getEnvelope();
59         }
60         else if (SoapHeader.class.equals(parameterType)) {
61             return request.getSoapHeader();
62         }
63         // should not happen
64         throw new UnsupportedOperationException();
65     }
66 }
67