summaryrefslogtreecommitdiff
path: root/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/SLMarshallerFactory.java
diff options
context:
space:
mode:
authormcentner <mcentner@8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4>2009-09-29 17:36:06 +0000
committermcentner <mcentner@8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4>2009-09-29 17:36:06 +0000
commitbd070e82c276afb8c1c3a9ddc3b5712783760881 (patch)
treed33ea8232d66b339554b3fbf41cb5ca846efc1e3 /bkucommon/src/main/java/at/gv/egiz/bku/slcommands/SLMarshallerFactory.java
parent9d4b3e9214f653d2556608958642d02814d4e7a3 (diff)
downloadmocca-bd070e82c276afb8c1c3a9ddc3b5712783760881.tar.gz
mocca-bd070e82c276afb8c1c3a9ddc3b5712783760881.tar.bz2
mocca-bd070e82c276afb8c1c3a9ddc3b5712783760881.zip
Logging issues fixed:
- Added possibility to configure logging of BKUWebstart. Logging is now configured from log4j configuration deployed with BKUWebstart in a first step. In a second step the webstart launcher looks for a log4j configuration file in the user's mooca configuration directory and updates the log4j configuration. - Logging of IAIK PKI properly initialized. IAIK PKI does not mess with the log4j configuration any longer. - Changed log4j accordingly (an appender is now needed as IAIK PKI does not reconfigure log4j any longer). Added css-stylesheet to ErrorResponses issued by the BKU to improve the presentation to the user. Changed dependencies of BKUWebStart (see Issue#469 https://egovlabs.gv.at/tracker/index.php?func=detail&aid=469&group_id=13&atid=134). DataURLConnection now uses the request encoding of SL < 1.2. application/x-www-form-urlencoded is now used as default encoding method. multipart/form-data is used only if transfer parameters are present in the request that require a Content-Type parameter. This can only be set with multipart/form-data. This is not in conformance with SL 1.2, however it should improve compatibility with applications. Therefore, removed the ability to configure the DataURLConnection implementation class. DataURLConnection now uses a streaming implementation for encoding of application/x-www-form-urlencoded requests. XWWWFormUrlImputDecoder now uses a streaming implementation for decoding of application/x-www-form-urlencoded requests. Fixed Bug in SLResultPart that caused a binary response to be provided as parameter "XMLResponse" in a multipart/form-data encoded request to DataURL. SLCommandFactory now supports unmarshalling of SL < 1.2 requests in order issue meaningful error messages. Therefore, the marshaling context for response marshaling had to be separated from the marshaling context for requests in order to avoid the marshaling of SL < 1.2 namespace prefixes in SL 1.2 responses. Target attribute in QualifiedProperties is now marshaled. (see Issue#470 https://egovlabs.gv.at/tracker/index.php?func=detail&aid=470&group_id=13&atid=134) Reporting of XML validation errors improved. git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@510 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4
Diffstat (limited to 'bkucommon/src/main/java/at/gv/egiz/bku/slcommands/SLMarshallerFactory.java')
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/slcommands/SLMarshallerFactory.java172
1 files changed, 172 insertions, 0 deletions
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/SLMarshallerFactory.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/SLMarshallerFactory.java
new file mode 100644
index 00000000..e0a375cf
--- /dev/null
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/SLMarshallerFactory.java
@@ -0,0 +1,172 @@
+/*
+* Copyright 2009 Federal Chancellery Austria and
+* Graz University of Technology
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package at.gv.egiz.bku.slcommands;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Marshaller;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import at.gv.egiz.bku.slexceptions.SLRuntimeException;
+import at.gv.egiz.marshal.MarshallerFactory;
+
+public class SLMarshallerFactory {
+
+ static Log log = LogFactory.getLog(SLMarshallerFactory.class);
+
+ /**
+ * The JAXBContext used for result marshaling.
+ * <p>
+ * Note: Different contexts are used for marshaling and unmarshaling of
+ * security layer requests and responses to avoid propagation of namespace
+ * declarations of legacy namespaces into marshaled results.
+ * </p>
+ * @see #jaxbContextLegacy
+ */
+ protected static JAXBContext context;
+
+ /**
+ * The JAXBContext used for marshaling of of results in the legacy namespace.
+ */
+ protected static JAXBContext legacyContext;
+
+ // ------------------- initialization on demand idiom -------------------
+ // see http://en.wikipedia.org/wiki/Initialization_on_demand_holder_idiom
+ // ----------------------------------------------------------------------
+
+ /**
+ * Private constructor called by {@link SLMarshallerFactoryInstanceHolder}.
+ */
+ private SLMarshallerFactory() {
+ // context is initialized immediately while the legacy context is initialized only on demand
+ try {
+ String slPkg = at.buergerkarte.namespaces.securitylayer._1.ObjectFactory.class.getPackage().getName();
+ String xmldsigPkg = org.w3._2000._09.xmldsig_.ObjectFactory.class.getPackage().getName();
+ String cardChannelPkg = at.buergerkarte.namespaces.cardchannel.ObjectFactory.class.getPackage().getName();
+ context = JAXBContext.newInstance(slPkg + ":" + xmldsigPkg + ":" + cardChannelPkg);
+ } catch (JAXBException e) {
+ log.error("Failed to setup JAXBContext security layer request.", e);
+ throw new SLRuntimeException(e);
+ }
+ }
+
+ /**
+ * The lazy instance holder for this SLMarshallerFactory.
+ */
+ private static class SLMarshallerFactoryInstanceHolder {
+ /**
+ * The instance returned by {@link SLMarshallerFactory#getInstance()}
+ */
+ private static final SLMarshallerFactory instance = new SLMarshallerFactory();
+ }
+
+ /**
+ * Get an instance of the <code>SLMarshallerFactory</code>.
+ */
+ public static SLMarshallerFactory getInstance() {
+ return SLMarshallerFactoryInstanceHolder.instance;
+ }
+
+ // ----------------------------------------------------------------------
+
+ /**
+ * Initialize the JAXBContext for the legacy namespace.
+ */
+ private static synchronized void ensureLegacyContext() {
+ // legacy marshaller is initialized only on demand
+ if (legacyContext == null) {
+ try {
+ String slPkgLegacy1_0 = at.buergerkarte.namespaces.securitylayer._20020225_.ObjectFactory.class.getPackage().getName();
+ String slPkgLegacy1_1 = at.buergerkarte.namespaces.securitylayer._20020831_.ObjectFactory.class.getPackage().getName();
+ String xmldsigPkg = org.w3._2000._09.xmldsig_.ObjectFactory.class.getPackage().getName();
+ String cardChannelPkg = at.buergerkarte.namespaces.cardchannel.ObjectFactory.class.getPackage().getName();
+ legacyContext = JAXBContext.newInstance(slPkgLegacy1_0 + ":" + slPkgLegacy1_1 + ":" + xmldsigPkg + ":" + cardChannelPkg);
+ } catch (JAXBException e) {
+ log.error("Failed to setup JAXBContext security layer request.", e);
+ throw new SLRuntimeException(e);
+ }
+ }
+ }
+
+ /**
+ * Creates an SL marshaller.
+ *
+ * @param formattedOutput
+ * <code>true</code> if the marshaller should produce formated
+ * output, <code>false</code> otherwise
+ * @return an SL marshaller
+ */
+ public Marshaller createMarshaller(boolean formattedOutput) {
+ return createMarshaller(formattedOutput, false);
+ }
+
+ /**
+ * Creates an SL marshaller.
+ *
+ * @param formattedOutput
+ * <code>true</code> if the marshaller should produce formated
+ * output, <code>false</code> otherwise
+ * @param fragment
+ * <code>true</code> if the marshaller should produce a XML fragment
+ * (omit XML declaration), <code>false</code> otherwise
+ * @return an SL marshaller
+ */
+ public Marshaller createMarshaller(boolean formattedOutput, boolean fragment) {
+ try {
+ return MarshallerFactory.createMarshaller(context, formattedOutput, fragment);
+ } catch (JAXBException e) {
+ log.fatal("Failed to marshall error response.", e);
+ throw new SLRuntimeException("Failed to marshall error response.", e);
+ }
+ }
+
+ /**
+ * Creates a legacy SL marshaller.
+ *
+ * @param formattedOutput
+ * <code>true</code> if the marshaller should produce formated
+ * output, <code>false</code> otherwise
+ * @return a legacy SL marshaller
+ */
+ public Marshaller createLegacyMarshaller(boolean formattedOutput) {
+ return createLegacyMarshaller(formattedOutput, false);
+ }
+
+ /**
+ * Creates a legacy SL marshaller.
+ *
+ * @param formattedOutput
+ * <code>true</code> if the marshaller should produce formated
+ * output, <code>false</code> otherwise
+ * @param fragment
+ * <code>true</code> if the marshaller should produce a XML fragment
+ * (omit XML declaration), <code>false</code> otherwise
+ * @return a legacy SL marshaller
+ */
+ public Marshaller createLegacyMarshaller(boolean formattedOutput, boolean fragment) {
+ try {
+ ensureLegacyContext();
+ return MarshallerFactory.createMarshaller(legacyContext, formattedOutput, fragment);
+ } catch (JAXBException e) {
+ log.fatal("Failed to marshall error response.", e);
+ throw new SLRuntimeException("Failed to marshall error response.", e);
+ }
+ }
+
+}