java - 如何访问 Spring Soap 端点中的 SOAP header ?

标签 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 方法主体中的 header 中检索该用户名,以便我可以使用它来查找该用户的现有数据,我有试图找到正在做的例子,到目前为止我还没有成功,有可能做到吗?我也考虑过在 SOAP 主体中传递用户名,但我想避免它。

最佳答案

Spring 论坛中有人对如何从端点类读取 header 有明确的解释:

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

关于java - 如何访问 Spring Soap 端点中的 SOAP header ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8798105/

相关文章:

java - 当Java Web服务部署在运行同一应用服务器的不同操作系统上时,同一消息的不同数字签名

java - CXF Web 服务服务器将请求凭证委托(delegate)给内部 Web 服务调用

spring - 如何防止 Spring JmsTemplate 单元测试在读取 ActiveMQ 队列时阻塞?

java - 在 Spring MVC 中使用 BeanNameUrlHandlerMapping 时找不到映射

ruby-on-rails - savon httperror 302 Rails 3.2

Magento Api错误 fatal error : Uncaught SoapFault exception: [4] Resource path is not callable

java - 使用 getBase Station Latitude()/Longitude() 的 CDMA android 手机的基站位置

java - JPA/hibernate : Annotations for already created table

java - 窗与窗的互动

regex - Spring security 3 带索引的拦截url模式