Skip to content

Commit

Permalink
Made onEndRequest non-default
Browse files Browse the repository at this point in the history
  • Loading branch information
phax committed Aug 26, 2024
1 parent ba1ed76 commit e4b6da1
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
* @author Philip Helger
* @since 0.9.3
*/
public class AS4IncomingDumperFileBased extends AbstractAS4IncomingDumperWithHeaders
public class AS4IncomingDumperFileBased extends AbstractAS4IncomingDumperWithHeaders <AS4IncomingDumperFileBased>
{
/**
* Callback interface to create a file based on the provided metadata.
Expand Down Expand Up @@ -136,12 +136,6 @@ protected OutputStream openOutputStream (@Nonnull final IAS4IncomingMessageMetad
return FileHelper.getBufferedOutputStream (aDumpFile);
}

public void onEndRequest (@Nonnull final IAS4IncomingMessageMetadata aMessageMetadata,
@Nullable final Exception aCaughtException)
{
// empty
}

/**
* Create a new instance for the provided directory.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import java.util.concurrent.atomic.AtomicBoolean;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.WillNotClose;

import com.helger.commons.ValueEnforcer;
Expand All @@ -37,7 +36,7 @@
* @author Philip Helger
* @since 0.9.8
*/
public class AS4IncomingDumperSingleUse extends AbstractAS4IncomingDumperWithHeaders
public class AS4IncomingDumperSingleUse extends AbstractAS4IncomingDumperWithHeaders <AS4IncomingDumperSingleUse>
{
private final AtomicBoolean m_aUsedOS = new AtomicBoolean (false);
private final OutputStream m_aOS;
Expand All @@ -62,10 +61,4 @@ protected OutputStream openOutputStream (@Nonnull final IAS4IncomingMessageMetad
throw new IllegalStateException ("This single-use dumper was already used.");
return m_aOS;
}

public void onEndRequest (@Nonnull final IAS4IncomingMessageMetadata aMessageMetadata,
@Nullable final Exception aCaughtException)
{
// empty
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,22 @@
import com.helger.commons.collection.impl.ICommonsList;
import com.helger.commons.http.CHttp;
import com.helger.commons.http.HttpHeaderMap;
import com.helger.commons.traits.IGenericImplTrait;
import com.helger.phase4.messaging.IAS4IncomingMessageMetadata;

/**
* Abstract version of {@link IAS4IncomingDumper} that emits all headers on the
* output stream.
*
* @author Philip Helger
* @param <IMPLTYPE>
* Implementation type (since v3.0.0)
* @since 0.9.7
*/
public abstract class AbstractAS4IncomingDumperWithHeaders implements IAS4IncomingDumper
public abstract class AbstractAS4IncomingDumperWithHeaders <IMPLTYPE extends AbstractAS4IncomingDumperWithHeaders <IMPLTYPE>>
implements
IAS4IncomingDumper,
IGenericImplTrait <IMPLTYPE>
{
public static final boolean DEFAULT_INCLUDE_HEADERS = true;

Expand All @@ -58,11 +64,13 @@ public final boolean isIncludeHeaders ()
* @param b
* <code>true</code> to include the headers in the dump,
* <code>false</code> if not.
* @return this for chaining (since v3.0.0)
* @since 2.5.2
*/
public final void setIncludeHeaders (final boolean b)
public final IMPLTYPE setIncludeHeaders (final boolean b)
{
m_bIncludeHeaders = b;
return thisAsT ();
}

/**
Expand Down Expand Up @@ -105,4 +113,10 @@ public OutputStream onNewRequest (@Nonnull final IAS4IncomingMessageMetadata aMe
}
return ret;
}

public void onEndRequest (@Nonnull final IAS4IncomingMessageMetadata aMessageMetadata,
@Nullable final Exception aCaughtException)
{
// empty
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
*
* @author Philip Helger
* @param <IMPLTYPE>
* Implementation type (since v3)
* Implementation type (since v3.0.0)
* @since 0.9.7
*/
public abstract class AbstractAS4OutgoingDumperWithHeaders <IMPLTYPE extends AbstractAS4OutgoingDumperWithHeaders <IMPLTYPE>>
Expand Down Expand Up @@ -141,4 +141,11 @@ public OutputStream onBeginRequest (@Nonnull final EAS4MessageMode eMsgMode,
}
return ret;
}

public void onEndRequest (@Nonnull final EAS4MessageMode eMsgMode,
@Nullable final IAS4IncomingMessageMetadata aMessageMetadata,
@Nullable final IAS4MessageState aState,
@Nonnull @Nonempty final String sMessageID,
@Nullable final Exception aCaughtException)
{}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import com.helger.phase4.messaging.EAS4MessageMode;
import com.helger.phase4.messaging.IAS4IncomingMessageMetadata;
import com.helger.phase4.servlet.IAS4MessageState;
import com.helger.phase4.v3.ChangePhase4V3;

/**
* Interface for dumping outgoing requests
Expand Down Expand Up @@ -97,11 +96,13 @@ OutputStream onBeginRequest (@Nonnull EAS4MessageMode eMsgMode,
* @param sMessageID
* The AS4 message ID of the outgoing message. Neither
* <code>null</code> nor empty.
* @param aCaughtException
* An optional exception caught during processing. May be
* <code>null</code>. Added in v3.0.0.
*/
@ChangePhase4V3 ("Make non default")
default void onEndRequest (@Nonnull final EAS4MessageMode eMsgMode,
@Nullable final IAS4IncomingMessageMetadata aMessageMetadata,
@Nullable final IAS4MessageState aState,
@Nonnull @Nonempty final String sMessageID)
{}
void onEndRequest (@Nonnull EAS4MessageMode eMsgMode,
@Nullable IAS4IncomingMessageMetadata aMessageMetadata,
@Nullable IAS4MessageState aState,
@Nonnull @Nonempty String sMessageID,
@Nullable Exception aCaughtException);
}
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ public <T> T sendGenericMessageWithRetries (@Nonnull final String sURL,

// This class holds the effective OutputStream to which the dump is written
final Wrapper <OutputStream> aDumpOSHolder = new Wrapper <> ();
IOException aCaughtException = null;
try
{
if (aRetrySettings.isRetryEnabled ())
Expand Down Expand Up @@ -390,13 +391,18 @@ public <T> T sendGenericMessageWithRetries (@Nonnull final String sURL,
}
}
}
catch (final IOException ex)
{
aCaughtException = ex;
throw ex;
}
finally
{
// Add the possibility to close open resources
if (aRealOutgoingDumper != null && aDumpOSHolder.isSet ())
try
{
aRealOutgoingDumper.onEndRequest (EAS4MessageMode.REQUEST, null, null, sMessageID);
aRealOutgoingDumper.onEndRequest (EAS4MessageMode.REQUEST, null, null, sMessageID, aCaughtException);
}
catch (final Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ public void applyToResponse (@Nonnull final IAS4ResponseAbstraction aHttpRespons
aOutgoingDumper.onEndRequest (EAS4MessageMode.RESPONSE,
m_aIncomingMessageMetadata,
m_aState,
m_sResponseMessageID);
m_sResponseMessageID,
(Exception) null);
}
}
catch (final IOException ex)
Expand Down Expand Up @@ -280,7 +281,8 @@ public void applyToResponse (@Nonnull final IAS4ResponseAbstraction aHttpRespons
aOutgoingDumper.onEndRequest (EAS4MessageMode.RESPONSE,
m_aIncomingMessageMetadata,
m_aState,
m_sResponseMessageID);
m_sResponseMessageID,
(Exception) null);
}
}
catch (final IOException ex)
Expand Down Expand Up @@ -685,8 +687,9 @@ private void _invokeSPIsForIncoming (@Nonnull final HttpHeaderMap aHttpHeaders,
"Only one of User OR Signal Message may be present");

