Getting org.apache.cxf.jaxws.spi.ProviderImpl not found Issue in AEM

Avatar

Avatar

touseefkhan4pk

Avatar

touseefkhan4pk

touseefkhan4pk

07-04-2021

I am working on an AEM maven project where I have to consume a web service. I am using Eclipse for writing code and for its implementation using CXF library. The code works fine in a sample project but as soon as I deploy package on CRXD in AEM and then try from it, it gives following error on the very first line while creating service object.

javax.xml.ws.spi.FactoryFinder$ConfigurationError: Provider org.apache.cxf.jaxws.spi.ProviderImpl not found

 

It is the code I am using. 

 

 ServiceXML serviceXml = new ServiceXML(wsdlURL, SERVICE_NAME);
        IServiceXML ixmlPort = serviceXml.getSAApiTPSIntegrationsXML();
        
        ((BindingProvider) ixmlPort).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "username");
        ((BindingProvider) ixmlPort).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "pssw0rd");
        
        final String username = "username";
        final String password = "pssw0rd";
        Authenticator.setDefault(new Authenticator() {
            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
                    return new PasswordAuthentication(
                            username,
                            password.toCharArray());
                    }
        });         

                
       metaData = ixmlPort.getMetadata("username", "CA");

These are the dependencies I have included in my pom

 

<dependency>
        <groupId>org.glassfish.metro</groupId>
        <artifactId>wssx-impl</artifactId>
        <version>3.0.0</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.apache.cxf/cxf-rt-frontend-jaxws -->
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-frontend-jaxws</artifactId>
        <version>3.3.2</version>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-transports-http</artifactId>
        <version>3.3.2</version>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-ws-security</artifactId>
        <version>3.3.2</version>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-ws-policy</artifactId>
        <version>3.3.2</version>
    </dependency>

I think probably it is unable to find this CXF library in AEM environment. I search a lot for its solution and only thing could found that in some scenarios people suggesting to use OSGI bundles for it. But I am wondering why would we need bundle when we have included dependencies in pom and these should be part of the package. Kindly guide.

 

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

Vijayalakshmi_S

MVP

Avatar

Vijayalakshmi_S

MVP

Vijayalakshmi_S
MVP

08-04-2021

HI @touseefkhan4pk,

In parent pom.xml,

 

<dependencyManagement>
        <dependencies>
	<!-- existing/already available dependencies of your project -->
	<!-- Newly added CXF dependencies -->	
	</dependencies>
</dependencyManagement>

 

In core pom.xml -> <dependencies> section

 

<dependencies>
	<!-- existing/already available dependencies of your project -->
	<!-- Newly added CXF dependencies without version -->
</dependencies>

 

In plugin section of your core pom.xml, it is same as you shared in your initial trial. Only issue in that was with version of maven-bundle-plugin used which was 2.0.1. So we need to update that. If you are doing it at parent level, you need not explicitly mention in submodules. If you couldn't get this let me know, Will elaborate again.

For now you try the below, I am amending on top of the one you shared initially. 

 

<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>5.1.2</version> 
<extensions>true</extensions>
<configuration>
<instructions>
<Import-Package>
org.osgi.framework,*;resolution:=optional
javax.inject;version=0.0.0,*
</Import-Package>
<Embed-Dependency>*</Embed-Dependency>
<Embed-Transitive>true</Embed-Transitive>
<Sling-Model-Packages>com.stewart.models</Sling-Model-Packages>
</instructions>
</configuration>
</plugin>

 

 

Vijayalakshmi_S

Hi @touseefkhan4pk,

Not sure why "Embed-Transitive" entry is not used in your plugin configuration (which I mentioned in my initial response to this thread.)

Significance of this is, added CXF dependencies might in turn be dependent on some of the dependencies which are referred to as Transitive dependencies or Compile time dependencies. To include the same as part of our bundle, we need to set Embed-Transitive to true. 

Please add this entry and try. 

 

Also not sure of the need for specifying the dependencies explicitly in <Embed-Dependency> entry. (adding "*" should be suffice)

 

Please find below Apache Maven bundle plugin documentation 

https://felix.apache.org/documentation/subprojects/apache-felix-maven-bundle-plugin-bnd.html

 

Update this thread if you still face any issues. 

