Package com.helger.phase4.sender
Class AbstractAS4MessageBuilder<IMPLTYPE extends AbstractAS4MessageBuilder<IMPLTYPE>>
java.lang.Object
com.helger.phase4.sender.AbstractAS4MessageBuilder<IMPLTYPE>
- Type Parameters:
IMPLTYPE- The implementation type
- All Implemented Interfaces:
com.helger.base.trait.IGenericImplTrait<IMPLTYPE>
- Direct Known Subclasses:
AbstractAS4PullRequestBuilder,AbstractAS4UserMessageBuilder
@NotThreadSafe
public abstract class AbstractAS4MessageBuilder<IMPLTYPE extends AbstractAS4MessageBuilder<IMPLTYPE>>
extends Object
implements com.helger.base.trait.IGenericImplTrait<IMPLTYPE>
Abstract builder base class with the requirements for all message types.
- Since:
- 0.10.0
- Author:
- Philip Helger
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Localeprotected IAS4ClientBuildMessageCallbackprotected IAS4CryptoFactoryprotected IAS4CryptoFactoryprotected final AS4CryptParamsprotected IHttpPosterprotected IAS4DecryptParameterModifierprotected com.helger.httpclient.HttpClientFactoryprotected HttpRetrySettingsprotected IAS4IncomingDumperprotected Localeprotected IAS4OutgoingDumperprotected IAS4RawResponseConsumerprotected IAS4RetryCallbackprotected OffsetDateTimeprotected IAS4SendingDateTimeConsumerprotected final AS4SigningParamsprotected ESoapVersionprotected Stringprotected Stringprotected String -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCreate a new builder, with the following fields already set:
httpClientFactory(HttpClientFactory)
cryptoFactory(IAS4CryptoFactory)
soapVersion(ESoapVersion)incomingAttachmentFactory(IAS4IncomingAttachmentFactory) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidInternal method that is invoked after successful sending took place.final @Nullable Stringfinal @NonNull IMPLTYPEas4ProfileID(@Nullable String sAS4ProfileID) Set the AS4 profile to be used.final @Nullable IAS4ClientBuildMessageCallbackfinal @NonNull IMPLTYPEbuildMessageCallback(@Nullable IAS4ClientBuildMessageCallback aBuildMessageCallback) Set a internal message callback.final @NonNull IMPLTYPEcryptoFactory(@Nullable IAS4CryptoFactory aCryptoFactory) Set the crypto factory to be used for signing and crypting.final @Nullable IAS4CryptoFactoryfinal @NonNull IMPLTYPEcryptoFactoryCrypt(@Nullable IAS4CryptoFactory aCryptoFactoryCrypt) Set the crypto factory to be used for crypting.final @Nullable IAS4CryptoFactoryfinal @NonNull IMPLTYPEcryptoFactorySign(@Nullable IAS4CryptoFactory aCryptoFactorySign) Set the crypto factory to be used for signing.final @NonNull AS4CryptParamsGet the mutable AS4 crypt parameters.final @Nullable IHttpPosterfinal @NonNull IMPLTYPEcustomHttpPoster(@Nullable IHttpPoster aCustomHttpPoster) Set the HTTP poster to be used.protected voidInternal method that is invoked after the required fields are checked but before sending takes place.final @Nullable IAS4DecryptParameterModifierfinal @NonNull IMPLTYPEdecryptRequestDataModifier(@Nullable IAS4DecryptParameterModifier aDecryptParameterModifier) Set an optional customizing callback that is invoked when decrypting a message, to be able to modify the decryption configuration.protected com.helger.base.state.ESuccessfinishFields(@NonNull AS4ResourceHelper aResHelper) Internal method that is invoked before the required field check is performed.final @Nullable com.helger.httpclient.HttpClientFactoryfinal @NonNull IMPLTYPEhttpClientFactory(@Nullable com.helger.httpclient.HttpClientFactory aHttpClientFactory) Set the HTTP client factory to be used.final @NonNull IMPLTYPEhttpClientFactory(@Nullable com.helger.httpclient.HttpClientSettings aHttpClientSettings) Set the HTTP client factory to be used.final @Nullable HttpRetrySettingsfinal @NonNull IMPLTYPEhttpRetrySettings(@Nullable HttpRetrySettings a) Set the HTTP retry settings to be used.final @NonNull IAS4IncomingAttachmentFactoryfinal @NonNull IMPLTYPEincomingAttachmentFactory(@NonNull IAS4IncomingAttachmentFactory aIAF) Set the incoming attachment factory to be used.final @Nullable IAS4IncomingDumperfinal @NonNull IMPLTYPEincomingDumper(@Nullable IAS4IncomingDumper aIncomingDumper) Set a specific incoming dumper for this builder.final @NonNull IAS4IncomingProfileSelectorfinal @NonNull IMPLTYPEincomingProfileSelector(@NonNull IAS4IncomingProfileSelector aIncomingProfileSelector) Set the selector for the AS4 profile of incoming messages.booleanCheck if all mandatory fields are set.final @Nullable Localelocale()final @NonNull IMPLTYPESet the locale to use.protected abstract voidSynchronously send the AS4 message.final @Nullable Stringfinal @NonNull IMPLTYPESet the optional AS4 message ID.final @Nullable IAS4OutgoingDumperfinal @NonNull IMPLTYPEoutgoingDumper(@Nullable IAS4OutgoingDumper aOutgoingDumper) Set a specific outgoing dumper for this builder.final @Nullable IAS4PModeResolverfinal @NonNull IMPLTYPEpmodeResolver(@Nullable IAS4PModeResolver aPModeResolver) Set the PMode resolver to be used.final @Nullable IAS4RawResponseConsumerfinal @NonNull IMPLTYPErawResponseConsumer(@Nullable IAS4RawResponseConsumer aRaweResponseConsumer) Set an optional handler for the synchronous result message received from the other side.final @Nullable Stringfinal @NonNull IMPLTYPErefToMessageID(@Nullable String sRefToMessageID) Set the optional AS4 reference to a previous message ID.final @Nullable IAS4RetryCallbackfinal @NonNull IMPLTYPEretryCallback(@Nullable IAS4RetryCallback aRetryCallback) Set an optional handler that is notified if an http sending will be retried.final @Nullable IAS4SenderInterruptfinal @NonNull IMPLTYPEsenderInterrupt(@Nullable IAS4SenderInterrupt aSenderInterrupt) Set the sender interrupt to be used.final @Nullable OffsetDateTimefinal @NonNull IMPLTYPEsendingDateTime(@Nullable OffsetDateTime aSendingDateTime) Set the optional sending date time.final @Nullable IAS4SendingDateTimeConsumerfinal @NonNull IMPLTYPEsendingDateTimeConsumer(@Nullable IAS4SendingDateTimeConsumer aSendingDTConsumer) Set the sending date time consumer to be used.final @NonNull com.helger.base.state.ESuccessSynchronously send the AS4 message.final @NonNull AS4SigningParamsGet the mutable AS4 signing parameters.final @Nullable ESoapVersionfinal @NonNull IMPLTYPEsoapVersion(@Nullable ESoapVersion eSoapVersion) Set the SOAP version to be used.final @NonNull IMPLTYPEwithCryptParams(@NonNull Consumer<? super AS4CryptParams> aConsumer) Modify the AS4 crypt parameters for this message.final @NonNull IMPLTYPEwithSigningParams(@NonNull Consumer<? super AS4SigningParams> aConsumer) Modify the AS4 signing parameters for this message.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.helger.base.trait.IGenericImplTrait
thisAsT
-
Field Details
-
DEFAULT_LOCALE
-
m_aCustomHttpPoster
-
m_aHttpClientFactory
protected com.helger.httpclient.HttpClientFactory m_aHttpClientFactory -
m_aCryptoFactorySign
-
m_aCryptoFactoryCrypt
-
m_aSigningParams
-
m_aCryptParams
-
m_sMessageID
-
m_sRefToMessageID
-
m_aSendingDateTime
-
m_eSoapVersion
-
m_aHttpRetrySettings
-
m_aLocale
-
m_sAS4ProfileID
-
m_aSendingDTConsumer
-
m_aBuildMessageCallback
-
m_aOutgoingDumper
-
m_aIncomingDumper
-
m_aDecryptParameterModifier
-
m_aRetryCallback
-
m_aResponseConsumer
-
-
Constructor Details
-
AbstractAS4MessageBuilder
protected AbstractAS4MessageBuilder()Create a new builder, with the following fields already set:
httpClientFactory(HttpClientFactory)
cryptoFactory(IAS4CryptoFactory)
soapVersion(ESoapVersion)incomingAttachmentFactory(IAS4IncomingAttachmentFactory)
-
-
Method Details
-
customHttpPoster
- Returns:
- The currently set
IHttpPoster. May benull. - Since:
- 1.3.10
-
customHttpPoster
Set the HTTP poster to be used. This is a very low level API and should only be used if you know what you are doing! It allows you to overwrite how the message is sent over the wire.
Note: if this method is used with a non-nullparameter,httpClientFactory()becomes useless- Parameters:
aCustomHttpPoster- The new HTTP poster to be used. May benullwhich means "use the default" poster.- Returns:
- this for chaining
- Since:
- 1.3.10
-
httpClientFactory
public final @Nullable com.helger.httpclient.HttpClientFactory httpClientFactory()- Returns:
- The currently set
HttpClientFactory. May benull.
-
httpClientFactory
public final @NonNull IMPLTYPE httpClientFactory(@Nullable com.helger.httpclient.HttpClientSettings aHttpClientSettings) Set the HTTP client factory to be used. If the passed settings are non-null, a newHttpClientFactoryis created with them, else anull-HttpClientFactoryis set.- Parameters:
aHttpClientSettings- The new HTTP client settings to be used. May benull.- Returns:
- this for chaining
-
httpClientFactory
public final @NonNull IMPLTYPE httpClientFactory(@Nullable com.helger.httpclient.HttpClientFactory aHttpClientFactory) Set the HTTP client factory to be used. By default a default instance ofHttpClientFactoryis used (set in the constructor) and there is no need to invoke this method.- Parameters:
aHttpClientFactory- The new HTTP client factory to be used. May benull.- Returns:
- this for chaining
-
cryptoFactorySign
- Returns:
- The currently set
IAS4CryptoFactoryfor signing. May benull. - Since:
- 2.2.0
- See Also:
-
cryptoFactorySign
Set the crypto factory to be used for signing. The default crypto factory is set in the constructor toAS4CryptoFactoryConfiguration.getDefaultInstance().- Parameters:
aCryptoFactorySign- The crypto factory to be used. May benull.- Returns:
- this for chaining
- Since:
- 2.2.0
-
cryptoFactoryCrypt
- Returns:
- The currently set
IAS4CryptoFactoryfor crypting. May benull. - Since:
- 2.2.0
- See Also:
-
cryptoFactoryCrypt
Set the crypto factory to be used for crypting. The default crypto factory is set in the constructor toAS4CryptoFactoryConfiguration.getDefaultInstanceOrNull().- Parameters:
aCryptoFactoryCrypt- The crypto factory to be used. May benull.- Returns:
- this for chaining
- Since:
- 2.2.0
-
cryptoFactory
Set the crypto factory to be used for signing and crypting. The default crypto factory is set in the constructor toAS4CryptoFactoryConfiguration.getDefaultInstanceOrNull().- Parameters:
aCryptoFactory- The crypto factory to be used. May benull.- Returns:
- this for chaining
- See Also:
-
signingParams
Get the mutable AS4 signing parameters.- Returns:
- The AS4 signing parameters to use for this message. Never
null. - Since:
- 2.1.4
- See Also:
-
withSigningParams
@ReturnsMutableObject public final @NonNull IMPLTYPE withSigningParams(@NonNull Consumer<? super AS4SigningParams> aConsumer) Modify the AS4 signing parameters for this message. This is a version that maintains chainability of the API.- Parameters:
aConsumer- Consumer for the AS4 signing parameters to use for this message. Must not benull.- Returns:
- this for chaining
- Since:
- 2.1.4
- See Also:
-
cryptParams
Get the mutable AS4 crypt parameters.- Returns:
- The AS4 crypt parameters to use for this message. Never
null. - Since:
- 2.1.4
- See Also:
-
withCryptParams
@ReturnsMutableObject public final @NonNull IMPLTYPE withCryptParams(@NonNull Consumer<? super AS4CryptParams> aConsumer) Modify the AS4 crypt parameters for this message. This is a version that maintains chainability of the API.- Parameters:
aConsumer- Consumer for the AS4 crypt parameters to use for this message. Must not benull.- Returns:
- this for chaining
- Since:
- 2.1.4
- See Also:
-
messageID
- Returns:
- The specific AS4 message ID to use. May be
nullif a random one should be generated. - Since:
- 3.0.0
-
messageID
Set the optional AS4 message ID. If this field is not set, a random message ID is created.- Parameters:
sMessageID- The optional AS4 message ID to be used. May benull.- Returns:
- this for chaining
-
refToMessageID
- Returns:
- The optional AS4 reference to a previous message ID. May be
null. - Since:
- 3.0.0
-
refToMessageID
Set the optional AS4 reference to a previous message ID. If this field is not set, it will not be emitted in the message.- Parameters:
sRefToMessageID- The optional AS4 reference to a previous message ID to be used. May benull.- Returns:
- this for chaining
- Since:
- 1.3.2
-
sendingDateTime
- Returns:
- The optional sending date time. May be
null. - Since:
- 3.0.0
-
sendingDateTime
Set the optional sending date time. If no time is specified, the current date time will be used.- Parameters:
aSendingDateTime- The sending date time to set. May benull.- Returns:
- this for chaining
- Since:
- 0.12.0
-
soapVersion
- Returns:
- The SOAP version to be used. May be
null.
-
soapVersion
Set the SOAP version to be used. The default is SOAP 1.2 and is set in the constructor. Usually you don't need to call that method.- Parameters:
eSoapVersion- The SOAP version to be used. May benull.- Returns:
- this for chaining
-
httpRetrySettings
- Returns:
- The HTTP retry settings to be used. May be
null. - Since:
- 3.0.0
-
httpRetrySettings
Set the HTTP retry settings to be used. If none are set, the default values are used.- Parameters:
a- The HTTP retry settings to be used. May benull.- Returns:
- this for chaining
-
locale
- Returns:
- The locale to be used. May be
null. - Since:
- 3.0.0
-
locale
Set the locale to use. The main purpose is to use the correct language for processing error message in response messages. This field must be set. The default value isDEFAULT_LOCALE.- Parameters:
a- The locale to use. May benull.- Returns:
- this for chaining
-
as4ProfileID
- Returns:
- The selected AS4 profile to use. May be
null. - Since:
- 2.8.2
-
as4ProfileID
Set the AS4 profile to be used. Must be provided for the builder to work.- Parameters:
sAS4ProfileID- The AS4 profile ID to be used.- Returns:
- this for chaining
- Since:
- 2.8.2
-
pmodeResolver
- Returns:
- The currently set
IAS4PModeResolver. May benull.
-
pmodeResolver
Set the PMode resolver to be used. This is only used to determine the PMode of an eventually received synchronous response message.- Parameters:
aPModeResolver- The PMode resolver to be used. May benull.- Returns:
- this for chaining
-
incomingAttachmentFactory
- Returns:
- The currently set
IAS4IncomingAttachmentFactory. Nevernull.
-
incomingAttachmentFactory
public final @NonNull IMPLTYPE incomingAttachmentFactory(@NonNull IAS4IncomingAttachmentFactory aIAF) Set the incoming attachment factory to be used. This is only used for an eventually received synchronous response message.- Parameters:
aIAF- The incoming attachment factory to be used. May not benull.- Returns:
- this for chaining
-
incomingProfileSelector
- Returns:
- The profile selector for incoming AS4 messages. Never
null. - Since:
- 0.13.0
-
incomingProfileSelector
public final @NonNull IMPLTYPE incomingProfileSelector(@NonNull IAS4IncomingProfileSelector aIncomingProfileSelector) Set the selector for the AS4 profile of incoming messages. This is only used for an eventually received synchronous response message.- Parameters:
aIncomingProfileSelector- The profile selector to use. May not benull.- Returns:
- this for chaining
- Since:
- 0.13.0
-
senderInterrupt
- Returns:
- The currently set
IAS4SenderInterrupt. May benull. - Since:
- 0.13.0
-
senderInterrupt
Set the sender interrupt to be used. This is only needed in very specific cases, isnullby default and should be handled with care.- Parameters:
aSenderInterrupt- The sender interrupt to be used. May benull.- Returns:
- this for chaining
- Since:
- 0.13.0
-
sendingDateTimeConsumer
- Returns:
- The currently set
IAS4SendingDateTimeConsumer. May benull. - Since:
- 2.2.2
-
sendingDateTimeConsumer
public final @NonNull IMPLTYPE sendingDateTimeConsumer(@Nullable IAS4SendingDateTimeConsumer aSendingDTConsumer) Set the sending date time consumer to be used. This may e.g. be needed to get the effective sending date time for Peppol reporting.- Parameters:
aSendingDTConsumer- The sender date time consumer to be used. May benull.- Returns:
- this for chaining
- Since:
- 2.2.2
-
buildMessageCallback
- Returns:
- The internal message callback. Usually this method is NOT needed. Use only when you know what you are doing.
- Since:
- 3.0.0
-
buildMessageCallback
public final @NonNull IMPLTYPE buildMessageCallback(@Nullable IAS4ClientBuildMessageCallback aBuildMessageCallback) Set a internal message callback. Usually this method is NOT needed. Use only when you know what you are doing.- Parameters:
aBuildMessageCallback- An internal to be used for the created message. May benull.- Returns:
- this for chaining
-
outgoingDumper
- Returns:
- The specific outgoing dumper of this builder. May be
null. - Since:
- 3.0.0
-
outgoingDumper
Set a specific outgoing dumper for this builder.- Parameters:
aOutgoingDumper- An outgoing dumper to be used. Maybenull. Ifnullthe global outgoing dumper is used.- Returns:
- this for chaining
-
incomingDumper
- Returns:
- The specific incoming dumper of this builder. May be
null. - Since:
- 3.0.0
-
incomingDumper
Set a specific incoming dumper for this builder.- Parameters:
aIncomingDumper- An incoming dumper to be used. Maybenull. Ifnullthe global incoming dumper is used.- Returns:
- this for chaining
-
decryptRequestDataModifier
- Returns:
- The decrypting customizing callback. May be
null. - Since:
- 3.0.0
-
decryptRequestDataModifier
public final @NonNull IMPLTYPE decryptRequestDataModifier(@Nullable IAS4DecryptParameterModifier aDecryptParameterModifier) Set an optional customizing callback that is invoked when decrypting a message, to be able to modify the decryption configuration. This is an edge case e.g. to allow RSA 1.5 algorithm names.- Parameters:
aDecryptParameterModifier- The modifier callback. May benull.- Returns:
- this for chaining
- Since:
- 2.2.0
-
retryCallback
- Returns:
- The HTTP retry callback to be invoked. May be
null. - Since:
- 3.0.0
-
retryCallback
Set an optional handler that is notified if an http sending will be retried. This method is optional and must not be called prior to sending.- Parameters:
aRetryCallback- The optional retry callback. May benull.- Returns:
- this for chaining
-
rawResponseConsumer
- Returns:
- The optional handler for the received raw response, very similar to the dumper. May be
null. - Since:
- 3.0.0
-
rawResponseConsumer
public final @NonNull IMPLTYPE rawResponseConsumer(@Nullable IAS4RawResponseConsumer aRaweResponseConsumer) Set an optional handler for the synchronous result message received from the other side. This method is optional and must not be called prior to sending. This method is very similar to using anincomingDumper(IAS4IncomingDumper)so you usually only need one or the other.- Parameters:
aRaweResponseConsumer- The optional response consumer. May benull.- Returns:
- this for chaining
-
finishFields
@OverrideOnDemand @OverridingMethodsMustInvokeSuper protected com.helger.base.state.ESuccess finishFields(@NonNull AS4ResourceHelper aResHelper) throws Phase4Exception Internal method that is invoked before the required field check is performed. Override to set additional dynamically created fields if necessary.
Don't add message properties in here, because if the required fields check fails than this method would be called again.
This is called beforeisEveryRequiredFieldSet()- Parameters:
aResHelper- The AS4 resource helper to use. Nevernull.- Returns:
ESuccess- nevernull. Returning failure here stops sending the message.- Throws:
Phase4Exception- if something goes wrong
-
isEveryRequiredFieldSet
@OverridingMethodsMustInvokeSuper public boolean isEveryRequiredFieldSet()Check if all mandatory fields are set. This method is called afterfinishFields(AS4ResourceHelper)and beforecustomizeBeforeSending()- Returns:
trueif all mandatory fields are set, and sending can continue.
-
customizeBeforeSending
Internal method that is invoked after the required fields are checked but before sending takes place. This is e.g. the perfect place to add custom message properties. This method is called afterisEveryRequiredFieldSet()and beforemainSendMessage().- Throws:
Phase4Exception- if something goes wrong
-
mainSendMessage
Synchronously send the AS4 message. This method is called aftercustomizeBeforeSending(). This method may only be called bysendMessage().- Throws:
Phase4Exception- In case of any error
-
afterSuccessfulSending
@OverrideOnDemand protected void afterSuccessfulSending()Internal method that is invoked after successful sending took place. This can e.g. be used to fulfill reporting requirements etc. This method must not throw an exception. This method is called aftermainSendMessage().- Since:
- 2.2.2
-
sendMessage
Synchronously send the AS4 message. First the internal "finishFields" method is called, to ensure all dynamic fields are filled - on failure this methods exits. AfterwardsisEveryRequiredFieldSet()is called to check that all mandatory elements are set - on failure this methods exits. Afterwards "customizeBeforeSending" is called to make final adjustments to the message. As the very last step, the customizable sender interrupt is invoked which may prevent the main message sending. As the last step "mainSendMessage" is invoked and "SUCCESS" is returned.
Note: since 0.13.0 this common implementation is in place.- Returns:
ESuccess.FAILUREif not all mandatory parameters are set or if sending failed,ESuccess.SUCCESSupon success. Nevernull. This result code does not reflect the semantics of a semantically correct message exchange or not. It just states, if the message was sent or nor. The rest needs to be determined separately.- Throws:
Phase4Exception- In case of any error- See Also:
-