final boolean bIsUserMessage = aEbmsUserMessage != null;
final String sMessageID = bIsUserMessage ? aEbmsUserMessage.getMessageInfo ().getMessageId ()
: aEbmsSignalMessage.getMessageInfo ().getMessageId ();
final String sMessageID = bIsUserMessage ? aEbmsUserMessage.getMessageInfo ().getMessageId () : aEbmsSignalMessage
.getMessageInfo ()
.getMessageId ();

// Get all processors
final ICommonsList <IAS4IncomingMessageProcessorSPI> aAllProcessors = m_aProcessorSupplier.get ();
Expand Down Expand Up @@ -909,8 +912,8 @@ private void _invokeSPIsForResponse (@Nonnull final IAS4MessageState aState,
byte [] aResponsePayload = null;
if (aResponseFactory != null)
{
final HttpEntity aRealHttpEntity = aHttpEntity != null ? aHttpEntity
: aResponseFactory.getHttpEntityForSending (aMimeType);
final HttpEntity aRealHttpEntity = aHttpEntity != null ? aHttpEntity : aResponseFactory.getHttpEntityForSending (
aMimeType);
if (aRealHttpEntity.isRepeatable ())
{
int nContentLength = (int) aRealHttpEntity.getContentLength ();
Expand Down Expand Up @@ -1658,9 +1661,8 @@ private IAS4ResponseFactory _handleSoapMessage (@Nonnull final HttpHeaderMap aHt
new ResponseHandlerXml ());
}
AS4HttpDebug.debug ( () -> "SEND-RESPONSE [async sent] received: " +
(aAsyncResponse == null ? "null"
: XMLWriter.getNodeAsString (aAsyncResponse,
AS4HttpDebug.getDebugXMLWriterSettings ())));
(aAsyncResponse == null ? "null" : XMLWriter.getNodeAsString (aAsyncResponse,
AS4HttpDebug.getDebugXMLWriterSettings ())));
};

final CompletableFuture <Void> aFuture = PhotonWorkerPool.getInstance ()
Expand Down Expand Up @@ -1878,8 +1880,8 @@ public void handleRequest (@Nonnull @WillClose final InputStream aRequestInputSt
if (aResponder != null)
{
// Response present -> send back
final IAS4OutgoingDumper aRealOutgoingDumper = m_aOutgoingDumper != null ? m_aOutgoingDumper
: AS4DumpManager.getOutgoingDumper ();
final IAS4OutgoingDumper aRealOutgoingDumper = m_aOutgoingDumper != null ? m_aOutgoingDumper : AS4DumpManager
.getOutgoingDumper ();
aResponder.applyToResponse (aHttpResponse, aRealOutgoingDumper);
}
else
Expand Down

0 comments on commit e4b6da1

Please sign in to comment.