use of com.helger.phase4.servlet.IAS4MessageState in project phase4 by phax.
the class StoringServletMessageProcessorSPI method processAS4UserMessage.
@Nonnull
public AS4MessageProcessorResult processAS4UserMessage(@Nonnull final IAS4IncomingMessageMetadata aMessageMetadata, @Nonnull final HttpHeaderMap aHttpHeaders, @Nonnull final Ebms3UserMessage aUserMessage, @Nonnull final IPMode aPMode, @Nullable final Node aPayload, @Nullable final ICommonsList<WSS4JAttachment> aIncomingAttachments, @Nonnull final IAS4MessageState aState, @Nonnull final ICommonsList<Ebms3Error> aProcessingErrorMessages) {
LOGGER.info("Received AS4 user message");
_dumpSoap(aMessageMetadata, aState);
// Dump all incoming attachments (but only if they are repeatable)
if (aIncomingAttachments != null) {
int nAttachmentIndex = 0;
for (final WSS4JAttachment aIncomingAttachment : aIncomingAttachments) {
if (aIncomingAttachment.isRepeatable())
_dumpIncomingAttachment(aMessageMetadata, aIncomingAttachment, nAttachmentIndex);
nAttachmentIndex++;
}
}
return AS4MessageProcessorResult.createSuccess();
}
use of com.helger.phase4.servlet.IAS4MessageState in project phase4 by phax.
the class ExampleReceiveMessageProcessorSPI method processAS4UserMessage.
@Nonnull
public AS4MessageProcessorResult processAS4UserMessage(@Nonnull final IAS4IncomingMessageMetadata aMessageMetadata, @Nonnull final HttpHeaderMap aHttpHeaders, @Nonnull final Ebms3UserMessage aUserMessage, @Nonnull final IPMode aPMode, @Nullable final Node aPayload, @Nullable final ICommonsList<WSS4JAttachment> aIncomingAttachments, @Nonnull final IAS4MessageState aState, @Nonnull final ICommonsList<Ebms3Error> aProcessingErrorMessages) {
LOGGER.info("Received AS4 user message");
_dumpSoap(aMessageMetadata, aState);
if (aIncomingAttachments != null) {
int nIndex = 1;
for (final WSS4JAttachment aIncomingAttachment : aIncomingAttachments) {
final File aFile = StorageHelper.getStorageFile(aMessageMetadata, "-" + nIndex + ".payload");
if (StreamHelper.copyInputStreamToOutputStream(aIncomingAttachment.getSourceStream(), FileHelper.getOutputStream(aFile)).isFailure())
LOGGER.error("Failed to write incoming attachment [" + nIndex + "] to '" + aFile.getAbsolutePath() + "'");
else
LOGGER.info("Wrote incoming attachment [" + nIndex + "] to '" + aFile.getAbsolutePath() + "'");
++nIndex;
}
}
return AS4MessageProcessorResult.createSuccess();
}
use of com.helger.phase4.servlet.IAS4MessageState in project phase4 by phax.
the class AS4RequestHandler method _createResponseUserMessage.
/**
* With this method it is possible to send a usermessage back, the method will
* check if signing is needed and if the message needs to be a mime message.
*
* @param aState
* The state of the incoming message. Never <code>null</code>.
* @param eSoapVersion
* the SOAP version to use. May not be <code>null</code>
* @param aResponseUserMsg
* the response user message that should be sent
* @param sMessagingID
* ID of the "Messaging" element
* @param aResponseAttachments
* attachments if any that should be added
* @param aSigningParams
* Signing parameters
* @param aCryptParams
* Encryption parameters
* @throws WSSecurityException
* on error
* @throws MessagingException
* on error
*/
@Nonnull
private IAS4ResponseFactory _createResponseUserMessage(@Nonnull final IAS4MessageState aState, @Nonnull final ESoapVersion eSoapVersion, @Nonnull final AS4UserMessage aResponseUserMsg, @Nonnull final ICommonsList<WSS4JAttachment> aResponseAttachments, @Nonnull final AS4SigningParams aSigningParams, @Nonnull final AS4CryptParams aCryptParams) throws WSSecurityException, MessagingException {
final String sResponseMessageID = aResponseUserMsg.getEbms3UserMessage().getMessageInfo().getMessageId();
final Document aSignedDoc = _signResponseIfNeeded(aResponseAttachments, aSigningParams, aResponseUserMsg.getAsSoapDocument(), eSoapVersion, aResponseUserMsg.getMessagingID());
final IAS4ResponseFactory ret;
if (aResponseAttachments.isEmpty()) {
// FIXME encryption of SOAP body is missing here
ret = new AS4ResponseFactoryXML(m_aMessageMetadata, aState, sResponseMessageID, aSignedDoc, eSoapVersion.getMimeType());
} else {
// Create (maybe encrypted) MIME message
final AS4MimeMessage aMimeMsg = _createMimeMessageForResponse(aSignedDoc, aResponseAttachments, eSoapVersion, aCryptParams);
ret = new AS4ResponseFactoryMIME(m_aMessageMetadata, aState, sResponseMessageID, aMimeMsg);
}
return ret;
}
use of com.helger.phase4.servlet.IAS4MessageState in project phase4 by phax.
the class AS4RequestHandler method _invokeSPIsForResponse.
private void _invokeSPIsForResponse(@Nonnull final IAS4MessageState aState, @Nullable final IAS4ResponseFactory aResponseFactory, @Nullable final HttpEntity aHttpEntity, @Nonnull final IMimeType aMimeType, @Nonnull @Nonempty final String sResponseMessageID) {
// Get response payload as byte array for multiple processing by the SPIs
final boolean bResponsePayloadIsAvailable = aResponseFactory != null;
byte[] aResponsePayload = null;
if (aResponseFactory != null) {
final HttpEntity aRealHttpEntity = aHttpEntity != null ? aHttpEntity : aResponseFactory.getHttpEntityForSending(aMimeType);
if (aRealHttpEntity.isRepeatable()) {
int nContentLength = (int) aRealHttpEntity.getContentLength();
if (nContentLength < 0)
nContentLength = 16 * CGlobal.BYTES_PER_KILOBYTE;
try (final NonBlockingByteArrayOutputStream aBAOS = new NonBlockingByteArrayOutputStream(nContentLength)) {
aRealHttpEntity.writeTo(aBAOS);
aResponsePayload = aBAOS.getBufferOrCopy();
} catch (final IOException ex) {
LOGGER.error("Error dumping response entity", ex);
}
} else
LOGGER.warn("Response entity is not repeatable and therefore not read for SPIs");
} else
LOGGER.info("No response factory present");
// Get all processors
final ICommonsList<IAS4ServletMessageProcessorSPI> aAllProcessors = m_aProcessorSupplier.get();
if (LOGGER.isDebugEnabled())
LOGGER.debug("Trying to invoke the following " + aAllProcessors.size() + " SPIs on message ID '" + aState.getMessageID() + "' and response message ID '" + sResponseMessageID + ": " + aAllProcessors);
for (final IAS4ServletMessageProcessorSPI aProcessor : aAllProcessors) if (aProcessor != null)
try {
if (LOGGER.isDebugEnabled())
LOGGER.debug("Invoking AS4 message processor " + aProcessor + " for response");
aProcessor.processAS4ResponseMessage(m_aMessageMetadata, aState, sResponseMessageID, aResponsePayload, bResponsePayloadIsAvailable);
if (LOGGER.isDebugEnabled())
LOGGER.debug("Finished invoking AS4 message processor " + aProcessor + " for response");
} catch (final RuntimeException ex) {
// Re-throw
throw ex;
} catch (final Exception ex) {
throw new IllegalStateException("Error invoking AS4 message processor " + aProcessor + " for response", ex);
}
}
use of com.helger.phase4.servlet.IAS4MessageState in project phase4 by phax.
the class AS4RequestHandler method _createResponseReceiptMessage.
/**
* @param aState
* The processing state of the incoming message. Never
* <code>null</code>.
* @param aSoapDocument
* document which should be used as source for the receipt to convert
* it to non-repudiation information. Can be <code>null</code>.
* @param eSoapVersion
* SOAPVersion which should be used
* @param aEffectiveLeg
* the leg that is used to determined, how the receipt should be build
* @param aUserMessage
* used if no non-repudiation information is needed, prints the
* usermessage in receipt. Can be <code>null</code>.
* @param aResponseAttachments
* that should be sent back if needed. Can be <code>null</code>.
* @throws WSSecurityException
*/
@Nonnull
private IAS4ResponseFactory _createResponseReceiptMessage(@Nonnull final IAS4MessageState aState, @Nullable final Document aSoapDocument, @Nonnull final ESoapVersion eSoapVersion, @Nonnull @Nonempty final String sResponseMessageID, @Nonnull final PModeLeg aEffectiveLeg, @Nullable final Ebms3UserMessage aUserMessage, @Nullable final ICommonsList<WSS4JAttachment> aResponseAttachments) throws WSSecurityException {
final AS4ReceiptMessage aReceiptMessage = AS4ReceiptMessage.create(eSoapVersion, sResponseMessageID, aUserMessage, aSoapDocument, _isSendNonRepudiationInformation(aEffectiveLeg)).setMustUnderstand(true);
// We've got our response
final Document aResponseDoc = aReceiptMessage.getAsSoapDocument();
final AS4SigningParams aSigningParams = new AS4SigningParams().setFromPMode(aEffectiveLeg.getSecurity());
final Document aSignedDoc = _signResponseIfNeeded(aResponseAttachments, aSigningParams, aResponseDoc, aEffectiveLeg.getProtocol().getSoapVersion(), aReceiptMessage.getMessagingID());
return new AS4ResponseFactoryXML(m_aMessageMetadata, aState, sResponseMessageID, aSignedDoc, eSoapVersion.getMimeType());
}
Aggregations