protected void sendSyncMDN( @Nonnull final String sClientInfo, @Nonnull final IAS2HttpResponseHandler aResponseHandler, @Nonnull final AS2Message aMsg, @Nonnull final DispositionType aDisposition, @Nonnull final String sText) { final boolean bMDNBlocked = aMsg.getPartnership().isBlockErrorMDN(); if (!bMDNBlocked) { try { final IAS2Session aSession = m_aReceiverModule.getSession(); final IMessageMDN aMdn = AS2Helper.createMDN(aSession, aMsg, aDisposition, sText); if (aMsg.isRequestingAsynchMDN()) { // if asyncMDN requested, close connection and initiate separate MDN // send final InternetHeaders aHeaders = new InternetHeaders(); aHeaders.setHeader(CAS2Header.HEADER_CONTENT_LENGTH, Integer.toString(0)); // Empty data final NonBlockingByteArrayOutputStream aData = new NonBlockingByteArrayOutputStream(); aResponseHandler.sendHttpResponse(HttpURLConnection.HTTP_OK, aHeaders, aData); s_aLogger.info( "Setup to send asynch MDN [" + aDisposition.getAsString() + "] " + sClientInfo + aMsg.getLoggingText()); // trigger explicit sending aSession.getMessageProcessor().handle(IProcessorSenderModule.DO_SENDMDN, aMsg, null); } else { // otherwise, send sync MDN back on same connection s_aLogger.info( "Sending back sync MDN [" + aDisposition.getAsString() + "] " + sClientInfo + aMsg.getLoggingText()); // Get data and therefore content length for sync MDN final NonBlockingByteArrayOutputStream aData = new NonBlockingByteArrayOutputStream(); final MimeBodyPart aPart = aMdn.getData(); StreamHelper.copyInputStreamToOutputStream(aPart.getInputStream(), aData); aMdn.setHeader(CAS2Header.HEADER_CONTENT_LENGTH, Integer.toString(aData.getSize())); // start HTTP response aResponseHandler.sendHttpResponse(HttpURLConnection.HTTP_OK, aMdn.getHeaders(), aData); // Save sent MDN for later examination try { aSession.getMessageProcessor().handle(IProcessorStorageModule.DO_STOREMDN, aMsg, null); } catch (final ComponentNotFoundException ex) { // No message processor found } catch (final NoModuleException ex) { // No module found in message processor } s_aLogger.info( "sent MDN [" + aDisposition.getAsString() + "] " + sClientInfo + aMsg.getLoggingText()); } } catch (final Exception ex) { final OpenAS2Exception we = WrappedOpenAS2Exception.wrap(ex); we.addSource(OpenAS2Exception.SOURCE_MESSAGE, aMsg); we.terminate(); } } }