1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.ws.transport;
18
19 import java.io.IOException;
20 import java.io.InputStream;
21 import java.io.OutputStream;
22 import java.util.Iterator;
23
24
25
26
27
28
29
30 public abstract class AbstractReceiverConnection extends AbstractWebServiceConnection {
31
32 private TransportInputStream requestInputStream;
33
34 private TransportOutputStream responseOutputStream;
35
36 protected final TransportInputStream createTransportInputStream() throws IOException {
37 if (requestInputStream == null) {
38 requestInputStream = new RequestTransportInputStream();
39 }
40 return requestInputStream;
41 }
42
43 protected final TransportOutputStream createTransportOutputStream() throws IOException {
44 if (responseOutputStream == null) {
45 responseOutputStream = new ResponseTransportOutputStream();
46 }
47 return responseOutputStream;
48 }
49
50 public final void close() throws IOException {
51 try {
52 if (requestInputStream != null) {
53 requestInputStream.close();
54 }
55 }
56 finally {
57 onClose();
58 }
59 }
60
61
62
63
64
65
66 protected void onClose() throws IOException {
67 }
68
69
70
71
72
73 protected abstract Iterator getRequestHeaderNames() throws IOException;
74
75
76
77
78
79 protected abstract Iterator getRequestHeaders(String name) throws IOException;
80
81
82 protected abstract InputStream getRequestInputStream() throws IOException;
83
84
85
86
87
88
89
90
91 protected abstract void addResponseHeader(String name, String value) throws IOException;
92
93
94 protected abstract OutputStream getResponseOutputStream() throws IOException;
95
96
97 private class RequestTransportInputStream extends TransportInputStream {
98
99 protected InputStream createInputStream() throws IOException {
100 return getRequestInputStream();
101 }
102
103 public Iterator getHeaderNames() throws IOException {
104 return getRequestHeaderNames();
105 }
106
107 public Iterator getHeaders(String name) throws IOException {
108 return getRequestHeaders(name);
109 }
110
111 public void close() throws IOException {
112
113 }
114
115
116 }
117
118
119 private class ResponseTransportOutputStream extends TransportOutputStream {
120
121 public void addHeader(String name, String value) throws IOException {
122 addResponseHeader(name, value);
123 }
124
125 protected OutputStream createOutputStream() throws IOException {
126 return getResponseOutputStream();
127 }
128
129 }
130
131
132 }