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;
18
19 import javax.xml.transform.Source;
20 import javax.xml.transform.sax.SAXResult;
21
22 import org.springframework.xml.transform.TransformerObjectSupport;
23
24 import org.xml.sax.ContentHandler;
25
26 /**
27 * Abstract base class for endpoints that handle the message payload with a SAX <code>ContentHandler</code>. Allows
28 * subclasses to create a response by returning a <code>Source</code>.
29 * <p/>
30 * Implementations of this class should create a new handler for each call of <code>createContentHandler</code>, because
31 * of thread safety. The handlers is later passed on to <code>createResponse</code>, so it can be used for holding
32 * request-specific state.
33 *
34 * @author Arjen Poutsma
35 * @see #createContentHandler()
36 * @see #getResponse(org.xml.sax.ContentHandler)
37 * @since 1.0.0
38 * @deprecated as of Spring Web Services 2.0, in favor of annotated endpoints
39 */
40 @Deprecated
41 public abstract class AbstractSaxPayloadEndpoint extends TransformerObjectSupport implements PayloadEndpoint {
42
43 /**
44 * Invokes the provided <code>ContentHandler</code> on the given request. After parsing has been done, the provided
45 * response is returned.
46 *
47 * @see #createContentHandler()
48 * @see #getResponse(org.xml.sax.ContentHandler)
49 */
50 public final Source invoke(Source request) throws Exception {
51 ContentHandler contentHandler = null;
52 if (request != null) {
53 contentHandler = createContentHandler();
54 SAXResult result = new SAXResult(contentHandler);
55 transform(request, result);
56 }
57 return getResponse(contentHandler);
58 }
59
60 /**
61 * Returns the SAX <code>ContentHandler</code> used to parse the incoming request payload. A new instance should be
62 * created for each call, because of thread-safety. The content handler can be used to hold request-specific state.
63 * <p/>
64 * If an incoming message does not contain a payload, this method will not be invoked.
65 *
66 * @return a SAX content handler to be used for parsing
67 */
68 protected abstract ContentHandler createContentHandler() throws Exception;
69
70 /**
71 * Returns the response to be given, if any. This method is called after the request payload has been parsed using
72 * the SAX <code>ContentHandler</code>. The passed <code>ContentHandler</code> is created by {@link
73 * #createContentHandler()}: it can be used to hold request-specific state.
74 * <p/>
75 * If an incoming message does not contain a payload, this method will be invoked with <code>null</code> as content
76 * handler.
77 *
78 * @param contentHandler the content handler used to parse the request
79 */
80 protected abstract Source getResponse(ContentHandler contentHandler) throws Exception;
81 }