【问题标题】:Get the request of a SOAP response using SOAPHandler使用 SOAPHandler 获取 SOAP 响应的请求
【发布时间】:2015-06-09 17:14:00
【问题描述】:

我有一个 SOAPHandler。我需要捕获响应的请求

public class SOAPLoggingHandler implements SOAPHandler<SOAPMessageContext> {

    @Override
    public boolean handleFault(SOAPMessageContext context) {
        writeMessageLogging(context);
        return true;
    }
    public boolean handleMessage(SOAPMessageContext context) {
        writeMessageLogging(context);
        return true;
    }

    private void writeMessageLogging(SOAPMessageContext smc) {
        Boolean outboundProperty = (Boolean) smc
                .get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);

        if (logger.isDebugEnabled()) {
            if (outboundProperty.booleanValue()) {
                logger.debug("Request message");
            } else {
                logger.debug("Response message:");
            }
        }
        SOAPMessage message = smc.getMessage();
        ByteArrayOutputStream out=null;
        try {
            if (!outboundProperty.booleanValue()) {
                String requestXML="Request of the Response, is possible?";
            }
                out = new ByteArrayOutputStream();
             message.writeTo(out);
             String strMsg = new String(out.toByteArray());
             logger.debug("strMsg:" + strMsg);
            out.close();
        } catch (Exception e) {
            logger.error("Exception in handler:", e);
        }finally{
            IOUtils.closeQuietly(out);
        }

    }
 }

见:

String requestXML="Request of the Response, is possible?";

是否可以在响应句柄中捕获请求?

【问题讨论】:

  • 删除了多余的句子。固定标点符号。

标签: java soap soaphandler


【解决方案1】:

我终于解决了我的问题:

public class SOAPLoggingHandler implements SOAPHandler { private static Logger logger = Logger.getLogger(SOAPLoggingHandler.class .getCanonicalName()); public static final String REQUEST_XML="REQUEST_XML"; @Override public boolean handleFault(SOAPMessageContext context) { writeMessageLogging(context); return true; } @Override public boolean handleMessage(SOAPMessageContext context) { writeMessageLogging(context); return true; } private void writeMessageLogging(SOAPMessageContext smc) { Boolean outboundProperty = (Boolean) smc .get(MessageContext.MESSAGE_OUTBOUND_PROPERTY); SOAPMessage message = smc.getMessage(); ByteArrayOutputStream out=null; try { out = new ByteArrayOutputStream(); message.writeTo(out); String strMsg = new String(out.toByteArray()); if (!outboundProperty.booleanValue()) { String requestXML=(String)smc.get(REQUEST_XML); logger.debug("Request of Response:"+requestXML); }else{ smc.put(REQUEST_XML,strMsg); } logger.debug("strMsg:" + strMsg); out.close(); } catch (Exception e) { logger.error("Exception in handler:", e); }finally{ IOUtils.closeQuietly(out); } } }

我为此使用 SOAPMessageContext。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-07
    相关资源
    最近更新 更多