【问题标题】:WEBSERVICES : How to store mal-formed XML in webservices?WEB SERVER:如何在 Web 服务中存储格式错误的 XML?
【发布时间】:2012-11-01 10:54:31
【问题描述】:

我正在托管一个网络服务。我想处理这种情况,以防客户端发送格式错误的 XML

这是我创建的处理程序

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

    SOAPMessage message = null;
    try
    {
               // This handling iss required in case a mal-formed XML is sent.    
               message = smc.getMessage();    
    }
    catch(Throwable t ) 
    { 
          // I want to log the XML in the database
          // But the problem is I don't know how to get the XML
          // as message is null.
    }

}

我进入了 catch(Throwable t) 块,在那里我没有关于发送的 XML 的信息。 我可以登录到错误日志表中的只是客户端发送了格式错误的 XML。

实际要求:

记录和存储格式错误的 XML 以进行跟踪。

【问题讨论】:

  • 这是 Java 吗?什么平台?
  • 无论你做什么,都不要catch (Throwable t)。捕获 Web 服务特定的异常类。

标签: java xml web-services


【解决方案1】:

请使用以下代码在soap消息中获取确切的行号和异常以进行日志记录:

public boolean handleMessage(SOAPMessageContext mc) {
    try {
        final SOAPMessage message = mc.getMessage();

        String i = convertToString(message);

        System.out.println(i);

        return true;
    } catch (Exception e) {
        System.out.println(e.getMessage());
//            e.printStackTrace();
        return false;
    }
}

此代码将处理任何格式错误的 SOAP 消息

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-15
    • 1970-01-01
    • 1970-01-01
    • 2011-06-01
    • 2011-05-05
    • 2011-10-10
    相关资源
    最近更新 更多