Mentions légales du service

Skip to content
Snippets Groups Projects
Commit c16d5f85 authored by Gabriel Landais's avatar Gabriel Landais
Browse files

Proxy <-> EVSClient

git-svn-id: https://scm.gforge.inria.fr/authscm/ycadoret/svn/gazelle/Maven/gazelle-proxy/trunk@20890 356b4b1a-1d2b-0410-8bf1-ffa24008f01e
parent 0ad23a85
No related branches found
No related tags found
No related merge requests found
......@@ -113,5 +113,12 @@
<groupId>net.ihe.gazelle.simulators.tls</groupId>
<artifactId>TLSSimulator-pki-jar</artifactId>
</dependency>
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
</dependency>
</dependencies>
</project>
package net.ihe.gazelle.proxy.action;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.Map;
import javax.faces.context.ExternalContext;
......@@ -14,8 +16,16 @@ import net.ihe.gazelle.proxy.model.message.AbstractMessage;
import net.ihe.gazelle.proxy.model.message.HL7Message;
import net.ihe.gazelle.proxy.model.message.HTTPMessage;
import net.ihe.gazelle.proxy.model.message.SyslogMessage;
import org.apache.commons.lang.ArrayUtils;
import net.ihe.gazelle.proxy.util.Preferences;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.multipart.ByteArrayPartSource;
import org.apache.commons.httpclient.methods.multipart.FilePart;
import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
import org.apache.commons.httpclient.methods.multipart.Part;
import org.apache.commons.httpclient.methods.multipart.PartSource;
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.tika.mime.MediaType;
import org.jboss.seam.ScopeType;
......@@ -104,7 +114,7 @@ public class MessageBean {
public void downloadFile(boolean inline) {
try {
HttpServletResponse response = (HttpServletResponse) extCtx.getResponse();
byte[] bytes = ArrayUtils.clone(message.getMessageReceived());
byte[] bytes = message.getMessageReceived();
ServletOutputStream servletOutputStream = response.getOutputStream();
response.setContentType("text/plain");
response.setContentLength(bytes.length);
......@@ -157,4 +167,38 @@ public class MessageBean {
String result = StringEscapeUtils.escapeHtml(source);
return "<pre>" + result + "</pre>";
}
public void validate() {
// First send the file to EVSClient
HttpClient client = new HttpClient();
PostMethod filePost = new PostMethod(Preferences.getProperty("evsclient.url") + "upload");
PartSource partSource = new ByteArrayPartSource("message", message.getMessageReceived());
Part[] parts = { new FilePart("message", partSource) };
filePost.setRequestEntity(new MultipartRequestEntity(parts, filePost.getParams()));
int status = -1;
try {
status = client.executeMethod(filePost);
} catch (Exception e) {
status = -1;
e.printStackTrace();
}
// redirect the user to the good page
boolean fail = false;
if (status == HttpStatus.SC_OK) {
try {
String fileName = filePost.getResponseBodyAsString();
String encodedFileName = URLEncoder.encode(fileName, "UTF-8");
HttpServletResponse response = (HttpServletResponse) extCtx.getResponse();
String url = Preferences.getProperty("evsclient.url") + "validate.seam?filename=" + encodedFileName;
response.sendRedirect(url);
} catch (IOException e) {
fail = true;
e.printStackTrace();
}
} else {
fail = true;
}
}
}
package net.ihe.gazelle.proxy.util;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class Preferences {
private static Properties preferences;
private static Object preferencesSync = new Object();
private Preferences() {
super();
// private!
}
public static String getProperty(String key) {
return getPreferences().getProperty(key);
}
private static Properties getPreferences() {
if (preferences == null) {
synchronized (preferencesSync) {
if (preferences == null) {
preferences = new Properties();
InputStream preferencesStream = Preferences.class.getResourceAsStream("/prefs.properties");
try {
preferences.load(preferencesStream);
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
return preferences;
}
}
evsclient.url=${evsclient.url}
......@@ -12,12 +12,18 @@
<h:commandLink action="#{messageBean.downloadFile(true)}"
rendered="#{messageBean.isDownloadable()}" value="View inline"
target="_blank" />
<br />
<rich:spacer height="10" rendered="#{messageBean.isDownloadable()}" />
<h:commandLink action="#{messageBean.validate()}"
rendered="#{messageBean.isDownloadable()}"
value="Validate using EVSClient" target="_blank" />
<rich:spacer height="10" />
<div style="font-family: monospace;"><rich:insert
rendered="#{messageBean.shouldDisplayMessageContent()}"
content="#{messageBean.message.getMessageReceivedAsString()}"
highlight="xml" /></div>
<div style="font-family: monospace;">
<rich:insert rendered="#{messageBean.shouldDisplayMessageContent()}"
content="#{messageBean.message.getMessageReceivedAsString()}"
highlight="xml" />
</div>
</ui:composition>
\ No newline at end of file
......@@ -201,6 +201,7 @@
</activation>
<properties>
<cas.service>http://127.0.0.1:8080/proxy/</cas.service>
<evsclient.url>http://127.0.0.1:8080/EVSClient/</evsclient.url>
<!-- development mode (disable in production) -->
<seam.debug>true</seam.debug>
......@@ -245,6 +246,7 @@
<properties>
<cas.service>http://gazelle.ihe.net/proxy/</cas.service>
<evsclient.url>http://gazelle.ihe.net/EVSClient/</evsclient.url>
<!-- development mode (disable in production) -->
<seam.debug>false</seam.debug>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment