简体   繁体   中英

Test @Webservice EJB with WebServiceContext (Arquillian)

I am having the same problem from this answer , but my environment uses Arquillian for testing instead of OpenEJB.

My problem is that I get the user Principal name programmatically and, although this works perfectly in the running application, this call fails with the following exception during test execution:

javax.ejb.EJBException: java.lang.IllegalStateException
    at org.jboss.ws.common.injection.ThreadLocalAwareWebServiceContext.getWebServiceContext(ThreadLocalAwareWebServiceContext.java:88)
    at org.jboss.ws.common.injection.ThreadLocalAwareWebServiceContext.getUserPrincipal(ThreadLocalAwareWebServiceContext.java:74)

Is there any way I can make this work? By mocking the WebServiceContext or something...

I ran into the same problem while testing today. From what I could see, the Handlers don't have view of the state of the Web Service. If this is something specific to Arquillian, I'm not sure.

However, this isn't a problem as the SOAPMessageContext parameter to the handleMessage method extends the MessageContext interface, so you should be able to access almost anything you need directly from the SOAPMessageContext without needing access to the WebServiceContext . The only obvious exception I could see was the user principal.

@Override
public boolean handleMessage(SOAPMessageContext soapMessageContext) {
  String value = (String) soapMessageContext.get("myKey");
}

Just one additional comment, if you want to put an object into the MessageContext map and also want it available inside your endpoint, make sure to set the scope:

soapMessageContext.put("myKey", "someValue");
soapMessageContext.setScope("myKey", MessageContext.Scope.APPLICATION);

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