jonesir
jonesir

Reputation: 33

How to bring SOAP capability to payara/micro in EJB project

I have an EJB project providing webservices (both SOAP and REST) running inside a container with payara/micro as base image, since payara/micro does not come with JAXWS(SOAP support) feature out of the box, however, by adding

cxf-rt-frontend-jaxws

and

cxf-rt-transports-http

as dependencies into the project as well as following this tutorial and put the following code instead:

@Override
public void loadBus(ServletConfig servletConfig) {
  super.loadBus(servletConfig);
  Bus bus = getBus();
  BusFactory.setDefaultBus(bus);
  Endpoint.publish("/MySoapService", new ASoapService());
}

I was able to make the SOAP interface almost available (wsdl information is publicly available already), and

http://localhost:8080/<my project name>/services

event listed out the available services as well their available methods and endpoints/WSDL/Target namespace information.

But when trying to access the SOAP service via SOAP client, I got on the server side errors with the following line of info:

...
Caused by: java.lang.NullPointerException: null
at com.example.ASoapService.getXxx
...

Where

ASoapService

Is Actually an EJB. So I tried instead to replace the above code with the following:

@EJB
ASoapService aSoapService
...
Endpoint.publish("/MySoapService", aSoapService);

During startup of container, I got

Caused by: javax.naming.NameNotFoundException: com.example.ASoapServiceF#com.example.ASoapService not found

By checking the logs, I found a possible reason: When SOAP part starts up with the following code

Endpoint.publish("/MySoapService", aSoapService);

The EJB Container is not yet ready and thus the lookup of

ASoapService

failed, is such assumption correct? Because normally you should see something like:

[2018-02-02T14:43:57.821+0000] [] [INFO] [AS-EJB-00054] [javax.enterprise.ejb.container] [tid: _ThreadID=1 _ThreadName=main] [timeMillis: 1517582637821] [levelValue: 800] Portable JNDI names for EJB ASoapService: [java:global/<my project name>/ASoapService, java:global/<my project name>/ASoapService!com.example.ASoapService]

during start up, which is not the case for my situation.

I am relatively new to EJB and Glassfish world, can I somehow force EJB container to start first? Or does it actually have anything to do with the starting sequence? How to combine the two together?

Thanks in advance.

Upvotes: 0

Views: 1126

Answers (1)

Ondro Mih&#225;lyi
Ondro Mih&#225;lyi

Reputation: 7710

You shouldn't be trying to force EJB container to start. Instead, try one of the following:

  • instead of @EJB ASoapService aSoapService to inject the EJB try @Inject ASoapService aSoapService - @Inject should wait for the dependencies therefore wait until the EJB is available
  • run the method Endpoint.publish from an object which is initialized after EJB container is ready, either from a startup singleton EJB or when CDI application scope is initialized: https://rmannibucau.wordpress.com/2015/03/10/cdi-and-startup/

Upvotes: 1

Related Questions