diff options
Diffstat (limited to 'bkucommon')
5 files changed, 188 insertions, 173 deletions
diff --git a/bkucommon/pom.xml b/bkucommon/pom.xml index 79516b1d..ccc1814d 100644 --- a/bkucommon/pom.xml +++ b/bkucommon/pom.xml @@ -20,7 +20,7 @@ <dependency> <groupId>at.gv.egiz</groupId> <artifactId>STALExt</artifactId> - <version>1.0.4-SNAPSHOT</version> + <version>1.0.2-SNAPSHOT</version> </dependency> <dependency> <groupId>commons-logging</groupId> @@ -62,6 +62,11 @@ <artifactId>spring-context</artifactId> <scope>test</scope> </dependency> + <!-- dependency to ensure NamespacePrefixmapper --> + <dependency> + <groupId>com.sun.xml.bind</groupId> + <artifactId>jaxb-impl</artifactId> + </dependency> </dependencies> <build> <plugins> diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/AbstractAssocArrayInfobox.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/AbstractAssocArrayInfobox.java index e7f96c06..ce03dcf9 100644 --- a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/AbstractAssocArrayInfobox.java +++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/AbstractAssocArrayInfobox.java @@ -16,6 +16,7 @@ */ package at.gv.egiz.bku.slcommands.impl; +import at.gv.egiz.marshal.NamespacePrefixMapperImpl; import java.io.ByteArrayOutputStream; import java.util.Arrays; import java.util.Collections; @@ -43,6 +44,8 @@ import at.gv.egiz.bku.slcommands.InfoboxReadResult; import at.gv.egiz.bku.slcommands.SLCommandContext; import at.gv.egiz.bku.slcommands.SLCommandFactory; import at.gv.egiz.bku.slexceptions.SLCommandException; +import at.gv.egiz.marshal.MarshallerFactory; +import javax.xml.bind.PropertyException; /** * An abstract base class for {@link Infobox} implementations of type associative array. @@ -257,8 +260,7 @@ public abstract class AbstractAssocArrayInfobox extends AbstractInfoboxImpl ByteArrayOutputStream result; try { - Marshaller marshaller = jaxbContext.createMarshaller(); - + Marshaller marshaller = MarshallerFactory.createMarshaller(jaxbContext); result = new ByteArrayOutputStream(); marshaller.marshal(jaxbElement, result); } catch (JAXBException e) { diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/CreateXMLSignatureResultImpl.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/CreateXMLSignatureResultImpl.java index 4969c85a..b352a51e 100644 --- a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/CreateXMLSignatureResultImpl.java +++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/CreateXMLSignatureResultImpl.java @@ -14,8 +14,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package at.gv.egiz.bku.slcommands.impl;
-
+package at.gv.egiz.bku.slcommands.impl; + +import at.gv.egiz.marshal.NamespacePrefixMapperImpl; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBElement; import javax.xml.bind.JAXBException; @@ -34,76 +35,78 @@ import at.buergerkarte.namespaces.securitylayer._1.CreateXMLSignatureResponseTyp import at.buergerkarte.namespaces.securitylayer._1.ObjectFactory; import at.gv.egiz.bku.slcommands.SLCommandFactory; import at.gv.egiz.bku.slexceptions.SLRuntimeException; -
-/**
- * This calls implements the result of the security layer command <code>CreateXMLSignature</code>.
- *
- * @author mcentner
- */
-public class CreateXMLSignatureResultImpl extends SLResultImpl {
-
- /**
- * Logging facility.
- */
- private static Log log = LogFactory.getLog(CreateXMLSignatureResultImpl.class);
-
- /**
- * The document containing the XMLSignature.
- */
- protected Document doc;
-
- /**
- * Creates a new instance of this CreateXMLSignatureResultImpl with the given
- * signature <code>document</code>.
- *
- * @param document the signature document
- *
- * @throws NullPointerException if <code>document</code> is <code>null</code>
- */
- public CreateXMLSignatureResultImpl(Document document) {
- super();
-
- if (document == null) {
- throw new NullPointerException("Argument 'document' must not be null.");
- }
-
- this.doc = document;
-
- marshallCreateXMLSignatureResponse();
- }
-
- /**
- * Marshalls the <code>CreateXMLSignatureResponse</code>.
- */
- private void marshallCreateXMLSignatureResponse() {
-
- ObjectFactory factory = new ObjectFactory();
-
- CreateXMLSignatureResponseType createCreateXMLSignatureResponseType = factory.createCreateXMLSignatureResponseType();
- JAXBElement<CreateXMLSignatureResponseType> createCreateXMLSignatureResponse = factory.createCreateXMLSignatureResponse(createCreateXMLSignatureResponseType);
-
- DocumentFragment fragment = doc.createDocumentFragment();
-
- JAXBContext jaxbContext = SLCommandFactory.getInstance().getJaxbContext();
- try {
- Marshaller marshaller = jaxbContext.createMarshaller();
- marshaller.marshal(createCreateXMLSignatureResponse, fragment);
- } catch (JAXBException e) {
- log.error("Failed to marshall 'CreateXMLSignatureResponse'", e);
- throw new SLRuntimeException(e);
- }
-
- Node child = fragment.getFirstChild();
- if (child instanceof Element) {
- Node node = doc.replaceChild(child, doc.getDocumentElement());
- child.appendChild(node);
- }
-
- }
+import at.gv.egiz.marshal.MarshallerFactory; +import javax.xml.bind.PropertyException; + +/** + * This calls implements the result of the security layer command <code>CreateXMLSignature</code>. + * + * @author mcentner + */ +public class CreateXMLSignatureResultImpl extends SLResultImpl { + + /** + * Logging facility. + */ + private static Log log = LogFactory.getLog(CreateXMLSignatureResultImpl.class); + + /** + * The document containing the XMLSignature. + */ + protected Document doc; + + /** + * Creates a new instance of this CreateXMLSignatureResultImpl with the given + * signature <code>document</code>. + * + * @param document the signature document + * + * @throws NullPointerException if <code>document</code> is <code>null</code> + */ + public CreateXMLSignatureResultImpl(Document document) { + super(); + + if (document == null) { + throw new NullPointerException("Argument 'document' must not be null."); + } + + this.doc = document; + + marshallCreateXMLSignatureResponse(); + } + + /** + * Marshalls the <code>CreateXMLSignatureResponse</code>. + */ + private void marshallCreateXMLSignatureResponse() { + + ObjectFactory factory = new ObjectFactory(); + + CreateXMLSignatureResponseType createCreateXMLSignatureResponseType = factory.createCreateXMLSignatureResponseType(); + JAXBElement<CreateXMLSignatureResponseType> createCreateXMLSignatureResponse = factory.createCreateXMLSignatureResponse(createCreateXMLSignatureResponseType); + + DocumentFragment fragment = doc.createDocumentFragment(); + + JAXBContext jaxbContext = SLCommandFactory.getInstance().getJaxbContext(); + try { + Marshaller marshaller = MarshallerFactory.createMarshaller(jaxbContext); + marshaller.marshal(createCreateXMLSignatureResponse, fragment); + } catch (JAXBException e) { + log.error("Failed to marshall 'CreateXMLSignatureResponse'", e); + throw new SLRuntimeException(e); + } + + Node child = fragment.getFirstChild(); + if (child instanceof Element) { + Node node = doc.replaceChild(child, doc.getDocumentElement()); + child.appendChild(node); + } + + } @Override public void writeTo(Result result, Templates templates) { writeTo(doc, result, templates); - }
-
-}
+ } + +} diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/InfoboxReadResultFileImpl.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/InfoboxReadResultFileImpl.java index d8295227..75e44afa 100644 --- a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/InfoboxReadResultFileImpl.java +++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/InfoboxReadResultFileImpl.java @@ -14,8 +14,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package at.gv.egiz.bku.slcommands.impl;
-
+package at.gv.egiz.bku.slcommands.impl; + +import at.gv.egiz.marshal.NamespacePrefixMapperImpl; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBElement; import javax.xml.bind.JAXBException; @@ -40,86 +41,88 @@ import at.gv.egiz.bku.slcommands.InfoboxReadResult; import at.gv.egiz.bku.slcommands.SLCommand; import at.gv.egiz.bku.slcommands.SLCommandFactory; import at.gv.egiz.bku.slexceptions.SLRuntimeException; -
-/**
- * This class implements the result of the security layer command <code>InfoboxReadRequest</code>.
- *
- * @author mcentner
- */
-public class InfoboxReadResultFileImpl extends SLResultImpl implements
- InfoboxReadResult {
-
- /**
- * Logging facility.
- */
- protected static Log log = LogFactory.getLog(InfoboxReadResultFileImpl.class);
-
- /**
- * The XML document containing the infobox content.
- */
- protected Document xmlDocument;
-
- /**
- * Creates the response document from the given <code>binaryContent</code>.
- *
- * @param binaryContent the infobox content
- * @param preserveSpace the value of the <code>preserveSpace</code> parameter
- *
- * @return the created response document
- */
- private Document createResponseDocument(byte[] binaryContent, boolean preserveSpace) {
-
- DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
- Document doc;
- try {
- doc = dbf.newDocumentBuilder().newDocument();
- } catch (ParserConfigurationException e) {
- // it should always be possible to create a new Document
- log.error("Failed to create XML document.", e);
- throw new SLRuntimeException(e);
- }
-
- ObjectFactory factory = new ObjectFactory();
-
- Base64XMLContentType base64XMLContentType = factory.createBase64XMLContentType();
- if (binaryContent == null) {
- XMLContentType xmlContentType = factory.createXMLContentType();
- if (preserveSpace) {
- xmlContentType.setSpace("preserve");
- }
- base64XMLContentType.setXMLContent(xmlContentType);
- } else {
- base64XMLContentType.setBase64Content(binaryContent);
- }
- InfoboxReadResponseType infoboxReadResponseType = factory.createInfoboxReadResponseType();
- infoboxReadResponseType.setBinaryFileData(base64XMLContentType);
-
- JAXBElement<InfoboxReadResponseType> infoboxReadResponse = factory.createInfoboxReadResponse(infoboxReadResponseType);
-
- JAXBContext context = SLCommandFactory.getInstance().getJaxbContext();
- try {
- Marshaller marshaller = context.createMarshaller();
- marshaller.marshal(infoboxReadResponse, doc);
- } catch (JAXBException e) {
- log.error("Failed to marshal 'InfoboxReadResponse' document.", e);
- throw new SLRuntimeException(e);
- }
-
- return doc;
-
- }
-
-
- /**
- * @return an XMLResult for marshalling the infobox to
- */
- public Result getXmlResult(boolean preserveSpace) {
-
- xmlDocument = createResponseDocument(null, preserveSpace);
-
- NodeList nodeList = xmlDocument.getElementsByTagNameNS(SLCommand.NAMESPACE_URI, "XMLContent");
- return new DOMResult(nodeList.item(0));
-
+import at.gv.egiz.marshal.MarshallerFactory; +import javax.xml.bind.PropertyException; + +/** + * This class implements the result of the security layer command <code>InfoboxReadRequest</code>. + * + * @author mcentner + */ +public class InfoboxReadResultFileImpl extends SLResultImpl implements + InfoboxReadResult { + + /** + * Logging facility. + */ + protected static Log log = LogFactory.getLog(InfoboxReadResultFileImpl.class); + + /** + * The XML document containing the infobox content. + */ + protected Document xmlDocument; + + /** + * Creates the response document from the given <code>binaryContent</code>. + * + * @param binaryContent the infobox content + * @param preserveSpace the value of the <code>preserveSpace</code> parameter + * + * @return the created response document + */ + private Document createResponseDocument(byte[] binaryContent, boolean preserveSpace) { + + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + Document doc; + try { + doc = dbf.newDocumentBuilder().newDocument(); + } catch (ParserConfigurationException e) { + // it should always be possible to create a new Document + log.error("Failed to create XML document.", e); + throw new SLRuntimeException(e); + } + + ObjectFactory factory = new ObjectFactory(); + + Base64XMLContentType base64XMLContentType = factory.createBase64XMLContentType(); + if (binaryContent == null) { + XMLContentType xmlContentType = factory.createXMLContentType(); + if (preserveSpace) { + xmlContentType.setSpace("preserve"); + } + base64XMLContentType.setXMLContent(xmlContentType); + } else { + base64XMLContentType.setBase64Content(binaryContent); + } + InfoboxReadResponseType infoboxReadResponseType = factory.createInfoboxReadResponseType(); + infoboxReadResponseType.setBinaryFileData(base64XMLContentType); + + JAXBElement<InfoboxReadResponseType> infoboxReadResponse = factory.createInfoboxReadResponse(infoboxReadResponseType); + + JAXBContext context = SLCommandFactory.getInstance().getJaxbContext(); + try { + Marshaller marshaller = MarshallerFactory.createMarshaller(context); + marshaller.marshal(infoboxReadResponse, doc); + } catch (JAXBException e) { + log.error("Failed to marshal 'InfoboxReadResponse' document.", e); + throw new SLRuntimeException(e); + } + + return doc; + + } + + + /** + * @return an XMLResult for marshalling the infobox to + */ + public Result getXmlResult(boolean preserveSpace) { + + xmlDocument = createResponseDocument(null, preserveSpace); + + NodeList nodeList = xmlDocument.getElementsByTagNameNS(SLCommand.NAMESPACE_URI, "XMLContent"); + return new DOMResult(nodeList.item(0)); + } /** @@ -142,21 +145,21 @@ public class InfoboxReadResultFileImpl extends SLResultImpl implements } - /**
- * Creates a new result document for this <code>InfoboxReadResult</code>
- * and sets the given <code>resultBytes</code> as content.
- *
- * @param resultBytes
- */
- public void setResultBytes(byte[] resultBytes) {
-
- xmlDocument = createResponseDocument(resultBytes, false);
-
- }
-
+ /** + * Creates a new result document for this <code>InfoboxReadResult</code> + * and sets the given <code>resultBytes</code> as content. + * + * @param resultBytes + */ + public void setResultBytes(byte[] resultBytes) { + + xmlDocument = createResponseDocument(resultBytes, false); + + } + @Override public void writeTo(Result result, Templates templates) { writeTo(xmlDocument, result, templates); - }
-
-}
+ } + +} diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/SLResultImpl.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/SLResultImpl.java index 99a3b119..0452bddf 100644 --- a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/SLResultImpl.java +++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/SLResultImpl.java @@ -41,6 +41,7 @@ import org.w3c.dom.Node; import at.buergerkarte.namespaces.securitylayer._1.ErrorResponseType; import at.buergerkarte.namespaces.securitylayer._1.ObjectFactory; +import at.gv.egiz.marshal.NamespacePrefixMapperImpl; import at.gv.egiz.bku.slcommands.SLCommandFactory; import at.gv.egiz.bku.slcommands.SLResult; import at.gv.egiz.bku.slexceptions.SLBindingException; @@ -49,6 +50,8 @@ import at.gv.egiz.bku.slexceptions.SLException; import at.gv.egiz.bku.slexceptions.SLRuntimeException; import at.gv.egiz.bku.utils.DebugOutputStream; import at.gv.egiz.bku.utils.DebugWriter; +import at.gv.egiz.marshal.MarshallerFactory; +import javax.xml.bind.PropertyException; /** * This class serves as an abstract base class for the implementation of a @@ -90,8 +93,7 @@ public abstract class SLResultImpl implements SLResult { private Marshaller getMarshaller() { try { JAXBContext context = SLCommandFactory.getInstance().getJaxbContext(); - Marshaller marshaller = context.createMarshaller(); - marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); + Marshaller marshaller = MarshallerFactory.createMarshaller(context, true); return marshaller; } catch (JAXBException e) { log.fatal("Failed to marshall error response.", e); |