Package com.helger.as2lib.client
Class AS2Client
- java.lang.Object
-
- com.helger.as2lib.client.AS2Client
-
public class AS2Client extends Object
A simple client that allows for sending AS2 Messages and retrieving of synchronous MDNs.- Author:
- Philip Helger
-
-
Constructor Summary
Constructors Constructor Description AS2Client()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidbeforeSend(AS2ClientSettings aSettings, AS2Session aSession, IMessage aMsg)Callback method that is invoked before the main sending.protected PartnershipbuildPartnership(AS2ClientSettings aSettings)Create a newPartnershipobject that is later used for message creation.protected AS2MessagecreateAS2MessageObj()protected CertificateFactorycreateCertificateFactory()protected AS2MessagecreateMessage(Partnership aPartnership, AS2ClientRequest aRequest)protected AS2ClientResponsecreateResponse()Create an empty response object that is to be filled.protected AS2SessioncreateSession()Create the AS2 session to be used.ProxygetHttpProxy()protected voidinitCertificateFactory(AS2ClientSettings aSettings, AS2Session aSession)This method initializes the certificate factory.protected voidinitMessageProcessor(AS2Session aSession)Init the message processor.protected voidinitPartnershipFactory(AS2Session aSession)Init the partnership factory.AS2ClientResponsesendSynchronous(AS2ClientSettings aSettings, AS2ClientRequest aRequest)Send the AS2 message synchronouslyAS2ClientsetAS2SenderModuleFactory(Supplier<AS2SenderModule> aAS2SenderModuleFactory)Set the factory to createAS2SenderModuleobjects internally.AS2ClientsetHttpProxy(Proxy aHttpProxy)Set the proxy server for transmission.
-
-
-
Method Detail
-
setAS2SenderModuleFactory
@Nonnull public AS2Client setAS2SenderModuleFactory(@Nonnull Supplier<AS2SenderModule> aAS2SenderModuleFactory)
Set the factory to createAS2SenderModuleobjects internally. By default a new instance ofAS2SenderModuleis created so you don't need to call this method.- Parameters:
aAS2SenderModuleFactory- The factory to be used. May not benull.- Returns:
- this for chaining
-
getHttpProxy
@Nullable public Proxy getHttpProxy()
- Returns:
- The current HTTP proxy used. Defaults to
null.
-
setHttpProxy
@Nonnull public AS2Client setHttpProxy(@Nullable Proxy aHttpProxy)
Set the proxy server for transmission.- Parameters:
aHttpProxy- The proxy to use. May benullto indicate no proxy.- Returns:
- this for chaining
-
buildPartnership
@Nonnull @OverrideOnDemand @OverridingMethodsMustInvokeSuper protected Partnership buildPartnership(@Nonnull AS2ClientSettings aSettings)
Create a newPartnershipobject that is later used for message creation. If you override this method, please ensure to call this class' version of the method first.- Parameters:
aSettings- The current client settings. Nevernull.- Returns:
- Non-
nullPartnership.
-
createAS2MessageObj
@Nonnull @OverrideOnDemand protected AS2Message createAS2MessageObj()
-
createMessage
@Nonnull @OverrideOnDemand @OverridingMethodsMustInvokeSuper protected AS2Message createMessage(@Nonnull Partnership aPartnership, @Nonnull AS2ClientRequest aRequest) throws jakarta.mail.MessagingException
- Throws:
jakarta.mail.MessagingException
-
createCertificateFactory
@Nonnull @OverrideOnDemand protected CertificateFactory createCertificateFactory()
- Returns:
- The certificate factory instance to be used. May not be
null.
-
initCertificateFactory
@OverrideOnDemand protected void initCertificateFactory(@Nonnull AS2ClientSettings aSettings, @Nonnull AS2Session aSession) throws AS2Exception
This method initializes the certificate factory. If you override this method, please make sure that you callaSession.setCertificateFactory (aCertFactory);.- Parameters:
aSettings- The AS2 client settings. Nevernull.aSession- The AS2 session to be initialized. Nevernull.- Throws:
AS2Exception- In case of error
-
initPartnershipFactory
@OverrideOnDemand protected void initPartnershipFactory(@Nonnull AS2Session aSession) throws AS2Exception
Init the partnership factory. If you override this method, please make sure that you callaSession.setPartnershipFactory (aPartnershipFactory);.- Parameters:
aSession- The AS2 session to be filled. Nevernull.- Throws:
AS2Exception- In case of error
-
initMessageProcessor
@OverrideOnDemand protected void initMessageProcessor(@Nonnull AS2Session aSession) throws AS2Exception
Init the message processor. If you override this method, please make sure that you callaSession.setMessageProcessor (aMessageProcessor);.- Parameters:
aSession- The AS2 session to be filled. Nevernull.- Throws:
AS2Exception- In case of error
-
createResponse
@Nonnull @OverrideOnDemand protected AS2ClientResponse createResponse()
Create an empty response object that is to be filled.- Returns:
- The empty response object and never
null.
-
createSession
@Nonnull @OverrideOnDemand protected AS2Session createSession()
Create the AS2 session to be used. This method must ensure an eventually needed proxy is set.- Returns:
- The new AS2 session and never
null.
-
beforeSend
@OverrideOnDemand protected void beforeSend(@Nonnull AS2ClientSettings aSettings, @Nonnull AS2Session aSession, @Nonnull IMessage aMsg)
Callback method that is invoked before the main sending. This may be used to customize the message.- Parameters:
aSettings- Client settings. Nevernull.aSession- Current session. Nevernull.aMsg- Current message. Nevernull.
-
sendSynchronous
@Nonnull public AS2ClientResponse sendSynchronous(@Nonnull AS2ClientSettings aSettings, @Nonnull AS2ClientRequest aRequest)
Send the AS2 message synchronously- Parameters:
aSettings- The settings to be used. May not benull.aRequest- The request data to be send. May not benull.- Returns:
- The response object. Never
null.
-
-