diff --git a/as2-lib/src/main/java/com/helger/as2lib/client/AS2Client.java b/as2-lib/src/main/java/com/helger/as2lib/client/AS2Client.java index e8d7d40e..44cc84ed 100644 --- a/as2-lib/src/main/java/com/helger/as2lib/client/AS2Client.java +++ b/as2-lib/src/main/java/com/helger/as2lib/client/AS2Client.java @@ -60,7 +60,10 @@ import com.helger.as2lib.processor.sender.IProcessorSenderModule; import com.helger.as2lib.session.AS2Session; import com.helger.as2lib.util.StringMap; +import com.helger.commons.ValueEnforcer; import com.helger.commons.annotation.OverrideOnDemand; +import com.helger.commons.factory.FactoryNewInstance; +import com.helger.commons.factory.IFactory; /** * A simple client that allows for sending AS2 Messages and retrieving of @@ -71,12 +74,26 @@ public class AS2Client { private static final Logger s_aLogger = LoggerFactory.getLogger (AS2Client.class); - + private IFactory m_aAS2SenderModuleFactory = FactoryNewInstance.create (AS2SenderModule.class, true); private Proxy m_aHttpProxy; public AS2Client () {} + /** + * Set the factory to create {@link AS2SenderModule} objects internally. + * By default a new instance of AS2SenderModule is created so you don't need + * to call this method. + * + * @param aAS2SenderModuleFactory + * The factory to be used. May not be null. + */ + @Nonnull + public void setAS2SenderModuleFactory (@Nonnull final IFactory aAS2SenderModuleFactory) + { + m_aAS2SenderModuleFactory = ValueEnforcer.notNull (aAS2SenderModuleFactory, "AS2SenderModuleFactory"); + } + /** * @return The current HTTP proxy used. Defaults to null. */ @@ -311,7 +328,7 @@ public AS2ClientResponse sendSynchronous (@Nonnull final AS2ClientSettings aSett // And create a sender module that directly sends the message // The message processor registration is required for the resending // feature - final AS2SenderModule aSender = new AS2SenderModule (); + final AS2SenderModule aSender = m_aAS2SenderModuleFactory.create(); aSender.initDynamicComponent (aSession, null); aSession.getMessageProcessor ().addModule (aSender);