01: package org.objectweb.celtix.systest.handlers;
02:
03: import java.io.IOException;
04: import java.util.Map;
05: import java.util.logging.Logger;
06: import java.util.zip.GZIPInputStream;
07: import java.util.zip.GZIPOutputStream;
08:
09: import javax.xml.ws.ProtocolException;
10: import javax.xml.ws.handler.MessageContext;
11:
12: import org.objectweb.celtix.context.StreamMessageContext;
13: import org.objectweb.celtix.handlers.StreamHandler;
14:
15: public class TestStreamHandler extends TestHandlerBase implements
16: StreamHandler {
17:
18: private static final Logger LOG = Logger
19: .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 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: public final boolean handleFault(StreamMessageContext ctx) {
57: methodCalled("handleFault");
58: printHandlerInfo("handleFault", isOutbound(ctx));
59: return true;
60: }
61:
62: public final void init(final Map map) {
63: methodCalled("init");
64: }
65:
66: public final void destroy() {
67: methodCalled("destroy");
68: }
69:
70: public final void close(MessageContext messageContext) {
71: methodCalled("close");
72: }
73:
74: public String toString() {
75: return getHandlerId();
76: }
77:
78: private void setupDecompressionInputStream(StreamMessageContext ctx) {
79: try {
80:
81: GZIPInputStream zipIn = new GZIPInputStream(ctx
82: .getInputStream());
83: ctx.setInputStream(zipIn);
84: } catch (IOException ex) {
85: throw new ProtocolException(ex);
86: }
87: }
88:
89: private void setupCompressionOutputStream(StreamMessageContext ctx) {
90:
91: try {
92: GZIPOutputStream zipOut = new GZIPOutputStream(ctx
93: .getOutputStream());
94: ctx.setOutputStream(zipOut);
95: } catch (IOException ex) {
96: throw new ProtocolException(ex);
97: }
98: }
99: }
|