use of com.helger.as2lib.util.dump.IHTTPIncomingDumper in project as2-lib by phax.
the class AS2MDNReceiverHandler method handle.
public void handle(@Nonnull final AbstractActiveNetModule aOwner, @Nonnull final Socket aSocket) {
final String sClientInfo = getClientInfo(aSocket);
if (LOGGER.isInfoEnabled())
LOGGER.info("incoming connection for receiving AsyncMDN [" + sClientInfo + "]");
final AS2Message aMsg = new AS2Message();
final boolean bQuoteHeaderValues = m_aReceiverModule.isQuoteHeaderValues();
final IAS2HttpResponseHandler aResponseHandler = new AS2HttpResponseHandlerSocket(aSocket, bQuoteHeaderValues);
// Time the transmission
final StopWatch aSW = StopWatch.createdStarted();
DataSource aMdnDataSource = null;
try {
// Read in the message request, headers, and data
final IHTTPIncomingDumper aIncomingDumper = getEffectiveHttpIncomingDumper();
aMdnDataSource = HTTPHelper.readAndDecodeHttpRequest(new AS2HttpRequestDataProviderInputStream(aSocket.getInputStream()), aResponseHandler, aMsg, aIncomingDumper);
} catch (final Exception ex) {
new AS2NetException(aSocket.getInetAddress(), aSocket.getPort(), ex).terminate();
}
aSW.stop();
if (aMdnDataSource == null) {
LOGGER.error("Not having a data source to operate on");
} else {
if (aMdnDataSource instanceof ByteArrayDataSource) {
if (LOGGER.isInfoEnabled())
LOGGER.info("received " + AS2IOHelper.getTransferRate(((ByteArrayDataSource) aMdnDataSource).directGetBytes().length, aSW) + " from " + sClientInfo + aMsg.getLoggingText());
} else {
LOGGER.info("received message from " + sClientInfo + aMsg.getLoggingText() + " in " + aSW.getMillis() + " ms");
}
handleIncomingMessage(sClientInfo, aMdnDataSource, aMsg, aResponseHandler);
}
}
use of com.helger.as2lib.util.dump.IHTTPIncomingDumper in project as2-lib by phax.
the class AbstractAS2ReceiveBaseXServletHandler method onRequest.
public final void onRequest(@Nonnull final HttpServletRequest aHttpRequest, @Nonnull final HttpServletResponse aHttpResponse, @Nonnull final EHttpVersion eHttpVersion, @Nonnull final EHttpMethod eHttpMethod, @Nonnull final IRequestWebScope aRequestScope) throws ServletException, IOException {
// Handle the incoming message, and return the MDN if necessary
final String sClientInfo = aHttpRequest.getRemoteAddr() + ":" + aHttpRequest.getRemotePort();
LOGGER.info("Starting to handle incoming AS2 request - " + sClientInfo);
// Create empty message
final AS2Message aMsg = new AS2Message();
aMsg.attrs().putIn(CNetAttribute.MA_SOURCE_IP, aHttpRequest.getRemoteAddr());
aMsg.attrs().putIn(CNetAttribute.MA_SOURCE_PORT, aHttpRequest.getRemotePort());
aMsg.attrs().putIn(CNetAttribute.MA_DESTINATION_IP, aHttpRequest.getLocalAddr());
aMsg.attrs().putIn(CNetAttribute.MA_DESTINATION_PORT, aHttpRequest.getLocalPort());
// Request type (e.g. "POST")
aMsg.attrs().putIn(HTTPHelper.MA_HTTP_REQ_TYPE, aHttpRequest.getMethod());
// Request URL (e.g. "/as2")
aMsg.attrs().putIn(HTTPHelper.MA_HTTP_REQ_URL, ServletHelper.getRequestRequestURI(aHttpRequest));
// Add all request headers to the AS2 message
aMsg.headers().setAllHeaders(aRequestScope.headers());
// Build the handler that performs the response handling
final boolean bQuoteHeaderValues = isQuoteHeaderValues();
final AS2OutputStreamCreatorHttpServletResponse aResponseHandler = new AS2OutputStreamCreatorHttpServletResponse(aHttpResponse, bQuoteHeaderValues);
// Read the S/MIME content in a byte array - memory!
// Chunked encoding was already handled, so read "as-is"
final long nContentLength = aHttpRequest.getContentLengthLong();
if (nContentLength > Integer.MAX_VALUE)
throw new IllegalStateException("Currently only payload with up to 2GB can be handled! This request has " + nContentLength + " bytes.");
// Open it once, and close it at the end
try (final ServletInputStream aRequestIS = aHttpRequest.getInputStream()) {
// Time the transmission
final StopWatch aSW = StopWatch.createdStarted();
DataSource aMsgDataSource = null;
try {
// Read in the message request, headers, and data
final IHTTPIncomingDumper aIncomingDumper = getEffectiveHttpIncomingDumper();
aMsgDataSource = HTTPHelper.readAndDecodeHttpRequest(new AS2HttpRequestDataProviderServletRequest(aRequestScope, aRequestIS), aResponseHandler, aMsg, aIncomingDumper);
} catch (final Exception ex) {
AS2Exception.log(ex.getClass(), true, "Failed to read Servlet Request: " + ex.getMessage(), null, null, ex.getCause());
}
aSW.stop();
if (aMsgDataSource == null) {
LOGGER.error("Not having a data source to operate on");
} else {
if (aMsgDataSource instanceof ByteArrayDataSource) {
if (LOGGER.isInfoEnabled())
LOGGER.info("received " + AS2IOHelper.getTransferRate(((ByteArrayDataSource) aMsgDataSource).directGetBytes().length, aSW) + " from " + sClientInfo + aMsg.getLoggingText());
} else {
LOGGER.info("received message from " + sClientInfo + aMsg.getLoggingText() + " in " + aSW.getMillis() + " ms");
}
handleIncomingMessage(sClientInfo, aMsgDataSource, aMsg, aResponseHandler);
}
}
}
use of com.helger.as2lib.util.dump.IHTTPIncomingDumper in project as2-lib by phax.
the class AS2ReceiverHandler method handle.
public void handle(@Nonnull final AbstractActiveNetModule aOwner, @Nonnull final Socket aSocket) {
final String sClientInfo = getClientInfo(aSocket);
if (LOGGER.isInfoEnabled())
LOGGER.info("Incoming connection " + sClientInfo);
final AS2Message aMsg = createMessage(aSocket);
final boolean bQuoteHeaderValues = m_aReceiverModule.isQuoteHeaderValues();
final IAS2HttpResponseHandler aResponseHandler = new AS2HttpResponseHandlerSocket(aSocket, bQuoteHeaderValues);
// Time the transmission
final StopWatch aSW = StopWatch.createdStarted();
DataSource aMsgDataSource = null;
try {
// Read in the message request, headers, and data
final IHTTPIncomingDumper aIncomingDumper = getEffectiveHttpIncomingDumper();
aMsgDataSource = HTTPHelper.readAndDecodeHttpRequest(new AS2HttpRequestDataProviderInputStream(aSocket.getInputStream()), aResponseHandler, aMsg, aIncomingDumper);
} catch (final Exception ex) {
new AS2NetException(aSocket.getInetAddress(), aSocket.getPort(), ex).terminate();
}
aSW.stop();
if (aMsgDataSource == null) {
LOGGER.error("Not having a data source to operate on");
} else {
if (aMsgDataSource instanceof ByteArrayDataSource) {
if (LOGGER.isInfoEnabled())
LOGGER.info("received " + AS2IOHelper.getTransferRate(((ByteArrayDataSource) aMsgDataSource).directGetBytes().length, aSW) + " from " + sClientInfo + aMsg.getLoggingText());
} else {
LOGGER.info("received message from " + sClientInfo + aMsg.getLoggingText() + " in " + aSW.getMillis() + " ms");
}
handleIncomingMessage(sClientInfo, aMsgDataSource, aMsg, aResponseHandler);
}
}
use of com.helger.as2lib.util.dump.IHTTPIncomingDumper in project as2-lib by phax.
the class AS2SenderModule method handle.
public void handle(@Nonnull final String sAction, @Nonnull final IMessage aBaseMsg, @Nullable final Map<String, Object> aOptions) throws AS2Exception {
final AS2Message aMsg = (AS2Message) aBaseMsg;
if (LOGGER.isInfoEnabled())
LOGGER.info("Submitting message" + aMsg.getLoggingText());
// verify all required information is present for sending
checkRequired(aMsg);
final int nRetries = getRetryCount(aMsg.partnership(), aOptions);
try (final AS2ResourceHelper aResHelper = new AS2ResourceHelper()) {
// Get Content-Transfer-Encoding to use
final String sContentTransferEncoding = aMsg.partnership().getContentTransferEncodingSend(EContentTransferEncoding.AS2_DEFAULT.getID());
final EContentTransferEncoding eCTE = EContentTransferEncoding.getFromIDCaseInsensitiveOrDefault(sContentTransferEncoding, EContentTransferEncoding.AS2_DEFAULT);
// compress and/or sign and/or encrypt the message if needed
final MimeBodyPart aSecuredData = secure(aMsg, eCTE);
// Calculate MIC after compress/sign/crypt was handled, because the
// message data might change if compression before signing is active.
final MIC aMIC;
if (aMsg.isRequestingMDN())
aMIC = calculateAndStoreMIC(aMsg);
else
aMIC = null;
if (LOGGER.isDebugEnabled())
LOGGER.debug("Setting message content type to '" + aSecuredData.getContentType() + "'");
aMsg.setContentType(aSecuredData.getContentType());
try (final IHTTPOutgoingDumper aOutgoingDumper = getHttpOutgoingDumper(aMsg)) {
final IHTTPIncomingDumper aIncomingDumper = getEffectiveHttpIncomingDumper();
// Use no CTE, because it was set on all MIME parts
_sendViaHTTP(aMsg, aSecuredData, aMIC, true ? null : eCTE, aOutgoingDumper, aIncomingDumper, aResHelper);
}
} catch (final AS2HttpResponseException ex) {
if (LOGGER.isErrorEnabled())
LOGGER.error("Http Response Error " + ex.getMessage());
ex.terminate(aMsg);
if (!doResend(IProcessorSenderModule.DO_SEND, aMsg, ex, nRetries))
throw ex;
} catch (final IOException ex) {
// Re-send if a network error occurs during transmission
final AS2Exception wioe = WrappedAS2Exception.wrap(ex).setSourceMsg(aMsg).terminate();
if (!doResend(IProcessorSenderModule.DO_SEND, aMsg, wioe, nRetries))
throw wioe;
} catch (final Exception ex) {
// Propagate error if it can't be handled by a re-send
throw WrappedAS2Exception.wrap(ex);
}
}
Aggregations