Expand my Community achievements bar.

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

How Do I enable Proxy for JCR connection

Avatar

Level 2

I'm using this simplest code to connect to AEM. This is working when I am not behind the proxy but it is not working with proxy. I do not see any option to give proxy while making connection. -

Jcr2davRepositoryFactory repositoryFactory = new Jcr2davRepositoryFactory();

 Map<String, Object> parameters = new HashMap();
 parameters.put("org.apache.jackrabbit.repository.uri", remoteURL);
 repository = repositoryFactory.getRepository(parameters);

Here repository is coming as null when I am behind the proxy server. Any solution?

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

You can specify the proxy server using the following code snippet. Just add these lines before you make the connection. 

System.setProperty("http.proxyHost", "<host-add>");
System.setProperty("http.proxyPort", "<port-number>");

Or you can pass them in arguments as system properties to the java program-

java -Dhttp.proxyHost=<hostname>   -Dhttp.proxyPort=<portname>  <FQN of main class>

View solution in original post

4 Replies

Avatar

Correct answer by
Employee Advisor

You can specify the proxy server using the following code snippet. Just add these lines before you make the connection. 

System.setProperty("http.proxyHost", "<host-add>");
System.setProperty("http.proxyPort", "<port-number>");

Or you can pass them in arguments as system properties to the java program-

java -Dhttp.proxyHost=<hostname>   -Dhttp.proxyPort=<portname>  <FQN of main class>

Avatar

Employee Advisor

Hi,

so you want to create JCR connection to a remote repository using Davex? I don't know if the provided API supports the usage of a proxy. It might work, but I've never tried it.  Have you already checked the available source code of jackrabbit, if this feature is supported?

kind regards,
Jörg

Avatar

Level 2

I had tried this before, it does not work

Avatar

Level 2

Hi Jorg,

The provided JCR API does not support this- 

http://svn.apache.org/repos/asf/jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrab...

In the getClient() method, if I add proxy code then I think it will work, I will have to try 

if (client == null) { client = new HttpClient(connectionManager); client.setHostConfiguration(hostConfig); // NOTE: null credentials only work if 'missing-auth-mapping' param is // set on the server org.apache.commons.httpclient.Credentials creds = null; if (sessionInfo != null) { checkSessionInfo(sessionInfo); creds = ((SessionInfoImpl) sessionInfo).getCredentials().getCredentials(); // always send authentication not waiting for 401 client.getParams().setAuthenticationPreemptive(true); } client.getState().setCredentials(AuthScope.ANY, creds);           /* client.getState().setProxyCredentials(authScope, creds); */clients.put(clientKey, client);