简体   繁体   中英

Inject Stateless (Webservice)Bean into another Bean

I try to make a little test with versioning a soap service. My idea was that the business logic always implement the newest version and a soap service provide its functionality. To support the older version of the interface I want to map the jaxb classes via mapping framework to the newer version and then call the endpoint implementation from the older endpoint. So in endpoint v1 I inject the endpoint v2 and call it from there. But it seems, that neither cdi nor ejb injection works:

@Stateless
@WebServiceProvider(serviceName = "WebserviceV1", wsdlLocation = "META-INF/wsdl/My.wsdl", targetNamespace = "http://smitch.ch/service/v1", portName = "ServicePortV1")
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public class ServiceImplV1 implements ServicePortV1 {

    private ModelMapper modelMapper = new ModelMapper();

    @Inject
    private ServiceImplV2 v2;

    @PostConstruct
    void configureMapping() {
       PropertyMap<v1.RequestType, v2.RequesType> specialCase = new PropertyMap<>() {
        protected void configure() {
            //...
        }
    };
    modelMapper.addMappings(specialCase);
}

    @Override
    public v1.ResponseType service(v1.RequestType soapRequest) {
       v2.RequestType v2Request = map(soapRequest, v2.RequestType.class);
       return map(v2.service(v2Request), v1.ResponseResponse.class);
   }
}

The version 2 endpoint is defined more or less the same way, but has implemented the business logic in the body.

I always get the error

WELD-001408 Unsatisfied dependencies for type [ServiceImplV2] with qualifiers [@Default] at injection point [[field] @Inject private v1.ServiceImplV1.v2]"}}

I use JBoss EAP 6.3. Is there some special behaviour in handling webservice endpoints?

Here some more information. Both classes are in the same package and yes, I have a beans.xml.

V2 looks like:

@Stateless
@WebServiceProvider(serviceName = "WebserviceV2", wsdlLocation = "META-INF/wsdl/MyV2.wsdl", targetNamespace = "http://smitch.ch/service/v2", portName = "ServicePortV2")
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public class ServiceImplV2 implements ServicePortV2 {

    @Inject
    private Processor processor;

    @Override
    public v2.ResponseType service(v2.RequestType soapRequest) {
       return processor.process(soapRequest);
    }

As Jan mentioned, try adding @LocalBean to the ServiceImpleV2 to add a no-interface view. Then you should be able to injet your webservice with @EJB or @Inject.

@Stateless
@LocalBean
@WebServiceProvider(serviceName = "WebserviceV2", wsdlLocation = "META-INF/wsdl/MyV2.wsdl", targetNamespace = "http://smitch.ch/service/v2", portName = "ServicePortV2")
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public class ServiceImplV2 implements ServicePortV2 {

    @Inject
    private Processor processor;

    @Override
    public v2.ResponseType service(v2.RequestType soapRequest) {
       return processor.process(soapRequest);
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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