简体   繁体   English

Web ServiceContext在Apache cxf Web服务中为null

[英]WebServiceContext is null in Apache cxf Web services

I'm trying to set the context of a CXF Apache web service by using the @Resource annotation. 我试图通过使用@Resource批注设置CXF Apache Web服务的上下文。 But the context always comes as null. 但是上下文始终为空。 Please help to overcome this problem. 请帮助克服这个问题。 Below is the webservice which I'm trying to access the messageContext. 以下是我正在尝试访问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();

Below is the configuration part which regarding to above web service. 以下是关于以上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>

Please help if anyone knows anything about this. 如果有人对此有所了解,请提供帮助。

You must use Setter Method on you WS Implementation. 您必须在WS实现中使用Setter方法。

If you want set parameter in message context you must set scope application for parameter. 如果要在消息上下文中设置参数,则必须设置参数的范围应用程序。

The Default Scope is Handler not visible in WS Implementation 在WS实现中,默认作用域是“处理程序”不可见

SoapHandler 肥皂处理程序

 public boolean handleMessage(SOAPMessageContext smc) {

 smc.put("ID_MESSAGGIO",message.getId());
 smc.setScope("ID_MESSAGGIO", MessageContext.Scope.APPLICATION);

}

WS Implementation 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);
    }

无需使用带注释的WebServiceContext,而仅在需要时创建新实例。

    WebServiceContext wsctx = new WebServiceContextImpl()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM