Proxy Servers

If your server requires HTTP requests to be made through a proxy, you can follow these steps to set up proxies for the server-side SDK.

SetupAnchorIcon

First, initialize your Braintree gateway with your API credentials:

  1. Java
BraintreeGateway gateway = new BraintreeGateway(
  Environment.PRODUCTION,
  "braintree_merchant_id",
  "braintree_public_key",
  "braintree_private_key"
);

You can then set a proxy URL and port for your Braintree configuration:

  1. Java
String proxyAddress = "your-proxy-domain.com";
int portNumber = 8080;

gateway.getConfiguration().setProxy(proxyAddress, portNumber);

You can also create a custom proxy object to pass into setProxy():

  1. Java
SocketAddress address = new InetSocketAddress("http://your-proxy-domain.com", 8080);
Proxy proxy = new Proxy(Proxy.Type.HTTP, address);

gateway.getConfiguration().setProxy(proxy);

Authenticated proxiesAnchorIcon

To configure an authenticated proxy, extend the abstract Authenticator class and override getPasswordAuthentication():

  1. Java
class CustomAuthenticator extends Authenticator {
  public PasswordAuthentication getPasswordAuthentication() {
    return new PasswordAuthentication("user", "password".toCharArray());
  }
}

Register your concrete subclass with the system by calling setDefault(Authenticator):

  1. Java
Authenticator authinstance = new CustomAuthenticator();
Authenticator.setDefault(authinstance);

For more on these examples and an overview of HTTP authentication in Java, see the Java documentation.

If you accept cookies, we’ll use them to improve and customize your experience and enable our partners to show you personalized PayPal ads when you visit other sites. Manage cookies and learn more