001: /*
002: * Copyright 2007 the original author or authors.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.springframework.ws.transport;
018:
019: import java.io.IOException;
020: import java.io.InputStream;
021: import java.io.OutputStream;
022: import java.util.Iterator;
023:
024: /**
025: * Abstract base class for {@link WebServiceConnection} implementations used for receiving requests.
026: *
027: * @author Arjen Poutsma
028: * @since 1.0.0
029: */
030: public abstract class AbstractReceiverConnection extends
031: AbstractWebServiceConnection {
032:
033: private TransportInputStream requestInputStream;
034:
035: private TransportOutputStream responseOutputStream;
036:
037: protected final TransportInputStream createTransportInputStream()
038: throws IOException {
039: if (requestInputStream == null) {
040: requestInputStream = new RequestTransportInputStream();
041: }
042: return requestInputStream;
043: }
044:
045: protected final TransportOutputStream createTransportOutputStream()
046: throws IOException {
047: if (responseOutputStream == null) {
048: responseOutputStream = new ResponseTransportOutputStream();
049: }
050: return responseOutputStream;
051: }
052:
053: /**
054: * Returns an iteration over all the header names this request contains. Returns an empty <code>Iterator</code> if
055: * there areno headers.
056: */
057: protected abstract Iterator getRequestHeaderNames()
058: throws IOException;
059:
060: /**
061: * Returns an iteration over all the string values of the specified header. Returns an empty <code>Iterator</code>
062: * if there are no headers of the specified name.
063: */
064: protected abstract Iterator getRequestHeaders(String name)
065: throws IOException;
066:
067: /** Returns the input stream to read the response from. */
068: protected abstract InputStream getRequestInputStream()
069: throws IOException;
070:
071: /**
072: * Adds a response header with the given name and value. This method can be called multiple times, to allow for
073: * headers with multiple values.
074: *
075: * @param name the name of the header
076: * @param value the value of the header
077: */
078: protected abstract void addResponseHeader(String name, String value)
079: throws IOException;
080:
081: /** Returns the output stream to write the request to. */
082: protected abstract OutputStream getResponseOutputStream()
083: throws IOException;
084:
085: /** Implementation of <code>TransportInputStream</code> for receiving-side connections. */
086: private class RequestTransportInputStream extends
087: TransportInputStream {
088:
089: protected InputStream createInputStream() throws IOException {
090: return getRequestInputStream();
091: }
092:
093: public Iterator getHeaderNames() throws IOException {
094: return getRequestHeaderNames();
095: }
096:
097: public Iterator getHeaders(String name) throws IOException {
098: return getRequestHeaders(name);
099: }
100:
101: }
102:
103: /** Implementation of <code>TransportOutputStream</code> for sending-side connections. */
104: private class ResponseTransportOutputStream extends
105: TransportOutputStream {
106:
107: public void addHeader(String name, String value)
108: throws IOException {
109: addResponseHeader(name, value);
110: }
111:
112: protected OutputStream createOutputStream() throws IOException {
113: return getResponseOutputStream();
114: }
115:
116: }
117:
118: }
|