[
https://issues.apache.org/jira/browse/CAMEL-11257?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16504737#comment-16504737
]
ASF GitHub Bot commented on CAMEL-11257:
----------------------------------------
punkhorn closed pull request #2364: [CAMEL-11257] Updated api for sending
asynchronous MDNs
URL: https://github.com/apache/camel/pull/2364
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/AS2AsynchronousMDNManager.java
b/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/AS2AsynchronousMDNManager.java
index 4318af4d127..6c9f2e7667c 100644
---
a/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/AS2AsynchronousMDNManager.java
+++
b/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/AS2AsynchronousMDNManager.java
@@ -18,6 +18,8 @@
import java.io.IOException;
import java.net.Socket;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.security.PrivateKey;
import java.security.cert.Certificate;
@@ -30,6 +32,7 @@
import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
+import org.apache.http.client.utils.URIBuilder;
import org.apache.http.impl.DefaultBHttpClientConnection;
import org.apache.http.message.BasicHttpEntityEnclosingRequest;
import org.apache.http.protocol.HttpCoreContext;
@@ -42,6 +45,7 @@
import org.apache.http.protocol.RequestExpectContinue;
import org.apache.http.protocol.RequestTargetHost;
import org.apache.http.protocol.RequestUserAgent;
+import org.apache.http.util.Args;
public class AS2AsynchronousMDNManager {
@@ -73,37 +77,6 @@
*/
public static final String AS2_CONNECTION = CAMEL_AS2_ASYNC_MDN_PREFIX +
"as2-connection";
- /**
- * The HTTP Context Attribute indicating the target host MDN sent to.
- */
- public static final String TARGET_HOST = CAMEL_AS2_ASYNC_MDN_PREFIX +
"target-host";
-
- /**
- * The HTTP Context Attribute indicating the target port MDN sent to.
- */
- public static final String TARGET_PORT = CAMEL_AS2_ASYNC_MDN_PREFIX +
"target-port";
-
- /**
- * The HTTP Context Attribute containing the subject header sent in MDN.
- */
- public static final String SUBJECT = CAMEL_AS2_ASYNC_MDN_PREFIX +
"subject";
-
- /**
- * The HTTP Context Attribute containing the internet e-mail address of
this
- * responding system
- */
- public static final String FROM = CAMEL_AS2_ASYNC_MDN_PREFIX + "from";
-
- /**
- * The HTTP Context Attribute indicating the AS2 name of MDN recipient.
- */
- public static final String AS2_TO = CAMEL_AS2_ASYNC_MDN_PREFIX + "as2-to";
-
- /**
- * The HTTP Context Attribute indicating the AS2 name of MDN sender.
- */
- public static final String AS2_FROM = CAMEL_AS2_ASYNC_MDN_PREFIX +
"as2-from";
-
/**
* The HTTP Context Attribute indicating the AS2 name of MDN sender.
*/
@@ -130,38 +103,37 @@ public AS2AsynchronousMDNManager(String as2Version,
.build();
}
- public HttpCoreContext send(DispositionNotificationMultipartReportEntity
mdn,
- String targetHostName,
- Integer targetPortNumber,
- String requestUri,
- String subject,
- String from,
- String as2From,
- String as2To)
+ public HttpCoreContext send(DispositionNotificationMultipartReportEntity
mdn,
+ String recipientDeliveryAddress)
throws HttpException {
- if (targetHostName == null || targetHostName.length() == 0) {
- targetHostName = "localhost";
- }
- if (targetPortNumber == null || targetPortNumber < 0) {
- targetPortNumber = 80;
+ Args.notNull(mdn, "mdn");
+ Args.notNull(recipientDeliveryAddress, "recipientDeliveryAddress");
+
+ URI uri = null;
+ try {
+ URIBuilder uriBuilder = new URIBuilder(recipientDeliveryAddress);
+ uri = uriBuilder.build();
+
+ } catch (URISyntaxException e) {
+ throw new HttpException("Invalid recipient delivery address URL",
e);
}
+ String requestUri = buildRequestURI(uri);
+
AS2BHttpClientConnection httpConnection = new
AS2BHttpClientConnection(8 * 1024);
try {
- HttpHost targetHost = new HttpHost(targetHostName,
targetPortNumber);
+
+ HttpHost targetHost = new HttpHost(uri.getHost(), uri.getPort(),
uri.getScheme());
// Create socket and bind to connection;
Socket socket = new Socket(targetHost.getHostName(),
targetHost.getPort());
httpConnection.bind(socket);
-
+
// Add Context attributes
HttpCoreContext httpContext = HttpCoreContext.create();
httpContext.setTargetHost(targetHost);
- httpContext.setAttribute(AS2AsynchronousMDNManager.SUBJECT,
subject);
- httpContext.setAttribute(AS2AsynchronousMDNManager.FROM, from);
- httpContext.setAttribute(AS2AsynchronousMDNManager.AS2_FROM,
as2From);
- httpContext.setAttribute(AS2AsynchronousMDNManager.AS2_TO, as2To);
+ httpContext.setAttribute(RECIPIENT_ADDRESS,
recipientDeliveryAddress);
BasicHttpEntityEnclosingRequest request = new
BasicHttpEntityEnclosingRequest("POST", requestUri);
request.setHeader(AS2Header.CONTENT_TYPE,
mdn.getMainMessageContentType());
@@ -202,4 +174,20 @@ private HttpResponse send(DefaultBHttpClientConnection
httpConnection, HttpReque
return response;
}
+
+ private String buildRequestURI(URI uri) {
+ StringBuilder sb = new StringBuilder();
+ if (uri.getPath() != null) {
+ sb.append(uri.getPath());
+ }
+ if (uri.getQuery() != null) {
+ sb.append('?');
+ sb.append(uri.getQuery());
+ }
+ if (uri.getFragment() != null) {
+ sb.append('#');
+ sb.append(uri.getFragment());
+ }
+ return sb.toString();
+ }
}
diff --git
a/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/protocol/RequestAsynchronousMDN.java
b/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/protocol/RequestAsynchronousMDN.java
index 1b599ca6c0e..c4276288675 100644
---
a/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/protocol/RequestAsynchronousMDN.java
+++
b/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/protocol/RequestAsynchronousMDN.java
@@ -21,7 +21,6 @@
import org.apache.camel.component.as2.api.AS2AsynchronousMDNManager;
import org.apache.camel.component.as2.api.AS2Constants;
import org.apache.camel.component.as2.api.AS2Header;
-import org.apache.camel.component.as2.api.InvalidAS2NameException;
import org.apache.camel.component.as2.api.Util;
import org.apache.http.HttpException;
import org.apache.http.HttpRequest;
@@ -47,35 +46,9 @@ public void process(HttpRequest request, HttpContext
context) throws HttpExcepti
/* MIME header */
request.addHeader(AS2Header.MIME_VERSION, AS2Constants.MIME_VERSION);
- /* Subject header */
- String subject =
coreContext.getAttribute(AS2AsynchronousMDNManager.SUBJECT, String.class);
- request.addHeader(AS2Header.SUBJECT, subject);
-
- /* From header */
- String from = coreContext.getAttribute(AS2AsynchronousMDNManager.FROM,
String.class);
- request.addHeader(AS2Header.FROM, from);
-
/* AS2-Version header */
request.addHeader(AS2Header.AS2_VERSION, as2Version);
- /* AS2-From header */
- String as2From =
coreContext.getAttribute(AS2AsynchronousMDNManager.AS2_FROM, String.class);
- try {
- Util.validateAS2Name(as2From);
- } catch (InvalidAS2NameException e) {
- throw new HttpException("Invalid AS-From name", e);
- }
- request.addHeader(AS2Header.AS2_FROM, as2From);
-
- /* AS2-To header */
- String as2To =
coreContext.getAttribute(AS2AsynchronousMDNManager.AS2_TO, String.class);
- try {
- Util.validateAS2Name(as2To);
- } catch (InvalidAS2NameException e) {
- throw new HttpException("Invalid AS-To name", e);
- }
- request.addHeader(AS2Header.AS2_TO, as2To);
-
/* Message-Id header */
// SHOULD be set to aid in message reconciliation
request.addHeader(AS2Header.MESSAGE_ID,
Util.createMessageId(senderFQDN));
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 533018f397f..48f6a4bb3d0 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
@@ -43,6 +43,7 @@
import org.apache.camel.component.as2.api.util.HttpMessageUtils;
import org.apache.camel.component.as2.api.util.MicUtils;
import org.apache.camel.component.as2.api.util.MicUtils.ReceivedContentMic;
+import org.apache.camel.test.AvailablePortFinder;
import org.apache.http.HttpEntity;
import org.apache.http.HttpEntityEnclosingRequest;
import org.apache.http.HttpException;
@@ -54,7 +55,6 @@
import org.apache.http.impl.EnglishReasonPhraseCatalog;
import org.apache.http.message.BasicHttpEntityEnclosingRequest;
import org.apache.http.message.BasicHttpResponse;
-import org.apache.http.protocol.HTTP;
import org.apache.http.protocol.HttpContext;
import org.apache.http.protocol.HttpCoreContext;
import org.apache.http.protocol.HttpDateGenerator;
@@ -116,7 +116,8 @@
private static final String METHOD = "POST";
private static final String TARGET_HOST = "localhost";
- private static final int TARGET_PORT = 8080;
+ private static final int TARGET_PORT =
AvailablePortFinder.getNextAvailable(8080);
+ private static final String RECIPIENT_DELIVERY_ADDRESS =
"http://localhost:" + TARGET_PORT + "/handle-receipts";
private static final String AS2_VERSION = "1.1";
private static final String USER_AGENT = "Camel AS2 Endpoint";
private static final String REQUEST_URI = "/";
@@ -131,7 +132,7 @@
private static final String[] SIGNED_RECEIPT_MIC_ALGORITHMS = new String[]
{"sha1", "md5"};
private static final HttpDateGenerator DATE_GENERATOR = new
HttpDateGenerator();
-
+
private static AS2ServerConnection testServer;
private AS2SignedDataGenerator gen;
@@ -147,22 +148,20 @@ private void setupKeysAndCertificates() throws Exception {
//
// set up our certificates
//
- KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA", "BC");
+ KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA", "BC");
kpg.initialize(1024, new SecureRandom());
String issueDN = "O=Punkhorn Software, C=US";
issueKP = kpg.generateKeyPair();
- issueCert = Utils.makeCertificate(
- issueKP, issueDN, issueKP, issueDN);
+ issueCert = Utils.makeCertificate(issueKP, issueDN, issueKP, issueDN);
//
// certificate we sign against
//
String signingDN = "CN=William J. Collins, [email protected],
O=Punkhorn Software, C=US";
signingKP = kpg.generateKeyPair();
- signingCert = Utils.makeCertificate(
- signingKP, signingDN, issueKP,
issueDN);
+ signingCert = Utils.makeCertificate(signingKP, signingDN, issueKP,
issueDN);
certList = new ArrayList<X509Certificate>();
@@ -178,30 +177,28 @@ public static void setUpOnce() throws Exception {
//
// set up our certificates
//
- KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA", "BC");
+ KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA", "BC");
kpg.initialize(1024, new SecureRandom());
String issueDN = "O=Punkhorn Software, C=US";
KeyPair issueKP = kpg.generateKeyPair();
- X509Certificate issueCert = Utils.makeCertificate(
- issueKP, issueDN, issueKP, issueDN);
+ X509Certificate issueCert = Utils.makeCertificate(issueKP, issueDN,
issueKP, issueDN);
//
// certificate we sign against
//
String signingDN = "CN=William J. Collins, [email protected],
O=Punkhorn Software, C=US";
KeyPair signingKP = kpg.generateKeyPair();
- X509Certificate signingCert = Utils.makeCertificate(
- signingKP, signingDN, issueKP,
issueDN);
+ X509Certificate signingCert = Utils.makeCertificate(signingKP,
signingDN, issueKP, issueDN);
List<X509Certificate> certList = new ArrayList<X509Certificate>();
certList.add(signingCert);
certList.add(issueCert);
-
- testServer = new AS2ServerConnection(AS2_VERSION, "MyServer-HTTP/1.1",
SERVER_FQDN, 8080, certList.toArray(new Certificate[0]),
signingKP.getPrivate());
+ testServer = new AS2ServerConnection(AS2_VERSION, "MyServer-HTTP/1.1",
SERVER_FQDN, 8080,
+ certList.toArray(new Certificate[0]), signingKP.getPrivate());
testServer.listen("*", new HttpRequestHandler() {
@Override
public void handle(HttpRequest request, HttpResponse response,
HttpContext context)
@@ -218,7 +215,6 @@ public void handle(HttpRequest request, HttpResponse
response, HttpContext conte
});
}
-
@AfterClass
public static void tearDownOnce() throws Exception {
testServer.close();
@@ -241,7 +237,8 @@ public void setUp() throws Exception {
// Create signing attributes
ASN1EncodableVector attributes = new ASN1EncodableVector();
- attributes.add(new SMIMEEncryptionKeyPreferenceAttribute(new
IssuerAndSerialNumber(new X500Name(signingCert.getIssuerDN().getName()),
signingCert.getSerialNumber())));
+ attributes.add(new SMIMEEncryptionKeyPreferenceAttribute(new
IssuerAndSerialNumber(
+ new X500Name(signingCert.getIssuerDN().getName()),
signingCert.getSerialNumber())));
attributes.add(new SMIMECapabilitiesAttribute(capabilities));
for (String signingAlgorithmName : AS2SignedDataGenerator
@@ -266,7 +263,8 @@ public void setUp() throws Exception {
@Test
public void plainEDIMessageTest() throws Exception {
- AS2ClientConnection clientConnection = new
AS2ClientConnection(AS2_VERSION, USER_AGENT, CLIENT_FQDN, TARGET_HOST,
TARGET_PORT);
+ AS2ClientConnection clientConnection = new
AS2ClientConnection(AS2_VERSION, USER_AGENT, CLIENT_FQDN,
+ TARGET_HOST, TARGET_PORT);
AS2ClientManager clientManager = new
AS2ClientManager(clientConnection);
HttpCoreContext httpContext = clientManager.send(EDI_MESSAGE,
REQUEST_URI, SUBJECT, FROM, AS2_NAME, AS2_NAME,
@@ -276,32 +274,40 @@ public void plainEDIMessageTest() throws Exception {
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 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 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());
+ 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(AS2MediaType.APPLICATION_EDIFACT));
+ assertTrue("Unexpected content type for message",
+
request.getFirstHeader(AS2Header.CONTENT_TYPE).getValue().startsWith(AS2MediaType.APPLICATION_EDIFACT));
assertTrue("Request does not contain entity", request instanceof
BasicHttpEntityEnclosingRequest);
- HttpEntity entity =
((BasicHttpEntityEnclosingRequest)request).getEntity();
+ HttpEntity entity = ((BasicHttpEntityEnclosingRequest)
request).getEntity();
assertNotNull("Request does not contain entity", entity);
assertTrue("Unexpected request entity type", entity instanceof
ApplicationEDIFACTEntity);
ApplicationEDIFACTEntity ediEntity = (ApplicationEDIFACTEntity) entity;
- assertTrue("Unexpected content type for entity",
ediEntity.getContentType().getValue().startsWith(AS2MediaType.APPLICATION_EDIFACT));
+ assertTrue("Unexpected content type for entity",
+
ediEntity.getContentType().getValue().startsWith(AS2MediaType.APPLICATION_EDIFACT));
assertTrue("Entity not set as main body of request",
ediEntity.isMainBody());
}
@Test
public void multipartSignedMessageTest() throws Exception {
- AS2ClientConnection clientConnection = new
AS2ClientConnection(AS2_VERSION, USER_AGENT, CLIENT_FQDN, TARGET_HOST,
TARGET_PORT);
+ AS2ClientConnection clientConnection = new
AS2ClientConnection(AS2_VERSION, USER_AGENT, CLIENT_FQDN,
+ TARGET_HOST, TARGET_PORT);
AS2ClientManager clientManager = new
AS2ClientManager(clientConnection);
HttpCoreContext httpContext = clientManager.send(EDI_MESSAGE,
REQUEST_URI, SUBJECT, FROM, AS2_NAME, AS2_NAME,
@@ -312,45 +318,55 @@ public void multipartSignedMessageTest() throws Exception
{
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 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 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());
+ 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(AS2MediaType.MULTIPART_SIGNED));
+ assertTrue("Unexpected content type for message",
+
request.getFirstHeader(AS2Header.CONTENT_TYPE).getValue().startsWith(AS2MediaType.MULTIPART_SIGNED));
assertTrue("Request does not contain entity", request instanceof
BasicHttpEntityEnclosingRequest);
- HttpEntity entity =
((BasicHttpEntityEnclosingRequest)request).getEntity();
+ HttpEntity entity = ((BasicHttpEntityEnclosingRequest)
request).getEntity();
assertNotNull("Request does not contain entity", entity);
assertTrue("Unexpected request entity type", entity instanceof
MultipartSignedEntity);
- MultipartSignedEntity signedEntity = (MultipartSignedEntity)entity;
+ MultipartSignedEntity signedEntity = (MultipartSignedEntity) entity;
assertTrue("Entity not set as main body of request",
signedEntity.isMainBody());
assertTrue("Request contains invalid number of mime parts",
signedEntity.getPartCount() == 2);
// Validated first mime part.
assertTrue("First mime part incorrect type ", signedEntity.getPart(0)
instanceof ApplicationEDIFACTEntity);
ApplicationEDIFACTEntity ediEntity = (ApplicationEDIFACTEntity)
signedEntity.getPart(0);
- assertTrue("Unexpected content type for first mime part",
ediEntity.getContentType().getValue().startsWith(AS2MediaType.APPLICATION_EDIFACT));
+ 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 ", signedEntity.getPart(1)
instanceof ApplicationPkcs7SignatureEntity);
+ assertTrue("Second mime part incorrect type ",
+ signedEntity.getPart(1) instanceof
ApplicationPkcs7SignatureEntity);
ApplicationPkcs7SignatureEntity signatureEntity =
(ApplicationPkcs7SignatureEntity) signedEntity.getPart(1);
- assertTrue("Unexpected content type for second mime part",
signatureEntity.getContentType().getValue().startsWith(AS2MediaType.APPLICATION_PKCS7_SIGNATURE));
+ 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());
}
@Test
public void signatureVerificationTest() throws Exception {
- AS2ClientConnection clientConnection = new
AS2ClientConnection(AS2_VERSION, USER_AGENT, CLIENT_FQDN, TARGET_HOST,
TARGET_PORT);
+ AS2ClientConnection clientConnection = new
AS2ClientConnection(AS2_VERSION, USER_AGENT, CLIENT_FQDN,
+ TARGET_HOST, TARGET_PORT);
AS2ClientManager clientManager = new
AS2ClientManager(clientConnection);
HttpCoreContext httpContext = clientManager.send(EDI_MESSAGE,
REQUEST_URI, SUBJECT, FROM, AS2_NAME, AS2_NAME,
@@ -360,10 +376,10 @@ public void signatureVerificationTest() throws Exception {
HttpRequest request = httpContext.getRequest();
assertTrue("Request does not contain entity", request instanceof
BasicHttpEntityEnclosingRequest);
- HttpEntity entity =
((BasicHttpEntityEnclosingRequest)request).getEntity();
+ HttpEntity entity = ((BasicHttpEntityEnclosingRequest)
request).getEntity();
assertNotNull("Request does not contain entity", entity);
assertTrue("Unexpected request entity type", entity instanceof
MultipartSignedEntity);
- MultipartSignedEntity multipartSignedEntity =
(MultipartSignedEntity)entity;
+ MultipartSignedEntity multipartSignedEntity = (MultipartSignedEntity)
entity;
MimeEntity signedEntity = multipartSignedEntity.getSignedDataEntity();
assertTrue("Signed entity wrong type", signedEntity instanceof
ApplicationEDIEntity);
ApplicationEDIEntity ediMessageEntity = (ApplicationEDIEntity)
signedEntity;
@@ -378,39 +394,44 @@ public void signatureVerificationTest() throws Exception {
@Test
public void mdnMessageTest() throws Exception {
- AS2ClientConnection clientConnection = new
AS2ClientConnection(AS2_VERSION, USER_AGENT, CLIENT_FQDN, TARGET_HOST,
TARGET_PORT);
+ AS2ClientConnection clientConnection = new
AS2ClientConnection(AS2_VERSION, USER_AGENT, CLIENT_FQDN,
+ TARGET_HOST, TARGET_PORT);
AS2ClientManager clientManager = new
AS2ClientManager(clientConnection);
HttpCoreContext httpContext = clientManager.send(EDI_MESSAGE,
REQUEST_URI, SUBJECT, FROM, AS2_NAME, AS2_NAME,
AS2MessageStructure.PLAIN,
ContentType.create(AS2MediaType.APPLICATION_EDIFACT, AS2Charset.US_ASCII),
null, null, null, DISPOSITION_NOTIFICATION_TO,
SIGNED_RECEIPT_MIC_ALGORITHMS);
-
+
HttpResponse response = httpContext.getResponse();
assertEquals("Unexpected method value", HttpVersion.HTTP_1_1,
response.getStatusLine().getProtocolVersion());
assertEquals("Unexpected method value", HttpStatus.SC_OK,
response.getStatusLine().getStatusCode());
- assertEquals("Unexpected method value",
EnglishReasonPhraseCatalog.INSTANCE.getReason(200, null),
response.getStatusLine().getReasonPhrase());
-
+ assertEquals("Unexpected method value",
EnglishReasonPhraseCatalog.INSTANCE.getReason(200, null),
+ response.getStatusLine().getReasonPhrase());
+
HttpEntity responseEntity = response.getEntity();
assertNotNull("Response entity", responseEntity);
assertTrue("Unexpected response entity type", responseEntity
instanceof MultipartSignedEntity);
MultipartSignedEntity responseSignedEntity = (MultipartSignedEntity)
responseEntity;
MimeEntity responseSignedDataEntity =
responseSignedEntity.getSignedDataEntity();
- assertTrue("Signed entity wrong type", responseSignedDataEntity
instanceof DispositionNotificationMultipartReportEntity);
- DispositionNotificationMultipartReportEntity reportEntity =
(DispositionNotificationMultipartReportEntity)responseSignedDataEntity;
+ assertTrue("Signed entity wrong type",
+ responseSignedDataEntity instanceof
DispositionNotificationMultipartReportEntity);
+ DispositionNotificationMultipartReportEntity reportEntity =
(DispositionNotificationMultipartReportEntity) responseSignedDataEntity;
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());
+ 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());
ApplicationPkcs7SignatureEntity signatureEntity =
responseSignedEntity.getSignatureEntity();
assertNotNull("Signature Entity", signatureEntity);
-
+
// Validate Signature
assertTrue("Signature is invalid", responseSignedEntity.isValid());
}
-
+
@Test
public void synchronousMdnMessageTest() throws Exception {
@@ -421,53 +442,65 @@ public void synchronousMdnMessageTest() throws Exception {
ApplicationEDIEntity ediEntity =
EntityUtils.createEDIEntity(EDI_MESSAGE,
ContentType.create(AS2MediaType.APPLICATION_EDIFACT,
AS2Charset.US_ASCII), null, false);
HttpEntityEnclosingRequest request = new
BasicHttpEntityEnclosingRequest("POST", REQUEST_URI);
+ HttpMessageUtils.setHeaderValue(request, AS2Header.SUBJECT, SUBJECT);
+ String httpdate = DATE_GENERATOR.getCurrentDate();
+ HttpMessageUtils.setHeaderValue(request, AS2Header.DATE, httpdate);
HttpMessageUtils.setHeaderValue(request, AS2Header.AS2_TO, AS2_NAME);
+ HttpMessageUtils.setHeaderValue(request, AS2Header.AS2_FROM, AS2_NAME);
String originalMessageId = Util.createMessageId(SERVER_FQDN);
HttpMessageUtils.setHeaderValue(request, AS2Header.MESSAGE_ID,
originalMessageId);
- HttpMessageUtils.setHeaderValue(request,
AS2Header.DISPOSITION_NOTIFICATION_OPTIONS, DISPOSITION_NOTIFICATION_OPTIONS);
+ HttpMessageUtils.setHeaderValue(request,
AS2Header.DISPOSITION_NOTIFICATION_OPTIONS,
+ DISPOSITION_NOTIFICATION_OPTIONS);
EntityUtils.setMessageEntity(request, ediEntity);
// Create response for MDN creation.
HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1,
200, "OK");
- String httpdate = DATE_GENERATOR.getCurrentDate();
- response.setHeader(HTTP.DATE_HEADER, httpdate);
+ httpdate = DATE_GENERATOR.getCurrentDate();
+ response.setHeader(AS2Header.DATE, httpdate);
response.setHeader(AS2Header.SERVER, REPORTING_UA);
// Create a receipt for edi message
Map<String, String> extensionFields = new HashMap<String, String>();
extensionFields.put("Original-Recipient", "rfc822;" + AS2_NAME);
AS2DispositionModifier dispositionModifier =
AS2DispositionModifier.createWarning("AS2 is cool!");
- String[] failureFields = new String[] {"failure-field-1" };
+ String[] failureFields = new String[] {"failure-field-1"};
String[] errorFields = new String[] {"error-field-1"};
String[] warningFields = new String[] {"warning-field-1"};
DispositionNotificationMultipartReportEntity mdn = new
DispositionNotificationMultipartReportEntity(request,
- response,
DispositionMode.AUTOMATIC_ACTION_MDN_SENT_AUTOMATICALLY,
AS2DispositionType.PROCESSED, dispositionModifier,
- failureFields, errorFields, warningFields,
- extensionFields, null, "boundary", true);
+ response,
DispositionMode.AUTOMATIC_ACTION_MDN_SENT_AUTOMATICALLY,
AS2DispositionType.PROCESSED,
+ dispositionModifier, failureFields, errorFields,
warningFields, extensionFields, null, "boundary",
+ true);
// Send MDN
- HttpCoreContext httpContext = mdnManager.send(mdn, TARGET_HOST,
TARGET_PORT, REQUEST_URI, SUBJECT, FROM, AS2_NAME, AS2_NAME);
+ HttpCoreContext httpContext = mdnManager.send(mdn,
RECIPIENT_DELIVERY_ADDRESS);
HttpRequest mndRequest = httpContext.getRequest();
- DispositionNotificationMultipartReportEntity reportEntity =
HttpMessageUtils.getEntity(mndRequest,
DispositionNotificationMultipartReportEntity.class);
+ DispositionNotificationMultipartReportEntity reportEntity =
HttpMessageUtils.getEntity(mndRequest,
+ DispositionNotificationMultipartReportEntity.class);
assertNotNull("Request does not contain resport", reportEntity);
assertEquals("Report entity contains invalid number of parts", 2,
reportEntity.getPartCount());
assertTrue("Report first part is not text entity",
reportEntity.getPart(0) instanceof TextPlainEntity);
- assertTrue("Report second part is not MDN entity",
reportEntity.getPart(1) instanceof AS2MessageDispositionNotificationEntity);
- AS2MessageDispositionNotificationEntity mdnEntity =
(AS2MessageDispositionNotificationEntity) reportEntity.getPart(1);
+ assertTrue("Report second part is not MDN entity",
+ reportEntity.getPart(1) instanceof
AS2MessageDispositionNotificationEntity);
+ AS2MessageDispositionNotificationEntity mdnEntity =
(AS2MessageDispositionNotificationEntity) reportEntity
+ .getPart(1);
assertEquals("Unexpected value for Reporting UA", REPORTING_UA,
mdnEntity.getReportingUA());
assertEquals("Unexpected value for Final Recipient", AS2_NAME,
mdnEntity.getFinalRecipient());
assertEquals("Unexpected value for Original Message ID",
originalMessageId, mdnEntity.getOriginalMessageId());
- assertEquals("Unexpected value for Disposition Mode",
DispositionMode.AUTOMATIC_ACTION_MDN_SENT_AUTOMATICALLY,
mdnEntity.getDispositionMode());
- assertEquals("Unexpected value for Disposition Type",
AS2DispositionType.PROCESSED, mdnEntity.getDispositionType());
- assertEquals("Unexpected value for Disposition Modifier",
dispositionModifier, mdnEntity.getDispositionModifier());
+ assertEquals("Unexpected value for Disposition Mode",
DispositionMode.AUTOMATIC_ACTION_MDN_SENT_AUTOMATICALLY,
+ mdnEntity.getDispositionMode());
+ assertEquals("Unexpected value for Disposition Type",
AS2DispositionType.PROCESSED,
+ mdnEntity.getDispositionType());
+ assertEquals("Unexpected value for Disposition Modifier",
dispositionModifier,
+ mdnEntity.getDispositionModifier());
assertArrayEquals("Unexpected value for Failure Fields",
failureFields, mdnEntity.getFailureFields());
assertArrayEquals("Unexpected value for Error Fields", errorFields,
mdnEntity.getErrorFields());
assertArrayEquals("Unexpected value for Warning Fields",
warningFields, mdnEntity.getWarningFields());
assertEquals("Unexpected value for Extension Fields", extensionFields,
mdnEntity.getExtensionFields());
ReceivedContentMic expectedMic =
MicUtils.createReceivedContentMic(request);
ReceivedContentMic mdnMic = mdnEntity.getReceivedContentMic();
- assertEquals("Unexpected value for Recieved Content Mic",
expectedMic.getEncodedMessageDigest(), mdnMic.getEncodedMessageDigest());
- LOG.debug(Util.printMessage(mndRequest));
+ assertEquals("Unexpected value for Recieved Content Mic",
expectedMic.getEncodedMessageDigest(),
+ mdnMic.getEncodedMessageDigest());
+ LOG.debug("\r\n" + Util.printMessage(mndRequest));
}
-
+
}
----------------------------------------------------------------
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)