Java 1.3 下的 SoapAction 问题
这个问题已经困扰我好几天了。 希望有人以前遇到过这个问题并制定了解决方法。
因此,我开发了一个中间件 Java 应用程序,它在执行过程中调用 SOAP 操作。 现在,这段代码在 1.6 JDK 下的行为运行良好:
// inside a try-catch block
SOAPConnectionFactory soapConnectionFactory =
SOAPConnectionFactory.newInstance();
SOAPConnection connection =
soapConnectionFactory.createConnection();
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage soapMsg = messageFactory.createMessage();
String soapAction = getHeaderUrl() + "/" + method + "\r\n";
MimeHeaders headers = soapMsg.getMimeHeaders();
headers.addHeader("SOAPAction", soapAction);
// review the SOAPAction header
int header_count =
soapMsg.getMimeHeaders().getHeader("SOAPAction").length;
out("SOAPActions (from Soap header): ");
if (header_count == 0) out ("No SOAPActions defined.");
for (int i=0; i<header_count; i++)
out("SOAPAction["+i+"] = \"" +
soapMsg.getMimeHeaders().getHeader("SOAPAction")[i]
+ "\"");
SOAPPart soapPart = soapMsg.getSOAPPart();
StreamSource s = new StreamSource(new StringReader(msg));
soapPart.setContent(s);
soapMsg.saveChanges();
ByteArrayOutputStream req_bytes = new ByteArrayOutputStream();
soapMsg.writeTo(req_bytes);
String req = new String(req_bytes.toByteArray());
SOAPMessage reply = connection.call(soapMsg, Url);
但是,当我在 1.3 或 1.4 JDK 下使用链接了 SOAP 库的完全相同的代码时,上面的所有内容都可以工作/编译/执行,除了事实上,标头的 SOAPAction 字段为空。 奇怪的是,当我检查该标头的值是什么(设置标头后立即出现的行)时,会显示适当的值。 然而,当它通过电线时,该字段是空的。 由于该字段向处理器指示我想要的资源,因此我的消息在门口被退回。
以前有人遇到过这个问题吗? 如果是这样,是否有可能的解决方法? (当然,如果需要,我愿意使用另一个库。)
更新:
我的类路径上的库如下:
- Xerces(resolver.jar、serializer.jar、xercesImpl.jar、xml- apis.jar)
- Saaj (saaj.jar)
- Axis (axis.jar
- JAX-RPC (jaxrpc.jar)
- 标准 SOAP(activation.jar、mail.jar、soap.jar、xerces.jar)
- Commons 日志记录和发现
提前致谢!
This problem has been bothering me for days. Hopefully someone has come across this before and has developed a workaround.
So I've developed a middleware Java app which during its execution invokes a SOAP action. Now, the behavior of this bit of code under the 1.6 JDK is working well:
// inside a try-catch block
SOAPConnectionFactory soapConnectionFactory =
SOAPConnectionFactory.newInstance();
SOAPConnection connection =
soapConnectionFactory.createConnection();
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage soapMsg = messageFactory.createMessage();
String soapAction = getHeaderUrl() + "/" + method + "\r\n";
MimeHeaders headers = soapMsg.getMimeHeaders();
headers.addHeader("SOAPAction", soapAction);
// review the SOAPAction header
int header_count =
soapMsg.getMimeHeaders().getHeader("SOAPAction").length;
out("SOAPActions (from Soap header): ");
if (header_count == 0) out ("No SOAPActions defined.");
for (int i=0; i<header_count; i++)
out("SOAPAction["+i+"] = \"" +
soapMsg.getMimeHeaders().getHeader("SOAPAction")[i]
+ "\"");
SOAPPart soapPart = soapMsg.getSOAPPart();
StreamSource s = new StreamSource(new StringReader(msg));
soapPart.setContent(s);
soapMsg.saveChanges();
ByteArrayOutputStream req_bytes = new ByteArrayOutputStream();
soapMsg.writeTo(req_bytes);
String req = new String(req_bytes.toByteArray());
SOAPMessage reply = connection.call(soapMsg, Url);
However, when I use this exact same code under 1.3 or 1.4 JDK with the SOAP libraries linked, everything above works/compiles/executes, except for the fact that the SOAPAction field of the header is blank. Weirdly enough, when I check what the value of that header is (the lines immediately following setting up the header) the appropriate value is displayed. However, when it goes over the wire, the field is empty. As this is the field which indicates the resource I want to the processor, my messages are getting turned back at the door.
Has anyone encountered this problem before? If so, are there possible workarounds? (I am, of course, willing to use another library if required.)
UPDATE:
The libraries on my classpath are as follows:
- Xerces (resolver.jar, serializer.jar, xercesImpl.jar, xml-apis.jar)
- Saaj (saaj.jar)
- Axis (axis.jar
- JAX-RPC (jaxrpc.jar)
- Standard SOAP (activation.jar, mail.jar, soap.jar, xerces.jar)
- Commons logging and discovery
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
奇特。 您说您正在链接 SOAP 库 - 到底是哪些?
我不会伤害尝试不同的 SOAP 堆栈,例如 CXF 或 JAX-WS-RI,尽管如果这两个堆栈中的任何一个支持 java 1.3,我会感到惊讶。
Peculiar. You say you're linking in the SOAP libraries - which ones, exactly?
I wouldn't hurt to try a different SOAP stack, such as CXF or JAX-WS-RI, although I'd surprised if either of those two supported java 1.3.
看起来这实际上可能是一个疏忽或一个错误,但无论如何我的解决方法是手动处理较低级别的 HTTP 内容,即:
事实证明这也比基于 SOAP 的解决方案更加简洁。
It looks like this may actually be an oversight or a bug, but at any rate my workaround was to handle the lower-level HTTP stuff manually, i.e.:
Turns out this is significantly more concise than the SOAP-based solution as well.