Apache cxf Web服务中的WebServiceContext为null

问题描述 投票:2回答:2

我正在尝试使用@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>

如果有人知道这件事,请帮忙。

java web-services resources cxf
2个回答
0
投票

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

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

默认范围是处理程序在WS实现中不可见

SoapHandler

 public boolean handleMessage(SOAPMessageContext smc) {

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

}

作为Islemantaion

   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()
© www.soinside.com 2019 - 2024. All rights reserved.