Skip to content

Commit

Permalink
Improved code readability
Browse files Browse the repository at this point in the history
  • Loading branch information
phax committed Sep 14, 2023
1 parent 61510f9 commit 8c3be6e
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,12 @@ public static void main (final String [] args)
try (final AS4ResourceHelper aResHelper = new AS4ResourceHelper ())
{
String sURL = "http://127.0.0.1:8080/as4";

// External holodeck
if (false)
sURL = "http://msh.holodeck-b2b.org:8080/msh";

// Deactivate if not sending to local holodeck
// Local holodeck
if (false)
sURL = "http://localhost:8080/msh/";

Expand All @@ -104,6 +106,7 @@ public static void main (final String [] args)
aHCS.setSSLContextTrustAll ();
if (false)
{
// BRZ internal
aHCS.setProxyHost (new HttpHost ("172.30.9.6", 8080));
aHCS.addNonProxyHostsFromPipeString ("localhost|127.0.0.1");
}
Expand All @@ -117,88 +120,91 @@ public static void main (final String [] args)
final ESoapVersion eSoapVersion = ESoapVersion.SOAP_12;
final IAS4CryptoFactory aCryptoFactory = AS4CryptoFactoryProperties.getDefaultInstance ();

if (true)
switch (4)
{
// No Mime Message Not signed or encrypted, just SOAP + Payload in
// SOAP
// -
// Body
// final Document aDoc = TestMessages.testSignedUserMessage
// (ESOAPVersion.SOAP_11, aPayload, aAttachments);
final AS4UserMessage aMsg = MockClientMessages.createUserMessageNotSigned (eSoapVersion,
aPayload,
aAttachments);
final Document aDoc = aMsg.getAsSoapDocument (aPayload);
aPost.setEntity (new HttpXMLEntity (aDoc, eSoapVersion.getMimeType ()));
}
else
if (false)
case 1:
{
// BodyPayload NOT SIGNED and NOT ENCRYPTED
final AS4UserMessage aMsg = MockClientMessages.createUserMessageNotSigned (eSoapVersion,
aPayload,
aAttachments);
final Document aDoc = aMsg.getAsSoapDocument (aPayload);
aPost.setEntity (new HttpXMLEntity (aDoc, eSoapVersion.getMimeType ()));
break;
}
case 2:
{
// BodyPayload SIGNED
final Document aDoc = MockClientMessages.createUserMessageSigned (eSoapVersion,
aPayload,
aAttachments,
aResHelper);
aPost.setEntity (new HttpXMLEntity (aDoc, eSoapVersion.getMimeType ()));
break;
}
else
if (false)
{
// BodyPayload ENCRYPTED
final AS4UserMessage aMsg = MockClientMessages.createUserMessageNotSigned (eSoapVersion,
aPayload,
aAttachments);
Document aDoc = aMsg.getAsSoapDocument (aPayload);
aDoc = AS4Encryptor.encryptSoapBodyPayload (aCryptoFactory,
eSoapVersion,
aDoc,
false,
AS4CryptParams.createDefault ().setAlias ("dummy"));

aPost.setEntity (new HttpXMLEntity (aDoc, eSoapVersion.getMimeType ()));
}
else
if (true)
{
aAttachments.add (WSS4JAttachment.createOutgoingFileAttachment (AS4OutgoingAttachment.builder ()
.data (ClassPathResource.getAsFile ("external/attachment/test.xml.gz"))
.mimeType (CMimeType.APPLICATION_GZIP)
.build (),
aResHelper));
final AS4UserMessage aMsg = MockClientMessages.createUserMessageNotSigned (eSoapVersion,
null,
aAttachments);
final AS4MimeMessage aMimeMsg = MimeMessageCreator.generateMimeMessage (eSoapVersion,
AS4Signer.createSignedMessage (aCryptoFactory,
aMsg.getAsSoapDocument (null),
eSoapVersion,
aMsg.getMessagingID (),
aAttachments,
aResHelper,
false,
AS4SigningParams.createDefault ()),
aAttachments);

// Move all global mime headers to the POST request
MessageHelperMethods.forEachHeaderAndRemoveAfterwards (aMimeMsg, aPost::addHeader, true);
aPost.setEntity (HttpMimeMessageEntity.create (aMimeMsg));
}
else
if (false)
{
Document aDoc = MockClientMessages.createUserMessageSigned (eSoapVersion,
aPayload,
aAttachments,
aResHelper);
aDoc = AS4Encryptor.encryptSoapBodyPayload (aCryptoFactory,
eSoapVersion,
aDoc,
false,
AS4CryptParams.createDefault ().setAlias ("dummy"));
aPost.setEntity (new HttpXMLEntity (aDoc, eSoapVersion.getMimeType ()));
}
else
throw new IllegalStateException ("Some test message should be selected :)");
case 3:
{
// BodyPayload ENCRYPTED
final AS4UserMessage aMsg = MockClientMessages.createUserMessageNotSigned (eSoapVersion,
aPayload,
aAttachments);
Document aDoc = aMsg.getAsSoapDocument (aPayload);
aDoc = AS4Encryptor.encryptSoapBodyPayload (aCryptoFactory,
eSoapVersion,
aDoc,
false,
AS4CryptParams.createDefault ()
.setAlias (aCryptoFactory.getKeyAlias ()));

aPost.setEntity (new HttpXMLEntity (aDoc, eSoapVersion.getMimeType ()));
break;
}
case 4:
{
// BodyPayload SIGNED and ENCRYPTED
Document aDoc = MockClientMessages.createUserMessageSigned (eSoapVersion,
aPayload,
aAttachments,
aResHelper);
aDoc = AS4Encryptor.encryptSoapBodyPayload (aCryptoFactory,
eSoapVersion,
aDoc,
false,
AS4CryptParams.createDefault ()
.setAlias (aCryptoFactory.getKeyAlias ()));
aPost.setEntity (new HttpXMLEntity (aDoc, eSoapVersion.getMimeType ()));
break;
}
case 5:
{
// MIME Message SIGNED
aAttachments.add (WSS4JAttachment.createOutgoingFileAttachment (AS4OutgoingAttachment.builder ()
.data (ClassPathResource.getAsFile ("external/attachment/test.xml.gz"))
.mimeType (CMimeType.APPLICATION_GZIP)
.build (),
aResHelper));
final AS4UserMessage aMsg = MockClientMessages.createUserMessageNotSigned (eSoapVersion,
null,
aAttachments);
final AS4MimeMessage aMimeMsg = MimeMessageCreator.generateMimeMessage (eSoapVersion,
AS4Signer.createSignedMessage (aCryptoFactory,
aMsg.getAsSoapDocument (null),
eSoapVersion,
aMsg.getMessagingID (),
aAttachments,
aResHelper,
false,
AS4SigningParams.createDefault ()),
aAttachments);

// Move all global mime headers to the POST request
MessageHelperMethods.forEachHeaderAndRemoveAfterwards (aMimeMsg, aPost::addHeader, true);
aPost.setEntity (HttpMimeMessageEntity.create (aMimeMsg));
break;
}
default:
throw new IllegalStateException ("Some test message should be selected :)");
}

// re-instantiate if you want to see the request that is getting sent
LOGGER.info (EntityUtils.toString (aPost.getEntity ()));
Expand Down
1 change: 1 addition & 0 deletions phase4-server-webapp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
<groupId>com.helger.peppol</groupId>
<artifactId>peppol-smp-client</artifactId>
</dependency>

<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
Expand Down

0 comments on commit 8c3be6e

Please sign in to comment.