Skip to content

Commit

Permalink
Made EuCtpPullRequestBuilder abstract
Browse files Browse the repository at this point in the history
  • Loading branch information
phax committed Aug 28, 2024
1 parent e0e7454 commit ee76bd0
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,19 @@
import com.helger.phase4.profile.euctp.AS4EuCtpProfileRegistarSPI;
import com.helger.phase4.sender.AbstractAS4PullRequestBuilder;

public class EuCtpPullRequestBuilder extends AbstractAS4PullRequestBuilder <EuCtpPullRequestBuilder>
/**
* Abstract EuCTP PullRequest builder class with sanity methods
*
* @param <IMPLTYPE>
* The implementation type
* @author Ulrik Stehling
* @author Philip Helger
*/
public abstract class AbstractEuCtpPullRequestBuilder <IMPLTYPE extends AbstractEuCtpPullRequestBuilder <IMPLTYPE>>
extends
AbstractAS4PullRequestBuilder <IMPLTYPE>
{
public EuCtpPullRequestBuilder ()
public AbstractEuCtpPullRequestBuilder ()
{
try
{
Expand All @@ -43,9 +53,9 @@ public EuCtpPullRequestBuilder ()
// Other signing parameters are located in the PMode security part
signingParams ().setKeyIdentifierType (AbstractEuCtpUserMessageBuilder.DEFAULT_KEY_IDENTIFIER_TYPE_SIGN);
signingParams ().setAlgorithmC14N (ECryptoAlgorithmC14N.C14N_EXCL_OMIT_COMMENTS);

// Use the BST value type "#X509PKIPathv1"
signingParams ().setUseSingleCertificate (false);

}
catch (final Exception ex)
{
Expand All @@ -54,8 +64,8 @@ public EuCtpPullRequestBuilder ()
}

@Nonnull
public EuCtpPullRequestBuilder httpClientFactory (@Nullable final KeyStore aKeyStore,
@Nullable final char [] aKeyPassword) throws GeneralSecurityException
public IMPLTYPE httpClientFactory (@Nullable final KeyStore aKeyStore, @Nullable final char [] aKeyPassword)
throws GeneralSecurityException
{
return httpClientFactory (new Phase4EuCtpHttpClientSettings (aKeyStore, aKeyPassword));
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,50 @@ private Phase4EuCtpSender ()
{}

/**
* @return Create a new Builder for AS4 messages if the payload is present.
* Never <code>null</code>.
* @return Create a new Builder for AS4 User Messages if the payload is
* present. Never <code>null</code>.
*/
@Nonnull
public static EuCtpUserMessageBuilder builder ()
public static EuCtpUserMessageBuilder builderUserMessage ()
{
return new EuCtpUserMessageBuilder();
return new EuCtpUserMessageBuilder ();
}

/**
* The builder class for sending AS4 messages using EuCTP profile specifics.
* Use {@link #sendMessage()} or {@link #sendMessageAndCheckForReceipt()} to
* trigger the main transmission.
* @return Create a new Builder for AS4 Pull Requests. Never
* <code>null</code>.
* @since 3.0.0
*/
@Nonnull
public static EuCtpPullRequestBuilder builderPullRequest ()
{
return new EuCtpPullRequestBuilder ();
}

/**
* The builder class for sending AS4 User Messages using EuCTP profile
* specifics. Use {@link #sendMessage()} or
* {@link #sendMessageAndCheckForReceipt()} to trigger the main transmission.
*
* @author Ulrik Stehling
*/
public static class EuCtpUserMessageBuilder extends AbstractEuCtpUserMessageBuilder <EuCtpUserMessageBuilder>
{
public EuCtpUserMessageBuilder()
public EuCtpUserMessageBuilder ()
{
super ();
}
}

/**
* The builder class for sending AS4 Pull Requests using EuCTP profile
* specifics. Use {@link #sendMessage()} to trigger the main transmission.
*
* @author Philip Helger
*/
public static class EuCtpPullRequestBuilder extends AbstractEuCtpPullRequestBuilder <EuCtpPullRequestBuilder>
{
public EuCtpPullRequestBuilder ()
{
super ();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,30 +138,32 @@ private static void _sendPullRequest (final Phase4EuCtpHttpClientSettings aHttpC
}

final List <String> attachmentsAsString = new ArrayList <> ();
final ESuccess eSuccess = new EuCtpPullRequestBuilder ().httpClientFactory (aHttpClientSettings)
.endpointURL ("https://conformance.customs.ec.europa.eu:8445/domibus/services/msh")
.mpc (sMPC)
.userMsgConsumer ( (aUserMsg, aMessageMetadata, aState) -> {
aUserMessageHolder.set (aUserMsg);

if (aState.hasDecryptedAttachments ())
{
// Remember all
// attachments
// here
for (final WSS4JAttachment attachment : aState.getDecryptedAttachments ())
{
final String parsedFile = StreamHelper.getAllBytesAsString (attachment.getSourceStream (),
StandardCharsets.UTF_8);
attachmentsAsString.add (parsedFile);
}
}
})
.signalMsgConsumer ( (aSignalMsg, aMMD, aState) -> {
aSignalMessageHolder.set (aSignalMsg);
})
.cryptoFactory (cryptoFactoryProperties)
.sendMessage ();
final ESuccess eSuccess = Phase4EuCtpSender.builderPullRequest ()
.httpClientFactory (aHttpClientSettings)
.endpointURL ("https://conformance.customs.ec.europa.eu:8445/domibus/services/msh")
.mpc (sMPC)
.userMsgConsumer ( (aUserMsg, aMessageMetadata, aState) -> {
aUserMessageHolder.set (aUserMsg);

if (aState.hasDecryptedAttachments ())
{
/*
* Remember all attachments
* here
*/
for (final WSS4JAttachment attachment : aState.getDecryptedAttachments ())
{
final String parsedFile = StreamHelper.getAllBytesAsString (attachment.getSourceStream (),
StandardCharsets.UTF_8);
attachmentsAsString.add (parsedFile);
}
}
})
.signalMsgConsumer ( (aSignalMsg, aMMD, aState) -> {
aSignalMessageHolder.set (aSignalMsg);
})
.cryptoFactory (cryptoFactoryProperties)
.sendMessage ();
//
LOGGER.info ("euctp pull request result: " + eSuccess);
LOGGER.info ("Pulled User Message: " + aUserMessageHolder.get ());
Expand All @@ -175,7 +177,7 @@ private static void _sendConnectionTest (final Phase4EuCtpHttpClientSettings aHt
final AS4CryptoFactoryProperties cryptoFactoryProperties)
{
EAS4UserMessageSendResult eResult;
eResult = Phase4EuCtpSender.builder ()
eResult = Phase4EuCtpSender.builderUserMessage ()
.httpClientFactory (aHttpClientSettings)
.fromPartyID (fromPartyID)
.fromPartyIDType (EuCtpPMode.DEFAULT_PARTY_TYPE_ID)
Expand Down Expand Up @@ -204,7 +206,7 @@ private static void _sendENSFilling (final Phase4EuCtpHttpClientSettings aHttpCl

final Wrapper <Ebms3SignalMessage> aSignalMsgHolder = new Wrapper <> ();
EAS4UserMessageSendResult eResult;
eResult = Phase4EuCtpSender.builder ()
eResult = Phase4EuCtpSender.builderUserMessage ()
.httpClientFactory (aHttpClientSettings)
.fromPartyID (fromPartyID)
.fromPartyIDType (EuCtpPMode.DEFAULT_PARTY_TYPE_ID)
Expand Down

0 comments on commit ee76bd0

Please sign in to comment.