01: /*
02: * Copyright 2005 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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
40: implements EndpointAdapter {
41:
42: public boolean supports(Object endpoint) {
43: return endpoint instanceof PayloadEndpoint;
44: }
45:
46: public void invoke(MessageContext messageContext, Object endpoint)
47: throws Exception {
48: PayloadEndpoint payloadEndpoint = (PayloadEndpoint) endpoint;
49: Source requestSource = messageContext.getRequest()
50: .getPayloadSource();
51: Source responseSource = payloadEndpoint.invoke(requestSource);
52: if (responseSource != null) {
53: WebServiceMessage response = messageContext.getResponse();
54: transform(responseSource, response.getPayloadResult());
55: }
56: }
57: }
|