Message Boards

Make SOAP client OOTB in Liferay 7.3 and Java 11

thumbnail
Eric D, modified 2 Years ago.

Make SOAP client OOTB in Liferay 7.3 and Java 11

Junior Member Posts: 55 Join Date: 3/25/16 Recent Posts

Hello,

I am doing a migration from Liferay 6.2 to Liferay 7.3 DXP in Java 11.

In Java 11, the librairies to make a SOAP client have been removed.

If we add them, we have differents problems.

Is there a simple way to make a SOAP client OOTB ?

We saw a lot of answers in this forum but this is a common fonctionnality, why it is SO complicated to implement it ?

I give you more explainations.

My client wants to migrate in Java 11. We have done the migration from 6.2 EE to 7.3 DXP and it works in Java 8 in Maven.

But the same jar failed in Java 11. We change the target destination and add the new libs but it fails.

        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>

        ...

        <dependency>
          <groupId>com.sun.xml.ws</groupId>
          <artifactId>jaxws-ri</artifactId>
          <version>2.3.4</version>
          <type>pom</type>
        </dependency>

When we look at the github source of Liferay or the differents posts, the way to solve this is in Gradle. We found no exemple in Maven.

Here are the differents problems we have :

    com.sun.xml.internal.ws.spi.ProviderImpl cannot be found

To solve this we have found this answer : https://issues.liferay.com/browse/LPS-98339

And It doesn't work because we need to make a client SOAP and not a server. But after I find another way with :

thread.setContextClassLoader(myClass.class.getClassLoader())

But after we have a pb with :

Unresolved requirement: Import-Package: javax.jws

We try to use the Liferay dependances but it fails :

        <dependency>
            <groupId>com.liferay</groupId>
            <artifactId>javax.jws</artifactId>
            <scope>provided</scope>
        </dependency>

We try after the official dependances :

         <dependency>
            <groupId>javax.jws</groupId>
            <artifactId>javax.jws-api</artifactId>
            <version>1.1</version>
        </dependency>

And now it works but we have to include the resource in the bnd.bnd :

    -includeresource:\
    META-INF/lib/javax.jws-api.jar=javax.jws-api-[0-9].[0-9]*.jar;lib:=true

After that, the current problem is :

    "A WebService annotation is not present on class"

But this class is generated by CXF !  And we see the correct annotation on this clas !!!

So we try another approch with the JAX-WS pluggin :

        <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>jaxws-maven-plugin</artifactId>
                <version>2.6</version>
                <executions>
                    <execution>
                        <id>wsimport-from-jdk</id>
                        <goals>
                            <goal>wsimport</goal>
                        </goals>
                    </execution>
                </executions>

    ...

Before we were using the CXF plugin :

        <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-codegen-plugin</artifactId>
                <version>${cxf.version}</version>
                <executions>
                    <execution>
                        <id>generate-sources</id>

        ...

But no sucess... Did anyone have an exemple of a client SOAP in Java 11 with Maven ?

We try to add the missing lib in tomcat/lib or tomcat/lib/ext but it doesn't work.

Any help will be appreciated...

Eric.

thumbnail
Fabian Bouché, modified 2 Years ago.

RE: Make SOAP client OOTB in Liferay 7.3 and Java 11 (Answer)

New Member Posts: 4 Join Date: 4/19/20 Recent Posts

Hi Eric,

I got it working this way: https://gist.github.com/fabian-bouche-liferay/bf7fdfb7c3d02052f642314b1ae7549b

You'll need this explicit import in the bnd.bnd file as well:

Import-Package:\
	org.apache.cxf.jaxws.spi,\
	*

It's still a bit mysterious to me (I did not have time to completely analyze it) but the critical part is to call the ProviderImpl constructor from within the @Activate annotated method.

Kind regards,

Fabian

thumbnail
Eric D, modified 2 Years ago.

RE: RE: Make SOAP client OOTB in Liferay 7.3 and Java 11

Junior Member Posts: 55 Join Date: 3/25/16 Recent Posts

Thank you Fabian foe your help,

Now it works for us.

We have to create a fragment to export the package CXF JAWS SPI with 7.3 version.

After that we use the CXF plugin in 3.3.0 version.

But for the maven dependency we use the 3.2.5 version.

Here the maven dependencies we have use :

<dependency>

    <groupId>javax.xml.bind</groupId>

    <artifactId>jaxb-api</artifactId>

    <version>2.3.1</version>

    <scope>provided</scope>

</dependency>

<dependency>

    <groupId>javax.xml.ws</groupId>

    <artifactId>jaxws-api</artifactId>

    <version>2.3.1</version>

    <scope>provided</scope>

</dependency>

<dependency>

    <groupId>javax.jws</groupId>

    <artifactId>javax.jws-api</artifactId>

    <version>1.1</version>

    <scope>provided</scope>

</dependency>

 <dependency>

        <groupId>org.apache.cxf</groupId>

        <artifactId>cxf-rt-frontend-jaxws</artifactId>

        <version>${cxf.version}</version>

        <scope>provided</scope>

</dependency>

The important is to use the same dependencies of Liferay to have no conflict.

 

Thank you SO much for your help Fabian,

Eric.

thumbnail
Eric D, modified 2 Years ago.

RE: Make SOAP client OOTB in Liferay 7.3 and Java 11

Junior Member Posts: 55 Join Date: 3/25/16 Recent Posts

Thank you Fabian,

I have try what you have explain but I have this error :

    Unresolved requirement: Import-Package: org.apache.cxf.jaxws.spi; version="[3.4.0,4.0.0)"_ [Sanitized]
    at org.eclipse.osgi.container.Module.start(Module.java:444)

Is it possible to share your project ? (and specialy your pom.xml et bnd.bnd)

