use of com.helger.phase4.soap.ESoapVersion in project phase4 by phax.
the class MockMessages method createErrorMessageSigned.
@Nonnull
public static Document createErrorMessageSigned(@Nonnull final ESoapVersion eSOAPVersion, @Nullable final ICommonsList<WSS4JAttachment> aAttachments, @Nonnull final AS4ResourceHelper aResMgr) throws WSSecurityException {
final ICommonsList<Ebms3Error> aEbms3ErrorList = new CommonsArrayList<>(EEbmsError.EBMS_INVALID_HEADER.getAsEbms3Error(Locale.US, null));
final AS4ErrorMessage aErrorMsg = AS4ErrorMessage.create(eSOAPVersion, "srcmsgid", aEbms3ErrorList).setMustUnderstand(true);
return AS4Signer.createSignedMessage(AS4CryptoFactoryProperties.getDefaultInstance(), aErrorMsg.getAsSoapDocument(), eSOAPVersion, aErrorMsg.getMessagingID(), aAttachments, aResMgr, false, AS4SigningParams.createDefault());
}
use of com.helger.phase4.soap.ESoapVersion in project phase4 by phax.
the class UserMessageDuplicateTest method testDuplicateSignedMessage.
@Test
public void testDuplicateSignedMessage() throws Exception {
final Node aPayload = DOMReader.readXMLDOM(new ClassPathResource(AS4TestConstants.TEST_SOAP_BODY_PAYLOAD_XML));
final ESoapVersion eSOAPVersion = ESoapVersion.AS4_DEFAULT;
final Document aDoc = MockMessages.createUserMessageSigned(eSOAPVersion, aPayload, null, s_aResMgr);
final HttpEntity aEntity = new HttpXMLEntity(aDoc, eSOAPVersion.getMimeType());
// Send first
final String sResponse = sendPlainMessage(aEntity, true, null);
assertTrue(sResponse.contains(AS4TestConstants.RECEIPT_ASSERTCHECK));
// Send second
sendPlainMessage(aEntity, false, EEbmsError.EBMS_OTHER.getErrorCode());
}
use of com.helger.phase4.soap.ESoapVersion in project phase4 by phax.
the class AS4RequestHandler method handleRequest.
/**
* This is the main handling routine when called from an abstract
* (non-Servlet) API
*
* @param aServletRequestIS
* The input stream with the request data. May not be
* <code>null</code>.
* @param aRequestHttpHeaders
* The HTTP headers of the request. May not be <code>null</code>.
* @param aHttpResponse
* The HTTP response to be filled. May not be <code>null</code>.
* @throws Phase4Exception
* in case the request is missing certain prerequisites. Since 0.9.11
* @throws IOException
* In case of IO errors
* @throws MessagingException
* MIME related errors
* @throws WSSecurityException
* In case of WSS4J errors
* @see #handleRequest(InputStream, HttpHeaderMap, IAS4ResponseAbstraction)
* for a more generic API
*/
public void handleRequest(@Nonnull @WillClose final InputStream aServletRequestIS, @Nonnull final HttpHeaderMap aRequestHttpHeaders, @Nonnull final IAS4ResponseAbstraction aHttpResponse) throws Phase4Exception, IOException, MessagingException, WSSecurityException {
final IAS4ParsedMessageCallback aCallback = (aHttpHeaders, aSoapDocument, eSoapVersion, aIncomingAttachments) -> {
// SOAP document and SOAP version are determined
// Collect all runtime errors
final ICommonsList<Ebms3Error> aErrorMessages = new CommonsArrayList<>();
final IAS4ResponseFactory aResponder = _handleSoapMessage(aHttpHeaders, aSoapDocument, eSoapVersion, aIncomingAttachments, aErrorMessages);
if (aResponder != null) {
// Response present -> send back
final IAS4OutgoingDumper aRealOutgoingDumper = m_aOutgoingDumper != null ? m_aOutgoingDumper : AS4DumpManager.getOutgoingDumper();
aResponder.applyToResponse(aHttpResponse, aRealOutgoingDumper);
} else {
// Success, HTTP No Content
aHttpResponse.setStatus(CHttp.HTTP_NO_CONTENT);
}
AS4HttpDebug.debug(() -> "RECEIVE-END with " + (aResponder != null ? "EBMS message" : "no content"));
};
AS4IncomingHandler.parseAS4Message(m_aIAF, m_aResHelper, m_aMessageMetadata, aServletRequestIS, aRequestHttpHeaders, aCallback, m_aIncomingDumper);
}
use of com.helger.phase4.soap.ESoapVersion in project phase4 by phax.
the class AS4RequestHandler method _createReversedUserMessage.
/**
* Takes an UserMessage and switches properties to reverse the direction. So
* previously it was C1 => C4, now its C4 => C1 Also adds attachments if there
* are some that should be added.
*
* @param eSoapVersion
* of the message
* @param sResponseMessageID
* The AS4 message ID of the response
* @param aUserMessage
* the message that should be reversed
* @param aResponseAttachments
* attachment that should be added
* @return the reversed usermessage in document form
*/
@Nonnull
private static AS4UserMessage _createReversedUserMessage(@Nonnull final ESoapVersion eSoapVersion, @Nonnull @Nonempty final String sResponseMessageID, @Nonnull final Ebms3UserMessage aUserMessage, @Nonnull final ICommonsList<WSS4JAttachment> aResponseAttachments) {
// Use current time
final Ebms3MessageInfo aEbms3MessageInfo = MessageHelperMethods.createEbms3MessageInfo(sResponseMessageID, aUserMessage.getMessageInfo().getMessageId());
final Ebms3PayloadInfo aEbms3PayloadInfo = MessageHelperMethods.createEbms3PayloadInfo(false, aResponseAttachments);
// Invert from and to role from original user message
final Ebms3PartyInfo aEbms3PartyInfo = MessageHelperMethods.createEbms3ReversePartyInfo(aUserMessage.getPartyInfo());
// Should be exactly the same as incoming message
final Ebms3CollaborationInfo aEbms3CollaborationInfo = aUserMessage.getCollaborationInfo();
// Need to switch C1 and C4 around from the original usermessage
// TODO make customizable via profile
final Ebms3MessageProperties aEbms3MessageProperties = new Ebms3MessageProperties();
{
Ebms3Property aFinalRecipient = null;
Ebms3Property aOriginalSender = null;
for (final Ebms3Property aProp : aUserMessage.getMessageProperties().getProperty()) {
if (aProp.getName().equals(CAS4.ORIGINAL_SENDER))
aOriginalSender = aProp;
else if (aProp.getName().equals(CAS4.FINAL_RECIPIENT))
aFinalRecipient = aProp;
}
if (aOriginalSender == null)
throw new IllegalStateException("Failed to determine new OriginalSender");
if (aFinalRecipient == null)
throw new IllegalStateException("Failed to determine new FinalRecipient");
aFinalRecipient.setName(CAS4.ORIGINAL_SENDER);
aOriginalSender.setName(CAS4.FINAL_RECIPIENT);
aEbms3MessageProperties.addProperty(aFinalRecipient);
aEbms3MessageProperties.addProperty(aOriginalSender);
}
return AS4UserMessage.create(aEbms3MessageInfo, aEbms3PayloadInfo, aEbms3CollaborationInfo, aEbms3PartyInfo, aEbms3MessageProperties, eSoapVersion);
}
use of com.helger.phase4.soap.ESoapVersion 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