palominolabs / sf-api-connector

Java API to Salesforce's REST and SOAP APIs
http://blog.palominolabs.com/2011/03/03/a-new-java-salesforce-api-library/
36 stars 22 forks source link

Connection refused with REST client #7

Closed marshallpierce closed 10 years ago

marshallpierce commented 10 years ago

Reported by Christopher Keith at http://blog.palominolabs.com/2011/03/03/a-new-java-salesforce-api-library/#comment-1213874681.

Content copied here:

Many thanks for making this available! I pulled and built the source. When I try to send a query, I get this error:

Connect to na15.salesforce.com:443 [na15.salesforce.com/96.43.146...., na15.salesforce.com/96.43.146....] failed: Connection refused: connect

I am, however, able to query using HttpURLConnection with the following URL:

https://na15.salesforce.com:443/services/data/v29.0/query?q=SELECT+name+from+Account

This is my code to configure the org (after getting the access token response):

pool.configureOrg(0, accessTokens.instance_url.substring("https://".length()),accessTokens.access_token);

And this to execute the query:

RestConnection connection = pool.getRestConnection(0); RestQueryResult restQueryResult = connection.query("SELECT name from " + type);

Any idea what's going on, or how I might debug this? Thanks again for any help.

chrisxkeith commented 10 years ago

The code that works using HttpURLConnection is also using a java.net.Authenticator to get through a proxy. I don't see any obvious way to set that up in the sf-api-connector. I started stepping through the code and got into some apache code (e.g., org.apache.http.impl.client.InternalHttpClient). I would prefer (if possible) to have changes in the connector instead of the apache code. I'll keep wandering around through the code to see if there's anything more I can dig out.

marshallpierce commented 10 years ago

@chrisxkeith can you give the latest code in master a try? It allows specifying a HttpClientBuilder when building the RestConnectionPoolImpl. See http://hc.apache.org/httpcomponents-client-4.3.x/tutorial/html/connmgmt.html#d5e473 for how to set up a HttpClientBuilder with proxy information.

chrisxkeith commented 10 years ago

Thank you, Marshall. I'm digging into something else right now (or trying to dig myself out of it :), but will look at this in a couple of days.

On Tue, Jan 28, 2014 at 9:40 PM, Marshall Pierce notifications@github.comwrote:

@chrisxkeith https://github.com/chrisxkeith can you give the latest code in master a try? It allows specifying a HttpClientBuilder when building the RestConnectionPoolImpl. See http://hc.apache.org/httpcomponents-client-4.3.x/tutorial/html/connmgmt.html#d5e473for how to set up a HttpClientBuilder with proxy information.

Reply to this email directly or view it on GitHubhttps://github.com/palominolabs/sf-api-connector/issues/7#issuecomment-33558150 .

-CK http://www.chriskeith.me/ck/

chrisxkeith commented 10 years ago

@marshallpierce I pulled the latest code. I understand how to use the HttpClientBuilder, but I have to specify a username and password (as well as hostname and port) to get through our proxy. I don't see any way to do that in HttpHost. Do you know how I would hook a username/password into this system? Thanks!

dinomite commented 10 years ago

@chrisxkeith It looks like you need to give HttpClientBuilder the proxy auth info with setProxyAuthenticationStrategy(). I don't have a proxy to test with, but perhaps this StackOverflow answer will point you in the right direction.

chrisxkeith commented 10 years ago

@dinomite Got it working! Thanks for the pointer. You can resolve/close this issue.

dinomite commented 10 years ago

Great! Let us know if you have any issues actually using the API.