| 1 package org.objectweb.celtix.systest.handlers; 2 3 4 import java.io.IOException ; 5 import java.util.Map ; 6 import java.util.logging.Logger ; 7 import java.util.zip.GZIPInputStream ; 8 import java.util.zip.GZIPOutputStream ; 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 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 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 setupCompressionOutputStream(ctx); 45 } 46 } else { 47 if (!isOutbound(ctx)) { 48 LOG.info("decompressing message stream"); 49 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 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 toString() { 77 return getHandlerId(); 78 } 79 80 private void setupDecompressionInputStream(StreamMessageContext ctx) { 81 try { 82 83 GZIPInputStream zipIn = new GZIPInputStream (ctx.getInputStream()); 84 ctx.setInputStream(zipIn); 85 } catch (IOException ex) { 86 throw new ProtocolException(ex); 87 } 88 } 89 90 private void setupCompressionOutputStream(StreamMessageContext ctx) { 91 92 try { 93 GZIPOutputStream zipOut = new GZIPOutputStream (ctx.getOutputStream()); 94 ctx.setOutputStream(zipOut); 95 } catch (IOException ex) { 96 throw new ProtocolException(ex); 97 } 98 } 99 } 100 | Popular Tags |