java 使用 JAX-WS 提取整个 SOAP 消息
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13147961/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Extracting whole SOAP message with JAX-WS
提问by user994165
I have an EJB stateless bean web service and would like to get access to the whole SOAP message, not just the SOAP Body as I'm currently getting in the parameter. I want to submit the message to a different component. I'm using Spring configuration but not Spring-WS. I followed this tutorial:
我有一个 EJB 无状态 bean Web 服务,并且想要访问整个 SOAP 消息,而不仅仅是我目前在参数中获取的 SOAP Body。我想将消息提交给不同的组件。我使用的是 Spring 配置,而不是 Spring-WS。我跟着这个教程:
http://java.dzone.com/articles/creating-soap-message-handlers
http://java.dzone.com/articles/creating-soap-message-handlers
as is and didn't make any changes for now. It just logs the SOAP message. handleMessage() isn't getting called.
照原样,暂时没有做任何更改。它只记录 SOAP 消息。handleMessage() 没有被调用。
@Stateless
@WebService(portName = "XRequest_PortType", serviceName = "XRequestService", endpointInterface = "XRequestPortType")
@Addressing(enabled = true)
@HandlerChain(file = "LogMessage_handler.xml")
@Interceptors(SpringBeanAutowiringInterceptor.class)
public class XRequest_PortTypeWS implements
XRequestPortType {
...}
The LogMessage_handler.xml is slightly different from the tutorial but I tried it both ways:
LogMessage_handler.xml 与教程略有不同,但我尝试了两种方式:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<javaee:handler-chains
xmlns:javaee="http://java.sun.com/xml/ns/javaee"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<javaee:handler-chain>
<javaee:handler>
<javaee:handler-class>com.test.ws.LogMessageHandle</javaee:handler-class>
</javaee:handler>
</javaee:handler-chain>
</javaee:handler-chains>
LogMessageHandler:
日志消息处理程序:
package com.test.ws;
import java.io.IOException;
import java.util.Collections;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.namespace.QName;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPMessage;
import javax.xml.ws.handler.MessageContext;
import javax.xml.ws.handler.soap.SOAPHandler;
import javax.xml.ws.handler.soap.SOAPMessageContext;
/**
*
* @author meerasubbarao
*/
public class LogMessageHandler implements SOAPHandler<SOAPMessageContext> {
public boolean handleMessage(SOAPMessageContext messageContext) {
log(messageContext);
return true;
}
public Set<QName> getHeaders() {
return Collections.EMPTY_SET;
}
public boolean handleFault(SOAPMessageContext messageContext) {
return true;
}
public void close(MessageContext context) {
}
private void log(SOAPMessageContext messageContext) {
SOAPMessage msg = messageContext.getMessage(); // Line 1
try {
msg.writeTo(System.out); // Line 3
} catch (SOAPException ex) {
Logger.getLogger(LogMessageHandler.class.getName()).log(
Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(LogMessageHandler.class.getName()).log(
Level.SEVERE, null, ex);
}
}
}
Is this even the best way to get the whole SOAP message? I would still need to to call a Spring bean from XRequest_PortTypeWS to send the SOAP message.
这甚至是获取整个 SOAP 消息的最佳方式吗?我仍然需要从 XRequest_PortTypeWS 调用 Spring bean 来发送 SOAP 消息。
采纳答案by user994165
I did use a SOAP Handler and was able to get the full SOAP Message. The details are in this other post.
我确实使用了 SOAP 处理程序并且能够获得完整的 SOAP 消息。详细信息在另一个帖子中。
回答by Denys
I've checked the article in http://java.dzone.com/articles/creating-soap-message-handlersand I noticed that you don't set up handler name in LogMessage_handler.xml and one more important thing is to locate LogMessage_handler.xml in the same package where is web service bean. Also please add @Remote annotation to webservice bean.
我检查了http://java.dzone.com/articles/creating-soap-message-handlers 中的文章, 我注意到您没有在 LogMessage_handler.xml 中设置处理程序名称,更重要的一件事是定位LogMessage_handler.xml 位于 Web 服务 bean 所在的同一个包中。还请在 webservice bean 中添加 @Remote 注释。