You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by dm...@apache.org on 2018/06/06 21:36:33 UTC
[camel] 01/03: [CAMEL-11257] Updated api for sending asynchronous
MDNs
This is an automated email from the ASF dual-hosted git repository.
dmvolod pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 0b072eb06bdaa8081b0a287768b8ed9b65366e9c
Author: William Collins <pu...@gmail.com>
AuthorDate: Wed Jun 6 12:57:24 2018 -0400
[CAMEL-11257] Updated api for sending asynchronous MDNs
---
.../as2/api/AS2AsynchronousMDNManager.java | 88 +++++------
.../as2/api/protocol/RequestAsynchronousMDN.java | 27 ----
.../camel/component/as2/api/AS2MessageTest.java | 164 ++++++++++++---------
3 files changed, 136 insertions(+), 143 deletions(-)
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 4318af4..6c9f2e7 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 @@ package org.apache.camel.component.as2.api;
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.HttpException;
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.RequestDate;
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 {
@@ -74,37 +78,6 @@ public class AS2AsynchronousMDNManager {
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.
*/
public static final String RECIPIENT_ADDRESS = CAMEL_AS2_ASYNC_MDN_PREFIX + "recipient-address";
@@ -130,38 +103,37 @@ public class AS2AsynchronousMDNManager {
.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 @@ public class AS2AsynchronousMDNManager {
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 1b599ca..c427628 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 java.io.IOException;
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 class RequestAsynchronousMDN implements HttpRequestInterceptor {
/* 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 533018f..61461d1 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
@@ -54,7 +54,6 @@ import org.apache.http.entity.ContentType;
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;
@@ -115,6 +114,7 @@ public class AS2MessageTest {
private static final Logger LOG = LoggerFactory.getLogger(AS2MessageTest.class);
private static final String METHOD = "POST";
+ private static final String RECIPIENT_DELIVERY_ADDRESS = "http://localhost:8080/handle-receipts";
private static final String TARGET_HOST = "localhost";
private static final int TARGET_PORT = 8080;
private static final String AS2_VERSION = "1.1";
@@ -131,7 +131,7 @@ public class AS2MessageTest {
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 +147,20 @@ public class AS2MessageTest {
//
// 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, E=punkhornsw@gmail.com, 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 +176,28 @@ public class AS2MessageTest {
//
// 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, E=punkhornsw@gmail.com, 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 +214,6 @@ public class AS2MessageTest {
});
}
-
@AfterClass
public static void tearDownOnce() throws Exception {
testServer.close();
@@ -241,7 +236,8 @@ public class AS2MessageTest {
// 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 +262,8 @@ public class AS2MessageTest {
@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 +273,40 @@ public class AS2MessageTest {
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 +317,55 @@ public class AS2MessageTest {
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 +375,10 @@ public class AS2MessageTest {
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 +393,44 @@ public class AS2MessageTest {
@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 +441,65 @@ public class AS2MessageTest {
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));
}
-
+
}
--
To stop receiving notification emails like this one, please contact
dmvolod@apache.org.