Expand my Community achievements bar.

SOLVED

Access AEM instance from another AEM instance

Avatar

Level 1

Hi Team, we have a requirement to get session of an AEM instance in another(different) AEM instance. I know that using jackrabbit-standalone(JcrUtil.getRepository we can get in standalone application). Same logic is not working when we try to access on aem server

AEM version is : 6.5

java version : java 8

Please suggest if there is any way to achieve this

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi,

 

I don’t think there is a way to connect remotely to another AEM instance via JCR. The traditional approach to address what you are trying to do is to have a "service" running on your AEM Target instance that performs the actions your AEM Source instance needs. This "service" could then be invoked from the AEM Source instance. I hope this makes sense.

For reference, check this link: Connecting an Instance of AEM to Another Remote Instance of AEM.

 

Hope this help



Esteban Bustamante

View solution in original post

3 Replies

Avatar

Correct answer by
Community Advisor

Hi,

 

I don’t think there is a way to connect remotely to another AEM instance via JCR. The traditional approach to address what you are trying to do is to have a "service" running on your AEM Target instance that performs the actions your AEM Source instance needs. This "service" could then be invoked from the AEM Source instance. I hope this makes sense.

For reference, check this link: Connecting an Instance of AEM to Another Remote Instance of AEM.

 

Hope this help



Esteban Bustamante

Avatar

Level 1

Hi EstebanBustamante,

 

Thank you for the reply!

Can we access JCR repo from spring boot application ?

I have tried adding the dependancy in local mvn repo & using it in pom.xml directly for testing purpose. However, logic works fine when I run the Java main Class from Eclipse

& not on spring boot application running on port 8080 with same logic

AEM is running on port 4502

Adding pom.xml is below for reference:

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

 

<groupId>com.example</groupId>

<artifactId>bootdemo</artifactId>

<version>0.0.1-SNAPSHOT</version>

<packaging>jar</packaging>

 

<name>bootDemo</name>

<description>Demo project for Spring Boot</description>

 

<parent>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-parent</artifactId>

<version>1.5.3.RELEASE</version>

<relativePath /> <!-- lookup parent from repository -->

</parent>

 

<properties>

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<java.version>1.8</java.version>

</properties>

 

<dependencies>

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-data-jpa</artifactId>

</dependency>

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-devtools</artifactId>

</dependency>

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-data-rest</artifactId>

</dependency>

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-web</artifactId>

</dependency>

 

<dependency>

<groupId>com.h2database</groupId>

<artifactId>h2</artifactId>

<scope>runtime</scope>

</dependency>

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-test</artifactId>

<scope>test</scope>

</dependency>

<dependency>

<groupId>org.springframework.restdocs</groupId>

<artifactId>spring-restdocs-mockmvc</artifactId>

<scope>test</scope>

</dependency>

<dependency>

<groupId>javax.xml.bind</groupId>

<artifactId>jaxb-api</artifactId>

<version>2.3.1</version>

</dependency>

<dependency>

<groupId>org.glassfish.jaxb</groupId>

<artifactId>jaxb-runtime</artifactId>

<version>2.3.1</version>

</dependency>

<dependency>

<groupId>org.apache.httpcomponents</groupId>

<artifactId>httpclient</artifactId>

<version>4.5.13</version>

</dependency>

<dependency>

<groupId>org.apache.httpcomponents</groupId>

<artifactId>httpcore</artifactId>

<version>4.4.14</version>

</dependency>

<dependency>

<groupId>com.opencsv</groupId>

<artifactId>opencsv</artifactId>

<version>5.5.2</version>

</dependency>

<!-- https://mvnrepository.com/artifact/org.json/json -->

<dependency>

<groupId>org.json</groupId>

<artifactId>json</artifactId>

<version>20230227</version>

</dependency>

<!-- Apache Sling -->

<dependency>

<groupId>org.apache.sling</groupId>

<artifactId>org.apache.sling.api</artifactId>

<version>2.23.4</version>

</dependency>

<dependency>

<groupId>javax.jcr</groupId>

<artifactId>jcr</artifactId>

<version>2.0</version>

</dependency>

<dependency>

<groupId>org.apache.jackrabbit.vault</groupId>

<artifactId>org.apache.jackrabbit.vault</artifactId>

<version>3.2.8</version>

</dependency>

<dependency>

<groupId>org.apache.jackrabbit</groupId>

