diff --git a/src/main/java/io/qameta/allure/bamboo/AllureArtifactsManager.java b/src/main/java/io/qameta/allure/bamboo/AllureArtifactsManager.java index bd15ad1..be78caa 100644 --- a/src/main/java/io/qameta/allure/bamboo/AllureArtifactsManager.java +++ b/src/main/java/io/qameta/allure/bamboo/AllureArtifactsManager.java @@ -35,14 +35,17 @@ import com.atlassian.sal.api.ApplicationProperties; import com.atlassian.sal.api.UrlMode; import com.google.common.collect.ImmutableList; + import org.apache.log4j.Logger; import org.apache.tools.ant.types.FileSet; import org.jetbrains.annotations.NotNull; import javax.annotation.Nullable; import javax.ws.rs.core.UriBuilder; + import java.io.File; import java.io.IOException; +import java.net.MalformedURLException; import java.net.URL; import java.nio.file.Path; import java.nio.file.Paths; @@ -135,10 +138,16 @@ Optional getArtifactUrl(final String planKeyString, final String buildNu } @Nullable - private String getLocalStorageURL(String planKeyString, String buildNumber, String filePath) { - final File file = getLocalStoragePath(planKeyString, buildNumber).resolve(filePath).toFile(); - final String fullPath = (file.isDirectory()) ? new File(file, "index.html").getAbsolutePath() : file.getAbsolutePath(); - return String.format("file://%s", fullPath); + private String getLocalStorageURL(String planKeyString, String buildNumber, String filePath) { + try { + final File file = getLocalStoragePath(planKeyString, buildNumber).resolve(filePath).toFile(); + final String fullPath = (file.isDirectory()) ? new File(file, "index.html").getAbsolutePath() : file.getAbsolutePath(); + return new File(fullPath).toURI().toURL().toString(); + + } catch (MalformedURLException e) { + // should never happen + throw new RuntimeException(e); + } } /** diff --git a/src/main/java/io/qameta/allure/bamboo/AllureReportServlet.java b/src/main/java/io/qameta/allure/bamboo/AllureReportServlet.java index 3e41754..68e1882 100644 --- a/src/main/java/io/qameta/allure/bamboo/AllureReportServlet.java +++ b/src/main/java/io/qameta/allure/bamboo/AllureReportServlet.java @@ -3,6 +3,7 @@ import com.atlassian.bamboo.plan.PlanResultKey; import com.atlassian.bamboo.resultsummary.ResultsSummary; import com.atlassian.bamboo.resultsummary.ResultsSummaryManager; + import org.apache.commons.io.IOUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -12,8 +13,10 @@ import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; + import java.io.IOException; import java.io.InputStream; +import java.net.URI; import java.net.URL; import java.nio.file.Files; import java.nio.file.Paths; @@ -70,14 +73,21 @@ protected void doHead(HttpServletRequest request, HttpServletResponse response) } private void setResponseHeaders(HttpServletResponse response, String fileUrl) throws IOException { - response.setStatus(HttpServletResponse.SC_OK); - final String file = new URL(fileUrl).getPath(); - final String mimeType = ofNullable(getServletContext().getMimeType(fileUrl)).orElse( - Files.probeContentType(Paths.get(file)) - ); - final String charsetPostfix = of("application", "text").anyMatch(mimeType::contains) ? ";charset=utf-8" : ""; - response.setHeader("Content-Type", mimeType + charsetPostfix); - response.setHeader("Content-Disposition", "inline; filename=\"" + Paths.get(fileUrl).getFileName().toString() + "\""); + + try { + response.setStatus(HttpServletResponse.SC_OK); + final URI file = new URL(fileUrl).toURI(); + final String mimeType = ofNullable(getServletContext().getMimeType(fileUrl)).orElse( + Files.probeContentType(Paths.get(file)) + ); + final String charsetPostfix = of("application", "text").anyMatch(mimeType::contains) ? ";charset=utf-8" : ""; + response.setHeader("Content-Type", mimeType + charsetPostfix); + response.setHeader("Content-Disposition", "inline; filename=\"" + Paths.get(file).getFileName().toString() + "\""); + + } catch (URISyntaxException e) { + // should never happen + throw new RuntimeException(e); + } } private Optional getArtifactUrl(HttpServletRequest request, HttpServletResponse response) {