use of com.helger.phase4.messaging.domain.AS4UserMessage 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.messaging.domain.AS4UserMessage in project phase4 by phax.
the class MockMessages method createUserMessageNotSigned.
@Nonnull
public static AS4UserMessage createUserMessageNotSigned(@Nonnull final ESoapVersion eSOAPVersion, @Nullable final Node aPayload, @Nullable final ICommonsList<WSS4JAttachment> aAttachments) {
// Add properties
final ICommonsList<Ebms3Property> aEbms3Properties = AS4TestConstants.getEBMSProperties();
final String sPModeID;
final Ebms3MessageInfo aEbms3MessageInfo = MessageHelperMethods.createEbms3MessageInfo();
final Ebms3PayloadInfo aEbms3PayloadInfo = MessageHelperMethods.createEbms3PayloadInfo(aPayload != null, aAttachments);
final Ebms3CollaborationInfo aEbms3CollaborationInfo;
final Ebms3PartyInfo aEbms3PartyInfo;
if (eSOAPVersion.equals(ESoapVersion.SOAP_11)) {
sPModeID = SOAP_11_PARTY_ID + "-" + SOAP_11_PARTY_ID;
aEbms3CollaborationInfo = MessageHelperMethods.createEbms3CollaborationInfo(sPModeID, DEFAULT_AGREEMENT, AS4TestConstants.TEST_SERVICE_TYPE, MockPModeGenerator.SOAP11_SERVICE, AS4TestConstants.TEST_ACTION, AS4TestConstants.TEST_CONVERSATION_ID);
aEbms3PartyInfo = MessageHelperMethods.createEbms3PartyInfo(CAS4.DEFAULT_INITIATOR_URL, SOAP_11_PARTY_ID, CAS4.DEFAULT_RESPONDER_URL, SOAP_11_PARTY_ID);
} else {
sPModeID = SOAP_12_PARTY_ID + "-" + SOAP_12_PARTY_ID;
aEbms3CollaborationInfo = MessageHelperMethods.createEbms3CollaborationInfo(sPModeID, DEFAULT_AGREEMENT, AS4TestConstants.TEST_SERVICE_TYPE, AS4TestConstants.TEST_SERVICE, AS4TestConstants.TEST_ACTION, AS4TestConstants.TEST_CONVERSATION_ID);
aEbms3PartyInfo = MessageHelperMethods.createEbms3PartyInfo(CAS4.DEFAULT_INITIATOR_URL, SOAP_12_PARTY_ID, CAS4.DEFAULT_RESPONDER_URL, SOAP_12_PARTY_ID);
}
final Ebms3MessageProperties aEbms3MessageProperties = MessageHelperMethods.createEbms3MessageProperties(aEbms3Properties);
return AS4UserMessage.create(aEbms3MessageInfo, aEbms3PayloadInfo, aEbms3CollaborationInfo, aEbms3PartyInfo, aEbms3MessageProperties, eSOAPVersion).setMustUnderstand(true);
}
use of com.helger.phase4.messaging.domain.AS4UserMessage in project phase4 by phax.
the class UserMessageManyAttachmentTest method testUserMessageManyAttachmentsSignedMimeSuccess.
@Test
public void testUserMessageManyAttachmentsSignedMimeSuccess() throws WSSecurityException, Exception {
final ICommonsList<WSS4JAttachment> aAttachments = new CommonsArrayList<>();
aAttachments.add(WSS4JAttachment.createOutgoingFileAttachment(Phase4OutgoingAttachment.builder().data(ClassPathResource.getAsFile(AS4TestConstants.TEST_SOAP_BODY_PAYLOAD_XML)).mimeTypeXML().build(), s_aResMgr));
aAttachments.add(WSS4JAttachment.createOutgoingFileAttachment(Phase4OutgoingAttachment.builder().data(ClassPathResource.getAsFile(AS4TestConstants.ATTACHMENT_TEST_IMG_JPG)).mimeType(CMimeType.IMAGE_JPG).build(), s_aResMgr));
aAttachments.add(WSS4JAttachment.createOutgoingFileAttachment(Phase4OutgoingAttachment.builder().data(ClassPathResource.getAsFile(AS4TestConstants.ATTACHMENT_SHORTXML2_XML)).mimeTypeXML().build(), s_aResMgr));
final AS4UserMessage aMsg = MockMessages.createUserMessageNotSigned(m_eSOAPVersion, null, aAttachments);
final AS4MimeMessage aMimeMsg = MimeMessageCreator.generateMimeMessage(m_eSOAPVersion, AS4Signer.createSignedMessage(m_aCryptoFactory, aMsg.getAsSoapDocument(), m_eSOAPVersion, aMsg.getMessagingID(), aAttachments, s_aResMgr, false, AS4SigningParams.createDefault()), aAttachments);
final String sResponse = sendMimeMessage(new HttpMimeMessageEntity(aMimeMsg), true, null);
assertTrue(sResponse.contains(AS4TestConstants.RECEIPT_ASSERTCHECK));
assertTrue(sResponse.contains(ECryptoAlgorithmSign.SIGN_ALGORITHM_DEFAULT.getAlgorithmURI()));
assertTrue(sResponse.contains(ECryptoAlgorithmSignDigest.SIGN_DIGEST_ALGORITHM_DEFAULT.getAlgorithmURI()));
}
use of com.helger.phase4.messaging.domain.AS4UserMessage in project phase4 by phax.
the class UserMessageManyAttachmentTest method testUserMessageManyAttachmentsSignedEncryptedMimeSuccess.
@Test
public void testUserMessageManyAttachmentsSignedEncryptedMimeSuccess() throws WSSecurityException, Exception {
final ICommonsList<WSS4JAttachment> aAttachments = new CommonsArrayList<>();
aAttachments.add(WSS4JAttachment.createOutgoingFileAttachment(Phase4OutgoingAttachment.builder().data(ClassPathResource.getAsFile(AS4TestConstants.TEST_SOAP_BODY_PAYLOAD_XML)).mimeTypeXML().build(), s_aResMgr));
aAttachments.add(WSS4JAttachment.createOutgoingFileAttachment(Phase4OutgoingAttachment.builder().data(ClassPathResource.getAsFile(AS4TestConstants.ATTACHMENT_TEST_IMG_JPG)).mimeType(CMimeType.IMAGE_JPG).build(), s_aResMgr));
aAttachments.add(WSS4JAttachment.createOutgoingFileAttachment(Phase4OutgoingAttachment.builder().data(ClassPathResource.getAsFile(AS4TestConstants.ATTACHMENT_SHORTXML2_XML)).mimeTypeXML().build(), s_aResMgr));
final AS4UserMessage aMsg = MockMessages.createUserMessageNotSigned(m_eSOAPVersion, null, aAttachments);
final Document aDoc = AS4Signer.createSignedMessage(m_aCryptoFactory, aMsg.getAsSoapDocument(), m_eSOAPVersion, aMsg.getMessagingID(), aAttachments, s_aResMgr, false, AS4SigningParams.createDefault());
final AS4MimeMessage aMimeMsg = AS4Encryptor.encryptMimeMessage(m_eSOAPVersion, aDoc, aAttachments, m_aCryptoFactory, false, s_aResMgr, m_aCryptParams);
final String sResponse = sendMimeMessage(new HttpMimeMessageEntity(aMimeMsg), true, null);
assertTrue(sResponse.contains(AS4TestConstants.RECEIPT_ASSERTCHECK));
assertTrue(sResponse.contains(ECryptoAlgorithmSign.SIGN_ALGORITHM_DEFAULT.getAlgorithmURI()));
assertTrue(sResponse.contains(ECryptoAlgorithmSignDigest.SIGN_DIGEST_ALGORITHM_DEFAULT.getAlgorithmURI()));
}
use of com.helger.phase4.messaging.domain.AS4UserMessage in project phase4 by phax.
the class UserMessageOneAttachmentTest method testUserMessageOneAttachmentEncryptedMimeSuccess.
@Test
public void testUserMessageOneAttachmentEncryptedMimeSuccess() throws Exception {
final ICommonsList<WSS4JAttachment> aAttachments = new CommonsArrayList<>();
aAttachments.add(WSS4JAttachment.createOutgoingFileAttachment(Phase4OutgoingAttachment.builder().data(ClassPathResource.getAsFile(AS4TestConstants.TEST_SOAP_BODY_PAYLOAD_XML)).mimeTypeXML().build(), s_aResMgr));
final AS4UserMessage aMsg = MockMessages.createUserMessageNotSigned(m_eSOAPVersion, null, aAttachments);
final AS4MimeMessage aMimeMsg = AS4Encryptor.encryptMimeMessage(m_eSOAPVersion, aMsg.getAsSoapDocument(), aAttachments, m_aCryptoFactory, false, s_aResMgr, m_aCryptParams);
final String sResponse = sendMimeMessage(new HttpMimeMessageEntity(aMimeMsg), true, null);
assertTrue(sResponse.contains(AS4TestConstants.RECEIPT_ASSERTCHECK));
}
Aggregations