Question

I have JAX-WS webservice, I want to run a method for each request.

I assume that my constructor runs for each request but it runs just once.

I think it happen because tomee use thread pool. My source code is:

@Stateless
@WebService(
    portName = "APIPort",
    serviceName = "APIService",
    targetNamespace = "http://telc.ir/wsdl",
    endpointInterface = "wsAPI.APIWS")
public class API implements APIWS {

    @Resource
    WebServiceContext wsContext;

    public API() {
        System.out.println("Webservice Called");
    }
}

is there any method that run on each request?

please help me.

Was it helpful?

Solution

I'd wager that @Stateless might be the culprit here...

OTHER TIPS

using constructor for EJB is normally not a feature (and I think it can even not be called on some versions). It is replaced by @PostConstruct to be able to use injection after init. That said it doesn't solve your issue.

You can just declare a facade for your service which will delegate to the EJB which would be a CDI bean @RequestScoped. Same note, use either constructor injections or @PostConstruct to init it but it is done by request ;)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top