How to get WebServiceContext into a CDI producer?
Issue
- We are trying to get HTTP headers on a SOAP Web Service in a producer method.
To do so, we would like to get WebServiceContext.
The web service is created as below:
------
package org.example.ejb;
import javax.ejb.Stateless;
import javax.inject.Inject;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import org.example.producer.logger.Logger;
@Stateless(mappedName = "Test", name = "Test")
@WebService(name = "Test", serviceName = "Test", portName = "TestPortType", targetNamespace = "http://test.example.org")
public class TestEjb {
@Inject
private Logger logger;
@WebMethod(action = "sayHello", operationName = "sayHello")
public void sayHello(@WebParam(name = "name") String name) {
logger.log("Test log");
System.out.printf("Hello %s!\n", name);
}
}
------
The producer is:
------
package org.example.producer;
import javax.enterprise.inject.Produces;
import javax.enterprise.inject.spi.InjectionPoint;
import javax.inject.Inject;
import javax.xml.ws.WebServiceContext;
import org.example.producer.logger.Logger;
public class TestProducer {
// How can I get context?
private WebServiceContext context;
@Produces
public Logger getLogger(InjectionPoint ip) {
System.out.println(context);
return new Logger(ip.getBean().getBeanClass());
}
}
-
Could you please tell us how to get the HTTP headers in the getLogger method ?
-
We cannot add the
WebServiceContextinjection (via @Resource annotation) in the Web Service because we are creating on internal Framework for developers. - The producer method should get the information from the context without impact on the existing applications.
Environment
- Red Hat JBoss Enterprise Application Platform (EAP)
- 6.4.x
- JBossWS-CXF
- WELD/CDI
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.