Skip to content

Commit

Permalink
Release 7.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
wallee-deployment-user committed Oct 31, 2023
1 parent dc66f02 commit 5fdeb22
Show file tree
Hide file tree
Showing 8 changed files with 321 additions and 81 deletions.
43 changes: 40 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Add this dependency to your project's POM:
<dependency>
<groupId>com.wallee</groupId>
<artifactId>wallee-java-sdk</artifactId>
<version>6.2.0</version>
<version>7.0.0</version>
<scope>compile</scope>
</dependency>
```
Expand All @@ -33,7 +33,7 @@ Add this dependency to your project's POM:
Add this dependency to your project's build file:

```groovy
compile "com.wallee:wallee-java-sdk:6.2.0"
compile "com.wallee:wallee-java-sdk:7.0.0"
```

### Others
Expand All @@ -46,7 +46,7 @@ mvn clean package

Then manually install the following JARs:

* `target/wallee-java-sdk-6.2.0.jar`
* `target/wallee-java-sdk-7.0.0.jar`
* `target/lib/*.jar`

## Usage
Expand Down Expand Up @@ -155,6 +155,43 @@ public class TransactionPaymentPageExample {
}

```
Consider using the following overloaded ApiClient constructor and following code snippet to gain access to a resource behind a **proxy** server with a Basic Authentication scheme
```java
// Create an instance of the ApiClient with the user's unique credentials and proxy information.
ApiClient apiClient = new ApiClient(userId, secret, String proxyHostname, int proxyPort);

Authenticator authenticator = new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
// Check if the authentication request is for a proxy
if (getRequestorType() == RequestorType.PROXY) {
// Check if the authentication scheme is Basic
if ("Basic".equalsIgnoreCase(getRequestingScheme())) {
// Return the PasswordAuthentication instance with the proxy credentials
return new PasswordAuthentication(proxyUsername, proxyPassword.toCharArray());
}
}

return null;
}
};

// Set the default Authenticator that will be used by the networking code when a proxy or an HTTP server asks for authentication.
// Authenticator.setDefault will set the java.net.Authenticator that processes all authentication requests.
Authenticator.setDefault(authenticator);
```
### Disable Basic authentication for HTTPS tunneling

>In some environments, certain authentication schemes may be undesirable when proxying HTTPS. Accordingly, the Basic authentication scheme has been deactivated, by default, in the Oracle
>Java Runtime, by adding Basic to the jdk.http.auth.tunneling.disabledSchemes networking property. Now, proxies requiring Basic authentication when setting up a tunnel for HTTPS
>will no longer succeed by default. If required, this authentication scheme can be reactivated by removing Basic from the jdk.http.auth.tunneling.disabledSchemes networking
>property, or by setting a system property of the same name to "" ( empty ) on the command line.
```java
System.setProperty("jdk.http.auth.tunneling.disabledSchemes", "");
System.setProperty("jdk.http.auth.proxying.disabledSchemes", "");
```

## Recommendation

It is recommended to create an instance of `ApiClient` per thread in a multithreaded environment to avoid any potential issues.
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'idea'
apply plugin: 'eclipse'

group = 'com.wallee'
version = '6.2.0'
version = '7.0.0'

buildscript {
repositories {
Expand Down Expand Up @@ -105,7 +105,7 @@ ext {

dependencies {
compile "io.swagger:swagger-annotations:$swagger_annotations_version"
compile "com.google.api-client:google-api-client:${google_api_client_version}" {
compile ("com.google.api-client:google-api-client:$google_api_client_version") {
exclude group: 'commons-codec', module: 'commons-codec'
}
compile "com.google.guava:guava:$guava_version"
Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ lazy val root = (project in file(".")).
settings(
organization := "com.wallee",
name := "wallee-java-sdk",
version := "6.2.0",
version := "7.0.0",
scalaVersion := "2.11.4",
scalacOptions ++= Seq("-feature"),
javacOptions in compile ++= Seq("-Xlint:deprecation"),
Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<artifactId>wallee-java-sdk</artifactId>
<packaging>jar</packaging>
<name>wallee-java-sdk</name>
<version>6.2.0</version>
<version>7.0.0</version>
<url>https://www.wallee.com</url>
<description>The SDK for simplifying the integration with wallee API.</description>
<scm>
Expand Down Expand Up @@ -53,8 +53,8 @@
<configuration>
<rules>
<requireMavenVersion>
<version>(,3.9)</version>
<message>Invalid Maven version. It should, at least, be 2.0</message>
<version>[3.2,3.8]</version>
<message>Invalid Maven version. It should be between 3.2 and 3.8 inclusive.</message>
</requireMavenVersion>
</rules>
</configuration>
Expand Down
165 changes: 121 additions & 44 deletions src/main/java/com/wallee/sdk/ApiClient.java
Original file line number Diff line number Diff line change
@@ -1,35 +1,51 @@
package com.wallee.sdk;

import com.wallee.sdk.service.*;

import java.net.InetSocketAddress;
import java.net.Proxy;
import java.util.HashMap;
import java.util.Map;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.google.api.client.http.AbstractHttpContent;
import com.google.api.client.http.HttpRequest;
import com.google.api.client.http.HttpRequestFactory;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.Json;
import com.google.api.client.http.HttpHeaders;

import java.io.IOException;
import java.io.OutputStream;

/**
* The ApiClient class is responsible for setting up and maintaining the state and configuration
* necessary to interact with a remote API service.
*/

