use of com.helger.phase4.attachment.WSS4JAttachment 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.attachment.WSS4JAttachment in project phase4 by phax.
the class AS4CEFOneWayFuncTest method testAS4_TA17.
/**
* Prerequisite:<br>
* eSENS_TA13.<br>
* The SMSH is simulated to send an AS4 User message with a compressed then
* signed payload to the RMSH.<br>
* <br>
* Predicate: <br>
* The RMSH sends back an AS4 non-repudiation receipt.
*
* @throws Exception
* In case of error
*/
@Test
public void testAS4_TA17() throws Exception {
final ICommonsList<WSS4JAttachment> aAttachments = new CommonsArrayList<>();
aAttachments.add(WSS4JAttachment.createOutgoingFileAttachment(Phase4OutgoingAttachment.builder().data(ClassPathResource.getAsFile(AS4TestConstants.ATTACHMENT_SHORTXML_XML)).mimeTypeXML().compressionGZIP().build(), s_aResMgr));
final Document aDoc = createTestSignedUserMessage(m_eSoapVersion, m_aPayload, aAttachments, s_aResMgr);
final AS4MimeMessage aMsg = MimeMessageCreator.generateMimeMessage(m_eSoapVersion, aDoc, aAttachments);
final String sResponse = sendMimeMessage(new HttpMimeMessageEntity(aMsg), true, null);
assertTrue(sResponse.contains(AS4TestConstants.NON_REPUDIATION_INFORMATION));
}
use of com.helger.phase4.attachment.WSS4JAttachment in project phase4 by phax.
the class MainOldAS4Client method main.
/**
* Starting point for the SAAJ - SOAP Client Testing
*
* @param args
* ignored
*/
public static void main(final String[] args) {
try (final AS4ResourceHelper aResHelper = new AS4ResourceHelper()) {
String sURL = "http://127.0.0.1:8080/as4";
if (false)
sURL = "http://msh.holodeck-b2b.org:8080/msh";
// Deactivate if not sending to local holodeck
if (false)
sURL = "http://localhost:8080/msh/";
final HttpClientSettings aHCS = new HttpClientSettings();
if (sURL.startsWith("https"))
aHCS.setSSLContextTrustAll();
if (false) {
aHCS.setProxyHost(new HttpHost("172.30.9.6", 8080));
aHCS.addNonProxyHostsFromPipeString("localhost|127.0.0.1");
}
final CloseableHttpClient aClient = new HttpClientFactory(aHCS).createHttpClient();
LOGGER.info("Sending to " + sURL);
final HttpPost aPost = new HttpPost(sURL);
final ICommonsList<WSS4JAttachment> aAttachments = new CommonsArrayList<>();
final Node aPayload = DOMReader.readXMLDOM(new ClassPathResource("SOAPBodyPayload.xml"));
final ESoapVersion eSoapVersion = ESoapVersion.SOAP_12;
final IAS4CryptoFactory aCryptoFactory = AS4CryptoFactoryProperties.getDefaultInstance();
if (true) {
// No Mime Message Not signed or encrypted, just SOAP + Payload in SOAP
// -
// Body
// final Document aDoc = TestMessages.testSignedUserMessage
// (ESOAPVersion.SOAP_11, aPayload, aAttachments);
final AS4UserMessage aMsg = MockClientMessages.createUserMessageNotSigned(eSoapVersion, aPayload, aAttachments);
final Document aDoc = aMsg.getAsSoapDocument(aPayload);
aPost.setEntity(new HttpXMLEntity(aDoc, eSoapVersion.getMimeType()));
} else if (false) {
// BodyPayload SIGNED
final Document aDoc = MockClientMessages.createUserMessageSigned(eSoapVersion, aPayload, aAttachments, aResHelper);
aPost.setEntity(new HttpXMLEntity(aDoc, eSoapVersion.getMimeType()));
} else if (false) {
// BodyPayload ENCRYPTED
final AS4UserMessage aMsg = MockClientMessages.createUserMessageNotSigned(eSoapVersion, aPayload, aAttachments);
Document aDoc = aMsg.getAsSoapDocument(aPayload);
aDoc = AS4Encryptor.encryptSoapBodyPayload(aCryptoFactory, eSoapVersion, aDoc, false, AS4CryptParams.createDefault().setAlias("dummy"));
aPost.setEntity(new HttpXMLEntity(aDoc, eSoapVersion.getMimeType()));
} else if (true) {
aAttachments.add(WSS4JAttachment.createOutgoingFileAttachment(Phase4OutgoingAttachment.builder().data(ClassPathResource.getAsFile("attachment/test.xml.gz")).mimeType(CMimeType.APPLICATION_GZIP).build(), aResHelper));
final AS4UserMessage aMsg = MockClientMessages.createUserMessageNotSigned(eSoapVersion, null, aAttachments);
final AS4MimeMessage aMimeMsg = MimeMessageCreator.generateMimeMessage(eSoapVersion, AS4Signer.createSignedMessage(aCryptoFactory, aMsg.getAsSoapDocument(null), eSoapVersion, aMsg.getMessagingID(), aAttachments, aResHelper, false, AS4SigningParams.createDefault()), aAttachments);
// Move all global mime headers to the POST request
MessageHelperMethods.forEachHeaderAndRemoveAfterwards(aMimeMsg, aPost::addHeader, true);
aPost.setEntity(new HttpMimeMessageEntity(aMimeMsg));
} else if (false) {
Document aDoc = MockClientMessages.createUserMessageSigned(eSoapVersion, aPayload, aAttachments, aResHelper);
aDoc = AS4Encryptor.encryptSoapBodyPayload(aCryptoFactory, eSoapVersion, aDoc, false, AS4CryptParams.createDefault().setAlias("dummy"));
aPost.setEntity(new HttpXMLEntity(aDoc, eSoapVersion.getMimeType()));
} else
throw new IllegalStateException("Some test message should be selected :)");
// re-instantiate if you want to see the request that is getting sent
LOGGER.info(EntityUtils.toString(aPost.getEntity()));
final CloseableHttpResponse aHttpResponse = aClient.execute(aPost);
LOGGER.info("GET Response Status:: " + aHttpResponse.getStatusLine().getStatusCode());
// print result
LOGGER.info(EntityUtils.toString(aHttpResponse.getEntity()));
} catch (final Exception e) {
LOGGER.error("Error occurred while sending SOAP Request to Server", e);
}
}
use of com.helger.phase4.attachment.WSS4JAttachment in project phase4 by phax.
the class MockClientMessages method createReceiptMessageSigned.
@Nonnull
public static Document createReceiptMessageSigned(@Nonnull final ESoapVersion eSoapVersion, @Nullable final Node aPayload, @Nullable final ICommonsList<WSS4JAttachment> aAttachments, @Nonnull @WillNotClose final AS4ResourceHelper aResHelper) throws WSSecurityException, DOMException {
final Document aUserMessage = createUserMessageSigned(eSoapVersion, aPayload, aAttachments, aResHelper);
final AS4ReceiptMessage aReceiptMsg = AS4ReceiptMessage.create(eSoapVersion, MessageHelperMethods.createRandomMessageID(), null, aUserMessage, true).setMustUnderstand(true);
final Document aDoc = aReceiptMsg.getAsSoapDocument();
return AS4Signer.createSignedMessage(AS4CryptoFactoryProperties.getDefaultInstance(), aDoc, eSoapVersion, aReceiptMsg.getMessagingID(), aAttachments, aResHelper, false, AS4SigningParams.createDefault());
}
use of com.helger.phase4.attachment.WSS4JAttachment in project phase4 by phax.
the class MockClientMessages method createUserMessageSoapNotSignedNotPModeConform.
@Nonnull
public static Document createUserMessageSoapNotSignedNotPModeConform(@Nonnull final ESoapVersion eSoapVersion, @Nullable final Node aPayload, @Nullable final ICommonsList<WSS4JAttachment> aAttachments) {
// Add properties
final ICommonsList<Ebms3Property> aEbms3Properties = new CommonsArrayList<>();
aEbms3Properties.add(MessageHelperMethods.createEbms3Property("ProcessInst", "PurchaseOrder:123456"));
aEbms3Properties.add(MessageHelperMethods.createEbms3Property("ContextID", "987654321"));
final Ebms3MessageInfo aEbms3MessageInfo = MessageHelperMethods.createEbms3MessageInfo();
final Ebms3PayloadInfo aEbms3PayloadInfo = MessageHelperMethods.createEbms3PayloadInfo(aPayload != null, aAttachments);
final Ebms3CollaborationInfo aEbms3CollaborationInfo = MessageHelperMethods.createEbms3CollaborationInfo("pm-esens-generic-resp", DEFAULT_AGREEMENT, "MyServiceTypes", "QuoteToCollect", "NewPurchaseOrder", "4321");
final Ebms3PartyInfo aEbms3PartyInfo = MessageHelperMethods.createEbms3PartyInfo(CAS4.DEFAULT_INITIATOR_URL, "testt", CAS4.DEFAULT_RESPONDER_URL, "testt");
final Ebms3MessageProperties aEbms3MessageProperties = MessageHelperMethods.createEbms3MessageProperties(aEbms3Properties);
final AS4UserMessage aDoc = AS4UserMessage.create(aEbms3MessageInfo, aEbms3PayloadInfo, aEbms3CollaborationInfo, aEbms3PartyInfo, aEbms3MessageProperties, eSoapVersion).setMustUnderstand(true);
return aDoc.getAsSoapDocument(aPayload);
}
Aggregations