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

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

davsclaus closed pull request #2348: [CAMEL-11257] Fixed serialization issue 
with non-MIME messages
URL: https://github.com/apache/camel/pull/2348
 
 
   

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 f13f28237eb..b2daab59113 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
@@ -49,7 +49,7 @@
      * Prefix for all AS2 HTTP Context Attributes used by the Http Client
      * Manager.
      */
-    public static final String CAMEL_AS2_CLIENT_PREFIX = "camel-as2.client";
+    public static final String CAMEL_AS2_CLIENT_PREFIX = "camel-as2.client.";
 
     /**
      * The HTTP Context Attribute indicating the AS2 message structure to be 
sent.
@@ -231,6 +231,7 @@ public HttpCoreContext send(String ediMessage,
             try {
                 MultipartSignedEntity multipartSignedEntity = new 
MultipartSignedEntity(applicationEDIEntity, gen,
                         AS2Charset.US_ASCII, AS2TransferEncoding.BASE64, true, 
null);
+                multipartSignedEntity.setMainBody(true);
                 EntityUtils.setMessageEntity(request, multipartSignedEntity);
             } catch (Exception e) {
                 throw new HttpException("Failed to sign message", e);
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 ff154f2bf13..c13dead8049 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
@@ -209,6 +209,7 @@ public static void parseMultipartSignedEntity(HttpMessage 
message)
             }
 
             multipartSignedEntity = parseMultipartSignedEntityBody(inbuffer, 
boundary, charsetName, contentTransferEncoding);
+            multipartSignedEntity.setMainBody(true);
 
             EntityUtils.setMessageEntity(message, multipartSignedEntity);
 
@@ -245,18 +246,11 @@ public static void parseApplicationEDIEntity(HttpMessage 
message) throws HttpExc
             Header transferEncoding = entity.getContentEncoding();
             String contentTransferEncoding = transferEncoding == null ? null : 
transferEncoding.getValue();
 
-            SessionInputBufferImpl inBuffer = new SessionInputBufferImpl(new 
HttpTransportMetricsImpl(), 8 * 1024);
+            AS2SessionInputBuffer inBuffer = new AS2SessionInputBuffer(new 
HttpTransportMetricsImpl(), 8 * 1024);
             inBuffer.bind(entity.getContent());
 
-            // Extract content from stream
-            CharArrayBuffer lineBuffer = new CharArrayBuffer(1024);
-            while (inBuffer.readLine(lineBuffer) != -1) {
-                lineBuffer.append("\r\n"); // add line delimiter
-            }
-
-            // Build application EDI entity
-            applicationEDIEntity = 
EntityUtils.createEDIEntity(lineBuffer.toString(), contentType,
-                    contentTransferEncoding, true);
+            applicationEDIEntity = parseEDIEntityBody(inBuffer, null, 
contentType, contentTransferEncoding);
+            applicationEDIEntity.setMainBody(true);
 
             EntityUtils.setMessageEntity(message, applicationEDIEntity);
         } catch (HttpException e) {
@@ -791,7 +785,9 @@ public static String parseBodyPartText(final 
AS2SessionInputBuffer inbuffer,
             }
 
             buffer.append(line);
-            buffer.append("\r\n");
+            if (inbuffer.isLastLineReadTerminatedByLineFeed()) {
+                buffer.append("\r\n");
+            }
             line.clear();
         }
 
diff --git 
a/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/io/AS2SessionInputBuffer.java
 
b/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/io/AS2SessionInputBuffer.java
index 630edeb9fa6..858c15c2fd1 100644
--- 
a/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/io/AS2SessionInputBuffer.java
+++ 
b/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/io/AS2SessionInputBuffer.java
@@ -49,6 +49,8 @@
     private int bufferpos;
     private int bufferlen;
     private CharBuffer cbuf;
+    
+    private boolean lastLineReadTerminatedByLineFeed;
 
     public AS2SessionInputBuffer(final HttpTransportMetricsImpl metrics,
                                  final int buffersize,
@@ -186,12 +188,14 @@ public int readLine(CharArrayBuffer charbuffer) throws 
IOException {
         final int maxLineLen = this.constraints.getMaxLineLength();
         int noRead = 0;
         boolean retry = true;
+        this.lastLineReadTerminatedByLineFeed = false;
         while (retry) {
             // attempt to find end of line (LF)
             int pos = -1;
             for (int i = this.bufferpos; i < this.bufferlen; i++) {
                 if (this.buffer[i] == HTTP.LF) {
                     pos = i;
+                    this.lastLineReadTerminatedByLineFeed = true;
                     break;
                 }
             }
@@ -218,14 +222,16 @@ public int readLine(CharArrayBuffer charbuffer) throws 
IOException {
                 }
                 noRead = fillBuffer();
                 if (noRead == -1) {
+                    // end of stream reached.
                     retry = false;
                 }
             }
         }
         if (noRead == -1 && this.linebuffer.isEmpty()) {
-            // indicate the end of stream
+            // end of stream reached with no further data in line buffer
             return -1;
         }
+        
         return lineFromLineBuffer(charbuffer);
     }
 
@@ -240,6 +246,10 @@ public String readLine() throws IOException {
         }
     }
 
+    public boolean isLastLineReadTerminatedByLineFeed() {
+        return lastLineReadTerminatedByLineFeed;
+    }
+
     @Override
     public boolean isDataAvailable(int timeout) throws IOException {
         return hasBufferedData();
@@ -343,7 +353,11 @@ private void addBytesToLinebuffer(int pos) throws 
IOException {
                 len = this.bufferlen - this.bufferpos;
             }
             this.linebuffer.append(this.buffer, this.bufferpos, len);
-            this.bufferpos = pos + 1;
+            if (pos != -1) {
+                this.bufferpos = pos + 1;
+            } else {
+                this.bufferpos = this.bufferlen;
+            }
         } catch (Exception e) {
             throw new IOException("failed to decode transfer encoding", e);
         }
diff --git 
a/components/camel-as2/camel-as2-api/src/test/java/org/apache/camel/component/as2/api/util/MicUtilsTest.java
 
b/components/camel-as2/camel-as2-api/src/test/java/org/apache/camel/component/as2/api/util/MicUtilsTest.java
index f5357861a2e..5cbaba709ac 100644
--- 
a/components/camel-as2/camel-as2-api/src/test/java/org/apache/camel/component/as2/api/util/MicUtilsTest.java
+++ 
b/components/camel-as2/camel-as2-api/src/test/java/org/apache/camel/component/as2/api/util/MicUtilsTest.java
@@ -74,7 +74,7 @@
             + "UNZ+1+00000000000778'";
 
     private static final String EXPECTED_MESSAGE_DIGEST_ALGORITHM = "sha1";
-    private static final String EXPECTED_ENCODED_MESSAGE_DIGEST = 
"PaQyByOuBL7XiYyts4Sdmvl1WME=";
+    private static final String EXPECTED_ENCODED_MESSAGE_DIGEST = 
"XUt+ug5GEDD0X9+Nv8DGYZZThOQ=";
 
     @Before
     public void setUp() throws Exception {
diff --git 
a/components/camel-as2/camel-as2-component/src/main/java/org/apache/camel/component/as2/AS2Component.java
 
b/components/camel-as2/camel-as2-component/src/main/java/org/apache/camel/component/as2/AS2Component.java
index 2bfd0de9c1c..7424fc81f55 100644
--- 
a/components/camel-as2/camel-as2-component/src/main/java/org/apache/camel/component/as2/AS2Component.java
+++ 
b/components/camel-as2/camel-as2-component/src/main/java/org/apache/camel/component/as2/AS2Component.java
@@ -16,16 +16,23 @@
  */
 package org.apache.camel.component.as2;
 