Here is the dependency we have added :

        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-frontend-jaxws</artifactId>
            <version>3.4.0</version>
        </dependency>

If we use another version under than 3.4.0 (we try 3.2.14), we have pb with the cxf-pluggin :

Failed to execute goal org.apache.cxf:cxf-codegen-plugin:3.2.14:wsdl2java

Or do you know wich liferay module export the package "org.apache.cxf.jaxws.spi.ProviderImpl" ?

Eric.

thumbnail
Fabian Bouché, modified 2 Years ago.

RE: RE: Make SOAP client OOTB in Liferay 7.3 and Java 11

New Member Posts: 4 Join Date: 4/19/20 Recent Posts

Hi Eric,

Indeed, you need to create a fragment to have an existing bundle export it.

In my DXP 7.2 setup, I got this:

Bundle-Name: cxf-provider-fragment
Bundle-SymbolicName: com.liferay.sample.fbo.cxf.provider.fragment
Fragment-Host:  com.liferay.portal.remote.soap.extender.impl
Export-Package: org.apache.cxf.jaxws.spi;version=3.2.5

You'll have to use the gogo shell to check the actual version of the package you are exporting.

My strategy relies on having my soap client use the same cxf version as liferay.

Sorry, I'd have to create a proper sample project for this. It's not inside of a repo I can share.

Kind regards,

Fabian

thumbnail
Eric D, modified 2 Years ago.

RE: RE: Make SOAP client OOTB in Liferay 7.3 and Java 11

Junior Member Posts: 55 Join Date: 3/25/16 Recent Posts

Hi Fabian,

In Liferay DXP 7.3 the version is 4.0.23 and the version of CXF is 3.2.14, so we create the fragment like this : 

Bundle-Name: Liferay Portal Remote SOAP Extender Implementation Fragment
Bundle-SymbolicName: test.remote-soap-extender
Bundle-Version: 1.0.0
Fragment-Host: com.liferay.portal.remote.soap.extender.impl;bundle-version="4.0.23"
Export-Package: org.apache.cxf.jaxws.spi;version=3.2.14

And in our module we import the same dependency (3.2.14) :

		<dependency>
		    <groupId>org.apache.cxf</groupId>
		    <artifactId>cxf-rt-frontend-jaxws</artifactId>
		    <version>3.2.14</version>
		    <scope>provided</scope>
		</dependency>

It seems to be better but after (the compilation is OK) but we need to exclude many packages:

Import-Package:\
	!com.sun.*,\
	\
	!javax.validation.*,\
	\
	!net.sf.cglib.proxy.*,\
	\
	!org.apache.abdera.*,\
	!org.apache.aries.*,\
	!org.apache.cxf.aegis.*,\
	!org.apache.cxf.ws.policy.*,\
	!org.apache.neethi.*,\
	!org.apache.velocity.*,\
	!org.apache.xml.resolver.*,\
	!org.apache.xmlbeans.*,\
	\
	!org.junit.*,\
	\
	!org.jvnet.fastinfoset.*,\
	!org.jvnet.staxex.*,\
	\
	!org.osgi.service.blueprint.*,\
	\
	!org.relaxng.datatype.*,\
	\
	!org.slf4j.spi.*,\
	\
	!org.springframework.*,\
	\
	org.apache.cxf.jaxws.spi,\
	*

And we still have an error with operation not found in wsdl...

After many hours and many days of work, we don't find a issue to this problem.
The same module works in java 8. Will it be possible to share an exemple of a SOAP client in Maven with java 11 ?

Eric.

thumbnail
Eric D, modified 2 Years ago.

RE: RE: Make SOAP client OOTB in Liferay 7.3 and Java 11

Junior Member Posts: 55 Join Date: 3/25/16 Recent Posts

Here are the errors we have in the logs :

The javax.jws.WebService annotation was already loaded by another classloader. Please check if there are multiple versions of the web service annotation jar in your classpath.
...
No method was found for the WSDL operation {http://xmlns.example.com/...

 

Mario González, modified 2 Years ago.

RE: Make SOAP client OOTB in Liferay 7.3 and Java 11

New Member Posts: 9 Join Date: 11/27/19 Recent Posts

Hi. I was facing the exact same issue, migrating from JDK8 to JDK11, in Liferay 7.3, and found this post after visiting several more. In the end, I've managed to find another solution, just in case is better for other cases.

First, I've generated all the required SOAP classes with apache cxf, but important, using the same version included with Liferay, in my case, apache-cxf-3.2.4. This is required to not depend on jar version not included with Liferay bundle. All the problems I faced where related to the fact that previously I used a newer apache cxf version, so then newer jws-api and jaxws-api where required

After that, only these 2 dependencies required in pom.xml:

<dependency>
            <groupId>javax.xml.ws</groupId>
            <artifactId>jaxws-api</artifactId>
            <version>2.3.0</version>
 </dependency>
 <dependency>
            <groupId>javax.jws</groupId>
            <artifactId>javax.jws-api</artifactId>
            <version>1.1</version>
 </dependency>

Both of them are present, so no other changes in bnd.bnd or whatever are required. When deploying the module, there are no dependency errors. But to avoid errors on execution, I've had to add resolver-20050927.jar on webapps/ROOT/WEB-INF/lib folder (check https://stackoverflow.com/questions/58319199/java-lang-classnotfoundexception-com-sun-org-apache-xml-internal-resolver-catal). Yes, it's supposed not to use in JDK version over 8, but, maybe related to the jax version Liferay includes, I haven't found the way to get rid of it.

Finally, I had to specify this jvm option on setenv.sh:

-Djavax.xml.ws.spi.Provider=com.sun.xml.ws.spi.ProviderImpl

If not specified, I ended up with the following exception:

Provider com.sun.xml.internal.ws.spi.ProviderImpl not found