Skip to content

enable proxy for Stripe HTTP connection#206

Merged
kyleconroy merged 3 commits into
stripe:masterfrom
xbwu:xbwu/proxy
Aug 21, 2015
Merged

enable proxy for Stripe HTTP connection#206
kyleconroy merged 3 commits into
stripe:masterfrom
xbwu:xbwu/proxy

Conversation

@xbwu
Copy link
Copy Markdown

@xbwu xbwu commented Aug 20, 2015

follow steps to tunnel Stripe connection through a proxy

Stripe.setConnectionProxy(<java.net.Proxy>)

// if proxy server requires authorization
Stripe.setProxyCredential(<java.net.PasswordAuthentication>)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it okay for PasswordAuthentication to return nil?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, the default impl is returning a null PasswordAuthentication. and i've verified.

scala> import java.net._
import java.net._
scala> import com.stripe._
import com.stripe._
scala> import com.stripe.model._
import com.stripe.model._
scala> val m = new java.util.HashMap[String, Object]
m: java.util.HashMap[String,Object] = {}
scala> m.put("description", "xbwu.enable.proxy.test")
res0: Object = null
scala> Stripe.apiKey="sk_test_..."
Stripe.apiKey: String = sk_test_...
scala> Stripe.setConnectionProxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("localhost", 3128)))
scala> Customer.create(m)
com.stripe.exception.APIConnectionException: IOException during API request to Stripe (https://api.stripe.com): Unable to tunnel through proxy. Proxy returns "HTTP/1.1 407 Proxy Authentication Required" Please check your internet connection and try again. If this problem persists,you should check Stripe's service status at https://twitter.com/stripestatus, or let us know at support@stripe.com.
scala> Stripe.setProxyCredential(new PasswordAuthentication("payment", "......".toCharArray))
scala> Customer.create(m)
res12: com.stripe.model.Customer =
<com.stripe.model.Customer@1074821682 id=cus_6pcgy8R2GZ0D7w> JSON: {......}
scala> Stripe.setProxyCredential(null)
scala> Stripe.setConnectionProxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("192.168.199.199", 3128)))
scala> Customer.create(m)
res29: com.stripe.model.Customer =
<com.stripe.model.Customer@589773472 id=cus_6pclJkgE5yM3N6> JSON: {......}

in my environment, localhost:3128 is tunneling to a proxy server which requires authorization, while 192.168.199.199:3128 is a proxy server doesn't need auth

@kyleconroy
Copy link
Copy Markdown
Contributor

@xbwu Fantastic.

kyleconroy added a commit that referenced this pull request Aug 21, 2015
enable proxy for Stripe HTTP connection
@kyleconroy kyleconroy merged commit 4c1fa91 into stripe:master Aug 21, 2015
@xbwu
Copy link
Copy Markdown
Author

xbwu commented Aug 24, 2015

thanks @kyleconroy, when should i expect new version being published to maven

@kyleconroy
Copy link
Copy Markdown
Contributor

@xbwu today or tomorrow. I'll ping here once it's released.

@xbwu
Copy link
Copy Markdown
Author

xbwu commented Aug 24, 2015

awesome, thanks @kyleconroy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants