You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2018/09/21 06:04:40 UTC
[camel] 01/03: [CAMEL-12605] Updated client integration tests
This is an automated email from the ASF dual-hosted git repository.
acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 69a9ad41394f66fdaf284fa764f329df5834e236
Author: William Collins <pu...@gmail.com>
AuthorDate: Thu Sep 20 09:43:51 2018 -0400
[CAMEL-12605] Updated client integration tests
---
.../camel/component/as2/api/AS2ClientManager.java | 18 ++--
.../src/main/docs/as2-component.adoc | 4 +-
.../camel/component/as2/AS2Configuration.java | 13 +--
.../as2/AS2ClientManagerIntegrationTest.java | 96 ++++++++++++++++++++++
.../as2/springboot/AS2ComponentConfiguration.java | 14 ++--
5 files changed, 122 insertions(+), 23 deletions(-)
diff --git a/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/AS2ClientManager.java b/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/AS2ClientManager.java
index c8eb044..c99f341 100644
--- a/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/AS2ClientManager.java
+++ b/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/AS2ClientManager.java
@@ -194,9 +194,9 @@ public class AS2ClientManager {
* @param signingPrivateKey - the private key used to sign EDI message
* @param dispositionNotificationTo - an RFC2822 address to request a receipt or <code>null</code> if no receipt requested
* @param signedReceiptMicAlgorithms - the senders list of signing algorithms for signing receipt, in preferred order, or <code>null</code> if requesting an unsigned receipt.
- * @param encryptionAlgorithm - the algorithm used to encrypt the message or <code>null</code> if sending EDI message unencrypted
- * @param encryptionCertificateChain - the chain of certificates used to encrypt the message or <code>null</code> if sending EDI message unencrypted
- * @param encryptionPrivateKey - the private key used to encrypt EDI message
+ * @param encryptingAlgorithm - the algorithm used to encrypt the message or <code>null</code> if sending EDI message unencrypted
+ * @param encryptingCertificateChain - the chain of certificates used to encrypt the message or <code>null</code> if sending EDI message unencrypted
+ * @param encryptingPrivateKey - the private key used to encrypt EDI message
* @return {@link HttpCoreContext} containing request and response used to send EDI message
* @throws HttpException when things go wrong.
*/
@@ -213,9 +213,9 @@ public class AS2ClientManager {
PrivateKey signingPrivateKey,
String dispositionNotificationTo,
String[] signedReceiptMicAlgorithms,
- AS2EncryptionAlgorithm encryptionAlgorithm,
- Certificate[] encryptionCertificateChain,
- PrivateKey encryptionPrivateKey)
+ AS2EncryptionAlgorithm encryptingAlgorithm,
+ Certificate[] encryptingCertificateChain,
+ PrivateKey encryptingPrivateKey)
throws HttpException {
Args.notNull(ediMessage, "EDI Message");
@@ -237,9 +237,9 @@ public class AS2ClientManager {
httpContext.setAttribute(AS2ClientManager.SIGNING_PRIVATE_KEY, signingPrivateKey);
httpContext.setAttribute(AS2ClientManager.DISPOSITION_NOTIFICATION_TO, dispositionNotificationTo);
httpContext.setAttribute(AS2ClientManager.SIGNED_RECEIPT_MIC_ALGORITHMS, signedReceiptMicAlgorithms);
- httpContext.setAttribute(AS2ClientManager.ENCRYPTING_ALGORITHM, encryptionAlgorithm);
- httpContext.setAttribute(AS2ClientManager.ENCRYPTING_CERTIFICATE_CHAIN, encryptionCertificateChain);
- httpContext.setAttribute(AS2ClientManager.ENCRYPTING_PRIVATE_KEY, encryptionPrivateKey);
+ httpContext.setAttribute(AS2ClientManager.ENCRYPTING_ALGORITHM, encryptingAlgorithm);
+ httpContext.setAttribute(AS2ClientManager.ENCRYPTING_CERTIFICATE_CHAIN, encryptingCertificateChain);
+ httpContext.setAttribute(AS2ClientManager.ENCRYPTING_PRIVATE_KEY, encryptingPrivateKey);
BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST", requestUri);
httpContext.setAttribute(HTTP_REQUEST, request);
diff --git a/components/camel-as2/camel-as2-component/src/main/docs/as2-component.adoc b/components/camel-as2/camel-as2-component/src/main/docs/as2-component.adoc
index 6a6705b..d4a4e2a 100644
--- a/components/camel-as2/camel-as2-component/src/main/docs/as2-component.adoc
+++ b/components/camel-as2/camel-as2-component/src/main/docs/as2-component.adoc
@@ -84,7 +84,7 @@ with the following path and query parameters:
| *dispositionNotificationTo* (common) | The value of the Disposition-Notification-To header. Assigning a value to this parameter requests a message disposition notification (MDN) for the AS2 message. | | String
| *ediMessageTransferEncoding* (common) | The transfer encoding of EDI message. | | String
| *ediMessageType* (common) | The content type of EDI message. One of application/edifact, application/edi-x12, application/edi-consent | | ContentType
-| *encryptingAlgorithmName* (common) | The name of algorithm used to encrypt EDI message. | | String
+| *encryptingAlgorithm* (common) | The algorithm used to encrypt EDI message. | | AS2EncryptionAlgorithm
| *encryptingCertificateChain* (common) | The chain of certificates used to encrypt EDI message. | | Certificate[]
| *encryptingPrivateKey* (common) | The key used to encrypt the EDI message. | | PrivateKey
| *from* (common) | The value of the From header of AS2 message. | | String
@@ -128,7 +128,7 @@ The component supports 28 options, which are listed below.
| *camel.component.as2.configuration.disposition-notification-to* | The value of the Disposition-Notification-To header. Assigning a value to this parameter requests a message disposition notification (MDN) for the AS2 message. | | String
| *camel.component.as2.configuration.edi-message-transfer-encoding* | The transfer encoding of EDI message. | | String
| *camel.component.as2.configuration.edi-message-type* | The content type of EDI message. One of application/edifact, application/edi-x12, application/edi-consent | | ContentType
-| *camel.component.as2.configuration.encrypting-algorithm-name* | The name of algorithm used to encrypt EDI message. | | String
+| *camel.component.as2.configuration.encrypting-algorithm* | The algorithm used to encrypt EDI message. | | AS2EncryptionAlgorithm
| *camel.component.as2.configuration.encrypting-certificate-chain* | The chain of certificates used to encrypt EDI message. | | Certificate[]
| *camel.component.as2.configuration.encrypting-private-key* | The key used to encrypt the EDI message. | | PrivateKey
| *camel.component.as2.configuration.from* | The value of the From header of AS2 message. | | String
diff --git a/components/camel-as2/camel-as2-component/src/main/java/org/apache/camel/component/as2/AS2Configuration.java b/components/camel-as2/camel-as2-component/src/main/java/org/apache/camel/component/as2/AS2Configuration.java
index b819c5a..73bc0fe 100644
--- a/components/camel-as2/camel-as2-component/src/main/java/org/apache/camel/component/as2/AS2Configuration.java
+++ b/components/camel-as2/camel-as2-component/src/main/java/org/apache/camel/component/as2/AS2Configuration.java
@@ -20,6 +20,7 @@ import java.security.PrivateKey;
import java.security.cert.Certificate;
import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.component.as2.api.AS2EncryptionAlgorithm;
import org.apache.camel.component.as2.api.AS2MessageStructure;
import org.apache.camel.component.as2.internal.AS2ApiName;
import org.apache.camel.spi.Metadata;
@@ -106,7 +107,7 @@ public class AS2Configuration {
private String[] signedReceiptMicAlgorithms;
@UriParam
- private String encryptingAlgorithmName;
+ private AS2EncryptionAlgorithm encryptingAlgorithm;
@UriParam
private Certificate[] encryptingCertificateChain;
@@ -413,15 +414,15 @@ public class AS2Configuration {
this.signedReceiptMicAlgorithms = signedReceiptMicAlgorithms;
}
- public String getEncryptingingAlgorithmName() {
- return signingAlgorithmName;
+ public AS2EncryptionAlgorithm getEncryptingingAlgorithm() {
+ return encryptingAlgorithm;
}
/**
- * The name of algorithm used to encrypt EDI message.
+ * The algorithm used to encrypt EDI message.
*/
- public void setEncryptingAlgorithmName(String signingAlgorithmName) {
- this.encryptingAlgorithmName = signingAlgorithmName;
+ public void setEncryptingAlgorithm(AS2EncryptionAlgorithm encryptingAlgorithm) {
+ this.encryptingAlgorithm = encryptingAlgorithm;
}
public Certificate[] getEncryptingCertificateChain() {
diff --git a/components/camel-as2/camel-as2-component/src/test/java/org/apache/camel/component/as2/AS2ClientManagerIntegrationTest.java b/components/camel-as2/camel-as2-component/src/test/java/org/apache/camel/component/as2/AS2ClientManagerIntegrationTest.java
index 75b1e10..58ad275 100644
--- a/components/camel-as2/camel-as2-component/src/test/java/org/apache/camel/component/as2/AS2ClientManagerIntegrationTest.java
+++ b/components/camel-as2/camel-as2-component/src/test/java/org/apache/camel/component/as2/AS2ClientManagerIntegrationTest.java
@@ -32,6 +32,7 @@ import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.as2.api.AS2AsynchronousMDNManager;
import org.apache.camel.component.as2.api.AS2Charset;
import org.apache.camel.component.as2.api.AS2Constants;
+import org.apache.camel.component.as2.api.AS2EncryptionAlgorithm;
import org.apache.camel.component.as2.api.AS2Header;
import org.apache.camel.component.as2.api.AS2MediaType;
import org.apache.camel.component.as2.api.AS2MessageStructure;
@@ -43,6 +44,7 @@ import org.apache.camel.component.as2.api.entity.AS2DispositionModifier;
import org.apache.camel.component.as2.api.entity.AS2DispositionType;
import org.apache.camel.component.as2.api.entity.AS2MessageDispositionNotificationEntity;
import org.apache.camel.component.as2.api.entity.ApplicationEDIEntity;
+import org.apache.camel.component.as2.api.entity.ApplicationPkcs7MimeEntity;
import org.apache.camel.component.as2.api.entity.ApplicationPkcs7SignatureEntity;
import org.apache.camel.component.as2.api.entity.DispositionMode;
import org.apache.camel.component.as2.api.entity.DispositionNotificationMultipartReportEntity;
@@ -227,6 +229,12 @@ public class AS2ClientManagerIntegrationTest extends AbstractAS2TestSupport {
headers.put("CamelAS2.dispositionNotificationTo", "mrAS2@example.com");
// parameter type is String[]
headers.put("CamelAS2.signedReceiptMicAlgorithms", null);
+ // parameter type is org.apache.camel.component.as2.api.AS2EncryptionAlgorithm
+ headers.put("CamelAS2.encryptingAlgorithm", null);
+ // parameter type is java.security.cert.Certificate[]
+ headers.put("CamelAS2.encryptingCertificateChain", null);
+ // parameter type is java.security.PrivateKey
+ headers.put("CamelAS2.encryptingPrivateKey", null);
final org.apache.http.protocol.HttpCoreContext result = requestBodyAndHeaders("direct://SEND", EDI_MESSAGE, headers);
@@ -275,6 +283,88 @@ public class AS2ClientManagerIntegrationTest extends AbstractAS2TestSupport {
}
@Test
+ public void envelopedMessageSendTest() throws Exception {
+ final Map<String, Object> headers = new HashMap<>();
+ // parameter type is String
+ headers.put("CamelAS2.requestUri", REQUEST_URI);
+ // parameter type is String
+ headers.put("CamelAS2.subject", SUBJECT);
+ // parameter type is String
+ headers.put("CamelAS2.from", FROM);
+ // parameter type is String
+ headers.put("CamelAS2.as2From", AS2_NAME);
+ // parameter type is String
+ headers.put("CamelAS2.as2To", AS2_NAME);
+ // parameter type is org.apache.camel.component.as2.api.AS2MessageStructure
+ headers.put("CamelAS2.as2MessageStructure", AS2MessageStructure.ENCRYPTED);
+ // parameter type is org.apache.http.entity.ContentType
+ headers.put("CamelAS2.ediMessageContentType", ContentType.create(AS2MediaType.APPLICATION_EDIFACT, AS2Charset.US_ASCII));
+ // parameter type is String
+ headers.put("CamelAS2.ediMessageTransferEncoding", EDI_MESSAGE_CONTENT_TRANSFER_ENCODING);
+ // parameter type is java.security.cert.Certificate[]
+ headers.put("CamelAS2.signingCertificateChain", null);
+ // parameter type is java.security.PrivateKey
+ headers.put("CamelAS2.signingPrivateKey", null);
+ // parameter type is String
+ headers.put("CamelAS2.dispositionNotificationTo", "mrAS2@example.com");
+ // parameter type is String[]
+ headers.put("CamelAS2.signedReceiptMicAlgorithms", null);
+ // parameter type is org.apache.camel.component.as2.api.AS2EncryptionAlgorithm
+ headers.put("CamelAS2.encryptingAlgorithm", AS2EncryptionAlgorithm.AES128_CBC);
+ // parameter type is java.security.cert.Certificate[]
+ headers.put("CamelAS2.encryptingCertificateChain", certList);
+ // parameter type is java.security.PrivateKey
+ headers.put("CamelAS2.encryptingPrivateKey", signingKP.getPrivate());
+
+ final org.apache.http.protocol.HttpCoreContext result = requestBodyAndHeaders("direct://SEND", EDI_MESSAGE, headers);
+
+ assertNotNull("send result", result);
+ LOG.debug("send: " + result);
+ HttpRequest request = result.getRequest();
+ assertNotNull("Request", request);
+ assertTrue("Request does not contain body", request instanceof HttpEntityEnclosingRequest);
+ HttpEntity entity = ((HttpEntityEnclosingRequest)request).getEntity();
+ assertNotNull("Request body", entity);
+ assertTrue("Request body does not contain ApplicationPkcs7Mime entity", entity instanceof ApplicationPkcs7MimeEntity);
+ MimeEntity envelopeEntity = ((ApplicationPkcs7MimeEntity)entity).getEncryptedEntity(signingKP.getPrivate());
+ assertTrue("Enveloped entity is not an EDI entity", envelopeEntity instanceof ApplicationEDIEntity);
+ String ediMessage = ((ApplicationEDIEntity)envelopeEntity).getEdiMessage();
+ assertEquals("EDI message is different", EDI_MESSAGE.replaceAll("[\n\r]", ""), ediMessage.replaceAll("[\n\r]", ""));
+
+ HttpResponse response = result.getResponse();
+ assertNotNull("Response", response);
+ assertTrue("Unexpected response type", HttpMessageUtils.getHeaderValue(response, AS2Header.CONTENT_TYPE).startsWith(AS2MimeType.MULTIPART_REPORT));
+ assertEquals("Unexpected mime version", AS2Constants.MIME_VERSION, HttpMessageUtils.getHeaderValue(response, AS2Header.MIME_VERSION));
+ assertEquals("Unexpected AS2 version", EXPECTED_AS2_VERSION, HttpMessageUtils.getHeaderValue(response, AS2Header.AS2_VERSION));
+ assertEquals("Unexpected MDN subject", EXPECTED_MDN_SUBJECT, HttpMessageUtils.getHeaderValue(response, AS2Header.SUBJECT));
+ assertEquals("Unexpected MDN from", MDN_FROM, HttpMessageUtils.getHeaderValue(response, AS2Header.FROM));
+ assertEquals("Unexpected AS2 from", AS2_NAME, HttpMessageUtils.getHeaderValue(response, AS2Header.AS2_FROM));
+ assertEquals("Unexpected AS2 to", AS2_NAME, HttpMessageUtils.getHeaderValue(response, AS2Header.AS2_TO));
+ assertNotNull("Missing message id", HttpMessageUtils.getHeaderValue(response, AS2Header.MESSAGE_ID));
+
+ HttpEntity responseEntity = response.getEntity();
+ assertNotNull("Response entity", responseEntity);
+ assertTrue("Unexpected response entity type", responseEntity instanceof DispositionNotificationMultipartReportEntity);
+ DispositionNotificationMultipartReportEntity reportEntity = (DispositionNotificationMultipartReportEntity)responseEntity;
+ assertEquals("Unexpected number of body parts in report", 2, reportEntity.getPartCount());
+ MimeEntity firstPart = reportEntity.getPart(0);
+ assertEquals("Unexpected content type in first body part of report", ContentType.create(AS2MimeType.TEXT_PLAIN, AS2Charset.US_ASCII).toString(), firstPart.getContentTypeValue());
+ MimeEntity secondPart = reportEntity.getPart(1);
+ assertEquals("Unexpected content type in second body part of report",
+ ContentType.create(AS2MimeType.MESSAGE_DISPOSITION_NOTIFICATION, AS2Charset.US_ASCII).toString(),
+ secondPart.getContentTypeValue());
+
+ assertTrue("", secondPart instanceof AS2MessageDispositionNotificationEntity);
+ AS2MessageDispositionNotificationEntity messageDispositionNotificationEntity = (AS2MessageDispositionNotificationEntity) secondPart;
+ assertEquals("Unexpected value for reporting UA", ORIGIN_SERVER_NAME, messageDispositionNotificationEntity.getReportingUA());
+ assertEquals("Unexpected value for final recipient", AS2_NAME, messageDispositionNotificationEntity.getFinalRecipient());
+ assertEquals("Unexpected value for original message ID", HttpMessageUtils.getHeaderValue(request, AS2Header.MESSAGE_ID), messageDispositionNotificationEntity.getOriginalMessageId());
+ assertEquals("Unexpected value for disposition mode", DispositionMode.AUTOMATIC_ACTION_MDN_SENT_AUTOMATICALLY, messageDispositionNotificationEntity.getDispositionMode());
+ assertEquals("Unexpected value for disposition type", AS2DispositionType.PROCESSED, messageDispositionNotificationEntity.getDispositionType());
+
+ }
+
+ @Test
public void multipartSignedMessageTest() throws Exception {
final Map<String, Object> headers = new HashMap<>();
// parameter type is String
@@ -301,6 +391,12 @@ public class AS2ClientManagerIntegrationTest extends AbstractAS2TestSupport {
headers.put("CamelAS2.dispositionNotificationTo", "mrAS2@example.com");
// parameter type is String[]
headers.put("CamelAS2.signedReceiptMicAlgorithms", SIGNED_RECEIPT_MIC_ALGORITHMS);
+ // parameter type is org.apache.camel.component.as2.api.AS2EncryptionAlgorithm
+ headers.put("CamelAS2.encryptingAlgorithm", null);
+ // parameter type is java.security.cert.Certificate[]
+ headers.put("CamelAS2.encryptingCertificateChain", null);
+ // parameter type is java.security.PrivateKey
+ headers.put("CamelAS2.encryptingPrivateKey", null);
final org.apache.http.protocol.HttpCoreContext result = requestBodyAndHeaders("direct://SEND", EDI_MESSAGE, headers);
diff --git a/platforms/spring-boot/components-starter/camel-as2-starter/src/main/java/org/apache/camel/component/as2/springboot/AS2ComponentConfiguration.java b/platforms/spring-boot/components-starter/camel-as2-starter/src/main/java/org/apache/camel/component/as2/springboot/AS2ComponentConfiguration.java
index 27ddc9b..0f65e1b 100644
--- a/platforms/spring-boot/components-starter/camel-as2-starter/src/main/java/org/apache/camel/component/as2/springboot/AS2ComponentConfiguration.java
+++ b/platforms/spring-boot/components-starter/camel-as2-starter/src/main/java/org/apache/camel/component/as2/springboot/AS2ComponentConfiguration.java
@@ -19,6 +19,7 @@ package org.apache.camel.component.as2.springboot;
import java.security.PrivateKey;
import java.security.cert.Certificate;
import javax.annotation.Generated;
+import org.apache.camel.component.as2.api.AS2EncryptionAlgorithm;
import org.apache.camel.component.as2.api.AS2MessageStructure;
import org.apache.camel.component.as2.internal.AS2ApiName;
import org.apache.camel.spring.boot.ComponentConfigurationPropertiesCommon;
@@ -177,9 +178,9 @@ public class AS2ComponentConfiguration
*/
private String[] signedReceiptMicAlgorithms;
/**
- * The name of algorithm used to encrypt EDI message.
+ * The algorithm used to encrypt EDI message.
*/
- private String encryptingAlgorithmName;
+ private AS2EncryptionAlgorithm encryptingAlgorithm;
/**
* The chain of certificates used to encrypt EDI message.
*/
@@ -378,12 +379,13 @@ public class AS2ComponentConfiguration
this.signedReceiptMicAlgorithms = signedReceiptMicAlgorithms;
}
- public String getEncryptingAlgorithmName() {
- return encryptingAlgorithmName;
+ public AS2EncryptionAlgorithm getEncryptingAlgorithm() {
+ return encryptingAlgorithm;
}
- public void setEncryptingAlgorithmName(String encryptingAlgorithmName) {
- this.encryptingAlgorithmName = encryptingAlgorithmName;
+ public void setEncryptingAlgorithm(
+ AS2EncryptionAlgorithm encryptingAlgorithm) {
+ this.encryptingAlgorithm = encryptingAlgorithm;
}
public Certificate[] getEncryptingCertificateChain() {