【问题标题】:XSL transformation not working in Apache camel application when deployed in JBoss eap 6.2 GA在 JBoss eap 6.2 GA 中部署时,XSL 转换在 Apache Camel 应用程序中不起作用
【发布时间】:2014-09-12 14:12:31
【问题描述】:

我有一个与 Web 服务对话的 Apache camel 应用程序。我需要将响应肥皂消息转换/解组为代理对象。我没有使用soap数据格式,而是使用jaxb转换,为此我需要首先从soap消息中提取xml。当我从命令行运行我的应用程序时,以下 xsl 和 soap 响应工作正常,但如果我在 JBoss eap 6.2 GA 上部署我的应用程序,它会失败。我的xsl,示例响应soap消息和生成的xml如下,

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
version="1.0">

<xsl:output method="xml" indent="no" />
<xsl:strip-space elements="*" />

<xsl:template match="/*">
    <xsl:copy-of select="/soapenv:Envelope/soapenv:Body/*" />
</xsl:template>

<xsl:template match="/*">
    <xsl:copy-of select="/s:Envelope/s:Body/*" />
</xsl:template>

<xsl:template match="node()|@*">
    <xsl:copy>
        <xsl:apply-templates select="node()|@*" />
    </xsl:copy>
</xsl:template>

示例soap消息是:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
    <ActivityId CorrelationId="8877bd15-990e-465f-acca-3b2f21945735"
        xmlns="http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics">b0480ae4-7692-4224-9082-662cbe8a6edc</ActivityId>
</s:Header>
<s:Body>
    <GetUserByEmailResponse xmlns="urn:RetailApi/AccountManagementService/v2">
        <GetUserByEmailResult xmlns:a="urn:RetailApi/Schemas/v2"
            xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
            <a:EmailAddress>a@b.com</a:EmailAddress>
            <a:FirstName>Scott</a:FirstName>
            <a:LastName>Tiger</a:LastName>
            <a:MobilePhoneNumber>3232326565</a:MobilePhoneNumber>
            <a:Title>Mr</a:Title>
            <a:UserId>xxxxx</a:UserId>
        </GetUserByEmailResult>
    </GetUserByEmailResponse>
</s:Body>

生成的xml是:

<?xml version="1.0" encoding="UTF-8"?>< xmlns="urn:RetailApi/AccountManagementService/v2"><><a:EmailAddress xmlns:a="urn:RetailApi/Schemas/v2">a@b.com</a:EmailAddress><a:FirstName xmlns:a="urn:RetailApi/Schemas/v2">Scott</a:FirstName><a:LastName xmlns:a="urn:RetailApi/Schemas/v2">Tiger</a:LastName><a:MobilePhoneNumber xmlns:a="urn:RetailApi/Schemas/v2">3232326565</a:MobilePhoneNumber><a:Title xmlns:a="urn:RetailApi/Schemas/v2">Mr</a:Title><a:UserId xmlns:a="urn:RetailApi/Schemas/v2">xxxx</a:UserId></></>

如您所见,生成的 xml 有几个问题。 之间有一个空格。最后有几个空白/空节点,如 。此外,这对节点丢失了。即 GetUserByEmailResponseGetUserByEmailResult,我得到一个空白节点,例如

在 jboss 应用服务器上部署并运行代码后,我得到:com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character ' ' (code 32) in prolog, after '&lt;'.

此问题仅在我通过应用服务器运行我的应用程序时发生,并且在我作为独立应用程序运行时不会发生。

非常感谢任何帮助。

【问题讨论】:

    标签: xml xslt soap apache-camel jboss6.x


    【解决方案1】:

    对于为什么您的 XSLT 生成仅在运行 JBoss 时验证的空间,这并不是一个真正的答案。

    但是,解决您的用例的另一种方法是使用简单的 xpath,根本不涉及 XSLT。

    final Namespaces ns = new Namespaces("soap", "http://schemas.xmlsoap.org/soap/envelope/");
    from("foo:bar")
      .setBody(ns.xpath("/soap:Envelope/soap:Body/*[1]",String.class)
      // do whatever
    

    如果您考虑使用这些组件,SpringWS 和 CXF 也可以自动处理这些内容。

    【讨论】:

    • 谢谢@Petter,但这个解决方案也没有运气:(
    【解决方案2】:

    经过大量挖掘/调试,我投降并选择了直截了当但不太干净的解决方案。我编写了一个实用方法来使用 String API 提取 xml。这就像一个魅力。

    【讨论】:

    • 嗨,我也面临同样的问题。你能告诉我你是怎么做的吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-17
    • 1970-01-01
    • 1970-01-01
    • 2020-03-09
    • 2020-02-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多