Note that there are some explanatory texts on larger screens.

plurals
  1. POextract Http Content-length from a web service response
    text
    copied!<p>I want to extract the HTTP Headers from a response, more exactly the content-length of the response in order to raise an exception if it exceeds a certain size. I've been trying to do this for two days now without any success. How can i do this and is it more clean to use an interceptor or a handler for this.</p> <p>here's a handler for logging the headers but it returns nothing</p> <pre><code>public class HeaderHandler implements SOAPHandler&lt;SOAPMessageContext&gt; { private final static Logger log = Logger.getLogger(HeaderHandler.class); private PrintStream out; public HeaderHandler() { setLogStream(System.out); } protected final void setLogStream(PrintStream ps) { out = ps; } public void init(Map c) { System.out.println("HeaderHandler : init() Called...."); } public Set&lt;QName&gt; getHeaders() { return null; } public boolean handleMessage(SOAPMessageContext smc) { System.out.println("HeaderHandler : handleMessage Called...."); logToSystemOut(smc); return true; } public boolean handleFault(SOAPMessageContext smc) { System.out.println("HeaderHandler : handleFault Called...."); logToSystemOut(smc); return true; } // nothing to clean up public void close(MessageContext messageContext) { System.out.println("HeaderHandler : close() Called...."); } // nothing to clean up public void destroy() { System.out.println("HeaderHandler : destroy() Called...."); } /* * Check the MESSAGE_OUTBOUND_PROPERTY in the context * to see if this is an outgoing or incoming message. * Write a brief message to the print stream and * output the message. The writeTo() method can throw * SOAPException or IOException */ protected void logToSystemOut(SOAPMessageContext smc) { Boolean outboundProperty = (Boolean) smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY); if (outboundProperty.booleanValue()) { out.println("\nOutbound message:"); } else { out.println("\nInbound message:"); } out.println("\n***********************************************************************************"); final Object o = smc.get(MessageContext.HTTP_RESPONSE_HEADERS); if (o != null) { out.println(o); } else { out.println("o null"); } } </code></pre> <p>}</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload