【问题标题】:How to find the corresponding pair of inbound and outbound messages in a soap handler如何在soap处理程序中找到相应的入站和出站消息对
【发布时间】:2022-02-10 01:00:19
【问题描述】:

当我使用 SOAP 处理程序时,我会在入站和出站消息中调用 handleMessage 方法。但是,如果有很多客户端发送很多消息,我如何才能看到哪两个对 handleMessage 的调用属于一对对应的入站和出站消息?例如。我想构建一个 SOAP 处理程序,它通过确定进出时的系统时间来衡量性能,因此我必须捕获一对相应的消息。 谢谢你的帮助, 托马斯

【问题讨论】:

  • 这将有助于添加有关您正在使用的 Web 服务框架或库的详细信息,如果可能的话,可能会显示一些代码,否则我们无法知道您使用了哪种处理程序。
  • 请澄清您的具体问题或提供其他详细信息以准确突出您的需求。正如目前所写的那样,很难准确地说出你在问什么。

标签: soap handler


【解决方案1】:

我刚刚找到了答案:

我的想法是这样的

public class ServerMessageHandler implements SOAPHandler<SOAPMessageContext> {

private long timeIn;

@Override
public boolean handleMessage(SOAPMessageContext messageContext) {
    boolean outbound = (Boolean) messageContext.get (MessageContext.MESSAGE_OUTBOUND_PROPERTY);
    if (!outbound) {this.timeIn = System.currentTimeMillis();}
    else {System.out.println("time: " + (System.currentTimeMillis() - this.timeIn));}
    return true;
}
...
}

因此,为了衡量处理时间,重要的是比较离开时间和相应的进入时间,而不仅仅是同时进入的其他一些客户的进入时间。 但一个解决方案是使用例如messageContext.get (MessageContext.SERVLET_REQUEST):

public boolean handleMessage(SOAPMessageContext messageContext) {
    boolean outbound = (Boolean) messageContext.get (MessageContext.MESSAGE_OUTBOUND_PROPERTY);
    ServletRequest request = (ServletRequest) messageContext.get (MessageContext.SERVLET_REQUEST);
    if (!outbound) {
        request.setAttribute("timeIn", System.currentTimeMillis());
    } else {
        Long timeIn = (Long) request.getAttribute("timeIn");
        System.out.println("time needed: " + (System.currentTimeMillis() - timeIn));
    }
    return true;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-11
    • 2016-07-24
    • 1970-01-01
    相关资源
    最近更新 更多