【问题标题】:JAXB Marshsall issue Weblogic12cJAXB Marshal 发布 Weblogic 12c
【发布时间】:2013-11-22 18:03:44
【问题描述】:

问题

应用程序迁移到 12c 和 jaxb 不起作用

说明

应用程序当前在 Weblogic 10 上并使用一些 Web 服务。我们使用 HttpURLConnection 将 XML 直接发布到 Web 服务。在发布之前我们对请求进行编组,在收到响应后我们对它们进行解组

该应用程序需要在 12c 上迁移,当我们在 12c 上测试该应用程序时,它的工作方式不一样。发送到 web 服务的请求有所不同。请参阅下面的架构、java 类和编组请求

Refund.xsd
----------
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:avis="http://www.avis.com/XMLSchema" elementFormDefault="unqualified">
    <xsd:element name="RefundRequest">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element ref="Request" avis:usage="ups"/>
                <xsd:element ref="DeliveryNumber" avis:usage="ups"/>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>

<!-- Request and DeliveryNumber attributes her -->

使用 Eclipse-->Generate--> JAxB 类生成 Refund.java 和相关类。 我在防火墙后面,在 JAXB 向导中它确实要求我提供代理。我没有提供任何 poxy。生成类

Refund.java

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "",propOrder = {
    "request",
    "barCodeDeliveryNumber"
})
@XmlRootElement(name = "TrackRequest")
public class RefundRequest{

    @XmlElement(name = "Request", required = true)
    protected Request request;
    @XmlElement(name = "DeliveryNumber", required = true)
    protected String deliveryNumber;

    /**
     * Gets the value of the request property.
     * 
     * @return
     *     possible object is
     *     {@link Request }
     *     
     */
    public Request getRequest() {
        return request;
    }

    /**
     * Sets the value of the request property.
     * 
     * @param value
     *     allowed object is
     *     {@link Request }
     *     
     */
    public void setRequest(Request value) {
        this.request = value;
    }

/**
 * Gets the value of the DeliveryNumber property.
 * 
 * @return
 *     possible object is
 *     {@link String }
 *     
 */
public String getDeliveryNumber() {
    return barCodeDeliveryNumber;
}

/**
 * Sets the value of the barCodeDeliveryNumber property.
 * 
 * @param value
 *     allowed object is
 *     {@link String }
 *     
 */
public void setDeliveryNumber(String value) {
    this.barCodeDeliveryNumber = value;
}

我将对象编组为 XML(见下文)并将其传递给 Web 服务。 Web 服务返回“XML 格式不正确”

应用程序库

javax.annotation_1.0.jar
javax.annotation_1.1.jar
javax.persistence_1.0.0.0_1-0.jar
javax.persistence_1.0.1.0_1-0.jar
javax.xml.bind_2.0.jar
javax.xml.bind_2.1.1.jar
jaxb-api.jar
jaxb-impl.jar
jaxws-api.jar
jaxws-rt.jar
jsr181-api.jar
jsr250-api.jar

使用 jrockit160_29 的 Weblogic 12c

代码片段

private static  Marshaller mreqinfo;
JAXBContext jxcreq =JAXBContext.newInstance(RefundRequest.class.getPackage().getName());
             mreqinfo=jxcreq.createMarshaller();

mreqinfo.marshall(refundRequestObj)

查看日志,我可以在 weblogic 12c 上看到以下编组请求。 有一个 xmlns:ns0="" 我认为这是造成问题的原因

**Marshalled Request - 在 weblogic 12c jrockit160_29 中尝试时不起作用 .**

需要去掉 xmlns:ns0=""

<?xml version="1.0" encoding="UTF-8"?>
<RefundRequest  xmlns:ns0="">
    <Request>
        <TransactionReference>
            <CustomerContext>YILE00010208201120.04.08.4|11/22/2013 12:28:31:085</CustomerContext>
        </TransactionReference>
        <RequestAction>Refund</RequestAction>
    </Request>
    <DeliveryNumber>974869</DeliveryNumber>
</RefundRequest>

***Weblogic 10 中的编组请求(weblogic 10 jrockit160_29 中的现有工作版本


<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<RefundRequest>
    <Request>
        <TransactionReference>
            <CustomerContext>YILE00010208201120.04.08.4|11/22/2013 12:28:31:085</CustomerContext>
        </TransactionReference>
        <RequestAction>Refund</RequestAction>
    </Request>
    <DeliveryNumber>974869</DeliveryNumber>
</RefundRequest>

【问题讨论】:

标签: web-services jaxb marshalling httpurlconnection


【解决方案1】:

在您使用的 WebLogic 12.1.1 中,EclipseLink JAXB (MOXy) 用作默认的 JAXB (JSR-222) 提供程序(请参阅:http://blog.bdoughan.com/2011/12/eclipselink-moxy-is-jaxb-provider-in.html)。您遇到的问题是由于已在 EclipseLink 2.3.3 版本(当前版本是 EclipseLink 2.5.1)中修复的错误造成的。

下面是一个链接,其中包含有关在 WebLogic 中使用更新版本的 EclipseLink 的说明:

如果您是 Oracle 支持客户,那么您可以与他们联系以请求针对此问题的官方补丁。

【讨论】:

    【解决方案2】:

    要解决此问题,您可以通过覆盖 Weblogic 12c 中的 jaxb jar 来添加自己的 jaxb jar(jaxb-core.jar、jaxb-impl.jar)。您可以通过将自己的 jaxb jar 放入您的战争中来做到这一点,在 WEB-INF/lib 下并使用 prefer-web-inf-classes 元素标记配置 weblogic.xml。然后把weblogic.xml放到你war的WEB-INF目录下

    prefer-web-inf-classes 元素

    weblogic.xml Web 应用程序部署描述符包含一个 元素(的子元素 元素)。默认情况下,此元素设置为 错误的。将此元素设置为 True 会破坏类加载器 委托模型,以便来自 Web 应用程序的类定义 优先于更高级别的类定义加载 类加载器。这允许 Web 应用程序使用它自己的版本 第三方类,它也可能是 WebLogic Server 的一部分。

    更多详情请参考此链接 http://docs.oracle.com/cd/E13222_01/wls/docs90/programming/classloading.html

    weblogic.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <wls:weblogic-web-app xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-web-app"    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.4/weblogic-web-app.xsd">
    <wls:weblogic-version>12.1.</wls:weblogic-version>
    <wls:container-descriptor>
        <wls:prefer-web-inf-classes>true</wls:prefer-web-inf-classes>
    </wls:container-descriptor>
    <wls:container-descriptor>
        <wls:show-archived-real-path-enabled>true</wls:show-archived-real-path-enabled>
    </wls:container-descriptor>
    <wls:context-root>your_context_root_name</wls:context-root>
    

    【讨论】:

      【解决方案3】:

      遇到了同样的问题:JAXB 放置了像 这样的前缀。 通过将 prefer-application-resources 添加到 weblogic-application.xml 解决:

      <?xml version="1.0" encoding="UTF-8"?>
      <weblogic-application>
          <prefer-application-resources>
             <resource-name>META-INF/services/javax.xml.bind.*</resource-name>
          </prefer-application-resources>
      </weblogic-application>
      

      【讨论】:

        猜你喜欢
        • 2020-12-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-12-29
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多