Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.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
Xslt 在Camel中,如何使用XSL转换的结果设置头值?_Xslt_Apache Camel - Fatal编程技术网

Xslt 在Camel中,如何使用XSL转换的结果设置头值?

Xslt 在Camel中,如何使用XSL转换的结果设置头值?,xslt,apache-camel,Xslt,Apache Camel,我正在使用camel在一个看起来像旧接口的新后端上实现一个代理。旧的API在请求正文中具有用户名/密码凭据,而新的后端服务使用基本身份验证。我有一个XSL,它将提取un/pw,对XML数据库进行简单的查找(凭证可能不完全映射),并将正确的凭证作为base64编码字符串返回。我不知道如何将其设置为http身份验证标头值(例如,如何将XSL转换作为.setHeader()调用中的表达式进行处理) 我有如下SOAP请求: <soapenv:Envelope> <soapenv:Bod

我正在使用camel在一个看起来像旧接口的新后端上实现一个代理。旧的API在请求正文中具有用户名/密码凭据,而新的后端服务使用基本身份验证。我有一个XSL,它将提取un/pw,对XML数据库进行简单的查找(凭证可能不完全映射),并将正确的凭证作为base64编码字符串返回。我不知道如何将其设置为http身份验证标头值(例如,如何将XSL转换作为.setHeader()调用中的表达式进行处理)

我有如下SOAP请求:

<soapenv:Envelope>
<soapenv:Body>
    <XService>
        <_Header  username="demo" password="demo"/>
        <_Body>
            <_RequestParameters xsi:type="RequestServiceReport">
            ...
            </_RequestParameters>
        </_Body>
    </XService>
</soapenv:Body>
from("jetty:http://161.228.88.168:8080/sap2rjm")
.choice()
.when().simple("${header.channel}")
    ...
.when().simple("${in.header.emx} == 'authenticate'")
    ...
    .endChoice()
// If the request is for a report, route it to the new service
.when().xpath("//_RequestParameters[@type='RequestServiceReport']")
    // TODO: How to get header from the body of the message and set as the header value?
    // Stylesheet transform_credentials will extract username/password from body, transform
    // for the new service (dev.reportjam) and will base4 encode to produce a string like this one...
    .setHeader("Authorization", constant("Basic ZGVtbzpkZW1v"))
    .to("xslt:transform_request.xsl")
    .to("http://dev.reportjam.com/services/ReportMix?bridgeEndpoint=true")
    .to("xslt:transform_response.xsl")
    .removeHeaders("*")
    .endChoice()

.otherwise()
    ...
    .endChoice()
.end();
我有另一个样式表,它将处理soap请求,提取un/pw,应用一些逻辑对其进行转换,然后对其进行base64编码,但我不知道如何在上面的setHeader()调用中调用它


谢谢

您可以使用xpath从XML正文中获取一些内容,然后将其存储为标题。

诀窍是编写xpath表达式使其工作。由于XML消息使用名称空间,因此还需要在xpath表达式中使用它们。有关更多详细信息,请参阅该链接

此外,还应该启用流缓存,因为您将在xpath表达式计算中读取消息体


请参阅此链接顶部有关流缓存和jetty的内容:

请显示一些代码或类似内容。您使用什么组件?很难从这个问题中看出您真正想要的是什么。谢谢克劳斯,但是xpath不能满足我的需要-我需要在主体上处理样式表以生成头值。
.setHeader("foo", xpath("/foo/bar"))