summaryrefslogtreecommitdiff
path: root/bkucommon
diff options
context:
space:
mode:
authorclemenso <clemenso@8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4>2010-01-26 17:23:06 +0000
committerclemenso <clemenso@8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4>2010-01-26 17:23:06 +0000
commit615cf8bb11a1253e36aaf2f01082ed6429836358 (patch)
treee7047e07a004f22eeb209835cb5620a5e2819fc9 /bkucommon
parent7af237ef102514aa817e567861dc25ab39b6dac0 (diff)
parentb184b9e753daee529a2996832286fbaf3bf3a696 (diff)
downloadmocca-615cf8bb11a1253e36aaf2f01082ed6429836358.tar.gz
mocca-615cf8bb11a1253e36aaf2f01082ed6429836358.tar.bz2
mocca-615cf8bb11a1253e36aaf2f01082ed6429836358.zip
[maven-release-plugin] copy for branch mocca-1.2.11-sha2
git-svn-id: https://joinup.ec.europa.eu/svn/mocca/branches/mocca-1.2.11-sha2@606 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4
Diffstat (limited to 'bkucommon')
-rw-r--r--bkucommon/pom.xml4
-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
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/AlgorithmMethodFactoryImpl.java2
-rw-r--r--bkucommon/src/test/java/moaspss/TestCreateAndVerifySignature.java4
-rw-r--r--bkucommon/src/test/resources/MOA-SPSS-1.3.wsdl2
8 files changed, 115 insertions, 74 deletions
diff --git a/bkucommon/pom.xml b/bkucommon/pom.xml
index 2ac6c5fc..0899ab23 100644
--- a/bkucommon/pom.xml
+++ b/bkucommon/pom.xml
@@ -3,13 +3,13 @@
<parent>
<artifactId>bku</artifactId>
<groupId>at.gv.egiz</groupId>
- <version>1.2.11</version>
+ <version>1.2.11-sha2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>at.gv.egiz</groupId>
<artifactId>bkucommon</artifactId>
<name>BKU Common</name>
- <version>1.2.11</version>
+ <version>1.2.11-sha2-SNAPSHOT</version>
<build>
<plugins>
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 82c1be53..93e5bb1c 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,12 +274,7 @@ public class DataUrlConnectionImpl implements DataUrlConnectionSPI {
InputStreamReader reader = new InputStreamReader(formParameter.getData(),
(formParameter.getCharSet() != null)
? formParameter.getCharSet()
- : "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).
+ : "UTF-8"); // assume request was application/x-www-form-urlencoded, formParam therefore UTF-8
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 6e84867e..8e3f6ece 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,11 +88,6 @@ 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
@@ -106,19 +101,7 @@ 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>
@@ -380,16 +363,37 @@ 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()});
+ }
- 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()});
+
+
+ // 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);
}
- return concreteFactory.createSLCommand(context, (JAXBElement<?>) object);
+ slCommand.init(context, (JAXBElement) object);
+
+ return slCommand;
}
} \ 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 b8e4030d..8a7edb71 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,25 +32,6 @@ 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)
@@ -59,7 +40,7 @@ public abstract class AbstractInfoboxCommandImpl<T> extends SLCommandImpl<T> {
String infoboxIdentifier = getInfoboxIdentifier(getRequestValue());
- infobox = infoboxFactory.createInfobox(infoboxIdentifier);
+ infobox = InfoboxFactory.getInstance().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 fdf94297..e9736f6d 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,6 +17,7 @@
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;
@@ -38,24 +39,68 @@ public class InfoboxFactory {
private static Log log = LogFactory.getLog(InfoboxFactory.class);
/**
- * The mapping of Infobox name to concrete Infobox factory.
+ * The singleton instance of this InfoboxFactory.
*/
- private HashMap<String, AbstractInfoboxFactory> infoboxFactories = new HashMap<String, AbstractInfoboxFactory>();
-
+ private static InfoboxFactory instance;
+
/**
- * @param infoboxFactories the infoboxFactories to set
+ * @return an instance of this InfoboxFactory
*/
- 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);
+ 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;
+ }
+
+ /**
+ * 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
+ */
+ public Class<? extends Infobox> getImplClass(String infoboxIdentifier) {
+ if (implementations != null) {
+ return implementations.get(infoboxIdentifier);
+ } else {
+ return null;
}
- this.infoboxFactories = factories;
}
/**
@@ -74,15 +119,31 @@ public class InfoboxFactory {
*/
public Infobox createInfobox(String infoboxIdentifier) throws SLCommandException, SLRuntimeException {
- AbstractInfoboxFactory factory = infoboxFactories.get(infoboxIdentifier);
- if (factory == null) {
+ Class<? extends Infobox> implClass = getImplClass(infoboxIdentifier);
+ if (implClass == null) {
+ // infobox not supported
log.info("Unsupported infobox '" + infoboxIdentifier + ".");
throw new SLCommandException(4002,
SLExceptionMessages.EC4002_INFOBOX_UNKNOWN,
new Object[] { infoboxIdentifier });
}
- return factory.createInfobox();
+ // 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;
}
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/AlgorithmMethodFactoryImpl.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/AlgorithmMethodFactoryImpl.java
index 9a958323..8391e450 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/AlgorithmMethodFactoryImpl.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/AlgorithmMethodFactoryImpl.java
@@ -45,7 +45,7 @@ public class AlgorithmMethodFactoryImpl implements AlgorithmMethodFactory {
/**
* Use SHA-2?
*/
- private static boolean SHA2 = true;
+ private static boolean SHA2 = false;
/**
* The signature algorithm URI.
diff --git a/bkucommon/src/test/java/moaspss/TestCreateAndVerifySignature.java b/bkucommon/src/test/java/moaspss/TestCreateAndVerifySignature.java
index a9397d31..8d995530 100644
--- a/bkucommon/src/test/java/moaspss/TestCreateAndVerifySignature.java
+++ b/bkucommon/src/test/java/moaspss/TestCreateAndVerifySignature.java
@@ -33,7 +33,7 @@ import org.xml.sax.SAXException;
import at.buergerkarte.namespaces.securitylayer._1.ErrorResponseType;
-//@Ignore
+@Ignore
public class TestCreateAndVerifySignature {
protected Element parseCreateXMLSignatureRequest(InputStream is)
@@ -141,7 +141,7 @@ public class TestCreateAndVerifySignature {
}
MOASPClient spClient = new MOASPClient();
- JAXBElement<VerifyXMLSignatureResponseType> verifySignature = spClient.verifySignature(cxsResp, ".", "qualifiedSignature+Test");
+ JAXBElement<VerifyXMLSignatureResponseType> verifySignature = spClient.verifySignature(cxsResp, ".", "qualifiedSignature");
VerifyXMLSignatureResponseType vxsResp = verifySignature.getValue();
int signatureCheck = vxsResp.getSignatureCheck().getCode().intValue();
if (signatureCheck != 0) {
diff --git a/bkucommon/src/test/resources/MOA-SPSS-1.3.wsdl b/bkucommon/src/test/resources/MOA-SPSS-1.3.wsdl
index 25accfce..8ec61420 100644
--- a/bkucommon/src/test/resources/MOA-SPSS-1.3.wsdl
+++ b/bkucommon/src/test/resources/MOA-SPSS-1.3.wsdl
@@ -51,7 +51,7 @@
</binding>
<service name="SignatureVerificationService">
<port name="SignatureVerificationPort" binding="tns:SignatureVerificationBinding">
- <soap:address location="http://localhost:8080/moa-spss/services/SignatureVerification"/>
+ <soap:address location="http://localhost:8088/moa-spss/services/SignatureVerification"/>
</port>
</service>
</definitions>