【问题标题】:Getting response from java soap handler从 java soap 处理程序获取响应
【发布时间】:2015-12-19 05:28:46
【问题描述】:

如果有人分享他解决以下问题的经验,我将不胜感激。 我在 JDK 实现中有一个 SOAP 服务(我相信它是 Metro)。

出于日志记录的目的,我们需要提取传入请求和生成响应的主体。 我尝试通过在服务器端实现一个 SOAPHandler 来获取它。 我将处理程序配置为 Spring bean。 我发现的所有示例基本上都复制了 Oracle 文档中的示例:https://docs.oracle.com/cd/E23943_01/web.1111/e13734/handlers.htm#WSADV170:

      public boolean handleMessage(SOAPMessageContext messageContext)
  {
     Boolean outboundProperty = (Boolean)
         messageContext.get (MessageContext.MESSAGE_OUTBOUND_PROPERTY);

     if (outboundProperty.booleanValue()) {
         System.out.println("\nOutbound message:");
     } else {
         System.out.println("\nInbound message:");
     }

     System.out.println("** Response: "+messageContext.getMessage().toString());
    return true;
  }

这里读取 SOAP 消息上下文的布尔属性之一,在我看来,它对应于请求或响应。​​

但是在我的实验中调试器从不进入响应对应的分支(else-branch)。这样的处理程序应该如何跟踪请求和响应?

我也想知道什么消息被读取为 messageContext.getMessage():是传入(请求)还是出站(响应)

我现在想知道是否真的可以通过实现 handleMessage() 方法来访问请求和响应? 单个处理程序是否会同时拦截请求及其响应? 我误解了这个例子吗?

还有... SOAPHandler - 它是每个请求(请求-响应对)的特定实例吗? 谢谢

【问题讨论】:

  • 是的,单一方法拦截请求和响应。

标签: java jax-ws soaphandler


【解决方案1】:

对 SoapHandler 试试这个:

Boolean isRequest = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
 if (isRequest) {
//handle request
 } else {
//handle response
         }

这适用于LogicalHandler:

 Boolean outboundProperty = (Boolean)
         messageContext.get (MessageContext.MESSAGE_OUTBOUND_PROPERTY);
     if (outboundProperty.booleanValue()) {
            System.out.println("\nOutbound message:");
     } else {
            System.out.println("\nInbound message:");
     }

【讨论】:

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