Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

Expose Reg ex Rest WEB Services in AEM

Avatar

Level 2

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

wcm.io Caravan

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.

1 Accepted Solution

Avatar

Correct answer by
Level 4

What I am seeing that your problem is a dependency issue, it means some libraries(directly and indirectly) are not properly configured to build, deploy and consume the bundle. I had similar issues with some libraries related with Jersey when I have to create a client for Livefyre comments(when AEM component didn't work properly - prior Adobe acquisition-). 

I had similar issues with some libraries related with Jersey when I was creating a client(bundle) for Livefyre comments(when AEM Livefyre component didn't work properly - prior Adobe acquisition-). 

View solution in original post

2 Replies

Avatar

Level 10

AEM does not ootb expose a web service. Like you said, you can use a Sling Servlet. But it does not expose a WSDL. I have never tried to use a 3rd party API to attempt to expose a ws.

Avatar

Correct answer by
Level 4

What I am seeing that your problem is a dependency issue, it means some libraries(directly and indirectly) are not properly configured to build, deploy and consume the bundle. I had similar issues with some libraries related with Jersey when I have to create a client for Livefyre comments(when AEM component didn't work properly - prior Adobe acquisition-). 

I had similar issues with some libraries related with Jersey when I was creating a client(bundle) for Livefyre comments(when AEM Livefyre component didn't work properly - prior Adobe acquisition-).