在Weblogic Server中使用JAXB解组 [英] Use JAXB unmarshalling in Weblogic Server

查看:97
本文介绍了在Weblogic Server中使用JAXB解组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Especifications:
- 服务器:Weblogic 9.2由客户修复。
- 由客户修复的wsdl和xsd文件定义的Web服务;不允许修改。

Especifications: - Server: Weblogic 9.2 fixed by customer. - Webservices defined by wsdl and xsd files fixed by customer; not modifications allowed.

在项目中我们需要开发一个邮件系统。这必须与Web服务进行共同的工作。我们创建一个Bean,从非root xsd元素(而不是wsdl)接收自动生成的类;这个bean做了这个常见的工作。邮件系统使用xsd文件中定义的元素接收xml,我们需要将这些元素信息丢弃到wsdlc生成的类中。有了这个对象,我们可以使用这个常见的bean。无法将邮件请求重定向到Web服务。

In the project we need to develope a mail system. This must do common work with the webservice. We create a Bean who recieves an auto-generated class from non-root xsd element (not wsdl); this bean do this common work. The mail system recieves a xml with elements defined in xsd file and we need to drop this elements info to wsdlc generated classes. With this objects we can use this common bean. Is not possible to redirect the mail request to the webservice.

我们正在寻找使用WL9.2资源执行此操作的代码,但我们没有找到任何内容。目前我们已尝试使用JAXB进行此解组:

We've looking for the code to do this with WL9.2 resources but we don't found anything. At the moment we've tried to use JAXB for this unmarshalling:

JAXBContext c = JAXBContext.newInstance(new Class[]{WasteDCSType.class});
Unmarshaller u = c.createUnmarshaller();
WasteDCSType w = u.unmarshal(waste, WasteDCSType.class).getValue();

废物变量是一个DOM元素对象。它不是根元素,因为根不包含在XSD中

waste variable is an DOM Element object. It isn't the root element 'cause the root isn't included in XSD

首先我们需要添加no-arg构造函数一些自动生成的类。没问题,我们解决了这个问题,最后我们解组了xml而没有错误Exceptions。但是我们遇到了属性问题。解组没有设定属性;它们都不在任何类中,不是简单属性,不是大或短枚举属性。任何类型的xml元素都没问题。

First we needed to add no-arg constructor in some autogenerated classes. No problem, we solved this and finally we unmarshalled the xml without error Exceptions. But we had problems with the attributes. The unmarshalling didn't set attributes; none of them in any class, not simple attributes, not large or short enumeration attributes. No problem with xml elements of any type.

我们无法从context string(包名)创建unmarshaller,因为wsldc没有创建ObjectFactory。如果我们设置架构,则不会建立元素描述并解组崩溃。

We can't create the unmarshaller from "context string" (the package name) 'cause not ObjectFactory has been create by wsldc. If we set the schema no element descriptions are founded and unmarshall crashes.

这是构建内容:

<taskdef name="jwsc" classname="weblogic.wsee.tools.anttasks.JwscTask" />
<taskdef name="wsdlc" classname="weblogic.wsee.tools.anttasks.WsdlcTask"/>    

 <target name="generate-from-wsdl">
        <wsdlc
            srcWsdl="${src.dir}/wsdls/e3s-environmentalMasterData.wsdl"
            destJwsDir="${src.dir}/webservices"
            destImplDir="${src.dir}/webservices"
            packageName="org.arc.eterws.generated"
            />
        <wsdlc
            srcWsdl="${src.dir}/wsdls/e3s-waste.wsdl"
            destJwsDir="${src.dir}/webservices"
            destImplDir="${src.dir}/webservices"
            packageName="org.arc.eterws.generated"
            />
    </target>

<target name="webservices" description="">
        <jwsc srcdir="${src.dir}/webservices" destdir="${dest.dir}" classpathref="wspath">
            <module contextPath="E3S" name="webservices">

                <jws file="org/arc/eterws/impl/IE3SEnvironmentalMasterDataImpl.java"
                        compiledWsdl="${src.dir}/webservices/e3s-environmentalMasterData_wsdl.jar"/>

                <jws file="org/arc/eterws/impl/Ie3SWasteImpl.java"
                        compiledWsdl="${src.dir}/webservices/e3s-waste_wsdl.jar"/>

                <descriptor file="${src.dir}/webservices/META-INF/web.xml"/>
            </module>

        </jwsc>
</target>

我的问题是:


  • Weblogic如何使用JAX-RPC技术解组xml
    ,我们可以用xsd元素执行
    吗?

  • 怎么能如果是,我们会这样做吗?

  • 如果没有,是否存在任何不复杂的
    解决此问题的方法?

  • 如果没有,我们必须使用XMLBean技术。或
    使用JAXB技术重新生成XSD。
    什么是最佳解决方案?

  • How Weblogic "unmarshall" the xml with the JAX-RPC tech and can we do the same with a xsd element?
  • How can we do this if yes?
  • If not, Exists any not complex solution to this problem?
  • If not, must we use XMLBean tech. or regenerate the XSD with JAXB tech.? What is the best solution?

注意:事实上,没有一个单独的xsd,而是一个复杂的xsd结构。

NOTE: There are not one single xsd but a complex xsd structure in fact.

推荐答案

如果指定邮件服务器正在接收的xml的XSD是相同的(字面上,通过相同的文件( s)或语义上具有与wsdl中包含的xsd相同的完全限定名称),那么jaxb生成的类应该能够直接传递。

If the XSD that specifies the xml the mail server is receiving is the same (either literally, by being the same file(s) or semantically by having the same fully qualified names) as the xsd included in the wsdl, then the jaxb generated classes should be able to be passed straight in.

如果不,那么来自邮件服务的xml blob根本无法直接发送到web服务。但是没关系,这就是你的经纪人bean的用途。

If not, then the xml blob from the mail service is simply NOT capable of being sent straight into the webservice. But that's ok, that's what your broker bean is for.

你正在解析xml,然后手动构造一个新对象(wsdl生成的jaxb对象)基于邮件服务器unmarshalled对象。

You unmarshall the xml as you are doing, then you manually construct a new object (the wsdl generated jaxb object) based on the mail server unmarshalled object.

我理解对象(邮件和web服务)可能逻辑相同,你就是希望有一些神奇的胶水,但XML要比那更严格。

I understand that the objects (mail and webservices) might be logically the same, and you're hoping for some magic glue, but XML is a lot stricter than that.

如果你试图从Web服务生成的类中使用JAXB unmarshaller来解组XML邮件服务,如果模式不是相同,完全将失败

If you're trying to use a JAXB unmarshaller from the web services generated classes to unmarshall XML from the mail service, again, this will totally fail if the schemas are not identical

请记住,这是重要的是,以下两个xml代码段 NOT 相同,无论您希望它们有多大。

Remember, and this is important, the following two xml snippets are NOT the same, no matter how much you might want them to be.

<blob xmlns="urn:mailserver.schema.generated">
   <from>blah</from>
   <to>wop</to>
   <message>this is a message</message>
</blob>

<blob xmlns="urn:webservice.wsdl.generated">
   <from>blah</from>
   <to>wop</to>
   <message>this is a message</message>
</blob>

这篇关于在Weblogic Server中使用JAXB解组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