1 package org.objectweb.celtix.bus.transports.http; 2 3 import java.io.ByteArrayOutputStream ; 4 import java.io.FilterOutputStream ; 5 import java.io.IOException ; 6 import java.io.OutputStream ; 7 8 import javax.xml.ws.handler.MessageContext; 9 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 15 extends MessageContextWrapper 16 implements OutputStreamMessageContext { 17 18 protected final AbstractHTTPServerTransport transport; 19 protected WrappedOutputStream origOut; 20 protected OutputStream out; 21 22 public AbstractHTTPServerOutputStreamContext(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 public void resetOut(OutputStream newOut) throws IOException { 72 ByteArrayOutputStream bout = (ByteArrayOutputStream )out; 73 if (bout.size() > 0) { 74 bout.writeTo(newOut); 75 } 76 out = newOut; 77 } 78 } 79 } | Popular Tags |