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.
Setup
First, initialize your Braintree gateway with your API credentials:
- 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:
- 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()
:
- Java
SocketAddress address = new InetSocketAddress("http://your-proxy-domain.com", 8080);
Proxy proxy = new Proxy(Proxy.Type.HTTP, address);
gateway.getConfiguration().setProxy(proxy);
Authenticated proxies
To configure an authenticated proxy, extend the abstract Authenticator
class and override getPasswordAuthentication()
:
- 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)
:
- 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.