View Javadoc

1   /*
2    * Copyright 2005-2010 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      public boolean supportsParameter(MethodParameter parameter) {
38          Class<?> parameterType = parameter.getParameterType();
39          return SoapMessage.class.equals(parameterType) || SoapBody.class.equals(parameterType) ||
40                  SoapEnvelope.class.equals(parameterType) || SoapHeader.class.equals(parameterType);
41      }
42  
43      public Object resolveArgument(MessageContext messageContext, MethodParameter parameter) {
44          Assert.isInstanceOf(SoapMessage.class, messageContext.getRequest());
45          SoapMessage request = (SoapMessage) messageContext.getRequest();
46  
47          Class<?> parameterType = parameter.getParameterType();
48  
49          if (SoapMessage.class.equals(parameterType)) {
50              return request;
51          }
52          else if (SoapBody.class.equals(parameterType)) {
53              return request.getSoapBody();
54          }
55          else if (SoapEnvelope.class.equals(parameterType)) {
56              return request.getEnvelope();
57          }
58          else if (SoapHeader.class.equals(parameterType)) {
59              return request.getSoapHeader();
60          }
61          // should not happen
62          throw new UnsupportedOperationException();
63      }
64  }