问题描述
我正在JBoss6服务器上运行基于Apache CXF 2.3.1的JAX-WS Web服务。
I'm running a JAX-WS web service which is based on Apache CXF 2.3.1 on a JBoss6 server.
我的服务提供的功能 getWeight
。此函数应根据SOAP标头中的其他信息以不同的单位(公斤,磅)返回值。为此,我添加了自己的拦截器:
My service offers a function getWeight
. This function should return the values in different units (kilos, pounds) depending on an additional information within the SOAP header. For that purpose I have added my own interceptor:
public class MySoapHeaderInterceptor extends AbstractSoapInterceptor
{
public MySoapHeaderInterceptor()
{
super(Phase.USER_PROTOCOL);
}
...
}
拦截工作正常,我可以从SOAP标头解析其他元素,并可以基于此元素设置变量:
The intercepting works fine and I can parse the additional element from the SOAP header and can set up a variable based on this element:
boolean poundsRequested = true;
现在发生了我的问题。我不知道如何将变量 poundsRequested
转发到我的实际WebService实现 MyServiceImpl
。此类正在调用另一个类 ValueReader
,在该类中,我最终需要SOAP标头中的信息。
Now my problem occurs. I don't know how to forward the variable poundsRequested
to my actual WebService implementation MyServiceImpl
. This class is calling another class ValueReader
where I finally need the information from the SOAP header.
我已经尝试设置全局静态变量 ValueReader.poundsRequested
。但是这样的解决方案不是线程安全的。
I've already tried to set up a global static variable ValueReader.poundsRequested
. But such a solution is not thread safe. It might happen that the calls of two clients interfere, and can overwrite each others set up variable.
总结:我基本上需要一个将变量从Apache CXF拦截器转发到实际的Web服务实现的可能性。此外,对于每个请求,此变量的值都必须是唯一的。
To sum up: I basically need a possibility to forward a variable from an Apache CXF Interceptor to the actual webservice implementation. Moreover the value of this variable needs to be unique for each request.
推荐答案
在拦截器中,您可以保存自己的值
In the interceptor, you can save the values that you need on the incoming message:
message.put("my.value", value);
在实现中,您可以执行以下两项操作之一:
Inside your implementation, you can do one of two things:
1 )通过@Resource事物注入标准的JAXWS WebServiceContext并调用
1) Have the standard JAXWS WebServiceContext injected via an @Resource thing and call
context.getMessageContext().get("my.value");
2)由于您仍然与CXF绑定,因此请执行以下操作:
2) Since you are tied to CXF anyway, do:
PhaseInterceptorChain.getCurrentMessage().get("my.value");
这篇关于Apache CXF:将信息从拦截器转发到实际的Web服务实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!