From 569a7e0186efc468b043214857b159b4614a400b Mon Sep 17 00:00:00 2001 From: Philip Helger Date: Fri, 13 Dec 2024 12:58:49 +0100 Subject: [PATCH] Using ph- methods where applicable --- .../mime/DataContentHandlerSoap12.java | 17 ++-- .../com/helger/phase4/util/AS4XMLHelper.java | 14 +-- .../phase4/client/MainOldAS4Client.java | 21 ----- .../phase4/CEF/AS4CEFOneWayFuncTest.java | 54 ++++++++---- .../phase4/CEF/AS4eSENSCEFOneWayFuncTest.java | 87 +++++++++---------- .../UserMessageFailureForgeryTest.java | 32 ++----- .../phase4/server/servlet/PModeCheckTest.java | 7 +- 7 files changed, 108 insertions(+), 124 deletions(-) diff --git a/phase4-lib/src/main/java/com/helger/phase4/messaging/mime/DataContentHandlerSoap12.java b/phase4-lib/src/main/java/com/helger/phase4/messaging/mime/DataContentHandlerSoap12.java index 3474d0fa6..f54a74277 100644 --- a/phase4-lib/src/main/java/com/helger/phase4/messaging/mime/DataContentHandlerSoap12.java +++ b/phase4-lib/src/main/java/com/helger/phase4/messaging/mime/DataContentHandlerSoap12.java @@ -18,6 +18,7 @@ import java.io.IOException; import java.io.OutputStream; +import java.util.Locale; import javax.annotation.Nonnull; import javax.annotation.WillNotClose; @@ -31,7 +32,10 @@ import org.eclipse.angus.mail.handlers.text_plain; import com.helger.commons.annotation.ReturnsMutableObject; +import com.helger.commons.collection.ArrayHelper; import com.helger.phase4.model.ESoapVersion; +import com.helger.xml.transform.LoggingTransformErrorListener; +import com.helger.xml.transform.XMLTransformerFactory; import jakarta.activation.ActivationDataFlavor; import jakarta.activation.DataSource; @@ -58,8 +62,8 @@ public class DataContentHandlerSoap12 extends text_plain @Override @Nonnull - protected Object getData (@Nonnull final ActivationDataFlavor aFlavor, @Nonnull final DataSource aDataSource) - throws IOException + protected Object getData (@Nonnull final ActivationDataFlavor aFlavor, + @Nonnull final DataSource aDataSource) throws IOException { if (aFlavor.getRepresentationClass () == StreamSource.class) return new StreamSource (aDataSource.getInputStream ()); @@ -67,8 +71,6 @@ protected Object getData (@Nonnull final ActivationDataFlavor aFlavor, @Nonnull throw new IOException ("Unsupported flavor " + aFlavor + " on DS " + aDataSource); } - /** - */ @Override public void writeTo (@Nonnull final Object aObj, @Nonnull final String sMimeType, @@ -76,7 +78,12 @@ public void writeTo (@Nonnull final Object aObj, { try { - final Transformer aTransformer = TransformerFactory.newInstance ().newTransformer (); + // Here we can use a secure transformer factory + final TransformerFactory aFactory = XMLTransformerFactory.createTransformerFactory (new LoggingTransformErrorListener (Locale.ROOT), + null); + XMLTransformerFactory.makeTransformerFactorySecure (aFactory, ArrayHelper.EMPTY_STRING_ARRAY); + final Transformer aTransformer = XMLTransformerFactory.newTransformer (aFactory); + final StreamResult aStreamResult = new StreamResult (aOS); if (aObj instanceof DataSource) { diff --git a/phase4-lib/src/main/java/com/helger/phase4/util/AS4XMLHelper.java b/phase4-lib/src/main/java/com/helger/phase4/util/AS4XMLHelper.java index 0537dd106..d11e326bf 100644 --- a/phase4-lib/src/main/java/com/helger/phase4/util/AS4XMLHelper.java +++ b/phase4-lib/src/main/java/com/helger/phase4/util/AS4XMLHelper.java @@ -16,8 +16,9 @@ */ package com.helger.phase4.util; +import java.util.Locale; + import javax.annotation.Nonnull; -import javax.xml.XMLConstants; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; @@ -27,12 +28,15 @@ import org.w3c.dom.Node; import com.helger.commons.ValueEnforcer; +import com.helger.commons.collection.ArrayHelper; import com.helger.commons.io.stream.NonBlockingStringWriter; import com.helger.phase4.marshaller.Ebms3NamespaceHandler; import com.helger.xml.serialize.write.EXMLSerializeIndent; import com.helger.xml.serialize.write.EXMLSerializeXMLDeclaration; import com.helger.xml.serialize.write.XMLWriter; import com.helger.xml.serialize.write.XMLWriterSettings; +import com.helger.xml.transform.LoggingTransformErrorListener; +import com.helger.xml.transform.XMLTransformerFactory; /** * AS4 XML helper methods. @@ -63,10 +67,10 @@ private static String _serializeRT (@Nonnull final Node aNode) { try { - final TransformerFactory tf = TransformerFactory.newInstance (); - tf.setAttribute (XMLConstants.ACCESS_EXTERNAL_DTD, ""); - tf.setAttribute (XMLConstants.ACCESS_EXTERNAL_STYLESHEET, ""); - final Transformer aTransformer = tf.newTransformer (); + final TransformerFactory aFactory = XMLTransformerFactory.createTransformerFactory (new LoggingTransformErrorListener (Locale.ROOT), + null); + XMLTransformerFactory.makeTransformerFactorySecure (aFactory, ArrayHelper.EMPTY_STRING_ARRAY); + final Transformer aTransformer = aFactory.newTransformer (); try (final NonBlockingStringWriter aSW = new NonBlockingStringWriter ()) { diff --git a/phase4-lib/src/test/java/com/helger/phase4/client/MainOldAS4Client.java b/phase4-lib/src/test/java/com/helger/phase4/client/MainOldAS4Client.java index 0ca68d416..8466b0e04 100644 --- a/phase4-lib/src/test/java/com/helger/phase4/client/MainOldAS4Client.java +++ b/phase4-lib/src/test/java/com/helger/phase4/client/MainOldAS4Client.java @@ -16,15 +16,8 @@ */ package com.helger.phase4.client; -import java.io.IOException; import java.nio.charset.StandardCharsets; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; - import org.apache.hc.client5.http.classic.methods.HttpPost; import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; import org.apache.hc.core5.http.ContentType; @@ -34,7 +27,6 @@ import org.slf4j.LoggerFactory; import org.w3c.dom.Document; import org.w3c.dom.Node; -import org.xml.sax.SAXException; import com.helger.commons.collection.impl.CommonsArrayList; import com.helger.commons.collection.impl.ICommonsList; @@ -67,25 +59,12 @@ public final class MainOldAS4Client private MainOldAS4Client () {} - @Nullable - public static Document getSoapEnvelope11ForTest (@Nonnull final String sPath) throws SAXException, - IOException, - ParserConfigurationException - { - final DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance (); - // never forget this! - domFactory.setNamespaceAware (true); - final DocumentBuilder builder = domFactory.newDocumentBuilder (); - return builder.parse (new ClassPathResource (sPath).getInputStream ()); - } - /** * Starting point for the SAAJ - SOAP Client Testing * * @param args * ignored */ - @SuppressWarnings ("resource") public static void main (final String [] args) { try (final AS4ResourceHelper aResHelper = new AS4ResourceHelper ()) diff --git a/phase4-test/src/test/java/com/helger/phase4/CEF/AS4CEFOneWayFuncTest.java b/phase4-test/src/test/java/com/helger/phase4/CEF/AS4CEFOneWayFuncTest.java index f982e9607..5b29fc470 100644 --- a/phase4-test/src/test/java/com/helger/phase4/CEF/AS4CEFOneWayFuncTest.java +++ b/phase4-test/src/test/java/com/helger/phase4/CEF/AS4CEFOneWayFuncTest.java @@ -27,7 +27,6 @@ import javax.xml.transform.Result; import javax.xml.transform.Source; -import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; @@ -66,6 +65,7 @@ import com.helger.phase4.server.MockPModeGenerator; import com.helger.phase4.server.message.MockMessages; import com.helger.phase4.util.AS4XMLHelper; +import com.helger.xml.transform.XMLTransformerFactory; public final class AS4CEFOneWayFuncTest extends AbstractCEFTestSetUp { @@ -122,7 +122,8 @@ public void testAS4_TA03 () throws Exception aEbms3PartyInfo, aEbms3MessageProperties, null, - m_eSoapVersion).setMustUnderstand (true); + m_eSoapVersion) + .setMustUnderstand (true); final Document aSignedDoc = AS4Signer.createSignedMessage (m_aCryptoFactory, aMsg.getAsSoapDocument (m_aPayload), @@ -201,7 +202,8 @@ public void testAS4_TA06 () throws Exception .data (ClassPathResource.getAsFile (AS4TestConstants.ATTACHMENT_SHORTXML_XML)) .mimeType (CMimeType.APPLICATION_XML) .compression (EAS4CompressionMode.GZIP) - .build (), s_aResMgr)); + .build (), + s_aResMgr)); final AS4MimeMessage aMsg = AS4MimeMessageHelper.generateMimeMessage (m_eSoapVersion, createTestSignedUserMessage (m_eSoapVersion, m_aPayload, @@ -234,7 +236,8 @@ public void testAS4_TA07 () throws Exception .data (ClassPathResource.getAsFile (AS4TestConstants.ATTACHMENT_SHORTXML_XML)) .mimeType (CMimeType.APPLICATION_XML) .compression (EAS4CompressionMode.GZIP) - .build (), s_aResMgr)); + .build (), + s_aResMgr)); final Document aDoc = createTestSignedUserMessage (m_eSoapVersion, m_aPayload, aAttachments, s_aResMgr); @@ -268,7 +271,8 @@ public void testAS4_TA08 () throws Exception .data (ClassPathResource.getAsFile (AS4TestConstants.ATTACHMENT_SHORTXML_XML)) .mimeTypeXML () .compressionGZIP () - .build (), s_aResMgr)); + .build (), + s_aResMgr)); final Document aDoc = createTestSignedUserMessage (m_eSoapVersion, m_aPayload, aAttachments, s_aResMgr); @@ -299,7 +303,8 @@ public void testAS4_TA09 () throws Exception .data (ClassPathResource.getAsFile (AS4TestConstants.ATTACHMENT_SHORTXML_XML)) .mimeTypeXML () .compressionGZIP () - .build (), s_aResMgr)); + .build (), + s_aResMgr)); final Document aDoc = createTestSignedUserMessage (m_eSoapVersion, m_aPayload, aAttachments, s_aResMgr); @@ -497,7 +502,8 @@ public void testAS4_TA15 () throws Exception .data (ClassPathResource.getAsFile (AS4TestConstants.ATTACHMENT_SHORTXML_XML)) .mimeTypeXML () .compressionGZIP () - .build (), s_aResMgr)); + .build (), + s_aResMgr)); final Document aDoc = createTestSignedUserMessage (m_eSoapVersion, m_aPayload, aAttachments, s_aResMgr); @@ -526,17 +532,20 @@ public void testAS4_TA16 () throws Exception .data (ClassPathResource.getAsFile (AS4TestConstants.ATTACHMENT_SHORTXML_XML)) .mimeTypeXML () .compressionGZIP () - .build (), s_aResMgr)); + .build (), + s_aResMgr)); aAttachments.add (WSS4JAttachment.createOutgoingFileAttachment (AS4OutgoingAttachment.builder () .data (ClassPathResource.getAsFile (AS4TestConstants.ATTACHMENT_TEST_IMG_JPG)) .mimeType (CMimeType.IMAGE_JPG) .compressionGZIP () - .build (), s_aResMgr)); + .build (), + s_aResMgr)); aAttachments.add (WSS4JAttachment.createOutgoingFileAttachment (AS4OutgoingAttachment.builder () .data (ClassPathResource.getAsFile (AS4TestConstants.ATTACHMENT_SHORTXML2_XML)) .mimeTypeXML () .compressionGZIP () - .build (), s_aResMgr)); + .build (), + s_aResMgr)); final Document aDoc = createTestSignedUserMessage (m_eSoapVersion, m_aPayload, aAttachments, s_aResMgr); @@ -564,7 +573,8 @@ public void testAS4_TA17 () throws Exception .data (ClassPathResource.getAsFile (AS4TestConstants.ATTACHMENT_SHORTXML_XML)) .mimeTypeXML () .compressionGZIP () - .build (), s_aResMgr)); + .build (), + s_aResMgr)); final Document aDoc = createTestSignedUserMessage (m_eSoapVersion, m_aPayload, aAttachments, s_aResMgr); @@ -595,7 +605,8 @@ public void testAS4_TA18 () throws Exception aAttachments.add (WSS4JAttachment.createOutgoingFileAttachment (AS4OutgoingAttachment.builder () .data (ClassPathResource.getAsFile (AS4TestConstants.ATTACHMENT_SHORTXML_XML)) .mimeTypeXML () - .build (), s_aResMgr)); + .build (), + s_aResMgr)); final Document aDoc = createTestSignedUserMessage (m_eSoapVersion, m_aPayload, aAttachments, s_aResMgr); @@ -604,7 +615,8 @@ public void testAS4_TA18 () throws Exception .data (ClassPathResource.getAsFile (AS4TestConstants.ATTACHMENT_SHORTXML_XML)) .mimeTypeXML () .compressionGZIP () - .build (), s_aResMgr)); + .build (), + s_aResMgr)); final AS4MimeMessage aMsg = AS4MimeMessageHelper.generateMimeMessage (m_eSoapVersion, aDoc, aAttachments); sendMimeMessage (HttpMimeMessageEntity.create (aMsg), false, EEbmsError.EBMS_VALUE_INCONSISTENT.getErrorCode ()); @@ -629,7 +641,8 @@ public void testAS4_TA19 () throws Exception aAttachments.add (WSS4JAttachment.createOutgoingFileAttachment (AS4OutgoingAttachment.builder () .data (ClassPathResource.getAsFile (AS4TestConstants.ATTACHMENT_SHORTXML_XML)) .mimeTypeXML () - .build (), s_aResMgr)); + .build (), + s_aResMgr)); final AS4UserMessage aMsg = MockMessages.createUserMessageNotSigned (m_eSoapVersion, null, aAttachments); final AS4MimeMessage aMimeMsg = AS4Encryptor.encryptToMimeMessage (m_eSoapVersion, @@ -671,14 +684,14 @@ public void testAS4_TA20 () throws Exception final NonBlockingByteArrayOutputStream outputStream = new NonBlockingByteArrayOutputStream (); final Source xmlSource = new DOMSource (aNL.item (0)); final Result outputTarget = new StreamResult (outputStream); - TransformerFactory.newInstance ().newTransformer ().transform (xmlSource, outputTarget); + XMLTransformerFactory.newTransformer ().transform (xmlSource, outputTarget); final byte [] aSrc = outputStream.toByteArray (); // Compression final NonBlockingByteArrayOutputStream aCompressedOS = new NonBlockingByteArrayOutputStream (); try (final InputStream aIS = new NonBlockingByteArrayInputStream (aSrc); - final OutputStream aOS = EAS4CompressionMode.GZIP.getCompressStream (aCompressedOS)) + final OutputStream aOS = EAS4CompressionMode.GZIP.getCompressStream (aCompressedOS)) { StreamHelper.copyInputStreamToOutputStream (aIS, aOS); } @@ -709,7 +722,8 @@ public void testAS4_TA21 () throws Exception .data (ClassPathResource.getAsFile (AS4TestConstants.ATTACHMENT_SHORTXML_XML)) .mimeTypeXML () .compressionGZIP () - .build (), s_aResMgr)); + .build (), + s_aResMgr)); final AS4UserMessage aMsg = MockMessages.createUserMessageNotSigned (m_eSoapVersion, null, aAttachments); final Document aDoc = AS4Signer.createSignedMessage (m_aCryptoFactory, @@ -793,11 +807,13 @@ public void testAS4_TA28 () throws Exception aAttachments.add (WSS4JAttachment.createOutgoingFileAttachment (AS4OutgoingAttachment.builder () .data (ClassPathResource.getAsFile (AS4TestConstants.ATTACHMENT_SHORTXML_XML)) .mimeTypeXML () - .build (), s_aResMgr)); + .build (), + s_aResMgr)); aAttachments.add (WSS4JAttachment.createOutgoingFileAttachment (AS4OutgoingAttachment.builder () .data (ClassPathResource.getAsFile (AS4TestConstants.ATTACHMENT_TEST_IMG_JPG)) .mimeType (CMimeType.IMAGE_JPG) - .build (), s_aResMgr)); + .build (), + s_aResMgr)); final AS4MimeMessage aMsg = AS4MimeMessageHelper.generateMimeMessage (m_eSoapVersion, MockMessages.createUserMessageNotSigned (m_eSoapVersion, diff --git a/phase4-test/src/test/java/com/helger/phase4/CEF/AS4eSENSCEFOneWayFuncTest.java b/phase4-test/src/test/java/com/helger/phase4/CEF/AS4eSENSCEFOneWayFuncTest.java index 22337fe67..4575d9479 100644 --- a/phase4-test/src/test/java/com/helger/phase4/CEF/AS4eSENSCEFOneWayFuncTest.java +++ b/phase4-test/src/test/java/com/helger/phase4/CEF/AS4eSENSCEFOneWayFuncTest.java @@ -21,8 +21,6 @@ import javax.annotation.Nonnegative; import javax.annotation.Nonnull; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; import org.apache.hc.core5.http.NoHttpResponseException; import org.junit.Test; @@ -70,6 +68,7 @@ import com.helger.phase4.model.message.AS4UserMessage; import com.helger.phase4.model.message.MessageHelperMethods; import com.helger.phase4.server.MockPModeGenerator; +import com.helger.xml.serialize.read.DOMReader; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http.HttpObject; @@ -103,11 +102,11 @@ public AS4eSENSCEFOneWayFuncTest () public void testEsens_TA01 () throws Exception { final AS4MimeMessage aMsg = AS4MimeMessageHelper.generateMimeMessage (m_eSoapVersion, - createTestSignedUserMessage (m_eSoapVersion, - m_aPayload, - null, - s_aResMgr), - null); + createTestSignedUserMessage (m_eSoapVersion, + m_aPayload, + null, + s_aResMgr), + null); final String sResponse = sendMimeMessage (HttpMimeMessageEntity.create (aMsg), true, null); assertTrue (sResponse.contains (AS4TestConstants.RECEIPT_ASSERTCHECK)); @@ -196,11 +195,11 @@ public void testEsens_TA04 () throws Exception s_aResMgr)); final AS4MimeMessage aMsg = AS4MimeMessageHelper.generateMimeMessage (m_eSoapVersion, - createTestSignedUserMessage (m_eSoapVersion, - m_aPayload, - aAttachments, - s_aResMgr), - aAttachments); + createTestSignedUserMessage (m_eSoapVersion, + m_aPayload, + aAttachments, + s_aResMgr), + aAttachments); final String sResponse = sendMimeMessage (HttpMimeMessageEntity.create (aMsg), true, null); @@ -239,11 +238,11 @@ public void testEsens_TA05 () throws Exception s_aResMgr)); final AS4MimeMessage aMsg = AS4MimeMessageHelper.generateMimeMessage (m_eSoapVersion, - createTestSignedUserMessage (m_eSoapVersion, - m_aPayload, - aAttachments, - s_aResMgr), - aAttachments); + createTestSignedUserMessage (m_eSoapVersion, + m_aPayload, + aAttachments, + s_aResMgr), + aAttachments); final String sResponse = sendMimeMessage (HttpMimeMessageEntity.create (aMsg), true, null); @@ -291,11 +290,11 @@ public void testEsens_TA06 () throws Exception s_aResMgr)); final AS4MimeMessage aMsg = AS4MimeMessageHelper.generateMimeMessage (m_eSoapVersion, - createTestSignedUserMessage (m_eSoapVersion, - m_aPayload, - aAttachments, - s_aResMgr), - aAttachments); + createTestSignedUserMessage (m_eSoapVersion, + m_aPayload, + aAttachments, + s_aResMgr), + aAttachments); final Multipart aMultipart = (Multipart) aMsg.getContent (); // 3 attachments + 1 Main/Bodypart @@ -339,11 +338,11 @@ public void testEsens_TA07 () throws Exception s_aResMgr)); final AS4MimeMessage aMsg = AS4MimeMessageHelper.generateMimeMessage (m_eSoapVersion, - createTestSignedUserMessage (m_eSoapVersion, - m_aPayload, - aAttachments, - s_aResMgr), - aAttachments); + createTestSignedUserMessage (m_eSoapVersion, + m_aPayload, + aAttachments, + s_aResMgr), + aAttachments); final String sResponse = sendMimeMessage (HttpMimeMessageEntity.create (aMsg), true, null); @@ -386,9 +385,7 @@ public void testEsens_TA09 () throws Exception // Would throw an error in our implementation since the user would have said // there is a payload (With the hyperlink reference) but nothing is // attached. - final DocumentBuilderFactory aDbfac = DocumentBuilderFactory.newInstance (); - final DocumentBuilder aDocBuilder = aDbfac.newDocumentBuilder (); - final Document aDoc = aDocBuilder.parse (ClassPathResource.getAsFile ("attachment/HyperlinkPayload.xml")); + final Document aDoc = DOMReader.readXMLDOM (new ClassPathResource ("attachment/HyperlinkPayload.xml")); sendPlainMessage (new HttpXMLEntity (aDoc, m_eSoapVersion.getMimeType ()), false, @@ -469,11 +466,11 @@ public void testEsens_TA10 () throws Exception { // send message final AS4MimeMessage aMsg = AS4MimeMessageHelper.generateMimeMessage (m_eSoapVersion, - createTestSignedUserMessage (m_eSoapVersion, - m_aPayload, - null, - s_aResMgr), - null); + createTestSignedUserMessage (m_eSoapVersion, + m_aPayload, + null, + s_aResMgr), + null); sendMimeMessage (HttpMimeMessageEntity.create (aMsg), false, EEbmsError.EBMS_OTHER.getErrorCode ()); } finally @@ -543,11 +540,11 @@ public HttpObject serverToProxyResponse (final HttpObject httpObject) { // send message final AS4MimeMessage aMsg = AS4MimeMessageHelper.generateMimeMessage (m_eSoapVersion, - createTestSignedUserMessage (m_eSoapVersion, - m_aPayload, - null, - s_aResMgr), - null); + createTestSignedUserMessage (m_eSoapVersion, + m_aPayload, + null, + s_aResMgr), + null); sendMimeMessage (HttpMimeMessageEntity.create (aMsg), true, null); } finally @@ -723,11 +720,11 @@ public HttpObject serverToProxyResponse (final HttpObject httpObject) { // send message final AS4MimeMessage aMsg = AS4MimeMessageHelper.generateMimeMessage (m_eSoapVersion, - createTestSignedUserMessage (m_eSoapVersion, - m_aPayload, - null, - s_aResMgr), - null); + createTestSignedUserMessage (m_eSoapVersion, + m_aPayload, + null, + s_aResMgr), + null); sendMimeMessage (HttpMimeMessageEntity.create (aMsg), false, EEbmsError.EBMS_OTHER.getErrorCode ()); } finally diff --git a/phase4-test/src/test/java/com/helger/phase4/server/message/UserMessageFailureForgeryTest.java b/phase4-test/src/test/java/com/helger/phase4/server/message/UserMessageFailureForgeryTest.java index f9cf942f5..dca2f2b5b 100644 --- a/phase4-test/src/test/java/com/helger/phase4/server/message/UserMessageFailureForgeryTest.java +++ b/phase4-test/src/test/java/com/helger/phase4/server/message/UserMessageFailureForgeryTest.java @@ -22,8 +22,6 @@ import java.util.Collection; import javax.annotation.Nonnull; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; import org.apache.hc.core5.http.io.entity.StringEntity; import org.junit.Test; @@ -103,10 +101,7 @@ public void testEmptyUserMessage () @Test public void testTwoUserMessagesShouldFail () throws Exception { - final DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance (); - domFactory.setNamespaceAware (true); // never forget this! - final DocumentBuilder builder = domFactory.newDocumentBuilder (); - final Document aDoc = builder.parse (new ClassPathResource ("testfiles/TwoUserMessages.xml").getInputStream ()); + final Document aDoc = DOMReader.readXMLDOM (new ClassPathResource ("testfiles/TwoUserMessages.xml")); sendPlainMessage (new HttpXMLEntity (aDoc, m_eSoapVersion.getMimeType ()), false, @@ -116,10 +111,7 @@ public void testTwoUserMessagesShouldFail () throws Exception @Test public void testUserMessageWithNoPartyIDShouldFail () throws Exception { - final DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance (); - domFactory.setNamespaceAware (true); // never forget this! - final DocumentBuilder builder = domFactory.newDocumentBuilder (); - final Document aDoc = builder.parse (new ClassPathResource ("testfiles/UserMessageNoPartyID.xml").getInputStream ()); + final Document aDoc = DOMReader.readXMLDOM (new ClassPathResource ("testfiles/UserMessageNoPartyID.xml")); sendPlainMessage (new HttpXMLEntity (aDoc, m_eSoapVersion.getMimeType ()), false, @@ -278,11 +270,11 @@ public void testUserMessageWithAttachmentPartInfoOnly () throws Exception s_aResMgr)); final AS4MimeMessage aMimeMsg = AS4MimeMessageHelper.generateMimeMessage (m_eSoapVersion, - MockMessages.createUserMessageNotSigned (m_eSoapVersion, - null, - aAttachments) - .getAsSoapDocument (), - aAttachments); + MockMessages.createUserMessageNotSigned (m_eSoapVersion, + null, + aAttachments) + .getAsSoapDocument (), + aAttachments); final AS4SoapMimeMultipart aMultipart = (AS4SoapMimeMultipart) aMimeMsg.getContent (); @@ -350,10 +342,7 @@ public void testUserMessageWithMoreAttachmentsThenPartInfo () throws Exception @Test public void testUserMessageWrongSigningAlgorithm () throws Exception { - final DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance (); - domFactory.setNamespaceAware (true); // never forget this! - final DocumentBuilder builder = domFactory.newDocumentBuilder (); - final Document aDoc = builder.parse (new ClassPathResource ("testfiles/WrongSigningAlgorithm.xml").getInputStream ()); + final Document aDoc = DOMReader.readXMLDOM (new ClassPathResource ("testfiles/WrongSigningAlgorithm.xml")); sendPlainMessage (new HttpXMLEntity (aDoc, m_eSoapVersion.getMimeType ()), false, @@ -363,10 +352,7 @@ public void testUserMessageWrongSigningAlgorithm () throws Exception @Test public void testUserMessageWrongSigningDigestAlgorithm () throws Exception { - final DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance (); - domFactory.setNamespaceAware (true); // never forget this! - final DocumentBuilder builder = domFactory.newDocumentBuilder (); - final Document aDoc = builder.parse (new ClassPathResource ("testfiles/WrongSigningDigestAlgorithm.xml").getInputStream ()); + final Document aDoc = DOMReader.readXMLDOM (new ClassPathResource ("testfiles/WrongSigningDigestAlgorithm.xml")); sendPlainMessage (new HttpXMLEntity (aDoc, m_eSoapVersion.getMimeType ()), false, diff --git a/phase4-test/src/test/java/com/helger/phase4/server/servlet/PModeCheckTest.java b/phase4-test/src/test/java/com/helger/phase4/server/servlet/PModeCheckTest.java index 4128a060d..eb403b5e4 100644 --- a/phase4-test/src/test/java/com/helger/phase4/server/servlet/PModeCheckTest.java +++ b/phase4-test/src/test/java/com/helger/phase4/server/servlet/PModeCheckTest.java @@ -22,8 +22,6 @@ import java.util.UUID; import javax.annotation.Nonnull; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; import org.junit.Before; import org.junit.Ignore; @@ -292,10 +290,7 @@ public void testUserMessageDifferentPropertiesValues () throws Exception @Test public void testNoResponderInMessageInvalidShouldReturnErrorMessage () throws Exception { - final DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance (); - domFactory.setNamespaceAware (true); // never forget this! - final DocumentBuilder builder = domFactory.newDocumentBuilder (); - final Document aDoc = builder.parse (new ClassPathResource ("testfiles/NoResponder.xml").getInputStream ()); + final Document aDoc = DOMReader.readXMLDOM (new ClassPathResource ("testfiles/NoResponder.xml")); sendPlainMessage (new HttpXMLEntity (aDoc, SOAP_VERSION.getMimeType ()), false,