0

I am trying to run the emp connector sample provided by Salesforce. When i tried running the sample, i was getting socket timeout. After investigating, i realized that our company is behind firewall and any traffic going outside needs to be routed via proxy.

I looked at the SFDC documentation and there was no information on how to add the proxy to the java client. After skimming through some jetty documentation, i was able to find it. I am able to connect to my SFDC org via Emp client but when it tries to connect to https://*.salesforce.com/cometd/43.0, i get a connection timeout.

When i run the same code without proxy (at my home desktop), everything looks great. So it looks like either the code is not yet supporting the proxy or i am setting the proxy wrong. Can someone help ?

LoginHelper.java

    public static BayeuxParameters login(URL loginEndpoint, String username, String password,
        BayeuxParameters parameters) throws Exception {
    HttpClient client = new HttpClient(parameters.sslContextFactory());
    URI proxyURI = new URI("https://PROXY_HOST:PROXY_PORT");
    try {
        AuthenticationStore auth = client.getAuthenticationStore();
        client.getProxyConfiguration().getProxies().add(new HttpProxy("PROXY_HOST", PROXY_PORT));
        auth.addAuthentication(new BasicAuthentication(proxyURI, "ProxyRealm", "PROXY_USER", "PROXY_PASSWORD"));
        //client.getProxyConfiguration().getProxies().addAll(parameters.proxies());
        client.start();
        URL endpoint = new URL(loginEndpoint, getSoapUri());
  • Possibly related: github.com/cometd/cometd/issues/833 – identigral Jan 8 at 23:19
  • i figured out the problem. I forgot to add the proxy in one more class. That did solve my issue and everything is working great – Darkdog Jan 10 at 0:58
  • Cool. Please write and accept your own answer (preferably with a code sample) to help other folks who might be reading this. – identigral Jan 10 at 1:53
0

What i did is added the proxy configuration in 2 JAVA files : 1) EmpConnector.java

  public EmpConnector(BayeuxParameters parameters) {
    this.parameters = parameters;
    httpClient = new HttpClient(parameters.sslContextFactory());
    ProxyConfiguration proxyConfig = httpClient.getProxyConfiguration();
    List<ProxyConfiguration.Proxy> proxies = proxyConfig.getProxies();
    HttpProxy pro = new HttpProxy("YOUR_PROXY_HOST", PROXY_PORT);
    proxies.add(pro);
    //httpClient.getProxyConfiguration().getProxies().addAll(parameters.proxies());
}

LoginHelper.java (login function)

client.start();
        ProxyConfiguration proxyConfig = client.getProxyConfiguration();
        List<ProxyConfiguration.Proxy> proxies = proxyConfig.getProxies();
        HttpProxy pro = new HttpProxy("YOUR_PROXT_HOST", PROXY_PORT);
        proxies.add(pro);
        URL endpoint = new URL(loginEndpoint, getSoapUri());
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.