在 Weblogic Server 中使用 JAXB 解组
具体规格: - 服务器:由客户修复的Weblogic 9.2。 - 由客户修复的 wsdl 和 xsd 文件定义的 Web 服务;不允许修改。
您好,
在项目中我们需要开发一个邮件系统。这必须与网络服务共同工作。我们创建一个 Bean,它从非根 xsd 元素(不是 wsdl)接收自动生成的类;这个 bean 做这个共同的工作。邮件系统收到一个 xml,其中包含 xsd 文件中定义的元素,我们需要将此元素信息放入 wsdlc 生成的类中。有了这个对象,我们就可以使用这个普通的 bean。无法将邮件请求重定向到 Web 服务。
我们一直在寻找使用 WL9.2 资源执行此操作的代码,但我们没有找到任何内容。目前,我们尝试使用 JAXB 进行此解组:
JAXBContext c = JAXBContext.newInstance(new Class[]{WasteDCSType.class});
Unmarshaller u = c.createUnmarshaller();
WasteDCSType w = u.unmarshal(waste, WasteDCSType.class).getValue();
waste 变量是一个 DOM Element 对象。它不是根元素,因为 XSD 中不包含根元素
首先,我们需要在一些自动生成的类中添加无参数构造函数。没问题,我们解决了这个问题,最后我们解组了 xml,没有出现错误异常。但我们在属性方面遇到了问题。解组没有设置属性;它们都不属于任何类,不是简单属性,也不是大或短的枚举属性。任何类型的 xml 元素都没有问题。
我们无法从“上下文字符串”(包名称)创建解组器,因为 wsldc 尚未创建 ObjectFactory。如果我们设置模式,则不会找到任何元素描述并且解组会崩溃。
这是构建内容:
<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 如何“解组” xml 有了 JAX-RPC 技术,我们能做什么 与 xsd 元素相同吗?
- 如果是的话我们该怎么做?
- 如果不是,则存在任何不复杂的 这个问题的解决办法?
- 如果没有,我们必须使用 XMLBean 技术。或者 使用 JAXB 技术重新生成 XSD。? 最好的解决方案是什么?
注意:实际上并不存在单一的 xsd,而是一个复杂的 xsd 结构。
Especifications:
- Server: Weblogic 9.2 fixed by customer.
- Webservices defined by wsdl and xsd files fixed by customer; not modifications allowed.
Hi,
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.
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();
waste variable is an DOM Element object. It isn't the root element 'cause the root isn't included in XSD
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.
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.
This is the build content:
<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>
My questions are:
- 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?
NOTE: There are not one single xsd but a complex xsd structure in fact.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果指定邮件服务器正在接收的 xml 的 XSD 与 wsdl 中包含的 xsd 相同(无论是字面意义上的相同文件,还是语义上具有相同的完全限定名称),则 jaxb 生成的类应该能够直接传入。
如果不能,则来自邮件服务的 xml blob 根本无法直接发送到 Web 服务中。但没关系,这就是您的代理 Bean 的用途。
您按照正在执行的操作解组 xml,然后根据邮件服务器解组对象手动构造一个新对象(wsdl 生成的 jaxb 对象)。
我知道对象(邮件和 Web 服务)在逻辑上可能是相同的,并且您希望有一些神奇的粘合剂,但 XML 比这严格得多。
如果您尝试使用 Web 服务生成的类中的 JAXB 解组器从邮件服务中解组 XML,那么如果架构不相同,这将完全失败。
请记住,这一点很重要,无论您多么希望以下两个 xml 片段不相同,它们都是一样的。
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.
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.
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.
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.
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
Remember, and this is important, the following two xml snippets are NOT the same, no matter how much you might want them to be.