[ 
https://issues.apache.org/jira/browse/CAMEL-12605?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16708760#comment-16708760
 ] 

ASF GitHub Bot commented on CAMEL-12605:
----------------------------------------

oscerd closed pull request #2650: [CAMEL-12605] Added further tests and fixes 
for compression
URL: https://github.com/apache/camel/pull/2650
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

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 915d210cc5f..5f7ce3bfc90 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
@@ -354,11 +354,11 @@ public HttpCoreContext send(String ediMessage,
             EntityUtils.setMessageEntity(request, 
pkcs7MimeEnvelopedDataEntity);
             break;
         }
-        case SIGNED_ENCRYPTED_COMPRESSED: {
+        case ENCRYPTED_COMPRESSED_SIGNED: {
             // Create Multipart Signed Entity containing EDI Entity
             AS2SignedDataGenerator signingGenrator = 
createSigningGenerator(httpContext);
             MultipartSignedEntity multipartSignedEntity = new 
MultipartSignedEntity(applicationEDIEntity, signingGenrator,
-                    AS2Charset.US_ASCII, AS2TransferEncoding.BASE64, true, 
null);
+                    AS2Charset.US_ASCII, AS2TransferEncoding.BASE64, false, 
null);
             
             // Create Compressed Entity containing Multipart Signed Entity
             CMSCompressedDataGenerator compressedDataGenerator = 
createCompressorGenerator(httpContext);
diff --git 
a/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/AS2MessageStructure.java
 
b/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/AS2MessageStructure.java
index 760d9f06949..4fe5ff56b92 100644
--- 
a/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/AS2MessageStructure.java
+++ 
b/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/AS2MessageStructure.java
@@ -24,7 +24,7 @@
     PLAIN_COMPRESSED(false, false, true),
     SIGNED_COMPRESSED(true, false, true),
     ENCRYPTED_COMPRESSED(false, true, true),
-    SIGNED_ENCRYPTED_COMPRESSED(true, true, true);
+    ENCRYPTED_COMPRESSED_SIGNED(true, true, true);
 
     private final boolean isSigned;
     private final boolean isEncrypted;
diff --git 
a/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/entity/EntityParser.java
 
b/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/entity/EntityParser.java
index 42a4b1bbbdc..f97b0ae8656 100644
--- 
a/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/entity/EntityParser.java
+++ 
b/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/entity/EntityParser.java
@@ -184,6 +184,8 @@ public static MimeEntity parseCompressedEntity(byte[] 
compressedData, InputExpan
             throws HttpException {
 
         byte[] uncompressedContent = uncompressData(compressedData, 
expanderProvider);
+        
+        String uncompressedContentString = new String(uncompressedContent);
 
         return parseEntity(uncompressedContent);
     }
@@ -198,7 +200,7 @@ public static MimeEntity parseEnvelopedEntity(byte[] 
envelopedContent, PrivateKe
     public static MimeEntity parseEntity(byte[] content) throws HttpException {
         
         try {
-            
+            String contentString = new String(content);
             InputStream is = new ByteArrayInputStream(content);
             AS2SessionInputBuffer inbuffer = new AS2SessionInputBuffer(new 
HttpTransportMetricsImpl(), DEFAULT_BUFFER_SIZE);
             inbuffer.bind(is);
diff --git 
a/components/camel-as2/camel-as2-api/src/test/java/org/apache/camel/component/as2/api/AS2MessageTest.java
 
b/components/camel-as2/camel-as2-api/src/test/java/org/apache/camel/component/as2/api/AS2MessageTest.java
index 5b9dc3e7523..b764d620bc4 100644
--- 
a/components/camel-as2/camel-as2-api/src/test/java/org/apache/camel/component/as2/api/AS2MessageTest.java
+++ 
b/components/camel-as2/camel-as2-api/src/test/java/org/apache/camel/component/as2/api/AS2MessageTest.java
@@ -929,6 +929,86 @@ public void envelopedAndCompressedMessageTest() throws 
Exception {
                 ediEntity.getEdiMessage().replaceAll("[\n\r]", ""));
     }
 
+    @Test
+    public void envelopedCompressedAndSignedMessageTest() throws Exception {
+        AS2ClientConnection clientConnection = new 
AS2ClientConnection(AS2_VERSION, USER_AGENT, CLIENT_FQDN,
+                TARGET_HOST, TARGET_PORT);
+        AS2ClientManager clientManager = new 
AS2ClientManager(clientConnection);
+        
+        LOG.info("Key Algoritm: " + signingKP.getPrivate().getAlgorithm());
+
+        HttpCoreContext httpContext = clientManager.send(EDI_MESSAGE, 
REQUEST_URI, SUBJECT, FROM, AS2_NAME, AS2_NAME,
+                AS2MessageStructure.ENCRYPTED_COMPRESSED_SIGNED,
+                ContentType.create(AS2MediaType.APPLICATION_EDIFACT, 
AS2Charset.US_ASCII), null,
+                AS2SignatureAlgorithm.SHA256WITHRSA, certList.toArray(new 
Certificate[0]), signingKP.getPrivate(),
+                AS2CompressionAlgorithm.ZLIB, DISPOSITION_NOTIFICATION_TO, 
SIGNED_RECEIPT_MIC_ALGORITHMS,
+                AS2EncryptionAlgorithm.AES128_CBC, certList.toArray(new 
Certificate[0]), signingKP.getPrivate());
+
+        HttpRequest request = httpContext.getRequest();
+        assertEquals("Unexpected method value", METHOD, 
request.getRequestLine().getMethod());
+        assertEquals("Unexpected request URI value", REQUEST_URI, 
request.getRequestLine().getUri());
+        assertEquals("Unexpected HTTP version value", HttpVersion.HTTP_1_1,
+                request.getRequestLine().getProtocolVersion());
+
+        assertEquals("Unexpected subject value", SUBJECT, 
request.getFirstHeader(AS2Header.SUBJECT).getValue());
+        assertEquals("Unexpected from value", FROM, 
request.getFirstHeader(AS2Header.FROM).getValue());
+        assertEquals("Unexpected AS2 version value", AS2_VERSION,
+                request.getFirstHeader(AS2Header.AS2_VERSION).getValue());
+        assertEquals("Unexpected AS2 from value", AS2_NAME, 
request.getFirstHeader(AS2Header.AS2_FROM).getValue());
+        assertEquals("Unexpected AS2 to value", AS2_NAME, 
request.getFirstHeader(AS2Header.AS2_TO).getValue());
+        assertTrue("Unexpected message id value",
+                
request.getFirstHeader(AS2Header.MESSAGE_ID).getValue().endsWith(CLIENT_FQDN + 
">"));
+        assertEquals("Unexpected target host value", TARGET_HOST + ":" + 
TARGET_PORT,
+                request.getFirstHeader(AS2Header.TARGET_HOST).getValue());
+        assertEquals("Unexpected user agent value", USER_AGENT,
+                request.getFirstHeader(AS2Header.USER_AGENT).getValue());
+        assertNotNull("Date value missing", 
request.getFirstHeader(AS2Header.DATE));
+        assertNotNull("Content length value missing", 
request.getFirstHeader(AS2Header.CONTENT_LENGTH));
+        assertTrue("Unexpected content type for message",
+                
request.getFirstHeader(AS2Header.CONTENT_TYPE).getValue().startsWith(AS2MimeType.APPLICATION_PKCS7_MIME));
+
+        assertTrue("Request does not contain entity", request instanceof 
BasicHttpEntityEnclosingRequest);
+        HttpEntity entity = ((BasicHttpEntityEnclosingRequest) 
request).getEntity();
+        assertNotNull("Request does not contain entity", entity);
+        assertTrue("Unexpected request entity type", entity instanceof 
ApplicationPkcs7MimeEnvelopedDataEntity);
+        ApplicationPkcs7MimeEnvelopedDataEntity envelopedEntity = 
(ApplicationPkcs7MimeEnvelopedDataEntity) entity;
+        assertTrue("Entity not set as main body of request", 
envelopedEntity.isMainBody());
+
+        // Validated enveloped part.
+        MimeEntity encryptedEntity = 
envelopedEntity.getEncryptedEntity(signingKP.getPrivate());
+        assertTrue("Enveloped mime part incorrect type ", encryptedEntity 
instanceof ApplicationPkcs7MimeCompressedDataEntity);
+        ApplicationPkcs7MimeCompressedDataEntity compressedDataEntity = 
(ApplicationPkcs7MimeCompressedDataEntity) encryptedEntity;
+        assertTrue("Unexpected content type for compressed mime part",
+                
compressedDataEntity.getContentType().getValue().startsWith(AS2MimeType.APPLICATION_PKCS7_MIME));
+        assertFalse("Enveloped mime type set as main body of request", 
compressedDataEntity.isMainBody());
+
+        // Validated compressed part.
+        MimeEntity compressedEntity = 
compressedDataEntity.getCompressedEntity(new ZlibExpanderProvider());
+        assertTrue("Enveloped mime part incorrect type ", compressedEntity 
instanceof MultipartSignedEntity);
+        MultipartSignedEntity multipartSignedEntity = (MultipartSignedEntity) 
compressedEntity;
+        assertTrue("Unexpected content type for compressed entity",
+                
multipartSignedEntity.getContentType().getValue().startsWith(AS2MediaType.MULTIPART_SIGNED));
+        assertFalse("Multipart signed entity set as main body of request", 
multipartSignedEntity.isMainBody());
+        assertTrue("Multipart signed entity contains invalid number of mime 
parts",
+                multipartSignedEntity.getPartCount() == 2);
+
+        // Validated first mime part.
+        assertTrue("First mime part incorrect type ", 
multipartSignedEntity.getPart(0) instanceof ApplicationEDIFACTEntity);
+        ApplicationEDIFACTEntity ediEntity = (ApplicationEDIFACTEntity) 
multipartSignedEntity.getPart(0);
+        assertTrue("Unexpected content type for first mime part",
+                
ediEntity.getContentType().getValue().startsWith(AS2MediaType.APPLICATION_EDIFACT));
+        assertFalse("First mime type set as main body of request", 
ediEntity.isMainBody());
+        
+        // Validate second mime part.
+        assertTrue("Second mime part incorrect type ",
+                multipartSignedEntity.getPart(1) instanceof 
ApplicationPkcs7SignatureEntity);
+        ApplicationPkcs7SignatureEntity signatureEntity = 
(ApplicationPkcs7SignatureEntity) multipartSignedEntity.getPart(1);
+        assertTrue("Unexpected content type for second mime part",
+                
signatureEntity.getContentType().getValue().startsWith(AS2MediaType.APPLICATION_PKCS7_SIGNATURE));
+        assertFalse("First mime type set as main body of request", 
signatureEntity.isMainBody());
+
+    }
+
 
 
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> Enhance the AS2 Component to send and receive encrypted AS2 messages
> --------------------------------------------------------------------
>
>                 Key: CAMEL-12605
>                 URL: https://issues.apache.org/jira/browse/CAMEL-12605
>             Project: Camel
>          Issue Type: Improvement
>    Affects Versions: 2.23.0
>            Reporter: William Collins
>            Assignee: William Collins
>            Priority: Major
>
> Enhance the AS2 Component to support encrypted AS2 messages per RFC4130



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to