如何在spring soap端点中访问SOAP头?

时间:2012-01-10 03:10:27

标签: java spring soap spring-security spring-ws

这是我的SOAP请求:

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:str="http://app.strategyblocks.com/ws/schema/strategyblocks">
    <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="...">
                <wsse:Username>admin</wsse:Username>
                <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">secret</wsse:Password>
            </wsse:UsernameToken>
        </wsse:Security>
    </soapenv:Header>
    <soapenv:Body>
        <str:updateKpiRequest>
            <str:company_id>1</str:company_id>
            <str:kpi>
                <str:external_id>1134511</str:external_id>
                <str:title>title</str:title>
                <str:description>description</str:description>
            </str:kpi>
        </str:updateKpiRequest>
    </soapenv:Body>
</soapenv:Envelope>

这是我的端点类:

@Endpoint
public class UpdateKpiEndpoint {

    // The namespace of both request and response as declared in the XSD file
    public static final String NAMESPACE_URI = "http://app.strategyblocks.com/ws/schema/strategyblocks";

    // The local name of the expected request.
    public static final String REQUEST_LOCAL_NAME = "updateKpiRequest";

    @PayloadRoot(localPart = REQUEST_LOCAL_NAME, namespace = NAMESPACE_URI)
    @ResponsePayload
    public UpdateKpiResponse processUpdateKpi(@RequestPayload UpdateKpiRequest updateKpiRequest) {
        try {

        } catch (Exception e) {
            UpdateKpiResponse response = new UpdateKpiResponse();
            response.setCode("FAILURE");
            response.setDescription("Problem with update kpi request");

            return response;
        }

        UpdateKpiResponse response = new UpdateKpiResponse();
        response.setCode("SUCCESS");
        response.setDescription("Kpi has been updated");

        return response;
    }

}

目前我在soap请求中传递UsernameToken进行身份验证,这一切都运行良好,我没有遇到任何问题。我希望能够实现的是从我的端点类中processUpdateKpi方法的主体中的标头中检索该用户名,以便我可以使用它来查找该用户的现有数据,我试图找到它的例子已经完成,到目前为止我还没有成功,是否有可能做到这一点?我也考虑过也在SOAP主体中传递用户名,但我想避免使用它。

1 个答案:

答案 0 :(得分:1)

春天论坛中有人清楚地解释了如何从端点类中读取标题:

http://forum.springsource.org/showthread.php?109560-Unable-to-read-SoapHeader-in-Endpoint-class