【问题标题】:WebServiceContext is null in Apache cxf Web servicesWebServiceContext 在 Apache cxf Web 服务中为空
【发布时间】:2014-08-16 17:54:51
【问题描述】:

我正在尝试使用 @Resource 注释设置 CXF Apache Web 服务的上下文。但是上下文总是为空。请帮助解决这个问题。下面是我试图访问 messageContext 的网络服务。

@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>

如果有人对此有所了解,请提供帮助。

【问题讨论】:

    标签: java web-services resources cxf


    【解决方案1】:

    您必须在您的 WS 实现上使用 Setter 方法。

    如果你想在消息上下文中设置参数,你必须为参数设置范围应用程序。

    默认作用域是 Handler 在 WS 实现中不可见

    肥皂处理器

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

    【讨论】:

      【解决方案2】:

      不要使用带注释的 WebServiceContext,只需在需要时创建新实例。

          WebServiceContext wsctx = new WebServiceContextImpl()
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-09-22
        • 2014-08-01
        • 1970-01-01
        • 1970-01-01
        • 2011-04-17
        • 2015-09-03
        • 2012-09-09
        相关资源
        最近更新 更多