summaryrefslogtreecommitdiff
path: root/bkucommon/src/main/java/at/gv/egiz
diff options
context:
space:
mode:
Diffstat (limited to 'bkucommon/src/main/java/at/gv/egiz')
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/binding/DataUrlConnectionImpl.java7
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/slcommands/SLCommandFactory.java54
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/AbstractInfoboxCommandImpl.java21
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/InfoboxFactory.java95
4 files changed, 68 insertions, 109 deletions
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/binding/DataUrlConnectionImpl.java b/bkucommon/src/main/java/at/gv/egiz/bku/binding/DataUrlConnectionImpl.java
index 93e5bb1c..82c1be53 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/binding/DataUrlConnectionImpl.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/binding/DataUrlConnectionImpl.java
@@ -274,7 +274,12 @@ public class DataUrlConnectionImpl implements DataUrlConnectionSPI {
InputStreamReader reader = new InputStreamReader(formParameter.getData(),
(formParameter.getCharSet() != null)
? formParameter.getCharSet()
- : "UTF-8"); // assume request was application/x-www-form-urlencoded, formParam therefore UTF-8
+ : "UTF-8");
+ // Note, using UTF-8 as fallback for decoding is safe.
+ // If the request was x-www-form-urlencoded,
+ // UTF-8 has been used for encoding of non-ASCII characters.
+ // If the request was multipart/form-data and contains any transfer parameters,
+ // the data URL request is going to be multipart/form-data encoded (see below).
while ((len = reader.read(cbuf)) != -1) {
urlEnc.write(cbuf, 0, len);
}
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/SLCommandFactory.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/SLCommandFactory.java
index 8e3f6ece..6e84867e 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/SLCommandFactory.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/SLCommandFactory.java
@@ -88,6 +88,11 @@ public class SLCommandFactory {
private Map<String, Class<? extends SLCommand>> slRequestTypeMap = new HashMap<String, Class<? extends SLCommand>>();
/**
+ * The mapping of a requests's qualified name to a concrete command factories.
+ */
+ private Map<QName, AbstractSLCommandFactory> slCommandFactories = new HashMap<QName, AbstractSLCommandFactory>();
+
+ /**
* Configures the singleton instance with command implementations
* @param commandImplMap
* @throws ClassNotFoundException
@@ -101,7 +106,19 @@ public class SLCommandFactory {
slRequestTypeMap.put(key, impl);
}
}
-
+
+ public void setConcreteFactories(Map<QName, AbstractSLCommandFactory> factories) {
+ if (log.isDebugEnabled()) {
+ StringBuilder sb = new StringBuilder();
+ sb.append("Registered sl command factory for");
+ for (QName qname : factories.keySet()) {
+ sb.append("\n " + qname + " : " + factories.get(qname).getClass());
+ }
+ log.debug(sb);
+ }
+ slCommandFactories = factories;
+ }
+
/**
* Register an {@link SLCommand} implementation class of a Security Layer
* command with the given <code>namespaceUri</code> and <code>localname</code>
@@ -363,37 +380,16 @@ public class SLCommandFactory {
log.info("Unsupported security layer request version : " + qName.getNamespaceURI());
throw new SLVersionException(qName.getNamespaceURI());
}
-
- Class<? extends SLCommand> implClass = getImplClass(qName);
- if (implClass == null) {
- // command not supported
- log.info("Unsupported command received: " + qName.toString());
- throw new SLCommandException(4011,
- SLExceptionMessages.EC4011_NOTIMPLEMENTED, new Object[]{qName.toString()});
- }
-
-
- // try to instantiate
- SLCommand slCommand;
- try {
- slCommand = implClass.newInstance();
- log.debug("SLCommand " + slCommand.getName() + " created.");
- } catch (InstantiationException e) {
- // unexpected error
- log.error("Failed to instantiate security layer command implementation.",
- e);
- throw new SLRuntimeException(e);
- } catch (IllegalAccessException e) {
- // unexpected error
- log.error("Failed to instantiate security layer command implementation.",
- e);
- throw new SLRuntimeException(e);
+ AbstractSLCommandFactory concreteFactory = slCommandFactories.get(qName);
+ if (concreteFactory == null) {
+ // command not supported
+ log.info("Unsupported command received: " + qName.toString());
+ throw new SLCommandException(4011,
+ SLExceptionMessages.EC4011_NOTIMPLEMENTED, new Object[]{qName.toString()});
}
- slCommand.init(context, (JAXBElement) object);
-
- return slCommand;
+ return concreteFactory.createSLCommand(context, (JAXBElement<?>) object);
}
} \ No newline at end of file
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/AbstractInfoboxCommandImpl.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/AbstractInfoboxCommandImpl.java
index 8a7edb71..b8e4030d 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/AbstractInfoboxCommandImpl.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/AbstractInfoboxCommandImpl.java
@@ -32,6 +32,25 @@ public abstract class AbstractInfoboxCommandImpl<T> extends SLCommandImpl<T> {
* The infobox implementation.
*/
protected Infobox infobox;
+
+ /**
+ * The infobox factory.
+ */
+ protected InfoboxFactory infoboxFactory;
+
+ /**
+ * @return the infoboxFactory
+ */
+ public InfoboxFactory getInfoboxFactory() {
+ return infoboxFactory;
+ }
+
+ /**
+ * @param infoboxFactory the infoboxFactory to set
+ */
+ public void setInfoboxFactory(InfoboxFactory infoboxFactory) {
+ this.infoboxFactory = infoboxFactory;
+ }
@Override
public void init(SLCommandContext ctx, Object request)
@@ -40,7 +59,7 @@ public abstract class AbstractInfoboxCommandImpl<T> extends SLCommandImpl<T> {
String infoboxIdentifier = getInfoboxIdentifier(getRequestValue());
- infobox = InfoboxFactory.getInstance().createInfobox(infoboxIdentifier);
+ infobox = infoboxFactory.createInfobox(infoboxIdentifier);
}
/**
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/InfoboxFactory.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/InfoboxFactory.java
index e9736f6d..fdf94297 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/InfoboxFactory.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/InfoboxFactory.java
@@ -17,7 +17,6 @@
package at.gv.egiz.bku.slcommands.impl;
import java.util.HashMap;
-import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -39,68 +38,24 @@ public class InfoboxFactory {
private static Log log = LogFactory.getLog(InfoboxFactory.class);
/**
- * The singleton instance of this InfoboxFactory.
+ * The mapping of Infobox name to concrete Infobox factory.
*/
- private static InfoboxFactory instance;
-
- /**
- * @return an instance of this InfoboxFactory
- */
- public synchronized static InfoboxFactory getInstance() {
- if (instance == null) {
- instance = new InfoboxFactory();
- }
- return instance;
- }
-
- /**
- * The mapping of infobox identifier to implementation class.
- */
- private HashMap<String, Class<? extends Infobox>> implementations;
-
- /**
- * Private constructor.
- */
- private InfoboxFactory() {
- }
-
- /**
- * Sets the mapping of infobox identifier to implementation class name.
- *
- * @param infoboxImplMap
- * a mapping of infobox identifiers to implementation class names
- *
- * @throws ClassNotFoundException
- * if implementation class is not an instance of {@link Infobox}
- */
- @SuppressWarnings("unchecked")
- public void setInfoboxImpl(Map<String, String> infoboxImplMap) throws ClassNotFoundException {
- HashMap<String, Class<? extends Infobox>> implMap = new HashMap<String, Class<? extends Infobox>>();
- ClassLoader cl = getClass().getClassLoader();
- for (String key : infoboxImplMap.keySet()) {
- Class<? extends Infobox> impl = (Class<? extends Infobox>) cl.loadClass(infoboxImplMap.get(key));
- log.debug("Registering infobox '" + key + "' implementation '" + impl.getCanonicalName() + "'.");
- implMap.put(key, impl);
- }
- implementations = implMap;
- }
-
+ private HashMap<String, AbstractInfoboxFactory> infoboxFactories = new HashMap<String, AbstractInfoboxFactory>();
+
/**
- * Returns the configured implementation class for the given
- * <code>infoboxIdentifier</code>.
- *
- * @param infoboxIdentifier
- * the infobox identifier
- *
- * @return the implementation class for the given infobox identifier or
- * <code>null</code> if there is no implementation class configured
+ * @param infoboxFactories the infoboxFactories to set
*/
- public Class<? extends Infobox> getImplClass(String infoboxIdentifier) {
- if (implementations != null) {
- return implementations.get(infoboxIdentifier);
- } else {
- return null;
+ public void setInfoboxFactories(
+ HashMap<String, AbstractInfoboxFactory> factories) {
+ if (log.isDebugEnabled()) {
+ StringBuilder sb = new StringBuilder();
+ sb.append("Registered infobox factories for");
+ for (String name : factories.keySet()) {
+ sb.append("\n " + name + " : " + factories.get(name).getClass());
+ }
+ log.debug(sb);
}
+ this.infoboxFactories = factories;
}
/**
@@ -119,31 +74,15 @@ public class InfoboxFactory {
*/
public Infobox createInfobox(String infoboxIdentifier) throws SLCommandException, SLRuntimeException {
- Class<? extends Infobox> implClass = getImplClass(infoboxIdentifier);
- if (implClass == null) {
- // infobox not supported
+ AbstractInfoboxFactory factory = infoboxFactories.get(infoboxIdentifier);
+ if (factory == null) {
log.info("Unsupported infobox '" + infoboxIdentifier + ".");
throw new SLCommandException(4002,
SLExceptionMessages.EC4002_INFOBOX_UNKNOWN,
new Object[] { infoboxIdentifier });
}
- // try to instantiate
- Infobox infobox;
- try {
- infobox = implClass.newInstance();
- log.debug("Infobox '" + infobox.getIdentifier() + "' created.");
- } catch (InstantiationException e) {
- // unexpected error
- log.error("Failed to instantiate infobox implementation.", e);
- throw new SLRuntimeException(e);
- } catch (IllegalAccessException e) {
- // unexpected error
- log.error("Failed to instantiate infobox implementation.", e);
- throw new SLRuntimeException(e);
- }
-
- return infobox;
+ return factory.createInfobox();
}