Commit 9edc8e7a authored by Malo Toudic's avatar Malo Toudic
Browse files
parent 1f0b0e01
......@@ -4,6 +4,7 @@ import com.uwyn.jhighlight.renderer.XhtmlRendererFactory;
import net.ihe.gazelle.simulator.message.model.TransactionInstance;
import net.ihe.gazelle.wstester.action.GwtTestStepValidation;
import net.ihe.gazelle.wstester.util.DateUtil;
import net.ihe.gazelle.wstester.util.DownloadFile;
import net.ihe.gazelle.wstester.util.Xml;
import org.hibernate.annotations.Type;
import org.slf4j.Logger;
......@@ -237,4 +238,16 @@ public class GwtTestStepResult implements Serializable {
return query.getUniqueResult();
}
public void downloadRequest() {
final String content = this.getMessages().getRequest().getContentAsString();
final String fileName = this.testStep.getLabel() + ".xml";
DownloadFile.exportToFile("text/xml", content, fileName);
}
public void downloadResponse() {
final String content = this.getMessages().getResponse().getContentAsString();
final String fileName = this.testStep.getLabel() + ".xml";
DownloadFile.exportToFile("text/xml", content, fileName);
}
}
package net.ihe.gazelle.wstester.util;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.io.IOUtils;
import org.jboss.seam.faces.FacesMessages;
import org.jboss.seam.international.StatusMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.activation.FileTypeMap;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
public class DownloadFile {
private static final Logger LOG = LoggerFactory.getLogger(DownloadFile.class);
public static void exportToFile(String content, String fileNameDestination) {
exportToFile((String) null, (String) content, fileNameDestination);
}
public static void exportToFile(String contentType, String content, String fileNameDestination) {
if (content != null) {
exportToFile(contentType, content.getBytes(), fileNameDestination);
}
}
public static void exportToFile(String contentType, byte[] bytes, String fileNameDestination) {
exportToFile(contentType, bytes, fileNameDestination, false);
}
public static void exportToFile(String contentType, byte[] bytes, String fileNameDestination, boolean inline) {
try {
showFile(bytes, fileNameDestination, !inline);
} catch (IOException var5) {
LOG.warn(var5.getMessage());
}
}
public static void showFile(String fullPath) {
showFile((String) fullPath, (String) null, false);
}
public static void showFile(String fullPath, String filename, boolean download) {
try {
File f = new File(fullPath);
if (filename == null) {
filename = f.getName();
}
InputStream inputStream = null;
if (f.exists()) {
inputStream = new FileInputStream(fullPath);
}
showFile((InputStream) inputStream, filename, download);
inputStream.close();
} catch (Exception var5) {
LOG.error(var5.getMessage());
FacesMessages.instance().add(StatusMessage.Severity.ERROR, "Impossible to display file : " + var5.getMessage(), new Object[0]);
}
}
public static void showFile(byte[] bytes, String filename, boolean download) throws IOException {
showFile((InputStream) (new ByteArrayInputStream(bytes)), filename, download);
}
public static void showFile(InputStream inputStream, String filename, boolean download) throws IOException {
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
HttpServletResponse response = (HttpServletResponse) externalContext.getResponse();
try {
while (true) {
response = (HttpServletResponse) PropertyUtils.getProperty(response, "response");
}
} catch (Exception var7) {
response.reset();
HttpServletRequest request = (HttpServletRequest) facesContext.getExternalContext().getRequest();
showFile(request, response, inputStream, filename, download);
inputStream.close();
facesContext.responseComplete();
}
}
public static void showFile(HttpServletRequest request, HttpServletResponse response, InputStream inputStream, String filename, boolean download) {
try {
if (inputStream != null) {
String userAgent = request.getHeader("user-agent");
boolean isInternetExplorer = userAgent.indexOf("MSIE") > -1;
int length = inputStream.available();
if (filename != null && filename.toLowerCase().endsWith(".pdf")) {
response.setContentType("application/pdf");
} else if (filename != null && filename.toLowerCase().endsWith(".xml")) {
response.setContentType("text/xml");
} else {
String contentType = FileTypeMap.getDefaultFileTypeMap().getContentType(filename);
response.setContentType(contentType);
}
byte[] fileNameBytes = filename.getBytes(isInternetExplorer ? "windows-1250" : "utf-8");
String dispositionFileName = "";
byte[] var10 = fileNameBytes;
int var11 = fileNameBytes.length;
for (int var12 = 0; var12 < var11; ++var12) {
byte b = var10[var12];
dispositionFileName = dispositionFileName + (char) (b & 255);
}
String disposition;
if (download) {
disposition = "attachment; filename=\"" + dispositionFileName + "\"";
} else {
disposition = "inline; filename=\"" + dispositionFileName + "\"";
}
response.setHeader("Content-disposition", disposition);
response.setContentLength(length);
ServletOutputStream servletOutputStream = response.getOutputStream();
IOUtils.copy(inputStream, servletOutputStream);
servletOutputStream.flush();
servletOutputStream.close();
inputStream.close();
}
} catch (Exception var14) {
LOG.error(var14.getMessage());
FacesMessages.instance().add(StatusMessage.Severity.ERROR, "Impossible to display file : " + var14.getMessage(), new Object[0]);
}
}
}
......@@ -103,7 +103,7 @@
<ui:define name="header">Request validation</ui:define>
<s:div rendered="#{testStepResult.getRequestValidation() != null}">
<h:outputText value="#{testStepResult.getRequestValidation().validationStatus}"
styleClass="gzl-label #{testStepResult.getRequestValidation().validationStatus}"/>
styleClass="gzl-label #{testStepResult.getRequestValidation().validationStatus}"/>
</s:div>
<s:div rendered="#{testStepResult.getRequestValidation() == null}">
<h:commandLink actionListener="#{testStepResult.validateRequest()}"
......@@ -116,7 +116,7 @@
<ui:define name="header">Response validation</ui:define>
<s:div rendered="#{testStepResult.getResponseValidation() != null}">
<h:outputText value="#{testStepResult.getResponseValidation().validationStatus}"
styleClass="gzl-label #{testStepResult.getResponseValidation().validationStatus}"/>
styleClass="gzl-label #{testStepResult.getResponseValidation().validationStatus}"/>
</s:div>
<s:div rendered="#{testStepResult.getResponseValidation() == null}">
<h:commandLink actionListener="#{testStepResult.validateResponse()}"
......@@ -171,8 +171,12 @@
<gri:panel>
<f:facet name="header">
<h:outputText value="Request"/>
<h:commandLink action="#{testStepResult.downloadRequest()}">
<s:span title="Download file" styleClass="gzl-icon-download text-info"/>
</h:commandLink>
</f:facet>
<s:decorate template="/layout/display/_display.xhtml">
<ui:define name="label">EVS Validation</ui:define>
<h:outputText value="#{testStepResult.getRequestValidation().validationStatus}"
......@@ -193,7 +197,8 @@
<s:decorate template="/layout/display/_display.xhtml"
rendered="#{testStepResult.getRequestValidation() != null}">
<ui:define name="label">EVS Validation permanent link</ui:define>
<h:outputLink value="#{testStepResult.getRequestValidation().permanentLink}" target="_blank">
<h:outputLink value="#{testStepResult.getRequestValidation().permanentLink}"
target="_blank">
<h:outputText value="#{testStepResult.getRequestValidation().permanentLink}"/>
</h:outputLink>
</s:decorate>
......@@ -209,6 +214,9 @@
<gri:panel>
<f:facet name="header">
<h:outputText value="Response"/>
<h:commandLink action="#{testStepResult.downloadResponse()}">
<s:span title="Download file" styleClass="gzl-icon-download text-info"/>
</h:commandLink>
</f:facet>
<s:decorate template="/layout/display/_display.xhtml">
......@@ -231,7 +239,8 @@
<s:decorate template="/layout/display/_display.xhtml"
rendered="#{testStepResult.getResponseValidation() != null}">
<ui:define name="label">EVS Validation permanent link</ui:define>
<h:outputLink value="#{testStepResult.getResponseValidation().permanentLink}" target="_blank">
<h:outputLink value="#{testStepResult.getResponseValidation().permanentLink}"
target="_blank">
<h:outputText value="#{testStepResult.getResponseValidation().permanentLink}"/>
</h:outputLink>
</s:decorate>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment