Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在SpringSOAP端点中访问SOAP头?_Java_Spring_Soap_Spring Security_Spring Ws - Fatal编程技术网

Java 如何在SpringSOAP端点中访问SOAP头?

Java 如何在SpringSOAP端点中访问SOAP头?,java,spring,soap,spring-security,spring-ws,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> <wss

以下是我的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>

目前,我正在soap请求中传递一个用于身份验证的
UsernameToken
,这一切都很好,我对它没有任何问题。我希望能够实现的是从端点类中的
processUpdateKpi
方法主体中的头中检索该用户名,这样我就可以使用它来查找该用户的现有数据,我已经尝试查找正在执行的示例,但到目前为止我还没有成功,是否可以这样做?我也曾考虑过在SOAP正文中传递用户名,但我想避免这种情况。

spring论坛中的某个人对如何从endpoint类读取头给出了明确的解释:


我不知道SoapHeader也可以自动注入,谢谢你(-:你知道吗?
@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;
    }

}