Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,22 @@ Add this dependency to your project's POM:
## Usage

The code examples on using this library are located in the library section of the java-sample-code repository: https://github.com/adyen/adyen-java-sample-code


## Proxy configuration

You can configure a proxy connection by injecting your own HttpURLConnectionClient on your client instance.

Example:
```
...
HttpURLConnectionClient httpURLConnectionClientWithProxy = new HttpURLConnectionClient();

Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("PROXY_HOST", PROXY_PORT));
httpURLConnectionClientWithProxy.setProxy(proxy);

client.setHttpClient(httpURLConnectionClientWithProxy);
```

## Support

If you have any problems, questions or suggestions, create an issue here or send your inquiry to support@adyen.com.
Expand Down
19 changes: 17 additions & 2 deletions src/main/java/com/adyen/httpclient/HttpURLConnectionClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.Proxy;
import java.net.URL;
import java.net.URLEncoder;
import java.util.Map;
Expand All @@ -35,6 +36,7 @@

public class HttpURLConnectionClient implements ClientInterface {
private static final String CHARSET = "UTF-8";
private Proxy proxy;

/**
* Does a POST request.
Expand Down Expand Up @@ -99,9 +101,14 @@ private String getQuery(Map<String, String> params) throws UnsupportedEncodingEx
*/
private HttpURLConnection createRequest(String requestUrl, String applicationName) throws IOException {
URL targetUrl = new URL(requestUrl);
HttpURLConnection httpConnection;

// set configurations
HttpURLConnection httpConnection = (HttpURLConnection) targetUrl.openConnection();
// Set proxy if configured
if (proxy != null) {
httpConnection = (HttpURLConnection) targetUrl.openConnection(proxy);
} else {
httpConnection = (HttpURLConnection) targetUrl.openConnection();
}
httpConnection.setUseCaches(false);
httpConnection.setDoOutput(true);
httpConnection.setRequestMethod("POST");
Expand Down Expand Up @@ -163,4 +170,12 @@ private String doPostRequest(HttpURLConnection httpConnection, String requestBod

return response;
}

public Proxy getProxy() {
return proxy;
}

public void setProxy(Proxy proxy) {
this.proxy = proxy;
}
}