如何更改Soap标头消息

时间:2015-01-13 10:13:24

标签: spring soap soapui soap-client spring-ws

我有肥皂请求发送到该服务。在发送之前我想编辑Soap标题

<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" soapenv:mustUnderstand="1">

这是我希望将mustUnderstand的值传递为0而不是1的头之一。因为如果我将值传递为1,我将得到一个异常。我得到的值为1的异常是:

org.springframework.ws.soap.client.SoapFaultClientException: One or more mandatory SOAP header blocks not understood

我已经通过将mustUnderstand值传递为0来检查Soap UI并且它有效。现在我想从我的客户那里发送同样的东西。

我尝试在应用程序conext bean定义xml文件中添加参数,但没有按照下面的方法解决

<property name="securementmustUnderstand"><value>false</value></property>

请告诉我如何在我的客户端更改mustUnderstand参数。

完整的bean定义如下:

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

    <bean id="reg" class="com.service.RegConsServiceImpl">
        <property name="regWebServiceTemplate" ref="regWebServiceTemplate"/>
    </bean>
    <bean id="regWebServiceTemplate" class="org.springframework.ws.client.core.WebServiceTemplate">
        <constructor-arg ref="messageFactory"/>
        <property name="marshaller" ref="marshaller"/>
        <property name="unmarshaller" ref="unmarshaller"/>
        <property name="interceptors">          
            <list>
                <ref bean="wsRegClientSecurityInterceptor"/>
            </list>
        </property> 
    </bean>

    <bean id="wsRegClientSecurityInterceptor" class="org.springframework.ws.soap.security.wss4j.Wss4jSecurityInterceptor">
        <property name="securementmustUnderstand">
            <value>false</value>
        </property>
        <property name="securementActions" value="UsernameToken" />
        <property name="securementPasswordType" value="PasswordText"/>
        <property name="securementPassword">
            <value>${registration.ws.password}</value>
        </property>
        <property name="securementUsername">
            <value>${registration.ws.username}</value>
        </property>
    </bean>
</beans>

以下是生成的肥皂消息

<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:Header>
        <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" soapenv:mustUnderstand="1">
            <wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="UsernameToken-3">
                <wsse:Username>test</wsse:Username>
                <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">test</wsse:Password>
            </wsse:UsernameToken>
        </wsse:Security>
    </soapenv:Header>
    <soapenv:Body>
        <ns3:GetRegInfo xmlns:ns3="http://www.test.com/regester" xmlns:ns2="http://www.test.com/regester2" xmlns:ns4="http://com.test.com.services.register">
            <ns3:personId>10</ns3:personId>
        </ns3:GetRegInfo>
    </soapenv:Body>
</soapenv:Envelope>

0 个答案:

没有答案