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

Context root doesn't include a random string #24984

Merged
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 @@ -395,7 +395,8 @@ public static void prepareSuccessful(HandlerContext handlerCtx) {
*/
public static void prepareException(HandlerContext handlerCtx, Throwable ex) {
Throwable rootException = getRootCause(ex);
prepareAlert("error", GuiUtil.getMessage("msg.Error"), rootException.getMessage());
prepareAlert("error", GuiUtil.getMessage("msg.Error"), rootException.getClass().getSimpleName()
+ ": " + rootException.getMessage());
GuiUtil.getLogger().info(GuiUtil.getCommonMessage("LOG_EXCEPTION_OCCURED") + ex.getLocalizedMessage());
if (GuiUtil.getLogger().isLoggable(Level.FINE)){
ex.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Map;
import java.security.SecureRandom;
import java.util.List;
import java.util.ListIterator;
import java.util.ArrayList;
Expand Down Expand Up @@ -93,7 +92,7 @@ public static void deleteFileFromTempDir(HandlerContext handlerCtx) throws IOExc
if (Files.exists(pathToFile)) {
try {
Files.delete(pathToFile);

Files.delete(pathToFile.getParent());
} catch (IOException x) {
logger.log(Level.WARNING, prepareFileNotDeletedMessage(deleteTempFile));

Expand Down Expand Up @@ -144,27 +143,21 @@ public static void uploadFileToTempDir(HandlerContext handlerCtx) {
if (lastIndex != -1) {
name = name.substring(lastIndex + 1, name.length());
}
int index = name.indexOf(".");
int index = name.lastIndexOf(".");
if (index <= 0) {
logger.info("name=" + name + ",index=" + index);
String mesg = GuiUtil.getMessage("msg.deploy.nullArchiveError");
GuiUtil.handleError(handlerCtx, mesg);
return;
}
String suffix = name.substring(index);
String prefix = name.substring(0, index);
handlerCtx.setOutputValue("origPath", prefix);
handlerCtx.setOutputValue("origPath", name);
try {
//createTempFile requires min. of 3 char for prefix.
if (prefix.length() <= 2) {
prefix = prefix + new SecureRandom().nextInt(100000);
}

tmpFile = File.createTempFile(prefix, suffix);
tmpFile.deleteOnExit();
// keep the filename for the temp file, it's used to generate the context root
tmpFile = createTempFileWithOriginalFileName(name);

//delete the file, otherwise FileUtils#moveTo throws file already exist error
tmpFile.delete();
// delete the file, otherwise FileUtils#moveTo called inside uploadedFile.write
// throws file already exist error
Files.deleteIfExists(tmpFile.toPath());

if (logger.isLoggable(Level.FINE)) {
logger.fine(GuiUtil.getCommonMessage("log.writeToTmpFile"));
Expand All @@ -178,11 +171,13 @@ public static void uploadFileToTempDir(HandlerContext handlerCtx) {
} catch (IOException ioex) {
try {
if (tmpFile != null) {
uploadTmpFile = tmpFile.getAbsolutePath();
Files.deleteIfExists(tmpFile.toPath());
Files.deleteIfExists(tmpFile.toPath().getParent());
}
} catch (Exception ex) {
//Handle AbsolutePathException here
// ignore nested exception, handle the original exception only
dmatej marked this conversation as resolved.
Show resolved Hide resolved
}
GuiUtil.handleException(handlerCtx, ioex);
} catch (Exception ex) {
GuiUtil.handleException(handlerCtx, ex);
}
Expand All @@ -193,6 +188,16 @@ public static void uploadFileToTempDir(HandlerContext handlerCtx) {
handlerCtx.setOutputValue("uploadedTempFile", uploadTmpFile);
}

private static File createTempFileWithOriginalFileName(String name) throws IOException {
final Path dir = Files.createTempDirectory(name);
dir.toFile().deleteOnExit();
dmatej marked this conversation as resolved.
Show resolved Hide resolved
final Path file = dir.resolve(name);
Files.createFile(file);
final File result = file.toFile();
result.deleteOnExit();
return result;
}

/**
* <p>
* This handler enable or disable the table text field according to the
Expand Down