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.server.endpoint.adapter;
18  
19  import java.lang.reflect.Method;
20  import javax.xml.transform.Source;
21  
22  import org.springframework.ws.WebServiceMessage;
23  import org.springframework.ws.context.MessageContext;
24  import org.springframework.ws.server.MessageDispatcher;
25  import org.springframework.ws.server.endpoint.MethodEndpoint;
26  import org.springframework.ws.soap.server.SoapMessageDispatcher;
27  
28  /**
29   * Adapter that supports endpoint methods that use marshalling. Supports methods with the following signature:
30   * <pre>
31   * void handleMyMessage(Source request);
32   * </pre>
33   * or
34   * <pre>
35   * Source handleMyMessage(Source request);
36   * </pre>
37   * I.e. methods that take a single {@link Source} parameter, and return either <code>void</code> or a {@link Source}.
38   * The method can have any name, as long as it is mapped by an {@link org.springframework.ws.server.EndpointMapping}.
39   * <p/>
40   * This adapter is registered by default by the {@link MessageDispatcher} and {@link SoapMessageDispatcher}.
41   *
42   * @author Arjen Poutsma
43   * @since 1.0.0
44   * @deprecated as of Spring Web Services 2.0, in favor of {@link DefaultMethodEndpointAdapter} and {@link
45   *             org.springframework.ws.server.endpoint.adapter.method.SourcePayloadMethodProcessor
46   *             SourcePayloadMethodProcessor}.
47   */
48  @Deprecated
49  public class PayloadMethodEndpointAdapter extends AbstractMethodEndpointAdapter {
50  
51      @Override
52      protected boolean supportsInternal(MethodEndpoint methodEndpoint) {
53          Method method = methodEndpoint.getMethod();
54          return (Void.TYPE.isAssignableFrom(method.getReturnType()) ||
55                  Source.class.isAssignableFrom(method.getReturnType())) && method.getParameterTypes().length == 1 &&
56                  Source.class.isAssignableFrom(method.getParameterTypes()[0]);
57  
58      }
59  
60      @Override
61      protected void invokeInternal(MessageContext messageContext, MethodEndpoint methodEndpoint) throws Exception {
62          Source requestSource = messageContext.getRequest().getPayloadSource();
63          Object result = methodEndpoint.invoke(requestSource);
64          if (result != null) {
65              Source responseSource = (Source) result;
66              WebServiceMessage response = messageContext.getResponse();
67              transform(responseSource, response.getPayloadResult());
68          }
69      }
70  }