SOAP中的XML头(JBoss)

时间:2014-04-16 09:37:11

标签: java java-ee soap jboss

我正在使用JBoss 5.1GA,默认情况下soap不带xml标头:

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"><soap:Body>
    ....
</soap:Body></soap:Envelope>

但我需要:

<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"><soap:Body>
    ....
</soap:Body></soap:Envelope>

我的肥皂处理程序:

public class XmlSOAPHandler implements SOAPHandler<SOAPMessageContext> {

    private static final Logger LOG = Logger.getLogger(XmlSOAPHandler.class);

    @Override
    public Set<QName> getHeaders() {
        return null;
    }

    @Override
    public boolean handleMessage(SOAPMessageContext context) {
        Boolean isOutbound = 
                (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
        if (isOutbound) {
            SOAPMessage soapMsg = context.getMessage();
            try {
                soapMsg.setProperty(SOAPMessage.CHARACTER_SET_ENCODING, "UTF-8");
                soapMsg.setProperty(SOAPMessage.WRITE_XML_DECLARATION, "true");
            } catch (SOAPException e) {
                LOG.error("Exception while setting properties");
            }
        }
        return true;
    }

    @Override
    public boolean handleFault(SOAPMessageContext context) {
        return true;
    }

    @Override
    public void close(MessageContext context) {
        //TODO
    }
}

处理程序附加到Web服务,成功拦截了soap消息,但未添加xml标头。我做错了什么?

0 个答案:

没有答案