You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2023/08/29 18:59:57 UTC
[camel] branch camel-3.21.x updated: CAMEL-19731 AS2: Fixed null pointer exception (#11229)
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch camel-3.21.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-3.21.x by this push:
new dc5cc7f4722 CAMEL-19731 AS2: Fixed null pointer exception (#11229)
dc5cc7f4722 is described below
commit dc5cc7f47224a3dbdef992b78614cfb2dcc2fa3a
Author: Dmitry Kryukov <dk...@users.noreply.github.com>
AuthorDate: Tue Aug 29 21:56:18 2023 +0300
CAMEL-19731 AS2: Fixed null pointer exception (#11229)
* CAMEL-19731 AS2: Fixed null pointer exception when request's header dispositionNotificationTo isn't set
* CAMEL-19731 simplified the null-check - now it causes early exit
---
.../component/as2/api/entity/EntityParser.java | 8 +++-
.../camel/component/as2/AS2ClientManagerIT.java | 56 ++++++++++++++++++++++
2 files changed, 63 insertions(+), 1 deletion(-)
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 cba6b1d7ab2..f370065b417 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
@@ -444,6 +444,10 @@ public final class EntityParser {
try {
// Determine Content Type of Message
String contentTypeStr = HttpMessageUtils.getHeaderValue(message, AS2Header.CONTENT_TYPE);
+ if (contentTypeStr == null) {
+ // contentTypeStr can be null when dispositionNotificationTo isn't set
+ return;
+ }
ContentType contentType = ContentType.parse(contentTypeStr);
// Determine Charset
@@ -457,7 +461,8 @@ public final class EntityParser {
String boundary = HttpMessageUtils.getParameterValue(message, AS2Header.CONTENT_TYPE, "boundary");
// Determine content transfer encoding
- String contentTransferEncoding = HttpMessageUtils.getHeaderValue(message, AS2Header.CONTENT_TRANSFER_ENCODING);
+ String contentTransferEncoding
+ = HttpMessageUtils.getHeaderValue(message, AS2Header.CONTENT_TRANSFER_ENCODING);
AS2SessionInputBuffer inBuffer = new AS2SessionInputBuffer(new HttpTransportMetricsImpl(), 8 * 1024);
inBuffer.bind(entity.getContent());
@@ -497,6 +502,7 @@ public final class EntityParser {
throw new HttpException("Failed to parse entity content", e);
}
}
+
}
public static MultipartSignedEntity parseMultipartSignedEntityBody(
diff --git a/components/camel-as2/camel-as2-component/src/test/java/org/apache/camel/component/as2/AS2ClientManagerIT.java b/components/camel-as2/camel-as2-component/src/test/java/org/apache/camel/component/as2/AS2ClientManagerIT.java
index cff3b7ba171..f969b8e39f4 100644
--- a/components/camel-as2/camel-as2-component/src/test/java/org/apache/camel/component/as2/AS2ClientManagerIT.java
+++ b/components/camel-as2/camel-as2-component/src/test/java/org/apache/camel/component/as2/AS2ClientManagerIT.java
@@ -88,6 +88,7 @@ import org.slf4j.LoggerFactory;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
@@ -243,6 +244,61 @@ public class AS2ClientManagerIT extends AbstractAS2ITSupport {
}
+ @Test
+ public void plainMessageSendTestWhenDispositionNotificationToNotSet() 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.PLAIN);
+ // parameter type is org.apache.http.entity.ContentType
+ headers.put("CamelAS2.ediMessageContentType",
+ ContentType.create(AS2MediaType.APPLICATION_EDIFACT, StandardCharsets.US_ASCII.name()));
+ // parameter type is String
+ headers.put("CamelAS2.ediMessageTransferEncoding", EDI_MESSAGE_CONTENT_TRANSFER_ENCODING);
+ // parameter type is String
+ headers.put("CamelAS2.attachedFileName", "");
+
+ final Triple<HttpEntity, HttpRequest, HttpResponse> result = executeRequest(headers);
+ HttpEntity responseEntity = result.getLeft();
+ HttpRequest request = result.getMiddle();
+ HttpResponse response = result.getRight();
+
+ assertNotNull(result, "send result");
+ LOG.debug("send: {}", result);
+ assertNotNull(request, "Request");
+ assertTrue(request instanceof HttpEntityEnclosingRequest, "Request does not contain body");
+ HttpEntity entity = ((HttpEntityEnclosingRequest) request).getEntity();
+ assertNotNull(entity, "Request body");
+ assertTrue(entity instanceof ApplicationEntity, "Request body does not contain EDI entity");
+ String ediMessage = ((ApplicationEntity) entity).getEdiMessage();
+ assertEquals(EDI_MESSAGE.replaceAll("[\n\r]", ""), ediMessage.replaceAll("[\n\r]", ""), "EDI message is different");
+
+ assertNotNull(response, "Response");
+ assertNull(HttpMessageUtils.getHeaderValue(response, AS2Header.CONTENT_TYPE),
+ "Unexpected non-null content type");
+ assertNull(HttpMessageUtils.getHeaderValue(response, AS2Header.MIME_VERSION),
+ "Unexpected mime version");
+ assertNull(HttpMessageUtils.getHeaderValue(response, AS2Header.AS2_VERSION),
+ "Unexpected AS2 version");
+ assertNull(HttpMessageUtils.getHeaderValue(response, AS2Header.SUBJECT),
+ "Unexpected MDN subject");
+ assertNull(HttpMessageUtils.getHeaderValue(response, AS2Header.FROM), "Unexpected MDN from");
+ assertNull(HttpMessageUtils.getHeaderValue(response, AS2Header.AS2_FROM), "Unexpected AS2 from");
+ assertNull(HttpMessageUtils.getHeaderValue(response, AS2Header.AS2_TO), "Unexpected AS2 to");
+ assertNull(HttpMessageUtils.getHeaderValue(response, AS2Header.MESSAGE_ID), "Missing message id");
+
+ assertNull(responseEntity, "Response entity");
+ }
+
@Test
public void plainMessageSend2Test() throws Exception {
final Map<String, Object> headers = new HashMap<>();