public class ApiClient {

private static final String DEFAULT_BASE_PATH = "https://app-wallee.com:443/api";

// Configuration fields
private int readTimeOut = 25;
private final String basePath;
private final HttpRequestFactory httpRequestFactory;
private final ObjectMapper objectMapper;
private final long userId;
private final String applicationKey;
private final Map<String, String> defaultHeaders;
private String basePath;
private HttpRequestFactory httpRequestFactory;
private ObjectMapper objectMapper;
private long userId;
private String applicationKey;
private Map<String, String> defaultHeaders = new HashMap<>();

// A reasonable default object mapper. Client can pass in a chosen ObjectMapper anyway, this is just for reasonable defaults.
// Proxy settings
private String proxyHostname;
private int proxyPort;

/**
* Creates a default ObjectMapper for JSON serialization/deserialization.
* This mapper will ignore unknown properties and set proper date formats among other configurations.
*/
private static ObjectMapper createDefaultObjectMapper() {
ObjectMapper objectMapper = new ObjectMapper()
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
Expand All @@ -40,60 +56,121 @@ private static ObjectMapper createDefaultObjectMapper() {
return objectMapper;
}


/**
* Constructor for ApiClient
*
* @param userId
* @param applicationKey
*/
public ApiClient(long userId, String applicationKey) {
this(userId, applicationKey, "https://app-wallee.com:443/api");
}

/**
* Constructor for ApiClient
*
* @param userId
* @param applicationKey
*/
public ApiClient(long userId, String applicationKey, String basePath) {
* Validates the primary inputs required for establishing a connection with the API.
*
* @param userId The user ID that will be authenticated.
* @param applicationKey The application key corresponding to the user's account, used for authentication.
* @param basePath The base URL for the API against which all the requests would be made.
* @throws IllegalArgumentException if any argument does not meet the criteria.
*/
private void validateInputs(long userId, String applicationKey, String basePath) {
if (applicationKey == null || applicationKey.trim().isEmpty()) {
throw new IllegalArgumentException("The application key cannot be empty or null.");
throw new IllegalArgumentException("Application key cannot be null or empty.");
}
if (userId < 1) {
throw new IllegalArgumentException("The user id is invalid.");
throw new IllegalArgumentException("User ID must be positive.");
}
if (basePath == null || basePath.trim().isEmpty()) {
throw new IllegalArgumentException("The base path cannot be empty.");
}

this.basePath = basePath;
throw new IllegalArgumentException("Base path cannot be null or empty.");
}
}

/**
* Initializes common properties for the API client.
*/
private void initializeBaseProperties(long userId, String applicationKey, String basePath) {
validateInputs(userId, applicationKey, basePath);
this.basePath = basePath;
this.userId = userId;
this.applicationKey = applicationKey;
this.defaultHeaders = new HashMap<>();
this.httpRequestFactory = this.createRequestFactory();
this.objectMapper = createDefaultObjectMapper();
}

public HttpRequestFactory getHttpRequestFactory() {
return httpRequestFactory;
/**
* Sets up the proxy properties for the API client.
*/
private void initializeProxyProperties(String proxyHostname, int proxyPort) {
this.proxyHostname = proxyHostname;
this.proxyPort = proxyPort;
}

public HttpRequestFactory createRequestFactory() {
/**
* Constructs an ApiClient with the default base path.
*/
public ApiClient(long userId, String applicationKey) {
this(userId, applicationKey, DEFAULT_BASE_PATH);
}

/**
* Constructs an ApiClient with a custom base path.
*/
public ApiClient(long userId, String applicationKey, String basePath) {
initializeBaseProperties(userId, applicationKey, basePath);
this.httpRequestFactory = createRequestFactory();
}

/**
* Constructor for ApiClient specifying user credentials, proxy details, and base path.
*
* @param userId user identifier for authentication.
* @param applicationKey unique application key for user authentication.
* @param basePath the base URL for API requests.
* @param proxyHostname the hostname of the proxy server.
* @param proxyPort the port of the proxy server.
*/
public ApiClient(long userId, String applicationKey, String basePath, String proxyHostname, int proxyPort) {
initializeBaseProperties(userId, applicationKey, basePath);
initializeProxyProperties(proxyHostname, proxyPort);
this.httpRequestFactory = createRequestFactory();
}

/**
* Constructor for ApiClient specifying user credentials with the default base path and proxy details.
*
* @param userId user identifier for authentication.
* @param applicationKey unique application key for user authentication.
* @param proxyHostname the hostname of the proxy server.
* @param proxyPort the port of the proxy server.
*/
public ApiClient(long userId, String applicationKey, String proxyHostname, int proxyPort) {
this(userId, applicationKey, DEFAULT_BASE_PATH, proxyHostname, proxyPort);
}

/**
* Creates an HttpRequestFactory configured for making HTTP requests. The method initializes a transport builder
* and potentially sets a proxy for it.
*
* @return HttpRequestFactory This factory is configured with the built transport and the interceptor.
* It is ready for making HTTP requests, handling the details of connection
* and protocol, allowing for high configurability and ease of modifications.
*/
private HttpRequestFactory createRequestFactory() {
final RequestInterceptor interceptor = new RequestInterceptor(this.userId, this.applicationKey, this.defaultHeaders);
NetHttpTransport transport = new NetHttpTransport();
return transport.createRequestFactory(new HttpRequestInitializer() {
public void initialize(HttpRequest request) {
request.setInterceptor(interceptor);
}
});
NetHttpTransport.Builder builder = new NetHttpTransport.Builder();

if (proxyHostname != null && !proxyHostname.isEmpty()) {
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHostname, proxyPort));
builder.setProxy(proxy);
}

NetHttpTransport transport = builder.build();

return transport.createRequestFactory(request -> request.setInterceptor(interceptor));
}

/**
* Allows the addition of default headers that will be sent with each request.
*/
public void addDefaultHeader (String key, String value) {
this.defaultHeaders.put(key, value);
}

// Standard getters and setters
public HttpRequestFactory getHttpRequestFactory() {
return httpRequestFactory;
}

public String getBasePath() {
return basePath;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/wallee/sdk/DefaultHeaders.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void intercept(HttpRequest request) throws IOException {

private HttpHeaders getDefaultHeaders() {
HttpHeaders headers = new HttpHeaders();
headers.put("x-meta-sdk-version", "6.2.0");
headers.put("x-meta-sdk-version", "7.0.0");
headers.put("x-meta-sdk-language", "java");
headers.put("x-meta-sdk-provider", "wallee");
headers.put("x-meta-sdk-language-version", System.getProperty("java.version"));
Expand Down
Loading

0 comments on commit 5fdeb22

Please sign in to comment.