Skip to content

Commit

Permalink
Merge pull request #111 from fredericBregier/v3.6.2c
Browse files Browse the repository at this point in the history
V3.6.2
  • Loading branch information
fredericBregier authored Jul 11, 2022
2 parents 068b0e7 + 3244684 commit 2f56c8a
Show file tree
Hide file tree
Showing 108 changed files with 2,145 additions and 1,961 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
*.jpg binary
*.jar binary
lib/phantomjs* binary
lib/geckodriver* binary

22 changes: 22 additions & 0 deletions WaarpCommon/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,28 @@
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>com.beust</groupId>
<artifactId>jcommander</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.detro</groupId>
<artifactId>ghostdriver</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>htmlunit-driver</artifactId>
<scope>test</scope>
</dependency>

</dependencies>
</project>
29 changes: 29 additions & 0 deletions WaarpCommon/src/main/java/org/waarp/common/command/ReplyCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ public enum ReplyCode {
*/
REPLY_350_REQUESTED_FILE_ACTION_PENDING_FURTHER_INFORMATION(350),

/**
* 400 Bad Request (Http)
*/
REPLY_400_BAD_REQUEST(400),

/**
* 421 Service not available, closing control connection. This may be a
* reply
Expand Down Expand Up @@ -457,6 +462,8 @@ public static ReplyCode getReplyCode(final int code)
return REPLY_332_NEED_ACCOUNT_FOR_LOGIN;
case 350:
return REPLY_350_REQUESTED_FILE_ACTION_PENDING_FURTHER_INFORMATION;
case 400:
return REPLY_400_BAD_REQUEST;
case 421:
return REPLY_421_SERVICE_NOT_AVAILABLE_CLOSING_CONTROL_CONNECTION;
case 425:
Expand Down Expand Up @@ -507,4 +514,26 @@ public static ReplyCode getReplyCode(final int code)
throw new InvalidArgumentException("Unknown ReplyCode " + code);
}
}

/**
* @param httpCode
*
* @return the associated ReplyCode from the given numerical code
*
* @throws InvalidArgumentException
*/
public static ReplyCode getReplyCodeFromHttp(final int httpCode)
throws InvalidArgumentException {
if (httpCode < 200) {
return REPLY_000_SPECIAL_NOSTATUS;
} else if (httpCode < 300) {
return REPLY_200_COMMAND_OKAY;
} else if (httpCode < 400) {
return REPLY_220_SERVICE_READY;
} else if (httpCode < 500) {
return REPLY_400_BAD_REQUEST;
} else {
return REPLY_500_SYNTAX_ERROR_COMMAND_UNRECOGNIZED;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import java.net.InetSocketAddress;
import java.security.cert.X509Certificate;
import java.util.List;

import static org.waarp.common.digest.WaarpBC.*;

Expand All @@ -39,12 +40,10 @@ public class WaarpSslContextFactory {
/**
* Internal Logger
*/
private static final WaarpLogger logger =
WaarpLoggerFactory.getLogger(WaarpSslContextFactory.class);
private static final WaarpLogger logger = WaarpLoggerFactory.getLogger(WaarpSslContextFactory.class);

private static final long DEFAULT_HANDSHAKE_TIMEOUT = 10000;
public static final String HAS_TRUST_MANAGER_IS_SERVER_MODE =
"Has TrustManager? {} Is ServerMode? {}";
public static final String HAS_TRUST_MANAGER_IS_SERVER_MODE = "Has TrustManager? {} Is ServerMode? {}";

static {
initializedTlsContext();
Expand All @@ -70,9 +69,25 @@ public class WaarpSslContextFactory {
*/
public WaarpSslContextFactory(final WaarpSecureKeyStore ggSecureKeyStore) {
// Both construct Client and Server mode
serverContext = initSslContextFactory(ggSecureKeyStore, true, false);
serverContextStartTls = initSslContextFactory(ggSecureKeyStore, true, true);
clientContext = initSslContextFactory(ggSecureKeyStore, false, false);
serverContext = initSslContextFactory(ggSecureKeyStore, true, false, null);
serverContextStartTls = initSslContextFactory(ggSecureKeyStore, true, true, null);
clientContext = initSslContextFactory(ggSecureKeyStore, false, false, null);
}

/**
* Create both CONTEXT with ciphers and/or protocols
*
* @param ggSecureKeyStore
* @param ciphers
* @param protocols
*/

public WaarpSslContextFactory(final WaarpSecureKeyStore ggSecureKeyStore, final List<String> ciphers,
final String... protocols) {
// Both construct Client and Server mode
serverContext = initSslContextFactory(ggSecureKeyStore, true, false, ciphers, protocols);
serverContextStartTls = initSslContextFactory(ggSecureKeyStore, true, true, ciphers, protocols);
clientContext = initSslContextFactory(ggSecureKeyStore, false, false, ciphers, protocols);
}

/**
Expand All @@ -81,15 +96,34 @@ public WaarpSslContextFactory(final WaarpSecureKeyStore ggSecureKeyStore) {
* @param ggSecureKeyStore
* @param serverMode
*/
public WaarpSslContextFactory(final WaarpSecureKeyStore ggSecureKeyStore,
final boolean serverMode) {
public WaarpSslContextFactory(final WaarpSecureKeyStore ggSecureKeyStore, final boolean serverMode) {
if (serverMode) {
serverContext = initSslContextFactory(ggSecureKeyStore, true, false, null);
serverContextStartTls = initSslContextFactory(ggSecureKeyStore, true, true, null);
clientContext = null;
} else {
clientContext = initSslContextFactory(ggSecureKeyStore, false, false, null);
serverContext = null;
serverContextStartTls = null;
}
}

/**
* Create only one of the CONTEXT with ciphers and/or protocols
*
* @param ggSecureKeyStore
* @param serverMode
* @param ciphers
* @param protocols
*/
public WaarpSslContextFactory(final WaarpSecureKeyStore ggSecureKeyStore, final boolean serverMode,
final List<String> ciphers, final String... protocols) {
if (serverMode) {
serverContext = initSslContextFactory(ggSecureKeyStore, true, false);
serverContextStartTls =
initSslContextFactory(ggSecureKeyStore, true, true);
serverContext = initSslContextFactory(ggSecureKeyStore, true, false, ciphers, protocols);
serverContextStartTls = initSslContextFactory(ggSecureKeyStore, true, true, ciphers, protocols);
clientContext = null;
} else {
clientContext = initSslContextFactory(ggSecureKeyStore, false, false);
clientContext = initSslContextFactory(ggSecureKeyStore, false, false, ciphers, protocols);
serverContext = null;
serverContextStartTls = null;
}
Expand All @@ -101,9 +135,9 @@ public WaarpSslContextFactory(final WaarpSecureKeyStore ggSecureKeyStore,
*
* @return the SSLContext
*/
private SslContext initSslContextFactory(
final WaarpSecureKeyStore ggSecureKeyStore, final boolean serverMode,
final boolean startTls) {
private SslContext initSslContextFactory(final WaarpSecureKeyStore ggSecureKeyStore,
final boolean serverMode, final boolean startTls,
final List<String> ciphers, final String... protocols) {
// Initialize the SSLContext to work with our key managers.
final WaarpSecureTrustManagerFactory secureTrustManagerFactory =
ggSecureKeyStore.getSecureTrustManagerFactory();
Expand All @@ -117,24 +151,18 @@ private SslContext initSslContextFactory(
}
if (serverMode) {
try {
return getInstanceForServer(ggSecureKeyStore.getKeyManagerFactory(),
certificates, needClientAuthentication,
startTls);
return getInstanceForServer(ggSecureKeyStore.getKeyManagerFactory(), certificates,
needClientAuthentication, startTls, ciphers, protocols);
} catch (final Throwable e) {//NOSONAR
logger.error("Failed to initialize the server-side SSLContext {}",
e.getMessage());
throw new Error("Failed to initialize the server-side SSLContext",
e);//NOSONAR
logger.error("Failed to initialize the server-side SSLContext {}", e.getMessage());
throw new Error("Failed to initialize the server-side SSLContext", e);//NOSONAR
}
} else {
try {
return getInstanceForClient(ggSecureKeyStore.getKeyManagerFactory(),
certificates);
return getInstanceForClient(ggSecureKeyStore.getKeyManagerFactory(), certificates);
} catch (final Throwable e) {//NOSONAR
logger.error("Failed to initialize the client-side SSLContext {}",
e.getMessage());
throw new Error("Failed to initialize the client-side SSLContext",
e);//NOSONAR
logger.error("Failed to initialize the client-side SSLContext {}", e.getMessage());
throw new Error("Failed to initialize the client-side SSLContext", e);//NOSONAR
}
}
}
Expand Down Expand Up @@ -164,12 +192,10 @@ public final SslContext getClientContext() {
*
* @return the sslhandler
*/
public final SslHandler createHandlerServer(final boolean needClientAuth,
final Channel channel) {
public final SslHandler createHandlerServer(final boolean needClientAuth, final Channel channel) {
logger.debug(HAS_TRUST_MANAGER_IS_SERVER_MODE, needClientAuth, true);
channel.config().setAutoRead(true);
final SslHandler sslHandler =
getServerContext().newHandler(channel.alloc());
final SslHandler sslHandler = getServerContext().newHandler(channel.alloc());
sslHandler.setHandshakeTimeoutMillis(DEFAULT_HANDSHAKE_TIMEOUT);
return sslHandler;
}
Expand All @@ -185,8 +211,7 @@ public final SslHandler createHandlerServer(final boolean needClientAuth,
*
* @return the sslhandler
*/
public final SslHandler createHandlerServer(final boolean needClientAuth,
final boolean startTls,
public final SslHandler createHandlerServer(final boolean needClientAuth, final boolean startTls,
final Channel channel) {
logger.debug(HAS_TRUST_MANAGER_IS_SERVER_MODE, needClientAuth, true);
channel.config().setAutoRead(true);
Expand Down Expand Up @@ -214,10 +239,8 @@ public final SslHandler createHandlerClient(final SocketChannel channel) {
final InetSocketAddress socketAddress = channel.remoteAddress();
final SslHandler sslHandler;
if (socketAddress != null) {
logger.debug("socket {} {}", socketAddress.getHostName(),
socketAddress.getPort());
sslHandler = getClientContext().newHandler(channel.alloc(),
socketAddress.getHostName(),
logger.debug("socket {} {}", socketAddress.getHostName(), socketAddress.getPort());
sslHandler = getClientContext().newHandler(channel.alloc(), socketAddress.getHostName(),
socketAddress.getPort());
} else {
sslHandler = getClientContext().newHandler(channel.alloc());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ public static int getNbConnection() {
* Close all database connections
*/
public static void closeAllConnection() {
logger.error("DEBUG Close All Connections");
logger.debug("DEBUG Close All Connections");
for (final DbSession session : listConnection.values()) {
logger.debug("Close (all) Db Conn: {}", session.getInternalId());
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,21 @@
*/
package org.waarp.common.database;

import org.waarp.common.database.model.DbType;
import org.waarp.common.logging.WaarpLogger;
import org.waarp.common.logging.WaarpLoggerFactory;

import java.sql.SQLException;

/**
* Constants value for database
*/
public class DbConstant {
/**
* Internal Logger
*/
private static final WaarpLogger logger =
WaarpLoggerFactory.getLogger(DbConstant.class);
/**
* Illegal value as SpecialId of transfer (any value above is valid)
*/
Expand All @@ -48,4 +59,23 @@ public class DbConstant {
*/
public static final int DELAYMAXCONNECTION = 30;

/**
* Print the error from SQLException
*
* @param ex
*/
public static void error(final SQLException ex) {
// handle any errors
logger.error(
"SQLException: " + ex.getMessage() + " SQLState: " + ex.getSQLState() +
" VendorError: " + ex.getErrorCode());
}

/**
* @return True if Db is used
*/
public static boolean isDbUsed() {
return admin != null && admin.getTypeDriver() != null &&
admin.getTypeDriver() != DbType.none;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public DbPreparedStatement(final DbSession ls, final String request)
} catch (final SQLException e1) {
logger.error("SQL Exception PreparedStatement: " + request + ' ' +
e.getMessage());
DbSession.error(e);
DbConstant.error(e);
preparedStatement = null;
setReady(false);
throw new WaarpDatabaseSqlException("SQL Exception PreparedStatement",
Expand Down Expand Up @@ -188,7 +188,7 @@ public DbPreparedStatement(final DbSession ls, final String request,
} catch (final SQLException e1) {
logger.error("SQL Exception PreparedStatement: " + request + ' ' +
e.getMessage());
DbSession.error(e);
DbConstant.error(e);
preparedStatement = null;
setReady(false);
throw new WaarpDatabaseSqlException("SQL Exception PreparedStatement",
Expand Down Expand Up @@ -236,7 +236,7 @@ public final void createPrepareStatement(final String requestarg)
logger.error(
"SQL Exception createPreparedStatement from {}:" + requestarg +
' ' + e.getMessage(), ls.getAdmin().getServer());
DbSession.error(e);
DbConstant.error(e);
realClose();
preparedStatement = null;
setReady(false);
Expand Down Expand Up @@ -285,7 +285,7 @@ public final void executeQuery()
} catch (final SQLException e) {
logger.error(
"SQL Exception executeQuery:" + request + ' ' + e.getMessage());
DbSession.error(e);
DbConstant.error(e);
close();
rs = null;
ls.checkConnectionNoException();
Expand Down Expand Up @@ -324,7 +324,7 @@ public final int executeUpdate()
logger.error(
"SQL Exception executeUpdate:" + request + ' ' + e.getMessage());
logger.debug("SQL Exception full stack trace", e);
DbSession.error(e);
DbConstant.error(e);
ls.checkConnectionNoException();
throw new WaarpDatabaseSqlException(
"SQL Exception executeUpdate: " + request, e);
Expand Down Expand Up @@ -391,7 +391,7 @@ public final boolean getNext()
logger.error("SQL Exception to getNextRow" +
(request != null? " [" + request + ']' : "") + ' ' +
e.getMessage());
DbSession.error(e);
DbConstant.error(e);
ls.checkConnectionNoException();
throw new WaarpDatabaseSqlException(
"SQL Exception to getNextRow: " + request, e);
Expand Down
Loading

0 comments on commit 2f56c8a

Please sign in to comment.