<artifactId>jackrabbit-api</artifactId>

<version>2.19.3</version>

</dependency>

<dependency>

<groupId>com.amazonaws</groupId>

<artifactId>aws-java-sdk-s3</artifactId>

<version>1.11.796</version>

</dependency>

<dependency>

<artifactId>aws-java-sdk-core</artifactId>

<groupId>com.amazonaws</groupId>

<version>1.11.796</version>

</dependency>

<dependency>

<groupId>com.akamai.edgegrid</groupId>

<artifactId>edgegrid-signer-core</artifactId>

<version>4.0.1</version>

</dependency>

<dependency>

<groupId>com.akamai.edgegrid</groupId>

<artifactId>edgegrid-signer-apache-http-client</artifactId>

<version>4.0.1</version>

</dependency>

<dependency>

<groupId>com.google.code.gson</groupId>

<artifactId>gson</artifactId>

<version>2.8.5</version>

</dependency>

<dependency>

<groupId>org.apache.jackrabbit</groupId>

<artifactId>jackrabbit-jcr-commons</artifactId>

<version>2.21.16</version>

</dependency>

<dependency>

<groupId>org.apache.poi</groupId>

<artifactId>poi</artifactId>

<version>3.9</version>

</dependency>

<dependency>

<groupId>log4j</groupId>

<artifactId>log4j</artifactId>

<version>1.2.17</version>

</dependency>

<dependency>

<groupId>org.jsoup</groupId>

<artifactId>jsoup</artifactId>

<version>1.17.2</version>

</dependency>

<!-- https://mvnrepository.com/artifact/org.apache.jackrabbit/jackrabbit-standalone -->

<dependency>

<groupId>org.apache.jackrabbit</groupId>

<artifactId>jackrabbit-standalone</artifactId>

<version>2.4.0</version>

<scope>system</scope>

<systemPath>C:/Softwares/bundles/jackrabbit-standalone-2.4.0.jar</systemPath>

</dependency>

</dependencies>

<build>

<plugins>

<plugin>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-maven-plugin</artifactId>

<configuration> <!-- added -->

<layout>ZIP</layout> <!-- to use PropertiesLaunchar -->

</configuration>

</plugin>

</plugins>

</build>

 

 

</project>

 

Code:

 

package com.example.demo.controller;
 
import java.util.List;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.jcr.Repository;
import javax.jcr.SimpleCredentials;
import javax.jcr.Node;
import org.apache.jackrabbit.commons.JcrUtils;
 
 
@RequestMapping("/RepoAccess")
@RestController
public class ErrorController {
 
@RequestMapping("/test")
public String getUserById() {
 
try {
//disableCertificateValidation();
    //Create a connection to the CQ repository running on local host
    Repository repository = JcrUtils.getRepository("http://localhost:4502/crx/server");
 
   //Create a Session
   javax.jcr.Session session = repository.login( new SimpleCredentials("admin", "admin".toCharArray()));
 
  //Create a node that represents the root node
  Node root = session.getRootNode();
 
  // Store content
  Node adobe = root.addNode("adobe");
  Node day = adobe.addNode("day");
  day.setProperty("message", "Adobe CQ is part of the Adobe Digital Marketing Suite!");
 
  // Retrieve content
  Node node = root.getNode("adobe/day");
  System.out.println(node.getPath());
  System.out.println(node.getProperty("message").getString());
 
  //Save the session changes and log out
  session.save();
  session.logout();
  }
catch(Exception e){
  e.printStackTrace();
  return e.getMessage();
  }
return "Landed on error page successfully!";
}
 
 
}

 

 Exception:

javax.jcr.RepositoryException: Unable to access a repository with the following settings:
org.apache.jackrabbit.repository.uri: http://10.232.192.52:4502/crx/server
The following RepositoryFactory classes were consulted:
org.apache.jackrabbit.commons.JndiRepositoryFactory: declined
Perhaps the repository you are trying to access is not available at the moment.
at org.apache.jackrabbit.commons.JcrUtils.getRepository(JcrUtils.java:224)
at org.apache.jackrabbit.commons.JcrUtils.getRepository(JcrUtils.java:264)

Avatar

Administrator

@Sushma3 Did you find the suggestion helpful? Please let us know if you require more information. Otherwise, please mark the answer as correct for posterity. If you've discovered a solution yourself, we would appreciate it if you could share it with the community. Thank you!



Kautuk Sahni