【问题标题】:Authorization bearer soap request授权不记名肥皂请求
【发布时间】:2017-05-12 16:03:01
【问题描述】:

我需要以某种方式在我的肥皂服务信封中包含一个值为"Authorization""Bearer xXsomeCode123xX" 的标头,这是我需要使用新标头编辑的代码部分,然后它返回给我一个xml 文档通过soap web 服务请求的一些数据。

            //SERVICE
            Service service = new Service();
            Call call = (Call) service.createCall();    
            call.setTargetEndpointAddress(new java.net.URL(endPointURL));
            call.setSOAPActionURI(soapActionURI);   

            //INVOKE
            SOAPEnvelope response = (SOAPEnvelope) call.invoke(new Message(soap.asXML()));              
            Document doc = new DOMReader().read(response.getAsDocument());  
            return doc;

这就是我在 SoapUI 中看到的(并且可以使用这样的标题集)

我知道这个问题令人困惑,而且我在互联网上进行了研究,但几乎每个标题都是由用户名:密码字段组成的,而我只有这个“授权”可以处理

【问题讨论】:

    标签: web-services soap


    【解决方案1】:

    如果您使用WebServiceTemplate,您可以使用WebServiceMessageCallback 执行marshalSendAndReceive 方法,在这些回调中您可以添加RequestHeader,您可以放置​​授权和不记名+令牌,您的方法doWithMessage 必须看起来如下:

    public void doWithMessage(WebServiceMessage webServiceMessage) throws IOException, TransformerException {
                        TransportContext context = TransportContextHolder.getTransportContext();
                        HeadersAwareSenderWebServiceConnection connection = (HeadersAwareSenderWebServiceConnection) context.getConnection();
                        connection.addRequestHeader("Authorization", String.format("Bearer %s", "********"));
    
                    }
    

    更多信息在link

    【讨论】:

      【解决方案2】:

      要在 SoapUI 中添加不记名授权标头,您必须: (请记住,Bearer 令牌属于 OAuth2)

      • 点击请求窗口左下角的“Auth”按钮
      • 使用“授权”下拉菜单,选择添加新授权。
      • 然后 - 类型 -> OAuth2,按 OK。你会看到一个名为
        的输入字段 访问令牌。只需将您的令牌插入其中即可。

      运行您的请求,在 http 日志中您会看到类似的内容: :DEBUG:>> "授权:承载.... [\r][\n]"

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-02-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-07-29
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多