我正在尝试使用@Resource注释设置CXF Apache Web服务的上下文。但是上下文总是为空。请帮助克服这个问题。下面是我正在尝试访问messageContext的Web服务。
@WebService(serviceName = "RequestManagerService", targetNamespace = IRMNamespaces.WSDL+IRMVersions.WSDL_VERSION)
@Addressing(enabled=true, required=true)
public class RequestManager implements IRequestManager{
@Resource
WebServiceContext context;
@WebMethod(action = IRMNamespaces.WSDL+IRMVersions.WSDL_VERSION+"/RequestManagerService/SubscriberStateChangeRequest", operationName = "subscriberStateChange")
@Oneway
public void subscriberStateChangeRequest(
@WebParam(partName = "subscriberStateChangeRequest", name = "subscriberStateChangeRequest", targetNamespace = IRMNamespaces.SERVICE+IRMVersions.WSDL_VERSION) SubscriberStateChangeRequestType subscriberStateChangeRequest) {
MessageContext ctx = context.getMessageContext();
以下是关于上述Web服务的配置部分。
<bean id="rmService" class="com.morpho.rm.core.base.process.service.RequestManager">
</bean>
<jaxws:endpoint id="RequestMangerIntf"
implementor="#rmService"
address="/RequestManager">
<jaxws:binding><soap:soapBinding version="1.2" mtomEnabled="false"/></jaxws:binding>
<jaxws:features>
<wsa:addressing xmlns:wsa="http://cxf.apache.org/ws/addressing" />
</jaxws:features>
<jaxws:properties>
<entry key="schema-validation-enabled" value="true" />
</jaxws:properties>
</jaxws:endpoint>
如果有人对此有所了解,请提供帮助。
答案 0 :(得分:0)
您必须在WS实施中使用Setter方法。
如果要在消息上下文中设置参数,则必须为参数设置范围应用程序。
默认范围是处理程序在WS实现中不可见
SoapHandler
public boolean handleMessage(SOAPMessageContext smc) {
smc.put("ID_MESSAGGIO",message.getId());
smc.setScope("ID_MESSAGGIO", MessageContext.Scope.APPLICATION);
}
WS实施
WebServiceContext context;
@Resource
public void setContext(WebServiceContext context) {
this.context = context;
}
@Override
public CreateAndStartRequestByValueResponse createAndStartRequestByValue(CreateAndStartRequestByValueRequest parameters) throws CreateAndStartRequestByValueException {
MessageContext messageContext = context.getMessageContext();
Long theValue = (Long) messageContext.get("ID_MESSAGGIO");
return controller.startCreateAndStartRequestByValue(parameters);
}
答案 1 :(得分:-2)
只需在需要时创建新实例,而不是使用带注释的WebServiceContext。
WebServiceContext wsctx = new WebServiceContextImpl()