Hello all,
I am attempting to write my own custom handler that does GZIP compression/decompression of a request/response. There is a lot of talk in the archives about such handlers, but I've only come across examples which actaully modify HttpSender and the AxisServlet :(.


I added the handler to both my client and server config wsdd files. The client seems to be creating the handler, but I don't think the server is getting the message(no logging) and the response object from the method call appears to be null, but there are no faults. I'm a little concerned that I am not replacing the messages correctly. Below is my handler code:

Thanks in advance.
 --m


public void invoke(MessageContext messageContext) throws AxisFault {

try {
if (messageContext.isClient()) {
//client side, compress request, decompress response
if (messageContext.getPastPivot()) {
log.fine("Decompressing response from server.");
messageContext.setResponseMessage(decompressMessage(messageContext.getResponseMessage()));
} else {
log.fine("Compressing request to server.");
messageContext.setRequestMessage(compressMessage(messageContext.getRequestMessage()));
}
} else {
//server side, compress response, decompress request
if (messageContext.getPastPivot()) {
log.fine("Compressing response to client.");
messageContext.setResponseMessage(compressMessage(messageContext.getResponseMessage()));
} else {
log.fine("Decompressing request from client.");
messageContext.setRequestMessage(decompressMessage(messageContext.getRequestMessage()));
}
}
} catch (Exception ex) {
log.error(ex);
throw AxisFault.makeFault(ex);
}
}


private Message compressMessage(Message toCompress) throws AxisFault {
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
try {
GZIPOutputStream gzos = new GZIPOutputStream(byteOut);


toCompress.writeTo(gzos);
gzos.close();
Message compressedMessage = new Message(new ByteArrayInputStream(byteOut.toByteArray()), true);
compressedMessage.setMessageType("gzip");
return compressedMessage;
} catch (IOException ex) {
throw AxisFault.makeFault(ex);
} catch (SOAPException ex) {
throw AxisFault.makeFault(ex);
} }


private Message decompressMessage(Message toDecompress) throws AxisFault {
if (!toDecompress.getMessageType().equals("gzip")) {
log.fine("Could not decompress message with content type " + toDecompress.getMessageType());
return toDecompress;
}
byte[] contents = toDecompress.getSOAPPartAsBytes();
try {
GZIPInputStream gzis = new GZIPInputStream(new ByteArrayInputStream(contents));


return new Message(gzis, true);
} catch (IOException ex) {
throw AxisFault.makeFault(ex);
} }
}

Reply via email to