touseefkhan4pk
Hi @Vijaylakshmi, I am providing Emebd-Transitive true and When I set Embed-Dependency as "*". It gives me this error "he default package '.' is not permitted by the Import-Package syntax. This can be caused by compile errors in Eclipse because Eclipse creates valid class files regardless of compile errors."
touseefkhan4pk
I build project with clean install -X. It gives some extra information regarding this error as " Failed to execute goal org.apache.felix:maven-bundle-plugin:5.1.2:bundle (default-bundle) on project stewart.cms: Error(s) found in bundle configuration -> [Help 1] org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.felix:maven-bundle-plugin:5.1.2:bundle (default-bundle) on project stewart.cms: Error(s) found in bundle configuration at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:215) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:156) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148)"
Vijayalakshmi_S

Hi @touseefkhan4pk,

Thanks for the input. The reason for that error(The default package '.' is not permitted by the Import-Package syntax) would be if any of the dependency's class file doesn't has a package name.

If you are able to spot that specific dependency, you can exclude the respective artifactId like below (instead of specifying the required dependencies which usually is huge list)

Vijayalakshmi_S_0-1618182318027.png

If you still face trouble with maven-bundle-plugin configuration, try the below. 

 

I just came across this KB link from Adobe Helpx which has CQ package containing OSGI bundle of CXF version 2.3.0

Details for the same - https://helpx.adobe.com/experience-manager/kb/jaxws-webservice-calls-not-working-aem-65.html

  • Revoke all the changes done as part of this (In particular, maven-bundle-plugin bring it back to last PROD version)
  • Install the CXF OSGI bundle which is available as CQ package in above link (via Package Manager of your local AEM instance)
  • Deploy your code base -> CXF related dependency that you are using in your code should be resolved with help of package that we deployed in previous step.
touseefkhan4pk

