1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.ws.transport.http;
18
19 import java.io.IOException;
20 import java.io.InputStream;
21 import java.io.OutputStream;
22 import java.net.URI;
23 import java.net.URISyntaxException;
24 import java.util.Iterator;
25 import javax.servlet.http.HttpServletRequest;
26 import javax.servlet.http.HttpServletResponse;
27
28 import org.springframework.ws.WebServiceMessage;
29 import org.springframework.ws.transport.AbstractReceiverConnection;
30 import org.springframework.ws.transport.EndpointAwareWebServiceConnection;
31 import org.springframework.ws.transport.FaultAwareWebServiceConnection;
32 import org.springframework.ws.transport.WebServiceConnection;
33 import org.springframework.ws.transport.support.EnumerationIterator;
34
35
36
37
38
39
40
41 public class HttpServletConnection extends AbstractReceiverConnection
42 implements EndpointAwareWebServiceConnection, FaultAwareWebServiceConnection {
43
44 private final HttpServletRequest httpServletRequest;
45
46 private final HttpServletResponse httpServletResponse;
47
48 private boolean statusCodeSet = false;
49
50
51
52
53
54 protected HttpServletConnection(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
55 this.httpServletRequest = httpServletRequest;
56 this.httpServletResponse = httpServletResponse;
57 }
58
59
60 public HttpServletRequest getHttpServletRequest() {
61 return httpServletRequest;
62 }
63
64
65 public HttpServletResponse getHttpServletResponse() {
66 return httpServletResponse;
67 }
68
69 public void endpointNotFound() {
70 getHttpServletResponse().setStatus(HttpTransportConstants.STATUS_NOT_FOUND);
71 statusCodeSet = true;
72 }
73
74
75
76
77
78 public boolean hasError() throws IOException {
79 return false;
80 }
81
82 public String getErrorMessage() throws IOException {
83 return null;
84 }
85
86
87
88
89
90 public URI getUri() throws URISyntaxException {
91 return new URI(httpServletRequest.getScheme(), null, httpServletRequest.getServerName(),
92 httpServletRequest.getServerPort(), httpServletRequest.getRequestURI(),
93 httpServletRequest.getQueryString(), null);
94 }
95
96
97
98
99
100 @Override
101 @SuppressWarnings("unchecked")
102 protected Iterator<String> getRequestHeaderNames() throws IOException {
103 return new EnumerationIterator(getHttpServletRequest().getHeaderNames());
104 }
105
106 @Override
107 @SuppressWarnings("unchecked")
108 protected Iterator<String> getRequestHeaders(String name) throws IOException {
109 return new EnumerationIterator(getHttpServletRequest().getHeaders(name));
110 }
111
112 @Override
113 protected InputStream getRequestInputStream() throws IOException {
114 return getHttpServletRequest().getInputStream();
115 }
116
117
118
119
120
121 @Override
122 protected void addResponseHeader(String name, String value) throws IOException {
123 getHttpServletResponse().addHeader(name, value);
124 }
125
126 @Override
127 protected OutputStream getResponseOutputStream() throws IOException {
128 return getHttpServletResponse().getOutputStream();
129 }
130
131 @Override
132 protected void onSendAfterWrite(WebServiceMessage message) throws IOException {
133 statusCodeSet = true;
134 }
135
136 @Override
137 public void onClose() throws IOException {
138 if (!statusCodeSet) {
139 getHttpServletResponse().setStatus(HttpTransportConstants.STATUS_ACCEPTED);
140 }
141 }
142
143
144
145
146
147 public boolean hasFault() throws IOException {
148 return false;
149 }
150
151 public void setFault(boolean fault) throws IOException {
152 if (fault) {
153 getHttpServletResponse().setStatus(HttpTransportConstants.STATUS_INTERNAL_SERVER_ERROR);
154 }
155 else {
156 getHttpServletResponse().setStatus(HttpTransportConstants.STATUS_OK);
157 }
158 statusCodeSet = true;
159 }
160 }