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
The following commit(s) were added to refs/heads/master by this push:
new 30192d6 Refactored AS2 Component API
30192d6 is described below
commit 30192d63f0290639e815df21ae37c9bc85f184d4
Author: William Collins <[email protected]>
AuthorDate: Sat Mar 9 11:37:36 2019 -0500
Refactored AS2 Component API
---
.../component/as2/api/AS2ServerConnection.java | 8 ++
.../component/as2/api/entity/EntityParser.java | 119 -----------------
.../component/as2/api/protocol/ResponseMDN.java | 32 ++---
.../component/as2/api/util/HttpMessageUtils.java | 145 +++++++++++++++++++++
.../camel/component/as2/api/util/MicUtils.java | 3 +-
.../apache/camel/component/as2/AS2Component.java | 2 -
.../camel/component/as2/AS2Configuration.java | 18 +--
.../apache/camel/component/as2/AS2Consumer.java | 11 +-
.../apache/camel/component/as2/AS2Producer.java | 19 +++
.../ContentTypeConverter.java} | 25 ++--
.../camel/component/as2/internal/AS2Constants.java | 3 +
.../as2/AS2ClientManagerIntegrationTest.java | 1 -
12 files changed, 224 insertions(+), 162 deletions(-)
diff --git
a/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/AS2ServerConnection.java
b/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/AS2ServerConnection.java
index 09b1061..edefb3d 100644
---
a/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/AS2ServerConnection.java
+++
b/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/AS2ServerConnection.java
@@ -210,6 +210,14 @@ public class AS2ServerConnection {
listenerThread.start();
}
+ public PrivateKey getSigningPrivateKey() {
+ return signingPrivateKey;
+ }
+
+ public PrivateKey getDecryptingPrivateKey() {
+ return decryptingPrivateKey;
+ }
+
public void close() {
if (listenerThread != null) {
synchronized (listenerThread) {
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 9652f5e9..c1ce287 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
@@ -38,7 +38,6 @@ import org.apache.camel.component.as2.api.util.EntityUtils;
import org.apache.camel.component.as2.api.util.HttpMessageUtils;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
-import org.apache.http.HttpEntityEnclosingRequest;
import org.apache.http.HttpException;
import org.apache.http.HttpMessage;
import org.apache.http.NameValuePair;
@@ -59,7 +58,6 @@ import org.bouncycastle.cms.Recipient;
import org.bouncycastle.cms.RecipientInformation;
import org.bouncycastle.cms.RecipientInformationStore;
import org.bouncycastle.cms.jcajce.JceKeyTransEnvelopedRecipient;
-import org.bouncycastle.cms.jcajce.ZlibExpanderProvider;
import org.bouncycastle.operator.InputExpanderProvider;
public final class EntityParser {
@@ -1068,121 +1066,4 @@ public final class EntityParser {
}
return fields;
}
-
- public static HttpEntity extractEdiPayload(HttpEntityEnclosingRequest
request, PrivateKey privateKey) throws HttpException {
-
- String contentTypeString = HttpMessageUtils.getHeaderValue(request,
AS2Header.CONTENT_TYPE);
- if (contentTypeString == null) {
- throw new HttpException("Failed to create MIC: content type
missing from request");
- }
- ContentType contentType = ContentType.parse(contentTypeString);
-
- parseAS2MessageEntity(request);
- MimeEntity ediEntity = null;
- switch (contentType.getMimeType().toLowerCase()) {
- case AS2MimeType.APPLICATION_EDIFACT:
- case AS2MimeType.APPLICATION_EDI_X12:
- case AS2MimeType.APPLICATION_EDI_CONSENT: {
- ediEntity = HttpMessageUtils.getEntity(request,
ApplicationEDIEntity.class);
- break;
- }
- case AS2MimeType.MULTIPART_SIGNED: {
- MultipartSignedEntity multipartSignedEntity =
HttpMessageUtils.getEntity(request,
- MultipartSignedEntity.class);
- ediEntity = multipartSignedEntity.getSignedDataEntity();
- break;
- }
- case AS2MimeType.APPLICATION_PKCS7_MIME: {
- switch(contentType.getParameter("smime-type")) {
- case "compressed-data": {
- ApplicationPkcs7MimeCompressedDataEntity compressedDataEntity
= HttpMessageUtils.getEntity(request,
ApplicationPkcs7MimeCompressedDataEntity.class);
- ediEntity =
extractEdiPayloadFromCompressedEntity(compressedDataEntity);
- break;
- }
- case "enveloped-data": {
- if (privateKey == null) {
- throw new HttpException("Failed to get EDI message from
encrypted request: private key is null");
- }
- ApplicationPkcs7MimeEnvelopedDataEntity envelopedDataEntity =
HttpMessageUtils.getEntity(request,
ApplicationPkcs7MimeEnvelopedDataEntity.class);
- ediEntity =
extractEdiPayloadFromEnvelopedEntity(envelopedDataEntity, privateKey);
- break;
- }
- default:
- throw new HttpException("Failed to create MIC: unknown " +
AS2MimeType.APPLICATION_PKCS7_MIME + " smime-type: " +
contentType.getParameter("smime-type"));
- }
- break;
- }
- default:
- throw new HttpException("Failed to create MIC: invalid content
type '" + contentType.getMimeType() + "' for message integrity check");
- }
-
- return ediEntity;
-
- }
-
- private static MimeEntity
extractEdiPayloadFromEnvelopedEntity(ApplicationPkcs7MimeEnvelopedDataEntity
envelopedDataEntity, PrivateKey privateKey) throws HttpException {
- MimeEntity ediEntity = null;
-
- MimeEntity entity = envelopedDataEntity.getEncryptedEntity(privateKey);
- String contentTypeString = entity.getContentTypeValue();
- if (contentTypeString == null) {
- throw new HttpException("Failed to create MIC: content type
missing from encrypted entity");
- }
- ContentType contentType = ContentType.parse(contentTypeString);
-
- switch(contentType.getMimeType().toLowerCase()) {
- case AS2MimeType.APPLICATION_EDIFACT:
- case AS2MimeType.APPLICATION_EDI_X12:
- case AS2MimeType.APPLICATION_EDI_CONSENT: {
- ediEntity = entity;
- break;
- }
- case AS2MimeType.MULTIPART_SIGNED: {
- MultipartSignedEntity multipartSignedEntity =
(MultipartSignedEntity) entity;
- ediEntity = multipartSignedEntity.getSignedDataEntity();
- break;
- }
- case AS2MimeType.APPLICATION_PKCS7_MIME: {
- if
(!"compressed-data".equals(contentType.getParameter("smime-type"))) {
- throw new HttpException("Failed to extract EDI payload:
invalid mime type '" + contentType.getParameter("smime-type") + "' for AS2
enveloped entity");
- }
- ApplicationPkcs7MimeCompressedDataEntity compressedDataEntity =
(ApplicationPkcs7MimeCompressedDataEntity) entity;
- ediEntity =
extractEdiPayloadFromCompressedEntity(compressedDataEntity);
- break;
- }
- default:
- throw new HttpException("Failed to extract EDI payload: invalid
content type '" + contentType.getMimeType() + "' for AS2 enveloped entity");
- }
-
- return ediEntity;
- }
-
- private static MimeEntity
extractEdiPayloadFromCompressedEntity(ApplicationPkcs7MimeCompressedDataEntity
compressedDataEntity) throws HttpException {
- MimeEntity ediEntity = null;
-
- MimeEntity entity = compressedDataEntity.getCompressedEntity(new
ZlibExpanderProvider());
- String contentTypeString = entity.getContentTypeValue();
- if (contentTypeString == null) {
- throw new HttpException("Failed to extract EDI payload: content
type missing from compressed entity");
- }
- ContentType contentType = ContentType.parse(contentTypeString);
-
- switch(contentType.getMimeType().toLowerCase()) {
- case AS2MimeType.APPLICATION_EDIFACT:
- case AS2MimeType.APPLICATION_EDI_X12:
- case AS2MimeType.APPLICATION_EDI_CONSENT: {
- ediEntity = entity;
- break;
- }
- case AS2MimeType.MULTIPART_SIGNED: {
- MultipartSignedEntity multipartSignedEntity =
(MultipartSignedEntity) entity;
- ediEntity = multipartSignedEntity.getSignedDataEntity();
- break;
- }
- default:
- throw new HttpException("Failed to extract EDI payload: invalid
content type '" + contentType.getMimeType() + "' for AS2 compressed entity");
- }
-
- return ediEntity;
- }
}
diff --git
a/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/protocol/ResponseMDN.java
b/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/protocol/ResponseMDN.java
index ee1b32d..f0b3deb 100644
---
a/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/protocol/ResponseMDN.java
+++
b/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/protocol/ResponseMDN.java
@@ -47,6 +47,7 @@ import org.apache.camel.component.as2.api.util.SigningUtils;
import org.apache.http.Header;
import org.apache.http.HttpEntityEnclosingRequest;
import org.apache.http.HttpException;
+import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.HttpResponseInterceptor;
import org.apache.http.protocol.HttpContext;
@@ -106,16 +107,17 @@ public class ResponseMDN implements
HttpResponseInterceptor {
}
HttpCoreContext coreContext = HttpCoreContext.adapt(context);
-
- HttpEntityEnclosingRequest request =
coreContext.getAttribute(HttpCoreContext.HTTP_REQUEST,
HttpEntityEnclosingRequest.class);
- if (request == null) {
- // Should never happen; but you never know
- LOG.debug("MDN not returned due to null request");
- throw new HttpException("request missing from HTTP context");
+
+ HttpRequest request =
coreContext.getAttribute(HttpCoreContext.HTTP_REQUEST, HttpRequest.class);
+ if (request == null || !(request instanceof
HttpEntityEnclosingRequest)) {
+ // Not an enclosing request so nothing to do.
+ return;
}
- LOG.debug("Processing MDN for request: {}", request);
- if (HttpMessageUtils.getHeaderValue(request,
AS2Header.DISPOSITION_NOTIFICATION_TO) == null) {
+ HttpEntityEnclosingRequest httpEntityEnclosingRequest =
(HttpEntityEnclosingRequest) request;
+ LOG.debug("Processing MDN for request: {}",
httpEntityEnclosingRequest);
+
+ if (HttpMessageUtils.getHeaderValue(httpEntityEnclosingRequest,
AS2Header.DISPOSITION_NOTIFICATION_TO) == null) {
// no receipt requested by sender
LOG.debug("MDN not returned: no receipt requested");
return;
@@ -123,17 +125,17 @@ public class ResponseMDN implements
HttpResponseInterceptor {
// Return a Message Disposition Notification Receipt in response body
String boundary = EntityUtils.createBoundaryValue();
- String mdnMessage = createMdnDescription(request, response,
DispositionMode.AUTOMATIC_ACTION_MDN_SENT_AUTOMATICALLY,
+ String mdnMessage = createMdnDescription(httpEntityEnclosingRequest,
response, DispositionMode.AUTOMATIC_ACTION_MDN_SENT_AUTOMATICALLY,
AS2DispositionType.PROCESSED, null, null, null, null, null,
AS2Charset.US_ASCII, DEFAULT_MDN_MESSAGE_TEMPLATE);
DispositionNotificationMultipartReportEntity multipartReportEntity =
new DispositionNotificationMultipartReportEntity(
- request, response,
DispositionMode.AUTOMATIC_ACTION_MDN_SENT_AUTOMATICALLY,
+ httpEntityEnclosingRequest, response,
DispositionMode.AUTOMATIC_ACTION_MDN_SENT_AUTOMATICALLY,
AS2DispositionType.PROCESSED, null, null, null, null, null,
AS2Charset.US_ASCII, boundary, true, decryptingPrivateKey, mdnMessage);
DispositionNotificationOptions dispositionNotificationOptions =
DispositionNotificationOptionsParser
.parseDispositionNotificationOptions(
- HttpMessageUtils.getHeaderValue(request,
AS2Header.DISPOSITION_NOTIFICATION_OPTIONS), null);
+
HttpMessageUtils.getHeaderValue(httpEntityEnclosingRequest,
AS2Header.DISPOSITION_NOTIFICATION_OPTIONS), null);
- String receiptAddress = HttpMessageUtils.getHeaderValue(request,
AS2Header.RECEIPT_DELIVERY_OPTION);
+ String receiptAddress =
HttpMessageUtils.getHeaderValue(httpEntityEnclosingRequest,
AS2Header.RECEIPT_DELIVERY_OPTION);
if (receiptAddress != null) {
// Asynchronous Delivery
@@ -152,7 +154,7 @@ public class ResponseMDN implements HttpResponseInterceptor
{
/* Subject header */
// RFC4130 - 7.3 - Subject header SHOULD be supplied
String subjectPrefix =
coreContext.getAttribute(AS2ServerManager.SUBJECT, String.class);
- String subject = HttpMessageUtils.getHeaderValue(request,
AS2Header.SUBJECT);
+ String subject =
HttpMessageUtils.getHeaderValue(httpEntityEnclosingRequest, AS2Header.SUBJECT);
if (subjectPrefix != null && subject != null) {
subject = subjectPrefix + subject;
} else if (subject != null) {
@@ -167,7 +169,7 @@ public class ResponseMDN implements HttpResponseInterceptor
{
response.addHeader(AS2Header.FROM, from);
/* AS2-From header */
- String as2From = HttpMessageUtils.getHeaderValue(request,
AS2Header.AS2_TO);
+ String as2From =
HttpMessageUtils.getHeaderValue(httpEntityEnclosingRequest, AS2Header.AS2_TO);
try {
AS2Utils.validateAS2Name(as2From);
} catch (InvalidAS2NameException e) {
@@ -176,7 +178,7 @@ public class ResponseMDN implements HttpResponseInterceptor
{
response.addHeader(AS2Header.AS2_FROM, as2From);
/* AS2-To header */
- String as2To = HttpMessageUtils.getHeaderValue(request,
AS2Header.AS2_FROM);
+ String as2To =
HttpMessageUtils.getHeaderValue(httpEntityEnclosingRequest, AS2Header.AS2_FROM);
try {
AS2Utils.validateAS2Name(as2To);
} catch (InvalidAS2NameException e) {
diff --git
a/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/util/HttpMessageUtils.java
b/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/util/HttpMessageUtils.java
index 0bf4962..a256065 100644
---
a/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/util/HttpMessageUtils.java
+++
b/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/util/HttpMessageUtils.java
@@ -16,7 +16,16 @@
*/
package org.apache.camel.component.as2.api.util;
+import java.security.PrivateKey;
+
+import org.apache.camel.component.as2.api.AS2Header;
+import org.apache.camel.component.as2.api.AS2MimeType;
+import org.apache.camel.component.as2.api.entity.ApplicationEDIEntity;
+import
org.apache.camel.component.as2.api.entity.ApplicationPkcs7MimeCompressedDataEntity;
+import
org.apache.camel.component.as2.api.entity.ApplicationPkcs7MimeEnvelopedDataEntity;
import org.apache.camel.component.as2.api.entity.EntityParser;
+import org.apache.camel.component.as2.api.entity.MimeEntity;
+import org.apache.camel.component.as2.api.entity.MultipartSignedEntity;
import org.apache.http.Header;
import org.apache.http.HeaderElement;
import org.apache.http.HttpEntity;
@@ -25,9 +34,11 @@ import org.apache.http.HttpException;
import org.apache.http.HttpMessage;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
+import org.apache.http.entity.ContentType;
import org.apache.http.io.SessionInputBuffer;
import org.apache.http.util.Args;
import org.apache.http.util.CharArrayBuffer;
+import org.bouncycastle.cms.jcajce.ZlibExpanderProvider;
public final class HttpMessageUtils {
@@ -114,4 +125,138 @@ public final class HttpMessageUtils {
return null;
}
+ public static ApplicationEDIEntity extractEdiPayload(HttpMessage message,
PrivateKey privateKey) throws HttpException {
+
+ String contentTypeString = getHeaderValue(message,
AS2Header.CONTENT_TYPE);
+ if (contentTypeString == null) {
+ throw new HttpException("Failed to create MIC: content type
missing from request");
+ }
+ ContentType contentType = ContentType.parse(contentTypeString);
+
+ EntityParser.parseAS2MessageEntity(message);
+ ApplicationEDIEntity ediEntity = null;
+ switch (contentType.getMimeType().toLowerCase()) {
+ case AS2MimeType.APPLICATION_EDIFACT:
+ case AS2MimeType.APPLICATION_EDI_X12:
+ case AS2MimeType.APPLICATION_EDI_CONSENT: {
+ ediEntity = getEntity(message, ApplicationEDIEntity.class);
+ break;
+ }
+ case AS2MimeType.MULTIPART_SIGNED: {
+ MultipartSignedEntity multipartSignedEntity = getEntity(message,
+ MultipartSignedEntity.class);
+ MimeEntity mimeEntity =
multipartSignedEntity.getSignedDataEntity();
+ if (mimeEntity instanceof ApplicationEDIEntity) {
+ ediEntity = (ApplicationEDIEntity) mimeEntity;
+ } else {
+ throw new HttpException("Failed to extract EDI payload:
invalid content type '" + mimeEntity.getContentTypeValue() + "' for AS2
compressed and signed message");
+ }
+ break;
+ }
+ case AS2MimeType.APPLICATION_PKCS7_MIME: {
+ switch(contentType.getParameter("smime-type")) {
+ case "compressed-data": {
+ ApplicationPkcs7MimeCompressedDataEntity compressedDataEntity
= getEntity(message, ApplicationPkcs7MimeCompressedDataEntity.class);
+ ediEntity =
extractEdiPayloadFromCompressedEntity(compressedDataEntity);
+ break;
+ }
+ case "enveloped-data": {
+ if (privateKey == null) {
+ throw new HttpException("Failed to extract EDI payload:
private key can not be null for AS2 enveloped message");
+ }
+ ApplicationPkcs7MimeEnvelopedDataEntity envelopedDataEntity =
getEntity(message, ApplicationPkcs7MimeEnvelopedDataEntity.class);
+ ediEntity =
extractEdiPayloadFromEnvelopedEntity(envelopedDataEntity, privateKey);
+ break;
+ }
+ default:
+ throw new HttpException("Failed to extract EDI message:
unknown " + AS2MimeType.APPLICATION_PKCS7_MIME + " smime-type: " +
contentType.getParameter("smime-type"));
+ }
+ break;
+ }
+ default:
+ throw new HttpException("Failed to extract EDI message: invalid
content type '" + contentType.getMimeType() + "' for AS2 request message");
+ }
+
+ return ediEntity;
+
+ }
+
+ private static ApplicationEDIEntity
extractEdiPayloadFromEnvelopedEntity(ApplicationPkcs7MimeEnvelopedDataEntity
envelopedDataEntity, PrivateKey privateKey) throws HttpException {
+ ApplicationEDIEntity ediEntity = null;
+
+ MimeEntity entity = envelopedDataEntity.getEncryptedEntity(privateKey);
+ String contentTypeString = entity.getContentTypeValue();
+ if (contentTypeString == null) {
+ throw new HttpException("Failed to extract EDI message: content
type missing from encrypted entity");
+ }
+ ContentType contentType = ContentType.parse(contentTypeString);
+
+ switch(contentType.getMimeType().toLowerCase()) {
+ case AS2MimeType.APPLICATION_EDIFACT:
+ case AS2MimeType.APPLICATION_EDI_X12:
+ case AS2MimeType.APPLICATION_EDI_CONSENT: {
+ ediEntity = (ApplicationEDIEntity) entity;
+ break;
+ }
+ case AS2MimeType.MULTIPART_SIGNED: {
+ MultipartSignedEntity multipartSignedEntity =
(MultipartSignedEntity) entity;
+ MimeEntity mimeEntity =
multipartSignedEntity.getSignedDataEntity();
+ if (mimeEntity instanceof ApplicationEDIEntity) {
+ ediEntity = (ApplicationEDIEntity) mimeEntity;
+ } else {
+
+ throw new HttpException("Failed to extract EDI payload:
invalid content type '" + mimeEntity.getContentTypeValue() + "' for AS2
compressed and signed entity");
+ }
+ break;
+ }
+ case AS2MimeType.APPLICATION_PKCS7_MIME: {
+ if
(!"compressed-data".equals(contentType.getParameter("smime-type"))) {
+ throw new HttpException("Failed to extract EDI payload:
invalid mime type '" + contentType.getParameter("smime-type") + "' for AS2
enveloped entity");
+ }
+ ApplicationPkcs7MimeCompressedDataEntity compressedDataEntity =
(ApplicationPkcs7MimeCompressedDataEntity) entity;
+ ediEntity =
extractEdiPayloadFromCompressedEntity(compressedDataEntity);
+ break;
+ }
+ default:
+ throw new HttpException("Failed to extract EDI payload: invalid
content type '" + contentType.getMimeType() + "' for AS2 enveloped entity");
+ }
+
+ return ediEntity;
+ }
+
+ public static ApplicationEDIEntity
extractEdiPayloadFromCompressedEntity(ApplicationPkcs7MimeCompressedDataEntity
compressedDataEntity) throws HttpException {
+ ApplicationEDIEntity ediEntity = null;
+
+ MimeEntity entity = compressedDataEntity.getCompressedEntity(new
ZlibExpanderProvider());
+ String contentTypeString = entity.getContentTypeValue();
+ if (contentTypeString == null) {
+ throw new HttpException("Failed to extract EDI payload: content
type missing from compressed entity");
+ }
+ ContentType contentType = ContentType.parse(contentTypeString);
+
+ switch(contentType.getMimeType().toLowerCase()) {
+ case AS2MimeType.APPLICATION_EDIFACT:
+ case AS2MimeType.APPLICATION_EDI_X12:
+ case AS2MimeType.APPLICATION_EDI_CONSENT: {
+ ediEntity = (ApplicationEDIEntity) entity;
+ break;
+ }
+ case AS2MimeType.MULTIPART_SIGNED: {
+ MultipartSignedEntity multipartSignedEntity =
(MultipartSignedEntity) entity;
+ MimeEntity mimeEntity =
multipartSignedEntity.getSignedDataEntity();
+ if (mimeEntity instanceof ApplicationEDIEntity) {
+ ediEntity = (ApplicationEDIEntity) mimeEntity;
+ } else {
+
+ throw new HttpException("Failed to extract EDI payload:
invalid content type '" + mimeEntity.getContentTypeValue() + "' for AS2
compressed and signed entity");
+ }
+ break;
+ }
+ default:
+ throw new HttpException("Failed to extract EDI payload: invalid
content type '" + contentType.getMimeType() + "' for AS2 compressed entity");
+ }
+
+ return ediEntity;
+ }
+
}
diff --git
a/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/util/MicUtils.java
b/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/util/MicUtils.java
index c3da303..a3b400d 100644
---
a/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/util/MicUtils.java
+++
b/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/util/MicUtils.java
@@ -26,7 +26,6 @@ import org.apache.camel.component.as2.api.AS2Header;
import org.apache.camel.component.as2.api.AS2MicAlgorithm;
import
org.apache.camel.component.as2.api.entity.DispositionNotificationOptions;
import
org.apache.camel.component.as2.api.entity.DispositionNotificationOptionsParser;
-import org.apache.camel.component.as2.api.entity.EntityParser;
import org.apache.http.HttpEntity;
import org.apache.http.HttpEntityEnclosingRequest;
import org.apache.http.HttpException;
@@ -93,7 +92,7 @@ public final class MicUtils {
return null;
}
- HttpEntity entity = EntityParser.extractEdiPayload(request,
decryptingPrivateKey);
+ HttpEntity entity = HttpMessageUtils.extractEdiPayload(request,
decryptingPrivateKey);
byte[] content = EntityUtils.getContent(entity);
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 d6c369b..084e7da 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
@@ -25,8 +25,6 @@ import org.apache.camel.component.as2.internal.AS2ApiName;
import org.apache.camel.spi.annotations.Component;
import org.apache.camel.support.component.AbstractApiComponent;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
* Represents the component that manages {@link AS2Endpoint}.
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 3b090aa..85f7b56 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
@@ -61,7 +61,7 @@ public class AS2Configuration {
private String targetHostname;
@UriParam
- private Integer targetPortNumber;
+ private Integer targetPortNumber = 80;
@UriParam(defaultValue = "camel.apache.org")
private String clientFqdn = "camel.apache.org";
@@ -193,7 +193,7 @@ public class AS2Configuration {
* Used in message ids sent by endpoint.
*/
public void setServerFqdn(String serverFqdn) {
- if (clientFqdn == null) {
+ if (serverFqdn == null) {
throw new RuntimeCamelException("Parameter 'serverFqdn' can not be
null");
}
this.serverFqdn = serverFqdn;
@@ -207,6 +207,9 @@ public class AS2Configuration {
* The host name (IP or DNS name) of target host.
*/
public void setTargetHostname(String targetHostname) {
+ if (targetHostname == null) {
+ throw new RuntimeCamelException("Parameter 'targetHostname' can
not be null");
+ }
this.targetHostname = targetHostname;
}
@@ -254,17 +257,6 @@ public class AS2Configuration {
/**
* The port number of server.
*/
- public void setServerPortNumber(String serverPortNumber) {
- try {
- this.serverPortNumber = Integer.valueOf(serverPortNumber);
- } catch (NumberFormatException e) {
- throw new RuntimeCamelException(String.format("Invalid target port
number: %s", targetPortNumber));
- }
- }
-
- /**
- * The port number of server.
- */
public void setServerPortNumber(Integer serverPortNumber) {
this.serverPortNumber = serverPortNumber;
}
diff --git
a/components/camel-as2/camel-as2-component/src/main/java/org/apache/camel/component/as2/AS2Consumer.java
b/components/camel-as2/camel-as2-component/src/main/java/org/apache/camel/component/as2/AS2Consumer.java
index bd14197..4b59d14 100644
---
a/components/camel-as2/camel-as2-component/src/main/java/org/apache/camel/component/as2/AS2Consumer.java
+++
b/components/camel-as2/camel-as2-component/src/main/java/org/apache/camel/component/as2/AS2Consumer.java
@@ -25,8 +25,11 @@ import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.component.as2.api.AS2ServerConnection;
import org.apache.camel.component.as2.api.AS2ServerManager;
+import org.apache.camel.component.as2.api.entity.ApplicationEDIEntity;
import org.apache.camel.component.as2.api.entity.EntityParser;
+import org.apache.camel.component.as2.api.util.HttpMessageUtils;
import org.apache.camel.component.as2.internal.AS2ApiName;
+import org.apache.camel.component.as2.internal.AS2Constants;
import org.apache.camel.support.component.AbstractApiConsumer;
import org.apache.camel.support.component.ApiConsumerHelper;
import org.apache.camel.support.component.ApiMethod;
@@ -36,6 +39,7 @@ import org.apache.http.HttpException;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.protocol.HttpContext;
+import org.apache.http.protocol.HttpCoreContext;
import org.apache.http.protocol.HttpRequestHandler;
/**
@@ -107,8 +111,13 @@ public class AS2Consumer extends
AbstractApiConsumer<AS2ApiName, AS2Configuratio
apiProxy.handleMDNResponse((HttpEntityEnclosingRequest)request, response,
context, "MDN Response", "Camel AS2 Server Endpoint");
}
+ ApplicationEDIEntity ediEntity =
HttpMessageUtils.extractEdiPayload(request,
as2ServerConnection.getDecryptingPrivateKey());
+
+ // Set AS2 Interchange property and EDI message into body of input
message.
Exchange exchange = getEndpoint().createExchange();
- exchange.getIn().setBody(context);
+ HttpCoreContext coreContext = HttpCoreContext.adapt(context);
+ exchange.setProperty(AS2Constants.AS2_INTERCHANGE, coreContext);
+ exchange.getIn().setBody(ediEntity.getEdiMessage());
try {
// send message to next processor in the route
diff --git
a/components/camel-as2/camel-as2-component/src/main/java/org/apache/camel/component/as2/AS2Producer.java
b/components/camel-as2/camel-as2-component/src/main/java/org/apache/camel/component/as2/AS2Producer.java
index 6af6266..fd8b8d3 100644
---
a/components/camel-as2/camel-as2-component/src/main/java/org/apache/camel/component/as2/AS2Producer.java
+++
b/components/camel-as2/camel-as2-component/src/main/java/org/apache/camel/component/as2/AS2Producer.java
@@ -16,9 +16,15 @@
*/
package org.apache.camel.component.as2;
+import org.apache.camel.Exchange;
+import
org.apache.camel.component.as2.api.entity.DispositionNotificationMultipartReportEntity;
import org.apache.camel.component.as2.internal.AS2ApiName;
+import org.apache.camel.component.as2.internal.AS2Constants;
import org.apache.camel.component.as2.internal.AS2PropertiesHelper;
import org.apache.camel.support.component.AbstractApiProducer;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.protocol.HttpCoreContext;
/**
* The AS2 producer.
@@ -28,4 +34,17 @@ public class AS2Producer extends
AbstractApiProducer<AS2ApiName, AS2Configuratio
public AS2Producer(AS2Endpoint endpoint) {
super(endpoint, AS2PropertiesHelper.getHelper());
}
+
+ @Override
+ public void interceptResult(Object methodResult, Exchange resultExchange) {
+ HttpCoreContext context = (HttpCoreContext) methodResult;
+ resultExchange.setProperty(AS2Constants.AS2_INTERCHANGE, context);
+ HttpResponse response = context.getResponse();
+ HttpEntity entity = response.getEntity();
+ if (entity != null && entity instanceof
DispositionNotificationMultipartReportEntity) {
+ resultExchange.getOut().setBody(entity);
+ } else {
+ resultExchange.getOut().setBody(null);
+ }
+ }
}
diff --git
a/components/camel-as2/camel-as2-component/src/main/java/org/apache/camel/component/as2/AS2Producer.java
b/components/camel-as2/camel-as2-component/src/main/java/org/apache/camel/component/as2/converter/ContentTypeConverter.java
similarity index 58%
copy from
components/camel-as2/camel-as2-component/src/main/java/org/apache/camel/component/as2/AS2Producer.java
copy to
components/camel-as2/camel-as2-component/src/main/java/org/apache/camel/component/as2/converter/ContentTypeConverter.java
index 6af6266..cb2e948 100644
---
a/components/camel-as2/camel-as2-component/src/main/java/org/apache/camel/component/as2/AS2Producer.java
+++
b/components/camel-as2/camel-as2-component/src/main/java/org/apache/camel/component/as2/converter/ContentTypeConverter.java
@@ -14,18 +14,25 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.camel.component.as2;
+package org.apache.camel.component.as2.converter;
-import org.apache.camel.component.as2.internal.AS2ApiName;
-import org.apache.camel.component.as2.internal.AS2PropertiesHelper;
-import org.apache.camel.support.component.AbstractApiProducer;
+import org.apache.camel.CamelException;
+import org.apache.camel.Converter;
+import org.apache.http.entity.ContentType;
/**
- * The AS2 producer.
+ * Content type related converters.
*/
-public class AS2Producer extends AbstractApiProducer<AS2ApiName,
AS2Configuration> {
-
- public AS2Producer(AS2Endpoint endpoint) {
- super(endpoint, AS2PropertiesHelper.getHelper());
+@Converter
+public enum ContentTypeConverter {
+ INSTANCE;
+
+ @Converter
+ public static ContentType toContentType(String contentTypeString) throws
CamelException {
+ try {
+ return ContentType.parse(contentTypeString);
+ } catch (Exception e) {
+ throw new CamelException("failed to convert String to
ContentType", e);
+ }
}
}
diff --git
a/components/camel-as2/camel-as2-component/src/main/java/org/apache/camel/component/as2/internal/AS2Constants.java
b/components/camel-as2/camel-as2-component/src/main/java/org/apache/camel/component/as2/internal/AS2Constants.java
index 6edda82..c967ac2 100644
---
a/components/camel-as2/camel-as2-component/src/main/java/org/apache/camel/component/as2/internal/AS2Constants.java
+++
b/components/camel-as2/camel-as2-component/src/main/java/org/apache/camel/component/as2/internal/AS2Constants.java
@@ -26,4 +26,7 @@ public interface AS2Constants {
// thread profile name for this component
String THREAD_PROFILE_NAME = "CamelAS2";
+
+ // header property containing the AS2 Interchange.
+ String AS2_INTERCHANGE = PROPERTY_PREFIX + "interchange";
}
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 a0638a7..70180f5 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
@@ -29,7 +29,6 @@ import java.util.Map;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
-import
org.apache.camel.component.as2.AS2ClientManagerIntegrationTest.RequestHandler;
import org.apache.camel.component.as2.api.AS2AsynchronousMDNManager;
import org.apache.camel.component.as2.api.AS2Charset;
import org.apache.camel.component.as2.api.AS2CompressionAlgorithm;