View Javadoc

1   /*
2    * Copyright 2005 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 javax.xml.transform.Source;
20  
21  import org.springframework.ws.WebServiceMessage;
22  import org.springframework.ws.context.MessageContext;
23  import org.springframework.ws.server.EndpointAdapter;
24  import org.springframework.ws.server.MessageDispatcher;
25  import org.springframework.ws.server.endpoint.PayloadEndpoint;
26  import org.springframework.ws.soap.server.SoapMessageDispatcher;
27  import org.springframework.xml.transform.TransformerObjectSupport;
28  
29  /**
30   * Adapter to use a <code>PayloadEndpoint</code> as the endpoint for a <code>EndpointInvocationChain</code>.
31   * <p/>
32   * This adapter is registered by default by the {@link MessageDispatcher} and {@link SoapMessageDispatcher}.
33   *
34   * @author Arjen Poutsma
35   * @see org.springframework.ws.server.endpoint.PayloadEndpoint
36   * @see org.springframework.ws.server.EndpointInvocationChain
37   * @since 1.0.0
38   */
39  public class PayloadEndpointAdapter extends TransformerObjectSupport implements EndpointAdapter {
40  
41      public boolean supports(Object endpoint) {
42          return endpoint instanceof PayloadEndpoint;
43      }
44  
45      public void invoke(MessageContext messageContext, Object endpoint) throws Exception {
46          PayloadEndpoint payloadEndpoint = (PayloadEndpoint) endpoint;
47          Source requestSource = messageContext.getRequest().getPayloadSource();
48          Source responseSource = payloadEndpoint.invoke(requestSource);
49          if (responseSource != null) {
50              WebServiceMessage response = messageContext.getResponse();
51              transform(responseSource, response.getPayloadResult());
52          }
53      }
54  }