Skip to content

Commit

Permalink
Migrated http-client module to next
Browse files Browse the repository at this point in the history
  • Loading branch information
sumeetphadnis committed Aug 13, 2024
1 parent 14a84ca commit 70b5a8a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 42 deletions.
3 changes: 2 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ agroal = '2.3'
flyway = '10.8.1'
h2 = '2.2.224'
testcontainers = '1.19.6'
httpAsyncClient = '4.1.5'

[libraries]
jpos = { module = "org.jpos:jpos", version.ref = "jpos" }
Expand Down Expand Up @@ -51,4 +52,4 @@ flywayPostgresql = { module = 'org.flywaydb:flyway-database-postgresql', version
flywayMysql = { module = 'org.flywaydb:flyway-mysql', version.ref='flyway' }
h2 = { module = 'com.h2database:h2', version.ref='h2' }
testcontainersPostgresql = { module = 'org.testcontainers:postgresql', version.ref='testcontainers' }

httpAsyncClient = { module = 'org.apache.httpcomponents:httpasyncclient', version.ref = 'httpAsyncClient' }
6 changes: 2 additions & 4 deletions modules/http-client/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
description = 'jPOS-EE :: QRest Client'

dependencies {
api libraries.jpos
api libraries.httpAsyncClient
api libs.jpos
api libs.httpAsyncClient
testImplementation project(':modules:qrest')
}

apply from: "${rootProject.projectDir}/jpos-app.gradle"

test {
dependsOn('installApp')
workingDir = "build/install/http-client"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,6 @@

package org.jpos.http.client;

import static org.jpos.util.Logger.log;

import java.io.IOException;
import java.io.Serializable;
import java.net.URI;
import java.security.KeyManagementException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.*;
import java.util.function.Consumer;

import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager;
import javax.security.cert.CertificateExpiredException;

import org.apache.commons.codec.binary.StringUtils;
import org.apache.http.*;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
Expand All @@ -51,29 +29,44 @@
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.concurrent.FutureCallback;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.conn.ssl.TrustAllStrategy;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;

import org.apache.http.impl.auth.BasicScheme;
import org.apache.http.impl.client.BasicAuthCache;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.DefaultRedirectStrategy;
import org.apache.http.impl.client.LaxRedirectStrategy;
import org.apache.http.impl.nio.client.HttpAsyncClientBuilder;
import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
import org.apache.http.impl.nio.client.HttpAsyncClientBuilder;
import org.apache.http.impl.nio.client.HttpAsyncClients;
import org.apache.http.message.BasicHeader;
import org.apache.http.util.EntityUtils;

import org.jpos.core.Configurable;
import org.jpos.core.Configuration;
import org.jpos.core.ConfigurationException;
import org.jpos.transaction.AbortParticipant;
import org.jpos.transaction.Context;
import org.jpos.util.Destroyable;
import org.jpos.util.Log;
import org.jpos.util.LogEvent;
import org.jpos.core.Configurable;
import org.jpos.core.Configuration;
import org.jpos.transaction.Context;

import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import java.io.IOException;
import java.io.Serializable;
import java.net.URI;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;

import static org.jpos.util.Logger.log;


@SuppressWarnings("unused")
Expand Down Expand Up @@ -117,6 +110,7 @@ public HttpQuery () {
super();
}

@Override
public int prepare (long id, Serializable o) {
Context ctx = (Context) o;

Expand All @@ -130,7 +124,7 @@ public int prepare (long id, Serializable o) {
//config example <property name="httpVersionName" value="1.1"/>
HttpVersion definedVersion = null;
String httpVersion = getVersion(ctx);
if(httpVersion != null && httpVersion.length() > 0) {
if(httpVersion != null && !httpVersion.isEmpty()) {
String[] majmin = httpVersion.split("\\."); // split into major and minor version numbers
definedVersion = new HttpVersion(Integer.parseInt(majmin[0]),
majmin.length > 1 ? Integer.parseInt(majmin[1]) : 0); // default to minor 0 if it can't be split
Expand Down Expand Up @@ -187,7 +181,7 @@ public void completed(HttpResponse result) {
}

ctx.put (statusName, sc); // status has to be the last entry because client might be waiting on it
ctx.resume();
ctx.resume(PREPARED);
}

@Override
Expand All @@ -198,18 +192,19 @@ public void failed(Exception ex) {
// java.net.ConnectException: Timeout connecting to [mydomain.com/xxx.xxx.xxx.xxx:ppp]
// java.net.SocketTimeoutException: ... (when no HTTP response)
ctx.log(ex);
ctx.resume();
ctx.resume(ABORTED);
}

@Override
public void cancelled() {
ctx.resume();
ctx.resume(ABORTED);
}
});

return PREPARED | PAUSE | NO_JOIN | READONLY;
}

@Override
public int prepareForAbort (long id, Serializable o) {
if (cfg.getBoolean ("on-abort", false))
return prepare (id, o);
Expand Down Expand Up @@ -324,10 +319,11 @@ public java.security.cert.X509Certificate[] getAcceptedIssuers() {
}

public void checkClientTrusted(X509Certificate[] certs, String authType) {
// ignored
}

public void checkServerTrusted(X509Certificate[] certs, String authType) {
log(new LogEvent(certs.toString() + " " + authType));
log(new LogEvent(Arrays.toString(certs) + " " + authType));
}
}
};
Expand All @@ -350,7 +346,7 @@ private String getURL (Context ctx) {
ctx.getString (urlName, url)
);
String params = ctx.getString (paramsName, "");
if (params.length() > 0) {
if (!params.isEmpty()) {
sb.append ('?');
sb.append (params);
}
Expand Down
3 changes: 1 addition & 2 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ include ':modules:seqno'
include ':modules:binlog'
include ':modules:binlog-quartz'
include ':modules:server-simulator'

include ':modules:http-client'
// include ':modules:dbtest'

dependencyResolutionManagement {
Expand Down Expand Up @@ -65,7 +65,6 @@ dependencyResolutionManagement {
// include ':modules:iso-http-client'
// include ':modules:iso-http-server'
// include ':modules:iso-http-servlet'
// include ':modules:http-client'
// include ':modules:elasticsearch'


Expand Down

0 comments on commit 70b5a8a

Please sign in to comment.