Expose Reg ex Rest WEB Services in AEM
Hi Guys,
I need to expose rest web services in AEM 6.3 and these rest services will be used by third party applications We can use sling servlets to expose as a rest service. But it is not suitable for my requirement. I need to expose as a reg ex servlet / Web service. It should accept many urls based on that path.
As per many developer blogs and my understanding as well, we can achieve this in two ways.
1. USING JAX-RS AND JERSEY
2. io.wcm.caravan
https://github.com/hstaudacher/osgi-jax-rs-connector
I tried Both the ways but, it is not working for me . Bundle is in active state and service is also in active state.
Balliut when I call the service it is showing 404 error .
My service is like
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Service;
import io.wcm.caravan.jaxrs.publisher.JaxRsComponent;
import javax.ws.rs.Produces;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.GET;
import javax.ws.rs.core.MediaType;
@Component(immediate = true)
@Service(JaxRsComponent.class)
@Path("/{tenantId}/index")
public class HalEntryPoint implements JaxRsComponent {
@GET
@Produces({MediaType.APPLICATION_JSON})
public String index(@PathParam("tenantId") String tenantId) {
// your code...
return "hi";
}
}
Maven pom file entry is
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>bundle name </Bundle-SymbolicName>
<Export-Package>
com.xxxx.abc.*
</Export-Package>
<Include-Resource>
{maven-resources}
</Include-Resource>
<Bundle-Activator>com.xxx.xxx.Some class name </Bundle-Activator>
<Caravan-JaxRs-ApplicationPath>/service/portals</Caravan-JaxRs-ApplicationPath>
<Import-Package>
javax.inject;version=0.0.0,
*
</Import-Package>
<!--
<Embed-Dependency>
artifactId1,
artifactId2;inline=true
</Embed-Dependency>
-->
<Sling-Model-Packages>
com.xxx.abc.an.core
</Sling-Model-Packages>
</instructions>
</configuration>
</plugin>
I can see the below errors in log file .
org.glassfish.hk2.api.MultiException: A MultiException has 2 exceptions. They are:
1. java.lang.NoClassDefFoundError: Could not initialize class org.glassfish.jersey.message.internal.MediaTypes
2. java.lang.IllegalStateException: Unable to perform operation: create on org.glassfish.jersey.message.internal.MessageBodyFactory
Any suggestions or examples please.
Thanks & Regards,
Prasad.