I wrote Java code to login to Salesforce and ran this code on a firewalled server. For this, I have to specify the proxy url and proxy port before connecting to Salesforce due to the firewall. However, I'm getting an unknownhostexception error for the proxy url. If I try to login via curl with the proxy settings, I am able to connect. How come there is a problem connecting using Java then? Any help is appreciated.

Java code :

        System.setProperty("https.protocols", "TLSv1,TLSv1.1,TLSv1.2");
        ConnectorConfig partnerConfig = new ConnectorConfig();
        partnerConfig.setAuthEndpoint(crmServer + "/services/Soap/u/38.0");
        partnerConfig.setProxy(this.proxyUrl, this.proxyPort);
        // Creating the connection automatically handles login and stores
        // the session in partnerConfig
        try {
            pConn = new PartnerConnection(partnerConfig);
        } catch (ConnectionException e) {
            if (e instanceof ApiFault) {
                return ((ApiFault) e).getExceptionMessage();

        // When PartnerConnection is instantiated, a login is implicitly
        // executed and, if successful,
        // a valid session is stored in the ConnectorConfig instance.
        // Use this key to initialize a BulkConnection:
        ConnectorConfig config = new ConnectorConfig();
        // The endpoint for the Bulk API service is the same as for the normal
        // SOAP uri until the /Soap/ part. From here it's '/async/versionNumber'
        String soapEndpoint = partnerConfig.getServiceEndpoint();
        String apiVersion = "38.0";
        String restEndpoint = soapEndpoint.substring(0, soapEndpoint.indexOf("Soap/")) + "async/" + apiVersion;
        // This should only be false when doing debugging.
        // Set this to true to see HTTP requests and responses on stdout
        config.setProxy(this.proxyUrl, this.proxyPort);

        try {
            bConn = new BulkConnection(config);
        } catch (AsyncApiException e) {
            return e.getMessage();
  • What does your Java code to configure the Proxy look like? Apr 20, 2017 at 2:56
  • What does the stack trace look like? Which line is throwing the exception? It might need to be traced via the setProxy method. Apr 20, 2017 at 21:55
  • I just wanted general suggestions and wanted to explore if there are quick and easy solutions. Its ok if nobody has come across this issue before- I'll fix it myself in due time. I don't really have the stacktrace right now because the code is run on a customer machine and I don't have access to that machine at the moment. Apr 21, 2017 at 17:43
  • I've seen all sorts of oddities with JVM versions and that library. Might be worth checking that as well. Apr 22, 2017 at 9:48
  • 1
    I'll take a deep dive this Thursday. If I figure it out, I'll post a solution. Thanks for your help, Daniel. Apr 24, 2017 at 15:03

1 Answer 1


Adding the following code before establishing a connection fixed it.

System.setProperty("http.proxyHost", crmProxyURL);
System.setProperty("http.proxyPort", crmProxyPort);

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.