Skip to content
New issue

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

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

Already on GitHub? # to your account

Context root doesn't include a random string #24984

Merged
Merged
Changes from 1 commit
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 @@ -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 @@ -144,24 +143,17 @@ 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();
Expand Down Expand Up @@ -193,6 +185,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();
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