如何将替代 XML 解析器与 Weblogic 和 Spring-ws 一起使用?
我正在使用 WebServiceGatewaySupport
来实现 SOAP 客户端。作为这些 SOAP 调用的一部分,我正在实现自己的 org.springframework.ws.client.core.SourceExtractor 来将返回的 XML 映射到我的域对象。
我似乎将一个 DOMSource
对象发送到 SourceExtractor,因此我尝试使用 DOM API 和内置于我的应用程序服务器(恰好是古老的 Weblogic 10.0 MP2)中的实现。然而,正如以下跟踪所证明的那样,实现似乎并不完整。
java.lang.AssertionError: UNIMPLEMENTED
at weblogic.xml.domimpl.NodeImpl.getTextContent(NodeImpl.java:198)
at com.cinfin.ecm.security.CICUserSourceExtractor.extractData(CICUserSourceExtractor.java:22)
at com.cinfin.ecm.security.CICUserSourceExtractor.extractData(CICUserSourceExtractor.java:1)
at org.springframework.ws.client.core.WebServiceTemplate$SourceExtractorMessageExtractor.extractData(WebServiceTemplate.java:807)
at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:596)
at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:537)
at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:492)
at org.springframework.ws.client.core.WebServiceTemplate.sendSourceAndReceive(WebServiceTemplate.java:479)
at org.springframework.ws.client.core.WebServiceTemplate.sendSourceAndReceive(WebServiceTemplate.java:470)
at org.springframework.ws.client.core.WebServiceTemplate.sendSourceAndReceive(WebServiceTemplate.java:458)
at com.cinfin.ecm.security.CICSecurityService.getRolesForUser(CICSecurityService.java:32)
at com.cinfin.ecm.security.CICSecurityServiceTest.testGetRolesForUser(CICSecurityServiceTest.java:29)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:592)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
显然,我的第一个问题是如何获取此 DOMSource 中节点的文本值?我可以使用 Spring/Spring-ws 来替换用于解组源的 XML 解析器吗?其次,这种实施方式是否正确?有没有一种更简单、更像 Spring 的方式来完成我正在做的事情?
I'm using WebServiceGatewaySupport
to implement a SOAP client. As part of those SOAP calls I'm implementing my own org.springframework.ws.client.core.SourceExtractor
to map the returned XML to my domain objects.
I seem to be getting a DOMSource
object sent to SourceExtractor, so I'm trying to use the DOM API and implementation built into my application server (which happens to be the ancient Weblogic 10.0 MP2). The implementation, however, seems to be incomplete as evidenced by the following trace.
java.lang.AssertionError: UNIMPLEMENTED
at weblogic.xml.domimpl.NodeImpl.getTextContent(NodeImpl.java:198)
at com.cinfin.ecm.security.CICUserSourceExtractor.extractData(CICUserSourceExtractor.java:22)
at com.cinfin.ecm.security.CICUserSourceExtractor.extractData(CICUserSourceExtractor.java:1)
at org.springframework.ws.client.core.WebServiceTemplate$SourceExtractorMessageExtractor.extractData(WebServiceTemplate.java:807)
at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:596)
at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:537)
at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:492)
at org.springframework.ws.client.core.WebServiceTemplate.sendSourceAndReceive(WebServiceTemplate.java:479)
at org.springframework.ws.client.core.WebServiceTemplate.sendSourceAndReceive(WebServiceTemplate.java:470)
at org.springframework.ws.client.core.WebServiceTemplate.sendSourceAndReceive(WebServiceTemplate.java:458)
at com.cinfin.ecm.security.CICSecurityService.getRolesForUser(CICSecurityService.java:32)
at com.cinfin.ecm.security.CICSecurityServiceTest.testGetRolesForUser(CICSecurityServiceTest.java:29)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:592)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
My first question is, obviously, how am I to get the text value of the nodes in this DOMSource
? Can I use Spring/Spring-ws to replace the XML parser used to unmarshall the source? Secondly, is this implementation on the right path? Is there an easier, more Spring-like way to do what I'm doing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题最终是 Bea/Oracle 使用他们自己的私有 API,而不是实现 DOM 标准接口。在调试代码并尝试了解在何处插入不同的 XML 解析器时,我注意到确实正在检索节点的文本数据。它位于
weblogic.xml.domimpl.TextImpl
类实例中的受保护成员变量String data
上。由于源代码尚未发布,我无法仅在类中查看如何访问该变量,因此我查看了方法名称以查找看起来很接近的内容。我找到了一个名为getData()
的方法。这是我的实现之前尝试做的事情(根据 DOM 接口,这可能正确也可能不正确):
现在的工作:
我仍然感谢那些更熟悉 Java DOM API 的人的评论,特别是可以纠正我的用法的评论
org.w3c.dom.Node
上可用的get*()
方法。The problem ended up being that Bea/Oracle, rather than implementing the DOM standard interface, uses their own private API. While debugging through my code trying to understand where to insert a different XML parser, I noticed that the text data of the node was indeed being retrieved. It was on a protected member variable
String data
in an instance of classweblogic.xml.domimpl.TextImpl
. Since the source isn't published I couldn't just look in the class to see how that variable was accessed, so I went looking through the method names for something that looked close. I found a method namedgetData()
.Here's what my implementation tried to do before (which may or may not be correct based on the DOM interface):
What is now working:
I would still appreciate comments from those more familiar with the Java DOM API, especially comments that would correct my usage of the
get*()
methods available onorg.w3c.dom.Node
.