diff --git a/gazelle-proxy-common-war/src/main/webapp/messages/commonDownload.xhtml b/gazelle-proxy-common-war/src/main/webapp/messages/commonDownload.xhtml index bbb85eb97b8892fffccb5484a0f34572d2c8628b..d3e8c363c8f8e3c4275f9938314f3f3984308e71 100644 --- a/gazelle-proxy-common-war/src/main/webapp/messages/commonDownload.xhtml +++ b/gazelle-proxy-common-war/src/main/webapp/messages/commonDownload.xhtml @@ -87,7 +87,7 @@ <rich:spacer width="10" /> <h:form> <h:commandLink - action="#{messageBean.validate(messageBean.message.id)}" + action="#{messageBean.validate()}" target="_blank"> <h:graphicImage value="/img/validate.gif" title="#{messages['net.ihe.gazelle.proxy.ValidateUsingEVSClient']}" diff --git a/gazelle-proxy-jar/pom.xml b/gazelle-proxy-jar/pom.xml index 4d98fa1da8227e8ece9ceadc4a0b8302cf017e1b..9c4b5c7071d1215e280b1a718b2cef674f78f4ad 100644 --- a/gazelle-proxy-jar/pom.xml +++ b/gazelle-proxy-jar/pom.xml @@ -63,11 +63,6 @@ <artifactId>gazelle-seam-tools-jar</artifactId> <type>ejb</type> </dependency> - <dependency> - <groupId>apache-httpclient</groupId> - <artifactId>commons-httpclient</artifactId> - <version>3.1</version> - </dependency> <dependency> <groupId>net.ihe.gazelle.proxy</groupId> <artifactId>gazelle-proxy-netty</artifactId> @@ -170,20 +165,18 @@ <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> </dependency> - - <!-- REST client --> - <dependency> - <groupId>org.jboss.resteasy</groupId> - <artifactId>resteasy-jaxrs</artifactId> - <version>${version.resteasy}</version> - </dependency> <dependency> <groupId>javax.jms</groupId> <artifactId>jms</artifactId> - <version>1.1</version> <scope>provided</scope> </dependency> + <dependency> + <groupId>net.ihe.gazelle</groupId> + <artifactId>gazelle-evsclient-connector</artifactId> + <version>1.0.0-SNAPSHOT</version> + <type>jar</type> + </dependency> </dependencies> </project> \ No newline at end of file diff --git a/gazelle-proxy-jar/src/main/java/net/ihe/gazelle/proxy/gui/MessageBean.java b/gazelle-proxy-jar/src/main/java/net/ihe/gazelle/proxy/gui/MessageBean.java index c62099af838404b53040d9b334468842d852ac8e..9505d722e3a4d850af98e522fd37d95a30300253 100644 --- a/gazelle-proxy-jar/src/main/java/net/ihe/gazelle/proxy/gui/MessageBean.java +++ b/gazelle-proxy-jar/src/main/java/net/ihe/gazelle/proxy/gui/MessageBean.java @@ -6,7 +6,6 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.Serializable; -import java.net.URLEncoder; import java.sql.Timestamp; import java.util.ArrayList; import java.util.List; @@ -19,6 +18,8 @@ import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import net.ihe.gazelle.evsclient.connector.api.EVSClientResults; +import net.ihe.gazelle.evsclient.connector.api.EVSClientServletConnector; import net.ihe.gazelle.hql.providers.EntityManagerService; import net.ihe.gazelle.proxy.admin.gui.ApplicationConfigurationManager; import net.ihe.gazelle.proxy.admin.gui.ApplicationConfigurationManagerLocal; @@ -36,22 +37,10 @@ import org.apache.commons.exec.CommandLine; import org.apache.commons.exec.DefaultExecutor; import org.apache.commons.exec.ExecuteException; import org.apache.commons.exec.PumpStreamHandler; -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.io.IOUtils; import org.apache.commons.lang.StringEscapeUtils; import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; -import org.jboss.resteasy.client.ClientExecutor; -import org.jboss.resteasy.client.ClientRequest; -import org.jboss.resteasy.client.ClientResponse; -import org.jboss.resteasy.client.core.executors.URLConnectionClientExecutor; import org.jboss.seam.Component; import org.jboss.seam.ScopeType; import org.jboss.seam.annotations.In; @@ -72,8 +61,6 @@ public class MessageBean implements Serializable { private static final Logger log = Logger.getLogger(MessageBean.class); - private static final ClientExecutor CLIENT_EXECUTOR = new URLConnectionClientExecutor(); - @In private EntityManager entityManager; @@ -89,6 +76,8 @@ public class MessageBean implements Serializable { private AbstractMessage message; + private String validatorUrl; + public AbstractMessage getMessage() { return message; } @@ -340,52 +329,11 @@ public class MessageBean implements Serializable { return "<pre>" + result + "</pre>"; } - public void validate(String proxyId) { - // First send the file to EVSClient - HttpClient client = new HttpClient(); - PostMethod filePost = new PostMethod(ApplicationConfigurationManager.instance().getEvsClientUrl() + "upload"); - - // use the type as file name - String messageType = message.getChannelType().name(); - PartSource partSource = null; - if (!messageType.equals("DICOM")) { - // encode byte before send it to EVS - byte[] bytes = message.getMessageReceived(); - bytes = Base64.encodeBase64(bytes); - - partSource = new ByteArrayPartSource(messageType, bytes); - } else { - partSource = message.getPartSource(messageType); - } - 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(); - } - // get the OID which uniquely identified the instance of the proxy + public void validate() { ApplicationConfigurationManagerLocal manager = ApplicationConfigurationManager.instance(); - String proxyOid = manager.getProxyOid(); - log.info("proxyId : " + proxyId); - // redirect the user to the good page - if (status == HttpStatus.SC_OK) { - try { - String key = filePost.getResponseBodyAsString(); - String encodedKey = URLEncoder.encode(key, "UTF-8"); - - HttpServletResponse response = (HttpServletResponse) extCtx.getResponse(); - // String url = Preferences.getProperty("evsclient.url") + "validate.seam?file=" + encodedKey; - String url = ApplicationConfigurationManager.instance().getEvsClientUrl() + "validate.seam?file=" - + encodedKey + "&externalId=" + proxyId + "&proxyType=" + messageType + "&toolOid=" + proxyOid; - - response.sendRedirect(url); - } catch (IOException e) { - log.error(e); - } - } + String evsClientUrl = manager.getEvsClientUrl(); + String toolOid = manager.getProxyOid(); + EVSClientServletConnector.sendToValidation(message, extCtx, evsClientUrl, toolOid); } public void intResult() { @@ -393,24 +341,19 @@ public class MessageBean implements Serializable { String oid = null; message = getMessage(); ArrayList<String> resultOidList = new ArrayList<String>(); - - if (urlParams != null && !urlParams.isEmpty()) { - if (urlParams.containsKey("oid")) { - String url = urlParams.get("oid"); - oid = Base64Decoding(url); - - if (message.getResultOid() != null) { - resultOidList = message.getResultOid(); - } - if (!(resultOidList.contains(oid))) { - resultOidList.add(oid); - message.setResultOid(resultOidList); - EntityManager entityManager = (EntityManager) Component.getInstance("entityManager"); - message = entityManager.merge(message); - entityManager.flush(); - } else { - log.error("This oid is already saved !"); - } + oid = EVSClientResults.getResultOidFromUrl(urlParams); + if (oid != null) { + if (message.getResultOid() != null) { + resultOidList = message.getResultOid(); + } + if (!(resultOidList.contains(oid))) { + resultOidList.add(oid); + message.setResultOid(resultOidList); + EntityManager entityManager = (EntityManager) Component.getInstance("entityManager"); + message = entityManager.merge(message); + entityManager.flush(); + } else { + log.error("This oid is already saved !"); } } } @@ -433,89 +376,16 @@ public class MessageBean implements Serializable { } } - public static String getValidationStatus(String oid) { - - // Chemin vers evs client - String validatorUrl = ApplicationConfigurationManager.instance().getEvsClientUrl(); // "http://192.168.20.100:8080/EVSClient/" - ClientRequest request = new ClientRequest(validatorUrl.concat("resteasy/GetValidationStatus"), CLIENT_EXECUTOR); - request.queryParameter("oid", oid); - ClientResponse<String> response = null; - try { - response = request.get(String.class); - if (response.getStatus() == 200 && response.getEntity() != null && !response.getEntity().isEmpty()) { - String validationStatus = response.getEntity(); - return validationStatus; - } else - return null; - } catch (Exception e) { - e.printStackTrace(); - return null; - } finally { - if (response != null) { - try { - response.releaseConnection(); - } catch (Exception e2) { - log.debug("Failed to release connection", e2); - } - } - } + public String getValidationStatus(String oid) { + return EVSClientResults.getValidationStatus(oid, getValidatorUrl()); } public String getValidationDate(String oid) { - - // Chemin vers evs client - String validatorUrl = ApplicationConfigurationManager.instance().getEvsClientUrl(); // "http://192.168.20.100:8080/EVSClient/" - ClientRequest request = new ClientRequest(validatorUrl.concat("resteasy/GetValidationDate"), CLIENT_EXECUTOR); - request.queryParameter("oid", oid); - ClientResponse<String> response = null; - try { - response = request.get(String.class); - if (response.getStatus() == 200 && response.getEntity() != null && !response.getEntity().isEmpty()) { - String validationDate = response.getEntity(); - return validationDate; - } else - return null; - } catch (Exception e) { - e.printStackTrace(); - return null; - } finally { - if (response != null) { - try { - response.releaseConnection(); - } catch (Exception e2) { - log.debug("Failed to release connection", e2); - } - } - } + return EVSClientResults.getValidationDate(oid, getValidatorUrl()); } - public static String getValidationPermanentLink(String oid) { - - // Chemin vers evs client - String validatorUrl = ApplicationConfigurationManager.instance().getEvsClientUrl(); // "http://192.168.20.100:8080/EVSClient/" - ClientRequest request = new ClientRequest(validatorUrl.concat("resteasy/GetValidationPermanentLink"), - CLIENT_EXECUTOR); - request.queryParameter("oid", oid); - ClientResponse<String> response = null; - try { - response = request.get(String.class); - if (response.getStatus() == 200 && response.getEntity() != null && !response.getEntity().isEmpty()) { - String validationPermanentLink = response.getEntity(); - return validationPermanentLink; - } else - return null; - } catch (Exception e) { - e.printStackTrace(); - return null; - } finally { - if (response != null) { - try { - response.releaseConnection(); - } catch (Exception e2) { - log.debug("Failed to release connection", e2); - } - } - } + public String getValidationPermanentLink(String oid) { + return EVSClientResults.getValidationPermanentLink(oid, getValidatorUrl()); } public String redirectToMessage(AbstractMessage message) { @@ -588,4 +458,11 @@ public class MessageBean implements Serializable { redirect.execute(); } + private String getValidatorUrl() { + if (this.validatorUrl == null) { + this.validatorUrl = ApplicationConfigurationManager.instance().getEvsClientUrl(); + } + return this.validatorUrl; + } + } diff --git a/gazelle-proxy-jar/src/main/java/net/ihe/gazelle/proxy/model/message/AbstractMessage.java b/gazelle-proxy-jar/src/main/java/net/ihe/gazelle/proxy/model/message/AbstractMessage.java index db7196beae0d0872a3ac22a21a629bcfa64bcf8a..0418654da1581f96547e85b426215a5b42f3c7ff 100644 --- a/gazelle-proxy-jar/src/main/java/net/ihe/gazelle/proxy/model/message/AbstractMessage.java +++ b/gazelle-proxy-jar/src/main/java/net/ihe/gazelle/proxy/model/message/AbstractMessage.java @@ -40,6 +40,8 @@ import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; +import net.ihe.gazelle.evsclient.connector.model.EVSClientValidatedObject; +import net.ihe.gazelle.evsclient.connector.utils.PartSourceUtils; import net.ihe.gazelle.proxy.netty.ChannelType; import net.ihe.gazelle.proxy.netty.channel.ProxySide; @@ -57,7 +59,7 @@ import org.slf4j.LoggerFactory; @Inheritance @DiscriminatorColumn(name = "pxy_abstract_message_type") @SequenceGenerator(name = "pxy_message_sequence", sequenceName = "pxy_message_id_seq", allocationSize = 1) -public abstract class AbstractMessage implements Comparable<AbstractMessage>, Serializable { +public abstract class AbstractMessage implements Comparable<AbstractMessage>, Serializable, EVSClientValidatedObject { private static Logger log = LoggerFactory.getLogger(AbstractMessage.class); @@ -145,6 +147,11 @@ public abstract class AbstractMessage implements Comparable<AbstractMessage>, Se } public abstract ChannelType getChannelType(); + + @Override + public String getType() { + return getChannelType().name(); + } public void setMessageReceivedAsString(String messageReceived) { this.messageReceived = messageReceived.getBytes(UTF_8); @@ -348,6 +355,16 @@ public abstract class AbstractMessage implements Comparable<AbstractMessage>, Se public PartSource getPartSource(String messageType) { return new ByteArrayPartSource(messageType, messageReceived); } + + @Override + public PartSource getPartSource(){ + return PartSourceUtils.buildEncoded64PartSource(messageReceived, getType()); + } + + @Override + public String getUniqueKey(){ + return Integer.toString(this.id); + } @Override public int compareTo(AbstractMessage o) { diff --git a/gazelle-proxy-jar/src/main/java/net/ihe/gazelle/proxy/model/message/DicomMessage.java b/gazelle-proxy-jar/src/main/java/net/ihe/gazelle/proxy/model/message/DicomMessage.java index 8cce5194ede42e1965ee0797115a866fbd945d5f..0324c80e017482eb5f705a6c9419a4ad5682018a 100644 --- a/gazelle-proxy-jar/src/main/java/net/ihe/gazelle/proxy/model/message/DicomMessage.java +++ b/gazelle-proxy-jar/src/main/java/net/ihe/gazelle/proxy/model/message/DicomMessage.java @@ -378,5 +378,10 @@ public class DicomMessage extends AbstractMessage implements java.io.Serializabl return null; } } + + @Override + public PartSource getPartSource() { + return getPartSource(getType()); + } }