01: package org.objectweb.celtix.bus.transports.http;
02:
03: import java.io.ByteArrayOutputStream;
04: import java.io.FilterOutputStream;
05: import java.io.IOException;
06: import java.io.OutputStream;
07:
08: import javax.xml.ws.handler.MessageContext;
09:
10: import org.objectweb.celtix.context.InputStreamMessageContext;
11: import org.objectweb.celtix.context.MessageContextWrapper;
12: import org.objectweb.celtix.context.OutputStreamMessageContext;
13:
14: public abstract class AbstractHTTPServerOutputStreamContext extends
15: MessageContextWrapper implements OutputStreamMessageContext {
16:
17: protected final AbstractHTTPServerTransport transport;
18: protected WrappedOutputStream origOut;
19: protected OutputStream out;
20:
21: public AbstractHTTPServerOutputStreamContext(
22: AbstractHTTPServerTransport tr, MessageContext ctx)
23: throws IOException {
24:
25: super (ctx);
26: transport = tr;
27: origOut = new WrappedOutputStream();
28: out = origOut;
29: }
30:
31: protected abstract void flushHeaders() throws IOException;
32:
33: public void setFault(boolean isFault) {
34: if (isFault) {
35: put(HTTP_RESPONSE_CODE, 500);
36: } else {
37: put(HTTP_RESPONSE_CODE, 200);
38: }
39: }
40:
41: public boolean isFault() {
42: return ((Integer) get(HTTP_RESPONSE_CODE)).intValue() == 500;
43: }
44:
45: public void setOneWay(boolean isOneWay) {
46: put(ONEWAY_MESSAGE_TF, isOneWay);
47: }
48:
49: public boolean isOneWay() {
50: Boolean b = (Boolean) get(ONEWAY_MESSAGE_TF);
51: return b == null ? false : b.booleanValue();
52: }
53:
54: public OutputStream getOutputStream() {
55: return out;
56: }
57:
58: public void setOutputStream(OutputStream o) {
59: out = o;
60: }
61:
62: public InputStreamMessageContext getCorrespondingInputStreamContext()
63: throws IOException {
64: return null;
65: }
66:
67: protected class WrappedOutputStream extends FilterOutputStream {
68: WrappedOutputStream() {
69: super (new ByteArrayOutputStream());
70: }
71:
72: public void resetOut(OutputStream newOut) throws IOException {
73: ByteArrayOutputStream bout = (ByteArrayOutputStream) out;
74: if (bout.size() > 0) {
75: bout.writeTo(newOut);
76: }
77: out = newOut;
78: }
79: }
80: }
|