You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by ga...@apache.org on 2007/03/29 21:13:04 UTC
svn commit: r523802 -
/geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/GeronimoDestination.java
Author: gawor
Date: Thu Mar 29 12:13:03 2007
New Revision: 523802
URL: http://svn.apache.org/viewvc?view=rev&rev=523802
Log:
set content-type take two
Modified:
geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/GeronimoDestination.java
Modified: geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/GeronimoDestination.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/GeronimoDestination.java?view=diff&rev=523802&r1=523801&r2=523802
==============================================================================
--- geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/GeronimoDestination.java (original)
+++ geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/GeronimoDestination.java Thu Mar 29 12:13:03 2007
@@ -33,7 +33,6 @@
import javax.xml.ws.handler.MessageContext;
import org.apache.cxf.Bus;
-import org.apache.cxf.io.AbstractWrappedOutputStream;
import org.apache.cxf.message.Message;
import org.apache.cxf.message.MessageImpl;
import org.apache.cxf.service.model.EndpointInfo;
@@ -194,6 +193,28 @@
*/
public void send(Message message) throws IOException {
Response response = (Response)request.get(Response.class);
+
+ // 1. handle response code
+ Integer i = (Integer) message.get(Message.RESPONSE_CODE);
+ if (i != null) {
+ response.setStatusCode(i.intValue());
+ }
+
+ // 2. handle response headers
+ updateResponseHeaders(message);
+
+ Map<String, List<String>> protocolHeaders =
+ (Map<String, List<String>>) message.get(Message.PROTOCOL_HEADERS);
+
+ // set headers of the HTTP response object
+ Iterator headers = protocolHeaders.entrySet().iterator();
+ while (headers.hasNext()) {
+ Map.Entry entry = (Map.Entry) headers.next();
+ String headerName = (String) entry.getKey();
+ String headerValue = getHeaderValue((List) entry.getValue());
+ response.setHeader(headerName, headerValue);
+ }
+
message.setContent(OutputStream.class, new WrappedOutputStream(message, response));
}
@@ -233,11 +254,11 @@
return buf.toString();
}
- protected void copyResponseHeaders(Message message, Response response) {
+ protected void setContentType(Message message, Response response) {
Map<String, List<String>> protocolHeaders =
(Map<String, List<String>>)message.get(Message.PROTOCOL_HEADERS);
- if (!protocolHeaders.containsKey(Message.CONTENT_TYPE)) {
+ if (protocolHeaders != null && !protocolHeaders.containsKey(Message.CONTENT_TYPE)) {
String ct = (String) message.get(Message.CONTENT_TYPE);
String enc = (String) message.get(Message.ENCODING);
@@ -249,68 +270,55 @@
} else if (enc != null) {
response.setContentType("text/xml; charset=" + enc);
}
- }
-
- // set headers of the HTTP response object
- Iterator headers = protocolHeaders.entrySet().iterator();
- while(headers.hasNext()) {
- Map.Entry entry = (Map.Entry)headers.next();
- String headerName = (String)entry.getKey();
- String headerValue = getHeaderValue((List)entry.getValue());
- response.setHeader(headerName, headerValue);
- }
+ }
}
-
- private class WrappedOutputStream extends AbstractWrappedOutputStream {
+
+ private class WrappedOutputStream extends OutputStream {
- protected Response response;
+ private Message message;
+ private Response response;
+ private OutputStream rawOutputStream;
- WrappedOutputStream(Message m, Response response) {
- super(m);
+ WrappedOutputStream(Message message, Response response) {
+ this.message = message;
this.response = response;
}
- protected void doFlush() throws IOException {
- OutputStream responseStream = flushHeaders(outMessage);
- if (null != responseStream && !alreadyFlushed()) {
- resetOut(responseStream, true);
- }
+ public void write(int b) throws IOException {
+ flushHeaders();
+ this.rawOutputStream.write(b);
}
-
- protected void doClose() {
- commitResponse();
+
+ public void write(byte b[]) throws IOException {
+ flushHeaders();
+ this.rawOutputStream.write(b);
}
- protected void onWrite() throws IOException {
+ public void write(byte b[], int off, int len) throws IOException {
+ flushHeaders();
+ this.rawOutputStream.write(b, off, len);
}
- private void commitResponse() {
- try {
- response.flushBuffer();
- } catch (IOException e) {
- getLogger().warning(e.getMessage());
- }
+ public void flush() throws IOException {
+ flushHeaders();
+ this.rawOutputStream.flush();
}
-
- protected OutputStream flushHeaders(Message outMessage) throws IOException {
- updateResponseHeaders(outMessage);
- Integer i = (Integer) outMessage.get(Message.RESPONSE_CODE);
- if (i != null) {
- response.setStatusCode(i.intValue());
- } else {
- response.setStatusCode(HttpURLConnection.HTTP_OK);
+ public void close() throws IOException {
+ flushHeaders();
+ this.rawOutputStream.close();
+ }
+
+ protected void flushHeaders() throws IOException {
+ if (this.rawOutputStream != null) {
+ return;
}
- copyResponseHeaders(outMessage, response);
- OutputStream responseStream = response.getOutputStream();
-
- if (isOneWay(outMessage)) {
- response.flushBuffer();
- }
+ setContentType(this.message, this.response);
- return responseStream;
+ this.rawOutputStream = this.response.getOutputStream();
}
- }
+ }
+
}