How to use third party api in AEM | Community
Skip to main content
Level 2
October 20, 2022

How to use third party api in AEM

  • October 20, 2022
  • 1 reply
  • 4030 views

Hi everyone,

 

I'm new to aem and is still learning based on the training project adobe provided.

I try to create a new servlet so i can upload file to AWS s3 bucket, but it returns build error and i don't know how to solve it so really prefer some help.

 

build error message:

 

Here is what i added into the pom file.

pom.xml

<dependency>
    <groupId>com.amazonaws</groupId>
    <artifactId>aws-java-sdk-osgi</artifactId>
    <version>1.12.322</version>
</dependency>
 
core/pom.xml
<dependency>
    <groupId>com.amazonaws</groupId>
    <artifactId>aws-java-sdk-osgi</artifactId>
</dependency>
 
I also download the newest aws-java-sdk-osgi jar file and installed it through web console.But the status is installed and when i try to start the bundle it returns the error below.

 

error log:

[FelixLogListener]
LogService.org.apache.felix.http.jetty Bundles: Cannot start (org.apache.felix.log.LogException: org.osgi.framework.BundleException: Unable to resolve com.amazonaws.aws-java-sdk-osgi [586](R 586.0): missing requirement [com.amazonaws.aws-java-sdk-osgi [586](R 586.0)] osgi.wiring.package; (&(osgi.wiring.package=com.fasterxml.jackson.dataformat.cbor)(version>=2.12.0)(!(version>=3.0.0))) Unresolved requirements: [[com.amazonaws.aws-java-sdk-osgi [586](R 586.0)] osgi.wiring.package; (&(osgi.wiring.package=com.fasterxml.jackson.dataformat.cbor)(version>=2.12.0)(!(version>=3.0.0)))])
org.apache.felix.log.LogException: org.osgi.framework.BundleException: Unable to resolve com.amazonaws.aws-java-sdk-osgi [586](R 586.0): missing requirement [com.amazonaws.aws-java-sdk-osgi [586](R 586.0)] osgi.wiring.package; (&(osgi.wiring.package=com.fasterxml.jackson.dataformat.cbor)(version>=2.12.0)(!(version>=3.0.0))) Unresolved requirements: [[com.amazonaws.aws-java-sdk-osgi [586](R 586.0)] osgi.wiring.package; (&(osgi.wiring.package=com.fasterxml.jackson.dataformat.cbor)(version>=2.12.0)(!(version>=3.0.0)))]

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

1 reply

Level 4
October 20, 2022

Hi @zonghuiliu ,

 

This is caused if the package imported is not exported by any bundle. The Import-Package declarations must be satisfied by the Export-package declaration of other included bundles in the Maven project.

 

To solve this add the package in the Export tag 

If your archetype is using maven-bundle-plugin then use the below in your pom.xml 

 

<Export-Package>

com.amazonaws.aws-java-sdk-osgi.*

</Export-Package>

 

If your archetype is using bnd-maven-plugin then use the below in your pom.xml

 

Export-Package: com.amazonaws.aws-java-sdk-osgi.*

 

 

Reference:

https://myaemlearnings.blogspot.com/2021/08/embedding-third-party-dependencyosgi.html

 

 

Level 2
October 20, 2022

Thank you for your reply.

 

I'm using bnd-maven-plugin but i still have no idea where to add the export package.

Below is how i made the change.

I'm sorry for this newbie question but could you please tell me the right place to add the export package description.

 

pom.xml

<!-- BND Maven Plugin -->
                       
        <plugin>
                             
          <groupId>biz.aQute.bnd</groupId>                  
          <artifactId>bnd-maven-plugin</artifactId>                  
          <version>${bnd.version}</version>              
          <executions>                    
            <execution>                      
              <id>bnd-process</id>                  
              <goals>                        
                <goal>bnd-process</goal>                    
              </goals>                    
              <configuration>                          
                <bnd>
                  <![CDATA[
Bundle-Category: ${componentGroupName}
Export-Package: com.amazonaws.aws-java-sdk-osgi.*

# export all versioned packages except for conditional ones (https://github.com/bndtools/bnd/issues/3721#issuecomment-579026778)
-exportcontents: ${removeall;${packages;VERSIONED};${packages;CONDITIONAL}}

-noextraheaders: true
-snapshot: SNAPSHOT

Bundle-DocURL:
-plugin org.apache.sling.caconfig.bndplugin.ConfigurationClassScannerPlugin
-plugin org.apache.sling.bnd.models.ModelsScannerPlugin
                                ]]>
                </bnd>
                                           
              </configuration>
                                     
            </execution>
                               
          </executions>
                             
          <dependencies>
                                   
            <dependency>
                                         
              <groupId>org.apache.sling</groupId>
                                         
              <artifactId>org.apache.sling.caconfig.bnd-plugin</artifactId>
                                         
              <version>1.0.2</version>
                                     
            </dependency>
                                   
            <dependency>
                                         
              <groupId>org.apache.sling</groupId>
                                         
              <artifactId>org.apache.sling.bnd.models</artifactId>
                                         
              <version>1.0.0</version>
                                     
            </dependency>
                                   
            <dependency>
                                         
              <groupId>org.apache.sling</groupId>
                                         
              <artifactId>scriptingbundle-maven-plugin</artifactId>
                                         
              <version>0.5.0</version>
                                     
            </dependency>
                               
          </dependencies>
                         
        </plugin>
 
core/pom.xml
 
<plugin>
                <groupId>biz.aQute.bnd</groupId>
                <artifactId>bnd-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>bnd-process</id>
                        <goals>
                            <goal>bnd-process</goal>
                        </goals>
                        <configuration>
                            <bnd><![CDATA[
Import-Package: javax.annotation;version=0.0.0,*
Export-Package: com.amazonaws.aws-java-sdk-osgi.*
                                ]]></bnd>
                                <instructions>
                    </instructions>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
Level 2
October 27, 2022

@zonghuiliu ,

 

From the image the servlet shows its satisfied but it should be in active state. Check the below sample servlet 

 

 

import static org.apache.sling.api.servlets.ServletResolverConstants.SLING_SERVLET_METHODS;
import static org.apache.sling.api.servlets.ServletResolverConstants.SLING_SERVLET_PATHS;

import java.io.IOException;

import javax.servlet.Servlet;
import javax.servlet.ServletException;

import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.servlets.SlingAllMethodsServlet;
import org.apache.sling.api.servlets.SlingSafeMethodsServlet;
import org.osgi.service.component.annotations.Component;

/**
* Servlet that writes some sample content into the response. 
*/

@Component(service = { Servlet.class }, property = { SLING_SERVLET_PATHS + "=/bin/upload",
SLING_SERVLET_METHODS + "= GET" })

public class SimpleServlet extends SlingSafeMethodsServlet {

private static final long serialVersionUID = 1L;

@Override
protected void doGet(final SlingHttpServletRequest req, final SlingHttpServletResponse resp)
throws ServletException, IOException {
final String resource = req.getParameter("path");
resp.setContentType("text/plain");
resp.getWriter().write("File path = " + resource);

}
}

 

 

 

 


Thank you for your reply!

 

I've tried your code but it returns the same error. Also all my servlets are in satisfied state and i have no idea how to turn them into active state.

 

Why does my new AEM servlet stay in satisfied stat... - Adobe Experience League Community - 453517

I've seen this post but I'am not using service in the servlet,also no unresolved dependency.

 

I'm wondering maybe something wrong with my pom file,so can you share your pom file,thank you in advance!