From c267087364754da68f7282688832711076ea789e Mon Sep 17 00:00:00 2001 From: "Niels Erik G. Nielsen" Date: Tue, 5 Mar 2013 11:41:26 -0500 Subject: [PATCH] Fixes support for posting pz2 service definition xml --- src/META-INF/context.xml | 2 -- .../indexdata/pz2utils4jsf/config/Pz2Config.java | 26 ++++++++++++++------ .../config/Pz2ConfigureByMk2Config.java | 8 +++--- .../pz2utils4jsf/config/Pz2ConfigureByWebXml.java | 10 +++++--- 4 files changed, 28 insertions(+), 18 deletions(-) diff --git a/src/META-INF/context.xml b/src/META-INF/context.xml index c4ecc5d..3fc49fe 100644 --- a/src/META-INF/context.xml +++ b/src/META-INF/context.xml @@ -4,6 +4,4 @@ auth="Container" type="javax.enterprise.inject.spi.BeanManager" factory="org.jboss.weld.resources.ManagerObjectFactory"/> - \ No newline at end of file diff --git a/src/main/java/com/indexdata/pz2utils4jsf/config/Pz2Config.java b/src/main/java/com/indexdata/pz2utils4jsf/config/Pz2Config.java index fc3c538..b3a92e1 100644 --- a/src/main/java/com/indexdata/pz2utils4jsf/config/Pz2Config.java +++ b/src/main/java/com/indexdata/pz2utils4jsf/config/Pz2Config.java @@ -1,5 +1,6 @@ package com.indexdata.pz2utils4jsf.config; +import java.io.IOException; import java.io.Serializable; import java.util.HashMap; import java.util.Map; @@ -7,6 +8,7 @@ import java.util.Map; import org.apache.log4j.Logger; import com.indexdata.masterkey.config.MissingMandatoryParameterException; +import com.indexdata.masterkey.config.ModuleConfiguration; import com.indexdata.masterkey.config.ModuleConfigurationGetter; public class Pz2Config implements ModuleConfigurationGetter, Serializable { @@ -14,19 +16,27 @@ public class Pz2Config implements ModuleConfigurationGetter, Serializable { private static final long serialVersionUID = -6801241975338182197L; private static Logger logger = Logger.getLogger(Pz2Config.class); Map properties = new HashMap(); + ModuleConfiguration moduleConfig = null; public Pz2Config () { - setStatics(); + setDefaults(); } - public Pz2Config (String pazpar2Url, String pazpar2ServiceId) { - setStatics(); - setPazpar2Url(pazpar2Url); - setPazpar2ServiceId(pazpar2ServiceId); - logger.debug("Creating pazpar2 configuration with "+ get("PAZPAR2_URL") + " and " + get("PAZPAR2_SERVICE_ID")); + public Pz2Config (Map parameters) { + setDefaults(); + for (String key : parameters.keySet()) { + properties.put(key, parameters.get(key)); + } + } + + public Pz2Config (ModuleConfiguration moduleConfig) throws IOException { + this.moduleConfig = moduleConfig; + for (String key : moduleConfig.getConfigMap().keySet()) { + properties.put(key, moduleConfig.getConfigParameter(key)); + } } - private void setStatics () { + private void setDefaults () { properties.put("PROXY_MODE","1"); properties.put("SERIALIZE_REQUESTS", "false"); properties.put("STREAMBUFF_SIZE", "4096"); @@ -69,7 +79,7 @@ public class Pz2Config implements ModuleConfigurationGetter, Serializable { @Override public String getConfigFilePath() { - return null; + return moduleConfig.getConfigFilePath(); } diff --git a/src/main/java/com/indexdata/pz2utils4jsf/config/Pz2ConfigureByMk2Config.java b/src/main/java/com/indexdata/pz2utils4jsf/config/Pz2ConfigureByMk2Config.java index 91cc08e..b4859b3 100644 --- a/src/main/java/com/indexdata/pz2utils4jsf/config/Pz2ConfigureByMk2Config.java +++ b/src/main/java/com/indexdata/pz2utils4jsf/config/Pz2ConfigureByMk2Config.java @@ -28,11 +28,9 @@ public class Pz2ConfigureByMk2Config implements Pz2Configurator { ServletContext servletContext = (ServletContext) externalContext.getContext(); MasterkeyConfiguration mkConfigContext = MasterkeyConfiguration.getInstance(servletContext, - "faces-component", ((HttpServletRequest) externalContext.getRequest()).getServerName()); - ModuleConfiguration moduleConfig = mkConfigContext.getModuleConfiguration("pz2client"); - String pazpar2Url = moduleConfig.get("PAZPAR2_URL"); - String pazpar2ServiceId = moduleConfig.get("PAZPAR2_SERVICE_ID"); - pz2config = new Pz2Config(pazpar2Url,pazpar2ServiceId); + "pazpar-application-jsf", ((HttpServletRequest) externalContext.getRequest()).getServerName()); + ModuleConfiguration moduleConfig = mkConfigContext.getModuleConfiguration("pz2client"); + pz2config = new Pz2Config(moduleConfig); } @Override diff --git a/src/main/java/com/indexdata/pz2utils4jsf/config/Pz2ConfigureByWebXml.java b/src/main/java/com/indexdata/pz2utils4jsf/config/Pz2ConfigureByWebXml.java index 3c6223f..72c5d75 100644 --- a/src/main/java/com/indexdata/pz2utils4jsf/config/Pz2ConfigureByWebXml.java +++ b/src/main/java/com/indexdata/pz2utils4jsf/config/Pz2ConfigureByWebXml.java @@ -1,5 +1,8 @@ package com.indexdata.pz2utils4jsf.config; +import java.util.HashMap; +import java.util.Map; + import javax.enterprise.context.SessionScoped; import javax.enterprise.inject.Alternative; import javax.faces.context.ExternalContext; @@ -21,9 +24,10 @@ public class Pz2ConfigureByWebXml implements Pz2Configurator { logger.debug("Instantiating Pazpar2 service configuration by web.xml parameters"); ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext(); ServletContext servletContext = (ServletContext) externalContext.getContext(); - String pazpar2Url = servletContext.getInitParameter("PAZPAR2_URL"); - String pazpar2ServiceId = servletContext.getInitParameter("PAZPAR2_SERVICE_ID"); - config = new Pz2Config(pazpar2Url,pazpar2ServiceId); + Map parameters = new HashMap(); + parameters.put("PAZPAR2_URL", servletContext.getInitParameter("PAZPAR2_URL")); + parameters.put("PAZPAR2_SERVICE_ID", servletContext.getInitParameter("PAZPAR2_SERVICE_ID")); + config = new Pz2Config(parameters); } @Override -- 1.7.10.4