Hi Everyone,
I have to use twilio message api [https://www.twilio.com/en-us], For that I have added dependancy in core pom file like below to use their apis.
core pom.xml:
<!-- communication web API https://mvnrepository.com/artifact/com.twilio.sdk/twilio -->
<dependency>
<groupId>com.twilio.sdk</groupId>
<artifactId>twilio</artifactId>
<version>10.1.5</version>
</dependency>
Post this, I got below build error:
if I build core module- build is success but getting cannot be resolved issue.
if I build whole project I got below build error:
[ERROR] The analyser found the following errors for author and publish :
[ERROR] [api-regions-exportsimports] com.sampleproject:sampleProject.core:1.0.0-SNAPSHOT: Bundle sampleProject.core:1.0.0-SNAPSHOT is importing pack
age(s) [com.twilio.type, com.twilio, com.twilio.rest.api.v2010.account, com.twilio.base] in start level 20 but no bundle is exporting these for that start level. (com.sampleproject:sampleProject.all:1.0.0-SNAPSHOT)
Due to above error I have embeded this in all pom.xml and I got another build error like below:
all pom.xml
<embedded>
<groupId>com.twilio.sdk</groupId>
<artifactId>twilio</artifactId>
<type>jar</type>
<target>/apps/sampleProject-packages/application/install</target>
</embedded>
Post this, I got below build error:
[ERROR] Failed to execute goal com.adobe.aem:aemanalyser-maven-plugin:1.4.10:project-analyse (aem-analyser) on project sampleProject.all: A fatal er
ror occurred while analysing the features, see error cause:: Unable to get bundle symbolic name from artifact com.twilio.sdk:twilio:10.1.5 -> [Help 1]
FYI - It looke like not a bundle, it's jar file. So I need your help to solve this dependancy issue, Thanks in advance.
Solved! Go to Solution.
Views
Replies
Total Likes
I was just checking the build success message and confirmed that it's working.
I work on your example and faced the same issue. Below is the recommendation
Step 1: convert the Jar to OSGi bundle refer to below link
https://experienceleague.adobe.com/en/docs/experience-cloud-kcs/kbarticles/ka-17475
Step 2: load the bundle from your project location or from your separate artifact repo
Step 3:
embed the package as shown in below plugin example
<embedded>
<groupId>com.twilio.sdk</groupId>
<artifactId>twilio</artifactId>
<type>jar</type>
<target>/apps/<your-project>/application/install</target>
</embedded>
<dependency>
<groupId>com.twilio.sdk</groupId>
<artifactId>twilio</artifactId>
<type>jar</type>
<scope>system</scope>
<systemPath>${project.basedir}/../<your-project>.ui.apps/src/main/resources/twilio-10.1.5.jar</systemPath>
</dependency>
The Twilio SDK is not an OSGi bundle out of the box, so you cannot directly include it as a dependency in your AEM project.
I have added like this in core pom.xml is this correct?
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Embed-Dependency>twilio;scope=compile|runtime;inline=true</Embed-Dependency>
<Bundle-SymbolicName>com.twilio.sdk.twilio</Bundle-SymbolicName>
<Bundle-Name>twilio</Bundle-Name>
<Bundle-Version>10.1.5</Bundle-Version>
<Private-Package>com.twilio.*</Private-Package>
</instructions>
</configuration>
</plugin>
yes @jeromeleslyv can you try and let me know the outcome
After raw build without servlet code, it got success but didn't deployed to aem, But If i run with one simple servlet which dependent on this getting compilation error
[ERROR] /D:/My Project/sampleProject/core/src/main/java/com/sampleproject/core/servlets/MessageServlet.java:[14,18] package com.twilio does not exist
[ERROR] /D:/My Project/sampleProject/core/src/main/java/com/sampleproject/core/servlets/MessageServlet.java:[15,41] package com.twilio.rest.api.v2010.account does not exist
[ERROR] /D:/My Project/sampleProject/core/src/main/java/com/sampleproject/core/servlets/MessageServlet.java:[16,23] package com.twilio.type does not exist
@jeromeleslyv try adding below dependency
@Jagadeesh_Prakash , I have added whatever you have mentioned in previous chat. Still I'm getting below error, can you try with below servlet?
ERROR:
[ERROR] The analyser found the following errors for author and publish :
[ERROR] [api-regions-exportsimports] com.sampleproject:sampleProject.core:1.0.0-SNAPSHOT: Bundle sampleProject.core:1.0.0-SNAPSHOT is importing pack
age(s) [com.twilio.type, com.twilio, com.twilio.rest.api.v2010.account, com.twilio.base] in start level 20 but no bundle is exporting these for that start level. (com.sampleproject:sampleProject.all:1.0.0-SNAPSHOT)
Servlet:
servlet call won't work in your post call but maven build should be success
package com.sampleproject.core.servlets;
import lombok.extern.slf4j.Slf4j;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.servlets.SlingAllMethodsServlet;
import org.osgi.service.component.annotations.Component;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
import java.io.IOException;
import com.twilio.Twilio;
import com.twilio.rest.api.v2010.account.Message;
import com.twilio.type.PhoneNumber;
import static org.apache.sling.api.servlets.ServletResolverConstants.SLING_SERVLET_PATHS;
@Component(service = { Servlet.class },
property = {
SLING_SERVLET_PATHS + "=/bin/sendmessage"
})
@Slf4j
public class MessageServlet extends SlingAllMethodsServlet {
public static final String ACCOUNT_SID = "abcd";
public static final String AUTH_TOKEN = "efgh";
@Override
protected void doPost( SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
Twilio.init("abcd", "efgh");
Message message = Message.creator(
new com.twilio.type.PhoneNumber("+919700606004"), //To number
new com.twilio.type.PhoneNumber("+13347006328"), //from number
"Hi, Admin sending a test message?")
.create();
log.debug(message.getSid());
response.getWriter().write("responsemessage:" +message.getSid());
}
}
I was just checking the build success message and confirmed that it's working.
I work on your example and faced the same issue. Below is the recommendation
Step 1: convert the Jar to OSGi bundle refer to below link
https://experienceleague.adobe.com/en/docs/experience-cloud-kcs/kbarticles/ka-17475
Step 2: load the bundle from your project location or from your separate artifact repo
Step 3:
embed the package as shown in below plugin example
<embedded>
<groupId>com.twilio.sdk</groupId>
<artifactId>twilio</artifactId>
<type>jar</type>
<target>/apps/<your-project>/application/install</target>
</embedded>
<dependency>
<groupId>com.twilio.sdk</groupId>
<artifactId>twilio</artifactId>
<type>jar</type>
<scope>system</scope>
<systemPath>${project.basedir}/../<your-project>.ui.apps/src/main/resources/twilio-10.1.5.jar</systemPath>
</dependency>
@jeromeleslyv Let me know the outcome if it is solved
Hi,
Please take a look at these threads:
https://myaemlearnings.blogspot.com/2021/08/embedding-third-party-dependencyosgi.html
Hope this helps.
@jeromeleslyv Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.
Views
Replies
Total Likes
Views
Likes
Replies