Thank you Lakshmi, I installed bundle for CXF (https://helpx.adobe.com/experience-manager/kb/jaxws-webservice-calls-not-working-aem-65.html) too but now it is giving null reference exception on line

ServiceXML serviceXml = new ServiceXML(wsdlURL, SERVICE_NAME);

Vijayalakshmi_S

Hi @touseefkhan4pk,

Is it possible for you to share the full error trace. 

Answers (5)

Answers (5)

Avatar

Avatar

touseefkhan4pk

Avatar

touseefkhan4pk

touseefkhan4pk

09-04-2021

Hi @Vijayalakshmi_S . Hi @Vijayalakshmi . After lot of hit & trial, i think my code manage to find CXF library in AEM but I am getting error "javax.xml.ws.WebServiceException: org.apache.cxf.service.factory.ServiceConstructionException".

 

This is my maven bundle plugin

          

<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>5.1.2</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Import-Package>
org.osgi.framework,
*;resolution:=optional
</Import-Package>
<Export-Package>
${export.package}.*,facebook4j.*,com.fasterxml.*,twitter4j.*,com.brightedge*,org.apache.cxf*,org.glassfish.m*
</Export-Package>
<Embed-Dependency>${embed.dependency},${maven.dependency},be-ixf-java-sdk-jar-with-dependencies,cxf-rt-frontend-jaxws,webservices-rt</Embed-Dependency>

<!--Require-Bundle>org.springframework.beans, org.springframework.core,
org.springframework.integration,org.springframework.context
</Require-Bundle-->
</instructions>
</configuration>
</plugin>

Avatar

Avatar

touseefkhan4pk

Avatar

touseefkhan4pk

touseefkhan4pk

08-04-2021

@Vijayalakshmi_S  Thanks for helping. I am really stuck here. Please help me to resolve this issue. I tried your solution but it didn't work. I don't have much knowledge about maven bundle plugin. I changed its something like this but it also didn't help. Please how should I write this maven bundle plugin with the above CXF dependencies ?

 

<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>5.1.2</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Import-Package>
org.osgi.framework,

*;resolution:=optional
</Import-Package>
<Export-Package>
${export.package}.*,facebook4j.*,com.fasterxml.*,twitter4j.*,com.brightedge.*
<!-- New CXF export -->
com.brightedge.*,org.apache.com,org.glassfish.*,javax.xml

</Export-Package>
<Embed-Dependency>
${embed.dependency},
itextpdf,xmlworker,

<!-- New CXF dependencies -->
cxf-rt-frontend-jaxws,
cxf-rt-frontend-simple,
cxf-rt-transports-http,
cxf-rt-transports-http-jetty,
cxf-rt-ws-security,
cxf-rt-features-logging,
webservices-rt,
webservices-api

</Embed-Dependency>
<Require-Bundle>org.apache.cxf.bundle</Require-Bundle>

</instructions>
</configuration>
</plugin>

Avatar

Avatar

Vijayalakshmi_S

MVP

Avatar

Vijayalakshmi_S

MVP

Vijayalakshmi_S
MVP

08-04-2021

Hi @touseefkhan4pk,

Update the maven-bundle-plugin version per the Maven version you are using. (One you are currently using is from 2009 - 2.0.1)

https://mvnrepository.com/artifact/org.apache.felix/maven-bundle-plugin

 

Avatar

Avatar

touseefkhan4pk

Avatar

touseefkhan4pk

touseefkhan4pk

07-04-2021

@Vijayalakshmi_S @Thanks for reply. This is my maven bundle plugin in my module's pom.

 

<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.0.1</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Import-Package>
org.osgi.framework,*;resolution:=optional
javax.inject;version=0.0.0,*
</Import-Package>
<Embed-Dependency>*</Embed-Dependency>
<Embed-Transitive>true</Embed-Transitive>
<Sling-Model-Packages>com.stewart.models</Sling-Model-Packages>
</instructions>
</configuration>
</plugin>

 

I added lines suggested by you but getting many error something like this;

 

java.lang.ArrayIndexOutOfBoundsException
java.lang.ArrayIndexOutOfBoundsException
java.lang.ArrayIndexOutOfBoundsException
java.lang.ArrayIndexOutOfBoundsException
java.lang.ArrayIndexOutOfBoundsException
[ERROR] Error building bundle com.myproject:myproject.integration:bundle:0.0.6 : Invalid class file: META-INF/versions/9/com/sun/tools/xjc/CatalogUtil.class
[ERROR] Error building bundle com.myproject:myproject.integration:bundle:0.0.6 : Invalid class file: META-INF/versions/9/com/sun/tools/xjc/XJC2Task.class
[ERROR] Error building bundle com.myproject:myproject.integration:bundle:0.0.6 : Invalid class file: module-info.class
[ERROR] Error building bundle com.myproject:myproject.integration:bundle:0.0.6 : Invalid class file: org/apache/cxf/wsdl11/WSDLManagerImpl.class
[ERROR] Error building bundle com.myproject:myproject.integration:bundle:0.0.6 : Invalid class file: org/apache/cxf/jaxb/io/DataWriterImpl.class
[ERROR] Error building bundle com.myproject:myproject.integration:bundle:0.0.6 : Invalid class file: META-INF/versions/9/org/glassfish/jaxb/core/StackHelper.class
[ERROR] Error building bundle com.myproject:myproject.integration:bundle:0.0.6 : Invalid class file: org/apache/cxf/transport/http/Headers.class
[ERROR] Error building bundle com.myproject:myproject.integration:bundle:0.0.6 : Invalid class file: org/apache/cxf/transport/servlet/CXFNonSpringServlet.class

Avatar

Avatar

Vijayalakshmi_S

MVP

Avatar

Vijayalakshmi_S

MVP

Vijayalakshmi_S
MVP

07-04-2021

Hi @touseefkhan4pk,

Added dependency should be resolvable as OSGI dependency/as a bundle when deployed in AEM.

Ideally this happens as part of core module build with the use of respective configurations as part of maven-bundle-plugin/bnd-maven-plugin (both the plugins are responsible for creating OSGI bundle of our java classes). 

If you are using maven-bundle-plugin, try to add the below in <configuration> -> <instructions> section

 

<Embed-Dependency>*</Embed-Dependency>
<Embed-Transitive>true</Embed-Transitive>

 

If you are using bnd-maven-plugin, -conditionalpackage entry is the respective configuration but it doesn't help completely. (It works for some dependency). In this case, we can create OSGI bundle outside project code base via standalone simple maven project using maven-bundle-plugin. Let know if you are looking for details in this case.