01: /*
02: * Copyright 2007 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 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: */
45: public class PayloadMethodEndpointAdapter extends
46: AbstractMethodEndpointAdapter {
47:
48: protected boolean supportsInternal(MethodEndpoint methodEndpoint) {
49: Method method = methodEndpoint.getMethod();
50: return (Void.TYPE.isAssignableFrom(method.getReturnType()) || Source.class
51: .isAssignableFrom(method.getReturnType()))
52: && method.getParameterTypes().length == 1
53: && Source.class.isAssignableFrom(method
54: .getParameterTypes()[0]);
55:
56: }
57:
58: protected void invokeInternal(MessageContext messageContext,
59: MethodEndpoint methodEndpoint) throws Exception {
60: Source requestSource = messageContext.getRequest()
61: .getPayloadSource();
62: Object result = methodEndpoint
63: .invoke(new Object[] { requestSource });
64: if (result != null) {
65: Source responseSource = (Source) result;
66: WebServiceMessage response = messageContext.getResponse();
67: transform(responseSource, response.getPayloadResult());
68: }
69: }
70: }
|