How Do I enable Proxy for JCR connection | Community
Skip to main content
Level 2
October 16, 2015
Solved

How Do I enable Proxy for JCR connection

  • October 16, 2015
  • 4 replies
  • 2421 views

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?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Kunal_Gaba_

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>

4 replies

Kunal_Gaba_
Kunal_Gaba_Accepted solution
October 16, 2015

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>

joerghoh
Adobe Employee
Adobe Employee
October 16, 2015

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

Level 2
October 16, 2015

I had tried this before, it does not work

Level 2
October 16, 2015

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/jackrabbit/spi2dav/RepositoryServiceImpl.java

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);