Make SOAP client OOTB in Liferay 7.3 and Java 11Make SOAP client OOTB in Liferay 7.3 and Java 11https://liferay.dev/c/message_boards/find_thread?p_l_id=119785333&threadId=1208211232024-03-29T14:12:51Z2024-03-29T14:12:51ZRE: Make SOAP client OOTB in Liferay 7.3 and Java 11Mario Gonzálezhttps://liferay.dev/c/message_boards/find_message?p_l_id=119785333&messageId=1211625082021-10-20T12:20:39Z2021-09-22T15:49:14Z<p>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.</p>
<p>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</p>
<p>After that, only these 2 dependencies required in pom.xml:</p>
<p><dependency><br />
<groupId>javax.xml.ws</groupId><br />
<artifactId>jaxws-api</artifactId><br />
<version>2.3.0</version><br /> </dependency><br />
<dependency><br />
<groupId>javax.jws</groupId><br />
<artifactId>javax.jws-api</artifactId><br />
<version>1.1</version><br /> </dependency></p>
<p>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.</p>
<p>Finally, I had to specify this jvm option on setenv.sh:</p>
<p>-Djavax.xml.ws.spi.Provider=com.sun.xml.ws.spi.ProviderImpl</p>
<p>If not specified, I ended up with the following exception:</p>
<pre>
<code>Provider com.sun.xml.internal.ws.spi.ProviderImpl not found</code></pre>Mario González2021-09-22T15:49:14ZRE: RE: Make SOAP client OOTB in Liferay 7.3 and Java 11Eric Dhttps://liferay.dev/c/message_boards/find_message?p_l_id=119785333&messageId=1209336932021-07-09T20:49:58Z2021-07-09T20:49:57Z<p>Thank you Fabian foe your help,</p>
<p>Now it works for us.</p>
<p>We have to create a fragment to export the package CXF JAWS SPI with
7.3 version.</p>
<p>After that we use the CXF plugin in 3.3.0 version.</p>
<p>But for the maven dependency we use the 3.2.5 version.</p>
<p>Here the maven dependencies we have use :</p>
<p><dependency></p>
<p> <groupId>javax.xml.bind</groupId></p>
<p> <artifactId>jaxb-api</artifactId></p>
<p> <version>2.3.1</version></p>
<p> <scope>provided</scope></p>
<p></dependency></p>
<p><dependency></p>
<p> <groupId>javax.xml.ws</groupId></p>
<p> <artifactId>jaxws-api</artifactId></p>
<p> <version>2.3.1</version></p>
<p> <scope>provided</scope></p>
<p></dependency></p>
<p><dependency></p>
<p> <groupId>javax.jws</groupId></p>
<p> <artifactId>javax.jws-api</artifactId></p>
<p> <version>1.1</version></p>
<p> <scope>provided</scope></p>
<p></dependency></p>
<p> <dependency></p>
<p> <groupId>org.apache.cxf</groupId></p>
<p> <artifactId>cxf-rt-frontend-jaxws</artifactId></p>
<p> <version>${cxf.version}</version></p>
<p> <scope>provided</scope></p>
<p></dependency></p>
<p>The important is to use the same dependencies of Liferay to have no conflict.</p>
<p> </p>
<p>Thank you SO much for your help Fabian,</p>
<p>Eric.</p>Eric D2021-07-09T20:49:57ZRE: RE: Make SOAP client OOTB in Liferay 7.3 and Java 11Eric Dhttps://liferay.dev/c/message_boards/find_message?p_l_id=119785333&messageId=1209265852021-07-07T21:19:27Z2021-07-07T21:19:26Z<p>Here are the errors we have in the logs :</p>
<pre>
<code class="language-java">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/...
</code></pre>
<p> </p>Eric D2021-07-07T21:19:26ZRE: RE: Make SOAP client OOTB in Liferay 7.3 and Java 11Eric Dhttps://liferay.dev/c/message_boards/find_message?p_l_id=119785333&messageId=1209264502021-07-07T21:12:22Z2021-07-07T21:12:21Z<p>Hi Fabian,</p>
<p>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 : </p>
<pre>
<code class="language-java">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</code></pre>
<p>And in our module we import the same dependency (3.2.14) :</p>
<pre>
<code class="language-java"> <dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>3.2.14</version>
<scope>provided</scope>
</dependency></code></pre>
<p>It seems to be better but after (the compilation is OK) but we need
to exclude many packages:</p>
<pre>
<code class="language-java">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,\
*</code></pre>
<p>And we still have an error with operation not found in wsdl...</p>
<p>After many hours and many days of work, we don't find a issue to this
problem.<br /> The same module works in java 8. Will it be possible to
share an exemple of a SOAP client in Maven with java 11 ?</p>
<p>Eric.</p>Eric D2021-07-07T21:12:21ZRE: RE: Make SOAP client OOTB in Liferay 7.3 and Java 11Fabian Bouchéhttps://liferay.dev/c/message_boards/find_message?p_l_id=119785333&messageId=1209245332021-07-07T14:10:13Z2021-07-07T13:35:05Z<p>Hi Eric,</p>
<p>Indeed, you need to create a fragment to have an existing bundle
export it.</p>
<p>In my DXP 7.2 setup, I got this:</p>
<pre>
<code>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</code></pre>
<p>You'll have to use the gogo shell to check the actual version of the
package you are exporting.</p>
<p>My strategy relies on having my soap client use the same cxf version
as liferay.</p>
<p>Sorry, I'd have to create a proper sample project for this. It's not
inside of a repo I can share.</p>
<p>Kind regards,</p>
<p>Fabian</p>Fabian Bouché2021-07-07T13:35:05ZRE: Make SOAP client OOTB in Liferay 7.3 and Java 11Eric Dhttps://liferay.dev/c/message_boards/find_message?p_l_id=119785333&messageId=1209239092021-07-07T11:05:13Z2021-07-07T11:05:12Z<p>Thank you Fabian,</p>
<p>I have try what you have explain but I have this error :</p>
<pre>
<code class="language-java"> 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)</code></pre>
<p>Is it possible to share your project ? (and specialy your pom.xml et bnd.bnd)</p>
<p>Here is the dependency we have added :</p>
<pre>
<code class="language-java"> <dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>3.4.0</version>
</dependency></code></pre>
<p>If we use another version under than 3.4.0 (we try 3.2.14), we have
pb with the cxf-pluggin :</p>
<pre>
<code class="language-java">Failed to execute goal org.apache.cxf:cxf-codegen-plugin:3.2.14:wsdl2java</code></pre>
<p>Or do you know wich liferay module export the package
"org.apache.cxf.jaxws.spi.ProviderImpl" ?</p>
<p>Eric.</p>Eric D2021-07-07T11:05:12ZRE: Make SOAP client OOTB in Liferay 7.3 and Java 11Fabian Bouchéhttps://liferay.dev/c/message_boards/find_message?p_l_id=119785333&messageId=1209156772021-07-09T20:17:30Z2021-07-05T16:00:44Z<p>Hi Eric,</p>
<p>I got it working this way: https://gist.github.com/fabian-bouche-liferay/bf7fdfb7c3d02052f642314b1ae7549b</p>
<p>You'll need this explicit import in the bnd.bnd file as well:</p>
<pre>
<code>Import-Package:\
org.apache.cxf.jaxws.spi,\
*</code></pre>
<p>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.</p>
<p>Kind regards,</p>
<p>Fabian</p>Fabian Bouché2021-07-05T16:00:44ZMake SOAP client OOTB in Liferay 7.3 and Java 11Eric Dhttps://liferay.dev/c/message_boards/find_message?p_l_id=119785333&messageId=1208211222021-10-04T17:07:03Z2021-06-06T20:28:41Z<p>Hello,</p>
<p>I am doing a migration from Liferay 6.2 to Liferay 7.3 DXP in Java 11.</p>
<p>In Java 11, the librairies to make a SOAP client have been removed.</p>
<p>If we add them, we have differents problems.</p>
<p>Is there a simple way to make a SOAP client OOTB ?</p>
<p>We saw a lot of answers in this forum but this is a common
fonctionnality, why it is SO complicated to implement it ?</p>
<p>I give you more explainations.</p>
<p>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.</p>
<p>But the same jar failed in Java 11. We change the target destination
and add the new libs but it fails.</p>
<p> <maven.compiler.source>11</maven.compiler.source><br />
<maven.compiler.target>11</maven.compiler.target></p>
<p> ...</p>
<p> <dependency><br />
<groupId>com.sun.xml.ws</groupId><br />
<artifactId>jaxws-ri</artifactId><br />
<version>2.3.4</version><br />
<type>pom</type><br /> </dependency></p>
<p>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.</p>
<p>Here are the differents problems we have :</p>
<p> com.sun.xml.internal.ws.spi.ProviderImpl cannot be found</p>
<p>To solve this we have found this answer : https://issues.liferay.com/browse/LPS-98339</p>
<p>And It doesn't work because we need to make a client SOAP and not a
server. But after I find another way with :</p>
<p>thread.setContextClassLoader(myClass.class.getClassLoader())</p>
<p>But after we have a pb with :</p>
<p>Unresolved requirement: Import-Package: javax.jws</p>
<p>We try to use the Liferay dependances but it fails :</p>
<p> <dependency><br />
<groupId>com.liferay</groupId><br />
<artifactId>javax.jws</artifactId><br />
<scope>provided</scope><br /> </dependency></p>
<p>We try after the official dependances :</p>
<p> <dependency><br />
<groupId>javax.jws</groupId><br />
<artifactId>javax.jws-api</artifactId><br />
<version>1.1</version><br /> </dependency></p>
<p>And now it works but we have to include the resource in the bnd.bnd :</p>
<p> -includeresource:\<br /> META-INF/lib/javax.jws-api.jar=javax.jws-api-[0-9].[0-9]*.jar;lib:=true</p>
<p>After that, the current problem is :</p>
<p> "A WebService annotation is not present on class"</p>
<p>But this class is generated by CXF ! And we see the correct
annotation on this clas !!!</p>
<p>So we try another approch with the JAX-WS pluggin :</p>
<p> <plugin><br />
<groupId>org.codehaus.mojo</groupId><br />
<artifactId>jaxws-maven-plugin</artifactId><br />
<version>2.6</version><br />
<executions><br /> <execution><br />
<id>wsimport-from-jdk</id><br />
<goals><br />
<goal>wsimport</goal><br />
</goals><br /> </execution><br />
</executions></p>
<p> ...</p>
<p>Before we were using the CXF plugin :</p>
<p> <groupId>org.apache.cxf</groupId><br />
<artifactId>cxf-codegen-plugin</artifactId><br />
<version>${cxf.version}</version><br />
<executions><br />
<execution><br /> <id>generate-sources</id></p>
<p> ...</p>
<p>But no sucess... Did anyone have an exemple of a client SOAP in Java
11 with Maven ?</p>