Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve VFS error handling and log config name in VFS error flow #2097

Merged
merged 2 commits into from
Sep 21, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.apache.synapse.commons.crypto.CryptoUtil;
import org.apache.synapse.commons.vfs.VFSConstants;
import org.apache.synapse.commons.vfs.VFSUtils;
import org.apache.synapse.transport.vfs.VFSTransportErrorHandler.LogType;

import java.net.UnknownHostException;
import java.text.DateFormat;
Expand Down Expand Up @@ -157,7 +158,9 @@ public String getFileURI() {
try {
return VFSUtils.resolveUriHost(fileURI);
} catch (UnknownHostException | FileSystemException e) {
log.warn("Unable to resolve the hostname of transport.vfs.FileURI : " + VFSUtils.maskURLPassword(fileURI), e);
String message = "Unable to resolve the hostname of transport.vfs.FileURI : " +
VFSUtils.maskURLPassword(fileURI);
VFSTransportErrorHandler.logException(log, LogType.WARN, message, getServiceName(), e);
}
}
return fileURI;
Expand All @@ -168,8 +171,9 @@ public String getReplyFileURI() {
try {
return VFSUtils.resolveUriHost(replyFileURI);
} catch (UnknownHostException | FileSystemException e) {
log.warn("Unable to resolve the hostname of transport.vfs.ReplyFileURI : " +
VFSUtils.maskURLPassword(replyFileURI), e);
String message = "Unable to resolve the hostname of transport.vfs.ReplyFileURI : " +
VFSUtils.maskURLPassword(replyFileURI);
VFSTransportErrorHandler.logException(log, LogType.WARN, message, getServiceName(), e);
}
}
return replyFileURI;
Expand Down Expand Up @@ -204,8 +208,9 @@ public String getMoveAfterProcess() {
try {
return VFSUtils.resolveUriHost(moveAfterProcess);
} catch (UnknownHostException | FileSystemException e) {
log.warn("Unable to resolve the hostname of transport.vfs.MoveAfterProcess: " +
VFSUtils.maskURLPassword(moveAfterProcess), e);
String message = "Unable to resolve the hostname of transport.vfs.MoveAfterProcess: " +
VFSUtils.maskURLPassword(moveAfterProcess);
VFSTransportErrorHandler.logException(log, LogType.WARN, message, getServiceName(), e);
}
}
return moveAfterProcess;
Expand All @@ -216,8 +221,9 @@ public String getMoveAfterMoveFailure() {
try {
return VFSUtils.resolveUriHost(moveAfterMoveFailure);
} catch (UnknownHostException | FileSystemException e) {
log.warn("Unable to resolve the hostname of transport.vfs.MoveAfterFailedMove: " +
VFSUtils.maskURLPassword(moveAfterMoveFailure), e);
String message = "Unable to resolve the hostname of transport.vfs.MoveAfterFailedMove: " +
VFSUtils.maskURLPassword(moveAfterMoveFailure);
VFSTransportErrorHandler.logException(log, LogType.WARN, message, getServiceName(), e);
}
}
return moveAfterMoveFailure;
Expand Down Expand Up @@ -264,8 +270,9 @@ public String getMoveAfterErrors() {
try {
return VFSUtils.resolveUriHost(moveAfterErrors);
} catch (UnknownHostException | FileSystemException e) {
log.warn("Unable to resolve the hostname of transport.vfs.MoveAfterErrors: " +
VFSUtils.maskURLPassword(moveAfterErrors), e);
String message = "Unable to resolve the hostname of transport.vfs.MoveAfterErrors: " +
VFSUtils.maskURLPassword(moveAfterErrors);
VFSTransportErrorHandler.logException(log, LogType.WARN, message, e);
}
}
return moveAfterErrors;
Expand All @@ -286,8 +293,9 @@ public String getMoveAfterFailure() {
try {
return VFSUtils.resolveUriHost(moveAfterFailure);
} catch (UnknownHostException | FileSystemException e) {
log.warn("Unable to resolve the hostname of transport.vfs.MoveAfterFailure: " +
VFSUtils.maskURLPassword(moveAfterFailure), e);
String message = "Unable to resolve the hostname of transport.vfs.MoveAfterFailure: " +
VFSUtils.maskURLPassword(moveAfterFailure);
VFSTransportErrorHandler.logException(log, LogType.WARN, message, getServiceName(), e);
}
}
return moveAfterFailure;
Expand Down Expand Up @@ -501,7 +509,6 @@ public void setSubfolderTimestamp(String subfolderTimestamp) {

@Override
public boolean loadConfiguration(ParameterInclude params) throws AxisFault {

decryptParamsIfRequired(params);
this.params = params;
resolveHostsDynamically = ParamUtils.getOptionalParamBoolean(params,
Expand All @@ -517,7 +524,8 @@ public boolean loadConfiguration(ParameterInclude params) throws AxisFault {
protected boolean loadConfigurationsFromService(ParameterInclude params) throws AxisFault {
fileURI = ParamUtils.getOptionalParam(params, VFSConstants.TRANSPORT_FILE_FILE_URI);
if (fileURI == null) {
log.warn("transport.vfs.FileURI parameter is missing in the proxy service configuration");
VFSTransportErrorHandler.logException(log, LogType.WARN,
"transport.vfs.FileURI parameter is missing in the proxy service configuration");
return false;
} else {

Expand Down Expand Up @@ -632,8 +640,9 @@ protected boolean loadConfigurationsFromService(ParameterInclude params) throws
fileSizeLimit = strFileSizeLimit != null ? Double.parseDouble(strFileSizeLimit) :
VFSConstants.DEFAULT_TRANSPORT_FILE_SIZE_LIMIT;
} catch (Exception e) {
log.warn("Error parsing specified file size limit - " + strFileSizeLimit +
", using default - unlimited");
String message = "Error parsing specified file size limit - " + strFileSizeLimit +
", using default - unlimited";
VFSTransportErrorHandler.logException(log, LogType.WARN, message);
}

moveAfterMoveFailure = ParamUtils.getOptionalParam(params,
Expand Down Expand Up @@ -674,8 +683,9 @@ protected boolean loadConfigurationsFromService(ParameterInclude params) throws
try {
fileProcessingInterval = Integer.parseInt(strFileProcessingInterval);
} catch (NumberFormatException nfe) {
log.warn("VFS File Processing Interval not set correctly. Current value is : "
+ strFileProcessingInterval, nfe);
String message = "VFS File Processing Interval not set correctly. Current value is : "
+ strFileProcessingInterval;
VFSTransportErrorHandler.logException(log, LogType.WARN, message, nfe);
}
}

Expand All @@ -685,8 +695,9 @@ protected boolean loadConfigurationsFromService(ParameterInclude params) throws
try {
fileProcessingCount = Integer.parseInt(strFileProcessingCount);
} catch (NumberFormatException nfe) {
log.warn("VFS File Processing Count not set correctly. Current value is : "
+ strFileProcessingCount, nfe);
String message = "VFS File Processing Count not set correctly. Current value is : "
+ strFileProcessingCount;
VFSTransportErrorHandler.logException(log, LogType.WARN, message, nfe);
}
}

Expand All @@ -700,8 +711,8 @@ protected boolean loadConfigurationsFromService(ParameterInclude params) throws
autoLockRelease = Boolean.parseBoolean(strAutoLock);
} catch (Exception e) {
autoLockRelease = false;
log.warn("VFS Auto lock removal not set properly. Current value is : "
+ strAutoLock, e);
String message = "VFS Auto lock removal not set properly. Current value is : " + strAutoLock;
VFSTransportErrorHandler.logException(log, LogType.WARN, message, e);
}
if (autoLockRelease) {
String strAutoLockInterval = ParamUtils.getOptionalParam(params,
Expand All @@ -712,9 +723,9 @@ protected boolean loadConfigurationsFromService(ParameterInclude params) throws
autoLockReleaseInterval = Long.parseLong(strAutoLockInterval);
} catch (Exception e) {
autoLockReleaseInterval = null;
log.warn(
"VFS Auto lock removal property not set properly. Current value is : "
+ strAutoLockInterval, e);
String message = "VFS Auto lock removal property not set properly. Current value is : "
+ strAutoLockInterval;
VFSTransportErrorHandler.logException(log, LogType.WARN, message, e);
}
}
String strAutoLockReleaseSameNode = ParamUtils.getOptionalParam(params,
Expand All @@ -726,9 +737,9 @@ protected boolean loadConfigurationsFromService(ParameterInclude params) throws
.parseBoolean(strAutoLockReleaseSameNode);
} catch (Exception e) {
autoLockReleaseSameNode = true;
log.warn(
"VFS Auto lock removal property not set properly. Current value is : "
+ autoLockReleaseSameNode, e);
String message = "VFS Auto lock removal property not set properly. Current value is : "
+ autoLockReleaseSameNode;
VFSTransportErrorHandler.logException(log, LogType.WARN, message, e);
}
}
}
Expand All @@ -744,7 +755,8 @@ protected boolean loadConfigurationsFromService(ParameterInclude params) throws
distributedLock = Boolean.parseBoolean(strDistributedLock);
} catch (Exception e) {
autoLockRelease = false;
log.warn("VFS Distributed lock not set properly. Current value is : " + strDistributedLock, e);
String message = "VFS Distributed lock not set properly. Current value is : " + strDistributedLock;
VFSTransportErrorHandler.logException(log, LogType.WARN, message, e);
}

