KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > celtix > bus > bindings > TestOutputStreamContext


1 package org.objectweb.celtix.bus.bindings;
2
3 import java.io.ByteArrayOutputStream JavaDoc;
4 import java.io.IOException JavaDoc;
5 import java.io.OutputStream JavaDoc;
6 import java.net.URL JavaDoc;
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 class TestOutputStreamContext
15     extends MessageContextWrapper
16     implements OutputStreamMessageContext {
17     ByteArrayOutputStream JavaDoc baos;
18     boolean isFaultMsg;
19
20     public TestOutputStreamContext(URL JavaDoc url, MessageContext ctx) throws IOException JavaDoc {
21         super(ctx);
22     }
23
24     void flushHeaders() throws IOException JavaDoc { }
25
26     public void setFault(boolean isFault) {
27         isFaultMsg = isFault;
28     }
29
30     public boolean isFault() {
31         return isFaultMsg;
32     }
33     
34     public void setOneWay(boolean isOneWay) {
35         put(ONEWAY_MESSAGE_TF, isOneWay);
36     }
37     
38     public boolean isOneWay() {
39         return ((Boolean JavaDoc)get(ONEWAY_MESSAGE_TF)).booleanValue();
40     }
41
42     public OutputStream JavaDoc getOutputStream() {
43         if (baos == null) {
44             baos = new ByteArrayOutputStream JavaDoc();
45         }
46         try {
47             baos.flush();
48         } catch (IOException JavaDoc ioe) {
49             //to do nothing
50
}
51         return baos;
52     }
53
54     public byte[] getOutputStreamBytes() {
55         return baos.toByteArray();
56     }
57     
58     public void setOutputStream(OutputStream JavaDoc o) { }
59
60     public InputStreamMessageContext getCorrespondingInputStreamContext() throws IOException JavaDoc {
61         return new TestInputStreamContext(baos.toByteArray());
62     }
63     
64     
65 }
66
Popular Tags