Loading data-discovery/src/main/java/webapi/SearchServlet.java +1 −0 Original line number Diff line number Diff line Loading @@ -102,6 +102,7 @@ public class SearchServlet extends javax.servlet.http.HttpServlet FormatResponseWrapper responseWrapper = (FormatResponseWrapper) response; responseWrapper.setPubdidArr(pubdidArr); responseWrapper.setDBConn(settings.dbConn); } else { Loading data-discovery/src/main/java/webapi/formatfilter/FormatResponseFilter.java +8 −12 Original line number Diff line number Diff line Loading @@ -32,7 +32,6 @@ public class FormatResponseFilter implements Filter public void init(FilterConfig filterConfig) throws ServletException { LOGGER.config("Default charset: " + Charset.defaultCharset()); LOGGER.config("DB: " + settings.dbConn.toString()); } public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) Loading @@ -42,10 +41,9 @@ public class FormatResponseFilter implements Filter LOGGER.fine("REQUEST START"); final String RESPONSE_ENCODING = "UTF-8"; final String DEFAULT_RESPONSEFORMAT = settings.defaults.responseFormat; final String DEFAULT_SKY_SYSTEM = settings.defaults.skySystem; final String DEFAULT_SPEC_SYSTEM = settings.defaults.specSystem; final String DEFAULT_TIME_SYSTEM = "MJD_UTC"; // FIXME take from confif file final String DEFAULT_RESPONSEFORMAT = "application/x-votable+xml"; final String DEFAULT_SKY_SYSTEM = "ICRS"; // FIXME use enums final String DEFAULT_SPEC_SYSTEM = "WAVE_Barycentric";// FIXME use enum ALSO in SearchServlet FormatResponseWrapper responseWrapper = new FormatResponseWrapper((HttpServletResponse) response); Loading @@ -66,7 +64,7 @@ public class FormatResponseFilter implements Filter Pos pos = Pos.parsePos(params, DEFAULT_SKY_SYSTEM); Band band = Band.parseBand(params, DEFAULT_SPEC_SYSTEM); DbPSearch.ObsCore[] obsCoreArr = queryObsCore(pubdidArr, pos, band); DbPSearch.ObsCore[] obsCoreArr = queryObsCore(responseWrapper.getDBConn(), pubdidArr, pos, band); String respFormat; String respFormatReq[] = params.get("RESPONSEFORMAT"); Loading @@ -77,8 +75,7 @@ public class FormatResponseFilter implements Filter } else { respFormat = settings.serviceUrls.responseFormat(); LOGGER.finest("responseFormat(from settings): " + respFormat); respFormat = DEFAULT_RESPONSEFORMAT; } response.setCharacterEncoding(RESPONSE_ENCODING); Loading Loading @@ -148,14 +145,13 @@ public class FormatResponseFilter implements Filter LOGGER.fine("REQUEST END"); } //@Override public void destroy() { LOGGER.fine("trace"); } private DbPSearch.ObsCore[] queryObsCore(String[] pubdidArr, Pos pos, Band band) private DbPSearch.ObsCore[] queryObsCore(DBConn dbConn, String[] pubdidArr, Pos pos, Band band) throws Exception { Loading @@ -164,7 +160,7 @@ public class FormatResponseFilter implements Filter DbPSearch dbps; synchronized(DbPSearch.class) { dbps = new DbPSearch(settings.dbConn); dbps = new DbPSearch(dbConn); } return dbps.queryOutputData(pubdidArr, pos, band); Loading data-discovery/src/main/java/webapi/formatfilter/FormatResponseSettings.java +9 −85 Original line number Diff line number Diff line import java.util.logging.Logger; import java.io.IOException; import java.io.InputStream; import java.util.Properties; import java.io.PrintWriter; class FormatResponseSettings { //private static final Logger LOGGER = Logger.getLogger("FormatResponseSettings"); public static class DefaultParamValues { String responseFormat; String skySystem; String specSystem; boolean showDuration; } /* public static class DBConn { private String uri; private String schema; private String user_name; private String password; public String uri() {return uri;} public String schema() {return schema;} public String userName() {return user_name;} public String password() {return password;} public String toString() { return uri + " schema[" + schema + "] " + user_name + " / " + password; } } */ public static class ServiceUrls { private String cutoutUrl; private String mergeUrl; private String surveysAbsPathname; private String respFormat; public boolean cutoutUrlIsSet() { return (cutoutUrl != null) && cutoutUrl.trim().isEmpty(); } public boolean mergeUrlIsSet() { return (mergeUrl != null) && mergeUrl.trim().isEmpty(); } public boolean surveysAbsPathnameIsSet() { return (surveysAbsPathname != null) && surveysAbsPathname.trim().isEmpty(); } public boolean responseFormatIsSet() { return (respFormat != null) && respFormat.trim().isEmpty(); } public String cutoutUrl() {return cutoutUrl;} public String mergeUrl() {return mergeUrl;} public String surveysAbsPathname() {return surveysAbsPathname;} public String responseFormat() {return respFormat;} public String toString() { return cutoutUrl + " " + mergeUrl + " " + surveysAbsPathname + " " + respFormat; return cutoutUrl + " " + mergeUrl; } } public DBConn dbConn; public ServiceUrls serviceUrls; public DefaultParamValues defaults; // will not start without config-file; no reasonable code-defaults can be invented public static FormatResponseSettings getInstance(String settingsFileName) { try Loading @@ -81,17 +34,14 @@ class FormatResponseSettings Properties properties = new Properties(); properties.load(ins); DBConn dbConn = loadDBConn(properties); ServiceUrls serviceUrls = loadServiceUrls(properties); DefaultParamValues defaults = loadDefaults(properties); return new FormatResponseSettings(dbConn, serviceUrls, defaults); return new FormatResponseSettings(serviceUrls); } else { throw new IllegalStateException(settingsFileName + " not found in classpath"); } } catch(IOException ex) { Loading @@ -99,48 +49,22 @@ class FormatResponseSettings } } private FormatResponseSettings(DBConn dbConn, ServiceUrls serviceUrls, DefaultParamValues defaults) { this.dbConn = dbConn; this.serviceUrls = serviceUrls; this.defaults = defaults; } private static DBConn loadDBConn(Properties properties) { DBConn dbConn = new DBConn(); dbConn.uri = properties.getProperty("db_uri","jdbc:postgresql://localhost:5432/vialactea").strip(); dbConn.schema = properties.getProperty("db_schema","datasets").strip(); dbConn.user_name = properties.getProperty("db_user_name","").strip(); dbConn.password = properties.getProperty("db_password","").strip(); return dbConn; } private static ServiceUrls loadServiceUrls(Properties properties) { ServiceUrls serviceUrls = new ServiceUrls(); serviceUrls.cutoutUrl = properties.getProperty("cutout_url","").strip(); serviceUrls.mergeUrl = properties.getProperty("merge_url","").strip(); serviceUrls.surveysAbsPathname = properties.getProperty("surveys_metadata_abs_pathname","/srv/surveys/surveys_metadata.csv").strip(); serviceUrls.respFormat = properties.getProperty("response_format","application/x-votable+xml").strip(); return serviceUrls; } private static DefaultParamValues loadDefaults(Properties properties) // instance public ServiceUrls serviceUrls; private FormatResponseSettings(ServiceUrls serviceUrls) { DefaultParamValues defaults = new DefaultParamValues(); defaults.responseFormat = properties.getProperty("default_response_format", "application/fits").strip(); defaults.skySystem = properties.getProperty("default_sky_system", "ICRS").strip(); defaults.specSystem = properties.getProperty("default_spec_system", "WAVE_Barycentric").strip(); defaults.showDuration = "yes".equals(properties.getProperty("show_duration", "no").strip()); return defaults; this.serviceUrls = serviceUrls; } } data-discovery/src/main/java/webapi/formatfilter/FormatResponseWrapper.java +6 −11 Original line number Diff line number Diff line Loading @@ -5,23 +5,18 @@ import javax.servlet.http.HttpServletResponseWrapper; class FormatResponseWrapper extends HttpServletResponseWrapper { // AuthPolicy auth; String[] pubdidArr; private String[] pubdidArr; private DBConn dbConn; public FormatResponseWrapper(HttpServletResponse response) { super(response); // auth = null; } public void setPubdidArr(String[] pubdidArr) { this.pubdidArr = pubdidArr; } public String[] getPubdidArr() { return this.pubdidArr; } /* public void setAuth(AuthPolicy auth) { // assert (this.search.inputs.auth != null); this.auth = auth; }*/ public void setDBConn(DBConn dbConn) { this.dbConn = dbConn; } public DBConn getDBConn() { return this.dbConn; } } Loading
data-discovery/src/main/java/webapi/SearchServlet.java +1 −0 Original line number Diff line number Diff line Loading @@ -102,6 +102,7 @@ public class SearchServlet extends javax.servlet.http.HttpServlet FormatResponseWrapper responseWrapper = (FormatResponseWrapper) response; responseWrapper.setPubdidArr(pubdidArr); responseWrapper.setDBConn(settings.dbConn); } else { Loading
data-discovery/src/main/java/webapi/formatfilter/FormatResponseFilter.java +8 −12 Original line number Diff line number Diff line Loading @@ -32,7 +32,6 @@ public class FormatResponseFilter implements Filter public void init(FilterConfig filterConfig) throws ServletException { LOGGER.config("Default charset: " + Charset.defaultCharset()); LOGGER.config("DB: " + settings.dbConn.toString()); } public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) Loading @@ -42,10 +41,9 @@ public class FormatResponseFilter implements Filter LOGGER.fine("REQUEST START"); final String RESPONSE_ENCODING = "UTF-8"; final String DEFAULT_RESPONSEFORMAT = settings.defaults.responseFormat; final String DEFAULT_SKY_SYSTEM = settings.defaults.skySystem; final String DEFAULT_SPEC_SYSTEM = settings.defaults.specSystem; final String DEFAULT_TIME_SYSTEM = "MJD_UTC"; // FIXME take from confif file final String DEFAULT_RESPONSEFORMAT = "application/x-votable+xml"; final String DEFAULT_SKY_SYSTEM = "ICRS"; // FIXME use enums final String DEFAULT_SPEC_SYSTEM = "WAVE_Barycentric";// FIXME use enum ALSO in SearchServlet FormatResponseWrapper responseWrapper = new FormatResponseWrapper((HttpServletResponse) response); Loading @@ -66,7 +64,7 @@ public class FormatResponseFilter implements Filter Pos pos = Pos.parsePos(params, DEFAULT_SKY_SYSTEM); Band band = Band.parseBand(params, DEFAULT_SPEC_SYSTEM); DbPSearch.ObsCore[] obsCoreArr = queryObsCore(pubdidArr, pos, band); DbPSearch.ObsCore[] obsCoreArr = queryObsCore(responseWrapper.getDBConn(), pubdidArr, pos, band); String respFormat; String respFormatReq[] = params.get("RESPONSEFORMAT"); Loading @@ -77,8 +75,7 @@ public class FormatResponseFilter implements Filter } else { respFormat = settings.serviceUrls.responseFormat(); LOGGER.finest("responseFormat(from settings): " + respFormat); respFormat = DEFAULT_RESPONSEFORMAT; } response.setCharacterEncoding(RESPONSE_ENCODING); Loading Loading @@ -148,14 +145,13 @@ public class FormatResponseFilter implements Filter LOGGER.fine("REQUEST END"); } //@Override public void destroy() { LOGGER.fine("trace"); } private DbPSearch.ObsCore[] queryObsCore(String[] pubdidArr, Pos pos, Band band) private DbPSearch.ObsCore[] queryObsCore(DBConn dbConn, String[] pubdidArr, Pos pos, Band band) throws Exception { Loading @@ -164,7 +160,7 @@ public class FormatResponseFilter implements Filter DbPSearch dbps; synchronized(DbPSearch.class) { dbps = new DbPSearch(settings.dbConn); dbps = new DbPSearch(dbConn); } return dbps.queryOutputData(pubdidArr, pos, band); Loading
data-discovery/src/main/java/webapi/formatfilter/FormatResponseSettings.java +9 −85 Original line number Diff line number Diff line import java.util.logging.Logger; import java.io.IOException; import java.io.InputStream; import java.util.Properties; import java.io.PrintWriter; class FormatResponseSettings { //private static final Logger LOGGER = Logger.getLogger("FormatResponseSettings"); public static class DefaultParamValues { String responseFormat; String skySystem; String specSystem; boolean showDuration; } /* public static class DBConn { private String uri; private String schema; private String user_name; private String password; public String uri() {return uri;} public String schema() {return schema;} public String userName() {return user_name;} public String password() {return password;} public String toString() { return uri + " schema[" + schema + "] " + user_name + " / " + password; } } */ public static class ServiceUrls { private String cutoutUrl; private String mergeUrl; private String surveysAbsPathname; private String respFormat; public boolean cutoutUrlIsSet() { return (cutoutUrl != null) && cutoutUrl.trim().isEmpty(); } public boolean mergeUrlIsSet() { return (mergeUrl != null) && mergeUrl.trim().isEmpty(); } public boolean surveysAbsPathnameIsSet() { return (surveysAbsPathname != null) && surveysAbsPathname.trim().isEmpty(); } public boolean responseFormatIsSet() { return (respFormat != null) && respFormat.trim().isEmpty(); } public String cutoutUrl() {return cutoutUrl;} public String mergeUrl() {return mergeUrl;} public String surveysAbsPathname() {return surveysAbsPathname;} public String responseFormat() {return respFormat;} public String toString() { return cutoutUrl + " " + mergeUrl + " " + surveysAbsPathname + " " + respFormat; return cutoutUrl + " " + mergeUrl; } } public DBConn dbConn; public ServiceUrls serviceUrls; public DefaultParamValues defaults; // will not start without config-file; no reasonable code-defaults can be invented public static FormatResponseSettings getInstance(String settingsFileName) { try Loading @@ -81,17 +34,14 @@ class FormatResponseSettings Properties properties = new Properties(); properties.load(ins); DBConn dbConn = loadDBConn(properties); ServiceUrls serviceUrls = loadServiceUrls(properties); DefaultParamValues defaults = loadDefaults(properties); return new FormatResponseSettings(dbConn, serviceUrls, defaults); return new FormatResponseSettings(serviceUrls); } else { throw new IllegalStateException(settingsFileName + " not found in classpath"); } } catch(IOException ex) { Loading @@ -99,48 +49,22 @@ class FormatResponseSettings } } private FormatResponseSettings(DBConn dbConn, ServiceUrls serviceUrls, DefaultParamValues defaults) { this.dbConn = dbConn; this.serviceUrls = serviceUrls; this.defaults = defaults; } private static DBConn loadDBConn(Properties properties) { DBConn dbConn = new DBConn(); dbConn.uri = properties.getProperty("db_uri","jdbc:postgresql://localhost:5432/vialactea").strip(); dbConn.schema = properties.getProperty("db_schema","datasets").strip(); dbConn.user_name = properties.getProperty("db_user_name","").strip(); dbConn.password = properties.getProperty("db_password","").strip(); return dbConn; } private static ServiceUrls loadServiceUrls(Properties properties) { ServiceUrls serviceUrls = new ServiceUrls(); serviceUrls.cutoutUrl = properties.getProperty("cutout_url","").strip(); serviceUrls.mergeUrl = properties.getProperty("merge_url","").strip(); serviceUrls.surveysAbsPathname = properties.getProperty("surveys_metadata_abs_pathname","/srv/surveys/surveys_metadata.csv").strip(); serviceUrls.respFormat = properties.getProperty("response_format","application/x-votable+xml").strip(); return serviceUrls; } private static DefaultParamValues loadDefaults(Properties properties) // instance public ServiceUrls serviceUrls; private FormatResponseSettings(ServiceUrls serviceUrls) { DefaultParamValues defaults = new DefaultParamValues(); defaults.responseFormat = properties.getProperty("default_response_format", "application/fits").strip(); defaults.skySystem = properties.getProperty("default_sky_system", "ICRS").strip(); defaults.specSystem = properties.getProperty("default_spec_system", "WAVE_Barycentric").strip(); defaults.showDuration = "yes".equals(properties.getProperty("show_duration", "no").strip()); return defaults; this.serviceUrls = serviceUrls; } }
data-discovery/src/main/java/webapi/formatfilter/FormatResponseWrapper.java +6 −11 Original line number Diff line number Diff line Loading @@ -5,23 +5,18 @@ import javax.servlet.http.HttpServletResponseWrapper; class FormatResponseWrapper extends HttpServletResponseWrapper { // AuthPolicy auth; String[] pubdidArr; private String[] pubdidArr; private DBConn dbConn; public FormatResponseWrapper(HttpServletResponse response) { super(response); // auth = null; } public void setPubdidArr(String[] pubdidArr) { this.pubdidArr = pubdidArr; } public String[] getPubdidArr() { return this.pubdidArr; } /* public void setAuth(AuthPolicy auth) { // assert (this.search.inputs.auth != null); this.auth = auth; }*/ public void setDBConn(DBConn dbConn) { this.dbConn = dbConn; } public DBConn getDBConn() { return this.dbConn; } }