0

我想从响应中提取 HTTP 标头,更准确地说是响应的内容长度,以便在超出特定大小时引发异常。我已经尝试这样做两天了,但没有任何成功。我该怎么做?为此使用拦截器或处理程序是否更干净。

这是一个记录标题的处理程序,但它什么也不返回

public class HeaderHandler implements SOAPHandler<SOAPMessageContext> {

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<QName> 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");
    }
}

}

4

0 回答 0