Hello,

I'ld ask a question about an use case of mine, I'm afraid I'm doing something wrong...

My software setup is Java EE 7 with Wildfly 10.1 and JDK 1.8, I need to talk to a SOAP webservice so I'm using JAX-WS Client integrated in Java EE 7.

My WS client is actually a stateless EJB (so is pooled by EJB container in Wildfly) and I obtain the WS port (proxy) in my @PostConstruct method:

example:


@Stateless
public class SpeseEJB
{

  @WebServiceRef
private InvioTelematicoSpeseSanitarie730PService invioTelematicoSpeseSanitarie730PService;

  private InvioTelematicoSS730PMtom invioTelematicoSS730PMtomPort;

  @PostConstruct
  public void init()
  {
invioTelematicoSS730PMtomPort = invioTelematicoSpeseSanitarie730PService.getInvioTelematicoSS730PMtomPort();
  }

private void setupWS(BindingProvider provider, String username, String password)
  {


provider.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, username);

provider.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password);
  }

  public void someothermethod(ConfigSTS configSTS)
  {
     // setting up auth credentials
setupWS((BindingProvider)invioTelematicoSS730PMtomPort, configSTS.getUsername(), configSTS.getPassword());

     try
     {
          // call the service using the port proxy
          invioTelematicoSS730PMtomPort.methodname(param, param, etc.);
     }
     catch (javax.xml.ws.soap.SOAPFaultException ex)
     {
            // etc. etc. etc.
     }

  }

}


My question is: am I wrong in creating the service ONCE per EJB istance and not per-invocation (into "someothermethod()" ? ) Should I move the "get port" invocation in the method so to use a local-scoped variable ?

I'm worried especially for the request context, every invocation of the method will use different username/password, but what if the request context is shared among every istance of EJB pool ?? EJB method are "single thread" but the container can invoke the method on many EJB instance at the sometime..

Googling around I found this thread:
https://stackoverflow.com/questions/10599959/is-this-jax-ws-client-call-thread-safe

I understand the adding something like:

provider.getRequestContext().put("thread.local.request.context","true");

just before the others getRequestContext(set username, etc.)

could solve..
Is this the correct solution ? or what ?


any help or suggestion will be much appreciated!


Many thanks in advance!


Kind regards


A. de Manzano
DQMicro

Reply via email to