Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public AS2ClientManager(AS2ClientConnection as2ClientConnection) {
* @param as2From - AS2 name of sender
* @param as2To - AS2 name of recipient
* @param as2MessageStructure - the structure of AS2 to send; see {@link AS2MessageStructure}
* @param ediMessageContentType - the content typw of EDI message
* @param ediMessageContentType - the content type of EDI message
* @param ediMessageTransferEncoding - the transfer encoding used to transport EDI message
* @param signingAlgorithm - the algorithm used to sign the message or <code>null</code> if sending EDI
* message unsigned
Expand All @@ -188,6 +188,8 @@ public AS2ClientManager(AS2ClientConnection as2ClientConnection) {
* EDI message unencrypted
* @param encryptingCertificateChain - the chain of certificates used to encrypt the message or <code>null</code>
* if sending EDI message unencrypted
* @param attachedFileName - the name of the attached file or <code>null</code> if user doesn't want to
* specify it
* @return {@link HttpCoreContext} containing request and response used to send EDI
* message
* @throws HttpException when things go wrong.
Expand All @@ -209,7 +211,8 @@ public HttpCoreContext send(
String dispositionNotificationTo,
String[] signedReceiptMicAlgorithms,
AS2EncryptionAlgorithm encryptingAlgorithm,
Certificate[] encryptingCertificateChain)
Certificate[] encryptingCertificateChain,
String attachedFileName)
throws HttpException {

Args.notNull(ediMessage, "EDI Message");
Expand Down Expand Up @@ -247,7 +250,8 @@ public HttpCoreContext send(
ApplicationEDIEntity applicationEDIEntity;
try {
applicationEDIEntity
= EntityUtils.createEDIEntity(ediMessage, ediMessageContentType, ediMessageTransferEncoding, false);
= EntityUtils.createEDIEntity(ediMessage, ediMessageContentType, ediMessageTransferEncoding, false,
attachedFileName);
} catch (Exception e) {
throw new HttpException("Failed to create EDI message entity", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
public class ApplicationEDIConsentEntity extends ApplicationEDIEntity {

public ApplicationEDIConsentEntity(String content, String charset, String contentTransferEncoding,
boolean isMainBody) {
super(content, ContentType.create(AS2MediaType.APPLICATION_EDI_CONSENT, charset), contentTransferEncoding, isMainBody);
boolean isMainBody, String fileName) {
super(content, ContentType.create(AS2MediaType.APPLICATION_EDI_CONSENT, charset), contentTransferEncoding, isMainBody,
fileName);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,32 @@
import java.io.OutputStream;

import org.apache.camel.component.as2.api.AS2Charset;
import org.apache.camel.component.as2.api.AS2Header;
import org.apache.camel.component.as2.api.CanonicalOutputStream;
import org.apache.camel.component.as2.api.util.EntityUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.Header;
import org.apache.http.HeaderIterator;
import org.apache.http.entity.ContentType;
import org.apache.http.util.Args;
import org.slf4j.helpers.MessageFormatter;

public abstract class ApplicationEDIEntity extends MimeEntity {

protected static final String CONTENT_DISPOSITION_PATTERN = "attachment; filename={}";

private final String ediMessage;

protected ApplicationEDIEntity(String ediMessage, ContentType contentType, String contentTransferEncoding,
boolean isMainBody) {
boolean isMainBody, String filename) {
this.ediMessage = Args.notNull(ediMessage, "EDI Message");
setContentType(Args.notNull(contentType, "Content Type").toString());
setContentTransferEncoding(contentTransferEncoding);
setMainBody(isMainBody);
if (StringUtils.isNotBlank(filename)) {
addHeader(AS2Header.CONTENT_DISPOSITION,
MessageFormatter.format(CONTENT_DISPOSITION_PATTERN, filename).getMessage());
}
}

public String getEdiMessage() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
public class ApplicationEDIFACTEntity extends ApplicationEDIEntity {

public ApplicationEDIFACTEntity(String content, String charset, String contentTransferEncoding,
boolean isMainBody) {
super(content, ContentType.create(AS2MediaType.APPLICATION_EDIFACT, charset), contentTransferEncoding, isMainBody);
boolean isMainBody, String filename) {
super(content, ContentType.create(AS2MediaType.APPLICATION_EDIFACT, charset), contentTransferEncoding, isMainBody,
filename);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
public class ApplicationEDIX12Entity extends ApplicationEDIEntity {

public ApplicationEDIX12Entity(String content, String charset, String contentTransferEncoding,
boolean isMainBody) {
super(content, ContentType.create(AS2MediaType.APPLICATION_EDI_X12, charset), contentTransferEncoding, isMainBody);
boolean isMainBody, String filename) {
super(content, ContentType.create(AS2MediaType.APPLICATION_EDI_X12, charset), contentTransferEncoding, isMainBody,
filename);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public static MimeEntity parseEntity(byte[] content) throws HttpException {
throw new HttpException("Failed to find Content-Type header in enveloped entity");
}

MimeEntity entity = parseEntityBody(inbuffer, null, entityContentType, entityContentTransferEncoding, headers);
MimeEntity entity = parseEntityBody(inbuffer, null, entityContentType, entityContentTransferEncoding, "", headers);
entity.removeAllHeaders();
entity.setHeaders(headers);

Expand Down Expand Up @@ -379,7 +379,7 @@ private static void parseApplicationEDIEntity(

try {

applicationEDIEntity = parseEDIEntityBody(inBuffer, null, contentType, contentTransferEncoding);
applicationEDIEntity = parseEDIEntityBody(inBuffer, null, contentType, contentTransferEncoding, "");
applicationEDIEntity.setMainBody(true);

EntityUtils.setMessageEntity(message, applicationEDIEntity);
Expand Down Expand Up @@ -540,7 +540,7 @@ public static MultipartSignedEntity parseMultipartSignedEntityBody(
}

MimeEntity signedEntity = parseEntityBody(inbuffer, boundary, signedEntityContentType,
signedEntityContentTransferEncoding, headers);
signedEntityContentTransferEncoding, "", headers);
signedEntity.removeAllHeaders();
signedEntity.setHeaders(headers);
multipartSignedEntity.addPart(signedEntity);
Expand Down Expand Up @@ -786,6 +786,7 @@ public static MimeEntity parseEntityBody(
String boundary,
ContentType entityContentType,
String contentTransferEncoding,
String filename,
Header[] headers)
throws ParseException {
CharsetDecoder previousDecoder = inbuffer.getCharsetDecoder();
Expand All @@ -804,7 +805,7 @@ public static MimeEntity parseEntityBody(
case AS2MimeType.APPLICATION_EDIFACT:
case AS2MimeType.APPLICATION_EDI_X12:
case AS2MimeType.APPLICATION_EDI_CONSENT:
entity = parseEDIEntityBody(inbuffer, boundary, entityContentType, contentTransferEncoding);
entity = parseEDIEntityBody(inbuffer, boundary, entityContentType, contentTransferEncoding, filename);
break;
case AS2MimeType.MULTIPART_SIGNED:
String multipartSignedBoundary = AS2HeaderUtils.getParameterValue(headers,
Expand Down Expand Up @@ -866,7 +867,8 @@ public static ApplicationEDIEntity parseEDIEntityBody(
AS2SessionInputBuffer inbuffer,
String boundary,
ContentType ediMessageContentType,
String contentTransferEncoding)
String contentTransferEncoding,
String filename)
throws ParseException {
CharsetDecoder previousDecoder = inbuffer.getCharsetDecoder();

Expand All @@ -884,7 +886,7 @@ public static ApplicationEDIEntity parseEDIEntityBody(
ediMessageBodyPartContent = EntityUtils.decode(ediMessageBodyPartContent, charset, contentTransferEncoding);
}
ApplicationEDIEntity applicationEDIEntity = EntityUtils.createEDIEntity(ediMessageBodyPartContent,
ediMessageContentType, contentTransferEncoding, false);
ediMessageContentType, contentTransferEncoding, false, filename);

return applicationEDIEntity;
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ public static InputStream decode(InputStream is, String encoding) throws CamelEx
}

public static ApplicationEDIEntity createEDIEntity(
String ediMessage, ContentType ediMessageContentType, String contentTransferEncoding, boolean isMainBody)
String ediMessage, ContentType ediMessageContentType, String contentTransferEncoding, boolean isMainBody,
String filename)
throws CamelException {
Args.notNull(ediMessage, "EDI Message");
Args.notNull(ediMessageContentType, "EDI Message Content Type");
Expand All @@ -196,11 +197,11 @@ public static ApplicationEDIEntity createEDIEntity(
}
switch (ediMessageContentType.getMimeType().toLowerCase()) {
case AS2MediaType.APPLICATION_EDIFACT:
return new ApplicationEDIFACTEntity(ediMessage, charset, contentTransferEncoding, isMainBody);
return new ApplicationEDIFACTEntity(ediMessage, charset, contentTransferEncoding, isMainBody, filename);
case AS2MediaType.APPLICATION_EDI_X12:
return new ApplicationEDIX12Entity(ediMessage, charset, contentTransferEncoding, isMainBody);
return new ApplicationEDIX12Entity(ediMessage, charset, contentTransferEncoding, isMainBody, filename);
case AS2MediaType.APPLICATION_EDI_CONSENT:
return new ApplicationEDIConsentEntity(ediMessage, charset, contentTransferEncoding, isMainBody);
return new ApplicationEDIConsentEntity(ediMessage, charset, contentTransferEncoding, isMainBody, filename);
default:
throw new CamelException("Invalid EDI entity mime type: " + ediMessageContentType.getMimeType());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@
import java.security.Security;
import java.security.cert.Certificate;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;

import org.apache.camel.component.as2.api.entity.AS2DispositionModifier;
import org.apache.camel.component.as2.api.entity.AS2DispositionType;
Expand Down Expand Up @@ -251,7 +248,8 @@ public void plainEDIMessageTest() throws Exception {

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, null, null, DISPOSITION_NOTIFICATION_TO, SIGNED_RECEIPT_MIC_ALGORITHMS, null, null);
null, null, null, null, null, DISPOSITION_NOTIFICATION_TO, SIGNED_RECEIPT_MIC_ALGORITHMS, null, null,
"file.txt");

HttpRequest request = httpContext.getRequest();
assertEquals(METHOD, request.getRequestLine().getMethod(), "Unexpected method value");
Expand Down Expand Up @@ -293,7 +291,7 @@ public void multipartSignedMessageTest() throws Exception {
HttpCoreContext httpContext = clientManager.send(EDI_MESSAGE, REQUEST_URI, SUBJECT, FROM, AS2_NAME, AS2_NAME,
AS2MessageStructure.SIGNED, ContentType.create(AS2MediaType.APPLICATION_EDIFACT, AS2Charset.US_ASCII),
null, AS2SignatureAlgorithm.SHA256WITHRSA, certList.toArray(new Certificate[0]), signingKP.getPrivate(),
null, DISPOSITION_NOTIFICATION_TO, SIGNED_RECEIPT_MIC_ALGORITHMS, null, null);
null, DISPOSITION_NOTIFICATION_TO, SIGNED_RECEIPT_MIC_ALGORITHMS, null, null, "file.txt");

HttpRequest request = httpContext.getRequest();
assertEquals(METHOD, request.getRequestLine().getMethod(), "Unexpected method value");
Expand Down Expand Up @@ -451,7 +449,7 @@ public void envelopedMessageTest(AS2EncryptionAlgorithm encryptionAlgorithm) thr
ContentType.create(AS2MediaType.APPLICATION_EDIFACT, AS2Charset.US_ASCII), null,
AS2SignatureAlgorithm.SHA256WITHRSA, certList.toArray(new Certificate[0]), signingKP.getPrivate(), null,
DISPOSITION_NOTIFICATION_TO, SIGNED_RECEIPT_MIC_ALGORITHMS, encryptionAlgorithm,
certList.toArray(new Certificate[0]));
certList.toArray(new Certificate[0]), "file.txt");

HttpRequest request = httpContext.getRequest();
assertEquals(METHOD, request.getRequestLine().getMethod(), "Unexpected method value");
Expand Down Expand Up @@ -509,7 +507,7 @@ public void envelopedAndSignedMessageTest(AS2EncryptionAlgorithm encryptionAlgor
ContentType.create(AS2MediaType.APPLICATION_EDIFACT, AS2Charset.US_ASCII), null,
AS2SignatureAlgorithm.SHA256WITHRSA, certList.toArray(new Certificate[0]), signingKP.getPrivate(), null,
DISPOSITION_NOTIFICATION_TO, SIGNED_RECEIPT_MIC_ALGORITHMS, encryptionAlgorithm,
certList.toArray(new Certificate[0]));
certList.toArray(new Certificate[0]), "file.txt");

HttpRequest request = httpContext.getRequest();
assertEquals(METHOD, request.getRequestLine().getMethod(), "Unexpected method value");
Expand Down Expand Up @@ -575,7 +573,7 @@ public void signatureVerificationTest() throws Exception {
HttpCoreContext httpContext = clientManager.send(EDI_MESSAGE, REQUEST_URI, SUBJECT, FROM, AS2_NAME, AS2_NAME,
AS2MessageStructure.SIGNED, ContentType.create(AS2MediaType.APPLICATION_EDIFACT, AS2Charset.US_ASCII),
null, AS2SignatureAlgorithm.SHA256WITHRSA, certList.toArray(new Certificate[0]), signingKP.getPrivate(),
null, DISPOSITION_NOTIFICATION_TO, SIGNED_RECEIPT_MIC_ALGORITHMS, null, null);
null, DISPOSITION_NOTIFICATION_TO, SIGNED_RECEIPT_MIC_ALGORITHMS, null, null, "file.txt");

HttpRequest request = httpContext.getRequest();
assertTrue(request instanceof BasicHttpEntityEnclosingRequest, "Request does not contain entity");
Expand Down Expand Up @@ -604,7 +602,8 @@ public void mdnMessageTest() throws Exception {

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, null, null, DISPOSITION_NOTIFICATION_TO, SIGNED_RECEIPT_MIC_ALGORITHMS, null, null);
null, null, null, null, null, DISPOSITION_NOTIFICATION_TO, SIGNED_RECEIPT_MIC_ALGORITHMS, null, null,
"file.txt");

HttpResponse response = httpContext.getResponse();
assertEquals(HttpVersion.HTTP_1_1, response.getStatusLine().getProtocolVersion(), "Unexpected method value");
Expand Down Expand Up @@ -646,7 +645,7 @@ public void asynchronousMdnMessageTest() throws Exception {

// Create plain edi request message to acknowledge
ApplicationEDIEntity ediEntity = EntityUtils.createEDIEntity(EDI_MESSAGE,
ContentType.create(AS2MediaType.APPLICATION_EDIFACT, AS2Charset.US_ASCII), null, false);
ContentType.create(AS2MediaType.APPLICATION_EDIFACT, AS2Charset.US_ASCII), null, false, "filename.txt");
HttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST", REQUEST_URI);
HttpMessageUtils.setHeaderValue(request, AS2Header.SUBJECT, SUBJECT);
String httpdate = DATE_GENERATOR.getCurrentDate();
Expand Down Expand Up @@ -681,6 +680,7 @@ public void asynchronousMdnMessageTest() throws Exception {
// Send MDN
HttpCoreContext httpContext = mdnManager.send(mdn, RECIPIENT_DELIVERY_ADDRESS);
HttpRequest mndRequest = httpContext.getRequest();
Arrays.stream(request.getHeaders(AS2Header.CONTENT_DISPOSITION)).forEach(System.out::println);
DispositionNotificationMultipartReportEntity reportEntity
= HttpMessageUtils.getEntity(mndRequest, DispositionNotificationMultipartReportEntity.class);
assertNotNull(reportEntity, "Request does not contain resport");
Expand Down Expand Up @@ -721,7 +721,7 @@ public void compressedMessageTest() throws Exception {
ContentType.create(AS2MediaType.APPLICATION_EDIFACT, AS2Charset.US_ASCII), null,
null, null, null, AS2CompressionAlgorithm.ZLIB,
DISPOSITION_NOTIFICATION_TO, SIGNED_RECEIPT_MIC_ALGORITHMS, null,
null);
null, "file.txt");

HttpRequest request = httpContext.getRequest();
assertEquals(METHOD, request.getRequestLine().getMethod(), "Unexpected method value");
Expand Down Expand Up @@ -775,7 +775,7 @@ public void compressedAndSignedMessageTest() throws Exception {
AS2SignatureAlgorithm.SHA256WITHRSA, certList.toArray(new Certificate[0]), signingKP.getPrivate(),
AS2CompressionAlgorithm.ZLIB,
DISPOSITION_NOTIFICATION_TO, SIGNED_RECEIPT_MIC_ALGORITHMS, null,
null);
null, "file.txt");

HttpRequest request = httpContext.getRequest();
assertEquals(METHOD, request.getRequestLine().getMethod(), "Unexpected method value");
Expand Down Expand Up @@ -842,7 +842,7 @@ public void envelopedAndCompressedMessageTest() throws Exception {
AS2MessageStructure.ENCRYPTED_COMPRESSED,
ContentType.create(AS2MediaType.APPLICATION_EDIFACT, AS2Charset.US_ASCII), "base64", null, null, null,
AS2CompressionAlgorithm.ZLIB, DISPOSITION_NOTIFICATION_TO, SIGNED_RECEIPT_MIC_ALGORITHMS,
AS2EncryptionAlgorithm.AES128_CBC, certList.toArray(new Certificate[0]));
AS2EncryptionAlgorithm.AES128_CBC, certList.toArray(new Certificate[0]), "file.txt");

HttpRequest request = httpContext.getRequest();
assertEquals(METHOD, request.getRequestLine().getMethod(), "Unexpected method value");
Expand Down Expand Up @@ -905,7 +905,7 @@ public void envelopedCompressedAndSignedMessageTest() throws Exception {
ContentType.create(AS2MediaType.APPLICATION_EDIFACT, AS2Charset.US_ASCII), null,
AS2SignatureAlgorithm.SHA256WITHRSA, certList.toArray(new Certificate[0]), signingKP.getPrivate(),
AS2CompressionAlgorithm.ZLIB, DISPOSITION_NOTIFICATION_TO, SIGNED_RECEIPT_MIC_ALGORITHMS,
AS2EncryptionAlgorithm.AES128_CBC, certList.toArray(new Certificate[0]));
AS2EncryptionAlgorithm.AES128_CBC, certList.toArray(new Certificate[0]), "file.txt");

HttpRequest request = httpContext.getRequest();
assertEquals(METHOD, request.getRequestLine().getMethod(), "Unexpected method value");
Expand Down
Loading