KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > celtix > systest > handlers > TestStreamHandler


1 package org.objectweb.celtix.systest.handlers;
2
3
4 import java.io.IOException JavaDoc;
5 import java.util.Map JavaDoc;
6 import java.util.logging.Logger JavaDoc;
7 import java.util.zip.GZIPInputStream JavaDoc;
8 import java.util.zip.GZIPOutputStream JavaDoc;
9
10 import javax.xml.ws.ProtocolException;
11 import javax.xml.ws.handler.MessageContext;
12
13 import org.objectweb.celtix.context.StreamMessageContext;
14 import org.objectweb.celtix.handlers.StreamHandler;
15
16 public class TestStreamHandler extends TestHandlerBase
17     implements StreamHandler {
18
19     private static final Logger JavaDoc LOG = Logger.getLogger(TestStreamHandler.class.getName());
20
21     public TestStreamHandler() {
22         this(true);
23     }
24
25     public TestStreamHandler(boolean serverSide) {
26         super(serverSide);
27     }
28
29     public String JavaDoc getHandlerId() {
30         return "streamHandler" + getId();
31     }
32     
33     public final boolean handleMessage(StreamMessageContext ctx) {
34
35         methodCalled("handleMessage");
36         printHandlerInfo("handleMessage", isOutbound(ctx));
37
38         if (isServerSideHandler()) {
39             if (!isOutbound(ctx)) {
40                 getHandlerInfoList(ctx).add(getHandlerId());
41             } else {
42                 LOG.info("compressing message stream");
43                 // compress outbound on server side
44
setupCompressionOutputStream(ctx);
45             }
46         } else {
47             if (!isOutbound(ctx)) {
48                 LOG.info("decompressing message stream");
49                 // decompress inbound on client side
50
setupDecompressionInputStream(ctx);
51             }
52         }
53         return true;
54     }
55
56
57     public final boolean handleFault(StreamMessageContext ctx) {
58         methodCalled("handleFault");
59         printHandlerInfo("handleFault", isOutbound(ctx));
60         return true;
61     }
62
63     public final void init(final Map JavaDoc map) {
64         methodCalled("init");
65     }
66
67     public final void destroy() {
68         methodCalled("destroy");
69     }
70
71     public final void close(MessageContext messageContext) {
72         methodCalled("close");
73     }
74
75
76     public String JavaDoc toString() {
77         return getHandlerId();
78     }
79
80     private void setupDecompressionInputStream(StreamMessageContext ctx) {
81         try {
82             
83             GZIPInputStream JavaDoc zipIn = new GZIPInputStream JavaDoc(ctx.getInputStream());
84             ctx.setInputStream(zipIn);
85         } catch (IOException JavaDoc ex) {
86             throw new ProtocolException(ex);
87         }
88     }
89
90     private void setupCompressionOutputStream(StreamMessageContext ctx) {
91
92         try {
93             GZIPOutputStream JavaDoc zipOut = new GZIPOutputStream JavaDoc(ctx.getOutputStream());
94             ctx.setOutputStream(zipOut);
95         } catch (IOException JavaDoc ex) {
96             throw new ProtocolException(ex);
97         }
98     }
99 }
100
Popular Tags