From ce1a767bf2510303a75386ce4ec43dc24113195f Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Wed, 12 Aug 2015 13:48:30 +0200 Subject: [PATCH] =?utf8?q?Continued=20with=20project:=20-=20Added=20databa?= =?utf8?q?se.backend.storagepath=20for=20file-based=20database=20backends?= =?utf8?q?=20(very=20simple)=20-=20Used=20getRealPath()=20to=20get=20serve?= =?utf8?q?r's=20full=20web=20path,=20but=20went=202=20up=20to=20get=20away?= =?utf8?q?=20from=20web-reachable=20path=20-=20Added=20catching=20of=20mor?= =?utf8?q?e=20thrown=20exceptions=20Signed-off-by:Roland=20H=C3=A4der=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../pizzaapplication/BasePizzaServiceSystem.java | 13 +++++++++++-- .../application/PizzaServiceApplication.java | 3 ++- .../customer/bean/PizzaServiceCustomerBean.java | 3 ++- web/WEB-INF/web.xml | 5 +++++ 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/java/org/mxchange/pizzaapplication/BasePizzaServiceSystem.java b/src/java/org/mxchange/pizzaapplication/BasePizzaServiceSystem.java index 0e0e7541..e85b321e 100644 --- a/src/java/org/mxchange/pizzaapplication/BasePizzaServiceSystem.java +++ b/src/java/org/mxchange/pizzaapplication/BasePizzaServiceSystem.java @@ -40,10 +40,19 @@ public class BasePizzaServiceSystem extends BaseFrameworkSystem { this.getLogger().debug(MessageFormat.format("name={0}", name)); // Get value - String value = context.getInitParameter(name).trim(); + String value = context.getInitParameter(name); + + // Is it null? + if (value == null) { + // Value is null + throw new NullPointerException(MessageFormat.format("value for {0} is null, maybe invalid context parameter?", name)); + } else if (name.equals("database.backend.storagepath")) { + // Need to expand this path + value = context.getRealPath(String.format("../../%s", value.trim())); + } // Debug log - this.getLogger().debug(MessageFormat.format("{0}={1}", name, value)); + this.getLogger().debug(MessageFormat.format("{0}={1}", name, value.trim())); // Set property this.setProperty(name, value); diff --git a/src/java/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java b/src/java/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java index c86e9328..06487532 100644 --- a/src/java/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java +++ b/src/java/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java @@ -18,6 +18,7 @@ package org.mxchange.pizzaapplication.application; import java.io.IOException; import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; import java.sql.SQLException; import java.text.MessageFormat; import java.util.Iterator; @@ -1128,7 +1129,7 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P try { // Get iterator on all its fields it = customer.iterator(); - } catch (final NoSuchMethodException ex) { + } catch (final NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) { this.abortProgramWithException(ex); } diff --git a/src/java/org/mxchange/pizzaapplication/customer/bean/PizzaServiceCustomerBean.java b/src/java/org/mxchange/pizzaapplication/customer/bean/PizzaServiceCustomerBean.java index 74f53fce..a3b06d43 100644 --- a/src/java/org/mxchange/pizzaapplication/customer/bean/PizzaServiceCustomerBean.java +++ b/src/java/org/mxchange/pizzaapplication/customer/bean/PizzaServiceCustomerBean.java @@ -17,6 +17,7 @@ package org.mxchange.pizzaapplication.customer.bean; import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; import java.util.Iterator; import java.util.Map; import org.mxchange.jcore.client.Client; @@ -244,7 +245,7 @@ public class PizzaServiceCustomerBean extends BasePizzaServiceSystem implements } @Override - public Iterator> iterator () throws NoSuchMethodException { + public Iterator> iterator () throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { // Deligate to "hidden" object return this.getContact().iterator(); } diff --git a/web/WEB-INF/web.xml b/web/WEB-INF/web.xml index 2676cd9a..ee0a8d0d 100644 --- a/web/WEB-INF/web.xml +++ b/web/WEB-INF/web.xml @@ -25,6 +25,11 @@ database.mysql.dbname test + + Data path for file-based database backends. This must be a relative path and it will reside 2 levels up from the server's web path. + database.backend.storagepath + data + A filter for setting character encoding to UTF-8 Utf8HttpFilter -- 2.39.5