if (distributedLock) {
Expand All @@ -756,9 +768,9 @@ protected boolean loadConfigurationsFromService(ParameterInclude params) throws
distributedLockTimeout = Long.parseLong(strDistributedLockTimeout);
} catch (Exception e) {
distributedLockTimeout = null;
log.warn(
"VFS Distributed lock timeout property not set properly. Current value is : "
+ strDistributedLockTimeout, e);
String message = "VFS Distributed lock timeout property not set properly. Current value is : "
+ strDistributedLockTimeout;
VFSTransportErrorHandler.logException(log, LogType.WARN, message, e);
}
}
}
Expand Down Expand Up @@ -799,15 +811,13 @@ private String resolveHostAtDeployment(String uri) throws AxisFault {
String errorMsg = "Unable to decode the malformed URI : " + VFSUtils.maskURLPassword(uri);
//log the error since if we only throw AxisFault, we won't get the entire stacktrace in logs to
// identify root cause to users
log.error(errorMsg, e);
throw new AxisFault(errorMsg, e);
VFSTransportErrorHandler.handleException(log, errorMsg, e);

} catch (UnknownHostException e) {
String errorMsg = "Error occurred while resolving hostname of URI : " + VFSUtils.maskURLPassword(uri);
//log the error since if we only throw AxisFault, we won't get the entire stacktrace in logs to
// identify root cause to users
log.error(errorMsg, e);
throw new AxisFault(errorMsg, e);
VFSTransportErrorHandler.handleException(log, errorMsg, e);
}
}
return uri;
Expand Down Expand Up @@ -848,7 +858,7 @@ private String decryptIfRequired(String parameter) throws AxisFault {
cryptoUtil = new CryptoUtil(secureVaultProperties);
}
if (!cryptoUtil.isInitialized()) {
throw new AxisFault("Error initialising cryptoutil");
VFSTransportErrorHandler.handleException(log, "Error initialising cryptoutil");
}
String toDecrypt = m.group(1);
toDecrypt = new String(cryptoUtil.decrypt(toDecrypt.getBytes()));
Expand Down
Loading