+import java.security.Security;
+
 import org.apache.camel.CamelContext;
 import org.apache.camel.Endpoint;
 import org.apache.camel.component.as2.internal.AS2ApiCollection;
 import org.apache.camel.component.as2.internal.AS2ApiName;
 import org.apache.camel.util.component.AbstractApiComponent;
+import org.bouncycastle.jce.provider.BouncyCastleProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Represents the component that manages {@link AS2Endpoint}.
  */
 public class AS2Component extends AbstractApiComponent<AS2ApiName, 
AS2Configuration, AS2ApiCollection> {
+    
+    private static final Logger LOG = 
LoggerFactory.getLogger(AS2Component.class);
 
     public AS2Component() {
         super(AS2Endpoint.class, AS2ApiName.class, 
AS2ApiCollection.getCollection());
@@ -55,5 +62,14 @@ protected Endpoint createEndpoint(String uri, String 
methodName, AS2ApiName apiN
     public void setConfiguration(AS2Configuration configuration) {
         super.setConfiguration(configuration);
     }
+    
+    @Override
+    protected void doStart() throws Exception {
+        super.doStart();
+        if (Security.getProvider("BC") == null) {
+            LOG.debug("Adding BouncyCastleProvider as security provider");
+            Security.addProvider(new BouncyCastleProvider());
+        }
+    }
 
 }
diff --git 
a/components/camel-as2/camel-as2-component/src/test/java/org/apache/camel/component/as2/AS2ServerManagerIntegrationTest.java
 
b/components/camel-as2/camel-as2-component/src/test/java/org/apache/camel/component/as2/AS2ServerManagerIntegrationTest.java
index 229c314d065..fda7aa01fed 100644
--- 
a/components/camel-as2/camel-as2-component/src/test/java/org/apache/camel/component/as2/AS2ServerManagerIntegrationTest.java
+++ 
b/components/camel-as2/camel-as2-component/src/test/java/org/apache/camel/component/as2/AS2ServerManagerIntegrationTest.java
@@ -170,6 +170,8 @@ public void receivePlainEDIMessageTest() throws Exception {
         ApplicationEDIFACTEntity ediEntity = (ApplicationEDIFACTEntity) entity;
         assertTrue("Unexpected content type for entity", 
ediEntity.getContentType().getValue().startsWith(AS2MediaType.APPLICATION_EDIFACT));
         assertTrue("Entity not set as main body of request", 
ediEntity.isMainBody());
+        String rcvdMessage = ediEntity.getEdiMessage().replaceAll("\r", "");
+        assertEquals("EDI message does not match", EDI_MESSAGE, rcvdMessage);
 
     }
 
@@ -307,4 +309,5 @@ public void configure() {
             }
         };
     }
+    
 }


 

----------------------------------------------------------------
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]


> Provide AS2 component to support Business Data Interchange Using HTTP
> ---------------------------------------------------------------------
>
>                 Key: CAMEL-11257
>                 URL: https://issues.apache.org/jira/browse/CAMEL-11257
>             Project: Camel
>          Issue Type: New Feature
>    Affects Versions: 2.19.1
>            Reporter: William Collins
>            Assignee: William Collins
>            Priority: Major
>             Fix For: 2.22.0
>
>
> AS2 Camel component should provide MIME-Based Secure Peer-to-Peer Business 
> Data Interchange Using HTTP as per RFC4120



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

Reply via email to