From f6aeca948562e306d8f3cd4359a7ec442c1704fc Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Thu, 7 Dec 2017 09:53:05 -0400 Subject: [PATCH 1/7] Add additional parameter parsing. --- .../fedoragsearch/server/GTransformer.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/FedoraGenericSearch/src/java/dk/defxws/fedoragsearch/server/GTransformer.java b/FedoraGenericSearch/src/java/dk/defxws/fedoragsearch/server/GTransformer.java index 75b85cc..5eede5f 100644 --- a/FedoraGenericSearch/src/java/dk/defxws/fedoragsearch/server/GTransformer.java +++ b/FedoraGenericSearch/src/java/dk/defxws/fedoragsearch/server/GTransformer.java @@ -14,6 +14,8 @@ import java.net.URL; import java.util.Date; +import java.util.Map; +import java.util.Properties; import javax.xml.transform.Source; import javax.xml.transform.Transformer; @@ -52,6 +54,20 @@ public class GTransformer { private static final Logger logger = Logger.getLogger(GTransformer.class); + + static protected final Properties customProperties = new Properties(); + static protected boolean customPropertiesLoaded = false; + + static { + try { + customProperties.load(Config.class.getResourceAsStream("custom_parameters.properties")); + customPropertiesLoaded = true; + } + catch (IOException no_load) { + logger.debug("Failed to load custom_parameters.properties... It may either not exist or be unreadable.", no_load); + } + } + int debuglength = 500; public GTransformer() { @@ -175,6 +191,14 @@ public StringBuffer transform(String xsltName, Source sourceStream, URIResolver transformer.setParameter((String)params[i], value); } transformer.setParameter("DATETIME", new Date()); + + if (customPropertiesLoaded) { + for (Map.Entry i: customProperties.entrySet()) { + final String name = (String) i.getKey(); + transformer.setParameter(name, i.getValue()); + } + } + StreamResult destStream = new StreamResult(new StringWriter()); try { transformer.transform(sourceStream, destStream); From 6679bdbf2dcbe13cb353de6af14550c297393973 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Thu, 7 Dec 2017 12:04:15 -0400 Subject: [PATCH 2/7] Avoid whitescreening... actual error pages, huzzah! --- .../dk/defxws/fedoragsearch/server/RESTImpl.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/FedoraGenericSearch/src/java/dk/defxws/fedoragsearch/server/RESTImpl.java b/FedoraGenericSearch/src/java/dk/defxws/fedoragsearch/server/RESTImpl.java index 958b687..20ef464 100644 --- a/FedoraGenericSearch/src/java/dk/defxws/fedoragsearch/server/RESTImpl.java +++ b/FedoraGenericSearch/src/java/dk/defxws/fedoragsearch/server/RESTImpl.java @@ -24,6 +24,7 @@ import org.apache.log4j.Appender; import org.apache.log4j.Logger; +import dk.defxws.fedoragsearch.server.errors.ConfigException; import dk.defxws.fedoragsearch.server.errors.GenericSearchException; /** @@ -110,12 +111,13 @@ public void doGet(HttpServletRequest request, HttpServletResponse response) logger.debug("logger appender name="+appender.getName()); } } + StringBuffer resultXml = new StringBuffer(""); + try { config = Config.getCurrentConfig(); if (configName!=null && !"configure".equals(operation)) { // mainly for test purposes config = Config.getConfig(configName); } - StringBuffer resultXml = new StringBuffer(""); repositoryName = request.getParameter(PARAM_REPOSITORYNAME); if (repositoryName==null) repositoryName=""; indexName = request.getParameter(PARAM_INDEXNAME); @@ -197,6 +199,15 @@ public void doGet(HttpServletRequest request, HttpServletResponse response) resultXml, params, getServletContext().getRealPath("/WEB-INF/classes")); } + if (logger.isInfoEnabled()) + logger.info("request="+request.getQueryString()+" timeusedms="+timeusedms); + } catch (ConfigException config_ex) { + resultXml = new StringBuffer(""); + resultXml.append(""); + resultXml.append(""); + logger.error(config_ex); + config_ex.printStackTrace(); + } // if (logger.isDebugEnabled()) // logger.debug("after "+restXslt+" result=\n"+resultXml); @@ -209,8 +220,7 @@ public void doGet(HttpServletRequest request, HttpServletResponse response) response.getOutputStream(), "UTF-8")); out.print(resultXml); out.close(); - if (logger.isInfoEnabled()) - logger.info("request="+request.getQueryString()+" timeusedms="+timeusedms); + } private String gfindObjects(HttpServletRequest request, HttpServletResponse response) From 3f402c6e1bc66e4f066f17a594c955721ad99207 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Thu, 7 Dec 2017 12:08:35 -0400 Subject: [PATCH 3/7] Move error bit around, change slightly. --- .../dk/defxws/fedoragsearch/server/RESTImpl.java | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/FedoraGenericSearch/src/java/dk/defxws/fedoragsearch/server/RESTImpl.java b/FedoraGenericSearch/src/java/dk/defxws/fedoragsearch/server/RESTImpl.java index 20ef464..ed711df 100644 --- a/FedoraGenericSearch/src/java/dk/defxws/fedoragsearch/server/RESTImpl.java +++ b/FedoraGenericSearch/src/java/dk/defxws/fedoragsearch/server/RESTImpl.java @@ -201,16 +201,6 @@ public void doGet(HttpServletRequest request, HttpServletResponse response) } if (logger.isInfoEnabled()) logger.info("request="+request.getQueryString()+" timeusedms="+timeusedms); - } catch (ConfigException config_ex) { - resultXml = new StringBuffer(""); - resultXml.append(""); - resultXml.append(""); - logger.error(config_ex); - config_ex.printStackTrace(); - } -// if (logger.isDebugEnabled()) -// logger.debug("after "+restXslt+" result=\n"+resultXml); - if (restXslt.indexOf(CONTENTTYPEHTML)>=0) response.setContentType("text/html; charset=UTF-8"); else @@ -220,7 +210,9 @@ public void doGet(HttpServletRequest request, HttpServletResponse response) response.getOutputStream(), "UTF-8")); out.print(resultXml); out.close(); - + } catch (ConfigException config_ex) { + response.sendError(500, config_ex.getMessage()); + } } private String gfindObjects(HttpServletRequest request, HttpServletResponse response) From 5bb64440d56d54bb5654625f181b3e6dde90923f Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Thu, 7 Dec 2017 14:09:50 -0400 Subject: [PATCH 4/7] Avoid a NullPointerException. --- .../src/java/dk/defxws/fedoragsearch/server/Config.java | 1 + 1 file changed, 1 insertion(+) diff --git a/FedoraGenericSearch/src/java/dk/defxws/fedoragsearch/server/Config.java b/FedoraGenericSearch/src/java/dk/defxws/fedoragsearch/server/Config.java index 3e3d212..6f3e9b2 100644 --- a/FedoraGenericSearch/src/java/dk/defxws/fedoragsearch/server/Config.java +++ b/FedoraGenericSearch/src/java/dk/defxws/fedoragsearch/server/Config.java @@ -713,6 +713,7 @@ private void checkStylesheet(String configPath) { transformer = tfactory.newTransformer(xslt); } catch (TransformerConfigurationException e) { errors.append("\n*** Stylesheet "+configPath+" error:\n"+e.toString()); + return; } String testSource = "\n"+ ""; From 7146887688b96b6c63a2a2a180f3f0ef00f0eb76 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Thu, 7 Dec 2017 14:10:50 -0400 Subject: [PATCH 5/7] Fix property handling. --- .../fedoragsearch/server/GTransformer.java | 35 +++++++++---------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/FedoraGenericSearch/src/java/dk/defxws/fedoragsearch/server/GTransformer.java b/FedoraGenericSearch/src/java/dk/defxws/fedoragsearch/server/GTransformer.java index 5eede5f..fbf88cf 100644 --- a/FedoraGenericSearch/src/java/dk/defxws/fedoragsearch/server/GTransformer.java +++ b/FedoraGenericSearch/src/java/dk/defxws/fedoragsearch/server/GTransformer.java @@ -55,19 +55,6 @@ public class GTransformer { private static final Logger logger = Logger.getLogger(GTransformer.class); - static protected final Properties customProperties = new Properties(); - static protected boolean customPropertiesLoaded = false; - - static { - try { - customProperties.load(Config.class.getResourceAsStream("custom_parameters.properties")); - customPropertiesLoaded = true; - } - catch (IOException no_load) { - logger.debug("Failed to load custom_parameters.properties... It may either not exist or be unreadable.", no_load); - } - } - int debuglength = 500; public GTransformer() { @@ -191,13 +178,25 @@ public StringBuffer transform(String xsltName, Source sourceStream, URIResolver transformer.setParameter((String)params[i], value); } transformer.setParameter("DATETIME", new Date()); - - if (customPropertiesLoaded) { - for (Map.Entry i: customProperties.entrySet()) { - final String name = (String) i.getKey(); - transformer.setParameter(name, i.getValue()); + + final Properties customProperties = new Properties(); + try { + final String path = String.format("/%s/%s", (new File(xsltName)).getParent(), "custom_parameters.properties"); + final InputStream customParameterStream = this.getClass().getResourceAsStream(path); + if (customParameterStream == null) { + logger.debug(String.format("The %s file does not exist.", path)); + } + else { + customProperties.load(customParameterStream); + for (final Map.Entry i: customProperties.entrySet()) { + final String name = (String) i.getKey(); + transformer.setParameter(name, i.getValue()); + } } } + catch (IOException no_load) { + logger.debug("Failed to load custom_parameters.properties... It may either not exist or be unreadable.", no_load); + } StreamResult destStream = new StreamResult(new StringWriter()); try { From 631de37443791a6a2408f4ca75b2ac310d8eb026 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Thu, 7 Dec 2017 14:11:51 -0400 Subject: [PATCH 6/7] Bump version. --- FedoraGenericSearch/build.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FedoraGenericSearch/build.xml b/FedoraGenericSearch/build.xml index 0c6795b..5152c5c 100644 --- a/FedoraGenericSearch/build.xml +++ b/FedoraGenericSearch/build.xml @@ -36,7 +36,7 @@ - + From 193be31b71f07edd9e1f5f6b3a932dcb872660ec Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Fri, 8 Dec 2017 09:49:34 -0400 Subject: [PATCH 7/7] "Real" semantic versioning... Had forgotten exact difference between minor and patch. --- FedoraGenericSearch/build.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FedoraGenericSearch/build.xml b/FedoraGenericSearch/build.xml index 5152c5c..5152093 100644 --- a/FedoraGenericSearch/build.xml +++ b/FedoraGenericSearch/build.xml @@ -36,7 +36,7 @@ - +