This is an automated email from the ASF dual-hosted git repository. orpiske pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push: new da0d257 (chores) camel-as2: cleanup exceptions (#5907) da0d257 is described below commit da0d257a983859c25add75047498aa2aa319d7e2 Author: Otavio Rodolfo Piske <orpi...@users.noreply.github.com> AuthorDate: Mon Aug 2 13:30:23 2021 +0200 (chores) camel-as2: cleanup exceptions (#5907) - Use specific exceptions instead of generic ones - Remove unuse exceptions for method signatures --- components/camel-as2/camel-as2-api/pom.xml | 6 +++++ .../ApplicationPkcs7MimeCompressedDataEntity.java | 5 ++-- .../ApplicationPkcs7MimeEnvelopedDataEntity.java | 5 ++-- .../entity/ApplicationPkcs7SignatureEntity.java | 5 ++-- .../camel/component/as2/api/util/EntityUtils.java | 28 ++++++++++++---------- 5 files changed, 27 insertions(+), 22 deletions(-) diff --git a/components/camel-as2/camel-as2-api/pom.xml b/components/camel-as2/camel-as2-api/pom.xml index 82d0810..6ced220 100644 --- a/components/camel-as2/camel-as2-api/pom.xml +++ b/components/camel-as2/camel-as2-api/pom.xml @@ -38,6 +38,12 @@ <dependencies> <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-api</artifactId> + <version>${project.version}</version> + </dependency> + + <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpcore</artifactId> </dependency> diff --git a/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/entity/ApplicationPkcs7MimeCompressedDataEntity.java b/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/entity/ApplicationPkcs7MimeCompressedDataEntity.java index d0e51b0..7f23ff0 100644 --- a/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/entity/ApplicationPkcs7MimeCompressedDataEntity.java +++ b/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/entity/ApplicationPkcs7MimeCompressedDataEntity.java @@ -32,6 +32,7 @@ import org.apache.http.message.BasicNameValuePair; import org.apache.http.util.Args; import org.bouncycastle.cms.CMSCompressedData; import org.bouncycastle.cms.CMSCompressedDataGenerator; +import org.bouncycastle.cms.CMSException; import org.bouncycastle.cms.CMSProcessableByteArray; import org.bouncycastle.cms.CMSTypedData; import org.bouncycastle.operator.InputExpanderProvider; @@ -107,7 +108,7 @@ public class ApplicationPkcs7MimeCompressedDataEntity extends MimeEntity { private byte[] createCompressedData( MimeEntity entity2Encrypt, CMSCompressedDataGenerator compressedDataGenerator, OutputCompressor compressor) - throws Exception { + throws IOException, CMSException { try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) { entity2Encrypt.writeTo(bos); bos.flush(); @@ -115,8 +116,6 @@ public class ApplicationPkcs7MimeCompressedDataEntity extends MimeEntity { CMSTypedData contentData = new CMSProcessableByteArray(bos.toByteArray()); CMSCompressedData compressedData = compressedDataGenerator.generate(contentData, compressor); return compressedData.getEncoded(); - } catch (Exception e) { - throw new Exception("", e); } } diff --git a/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/entity/ApplicationPkcs7MimeEnvelopedDataEntity.java b/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/entity/ApplicationPkcs7MimeEnvelopedDataEntity.java index 1bad698..b76b7b0 100644 --- a/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/entity/ApplicationPkcs7MimeEnvelopedDataEntity.java +++ b/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/entity/ApplicationPkcs7MimeEnvelopedDataEntity.java @@ -33,6 +33,7 @@ import org.apache.http.message.BasicNameValuePair; import org.apache.http.util.Args; import org.bouncycastle.cms.CMSEnvelopedData; import org.bouncycastle.cms.CMSEnvelopedDataGenerator; +import org.bouncycastle.cms.CMSException; import org.bouncycastle.cms.CMSProcessableByteArray; import org.bouncycastle.cms.CMSTypedData; import org.bouncycastle.operator.OutputEncryptor; @@ -107,7 +108,7 @@ public class ApplicationPkcs7MimeEnvelopedDataEntity extends MimeEntity { private byte[] createEncryptedData( MimeEntity entity2Encrypt, CMSEnvelopedDataGenerator envelopedDataGenerator, OutputEncryptor encryptor) - throws Exception { + throws IOException, CMSException { try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) { entity2Encrypt.writeTo(bos); bos.flush(); @@ -115,8 +116,6 @@ public class ApplicationPkcs7MimeEnvelopedDataEntity extends MimeEntity { CMSTypedData contentData = new CMSProcessableByteArray(bos.toByteArray()); CMSEnvelopedData envelopedData = envelopedDataGenerator.generate(contentData, encryptor); return envelopedData.getEncoded(); - } catch (Exception e) { - throw new Exception("", e); } } diff --git a/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/entity/ApplicationPkcs7SignatureEntity.java b/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/entity/ApplicationPkcs7SignatureEntity.java index 22ca710..9047239 100644 --- a/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/entity/ApplicationPkcs7SignatureEntity.java +++ b/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/entity/ApplicationPkcs7SignatureEntity.java @@ -30,6 +30,7 @@ import org.apache.http.HeaderIterator; import org.apache.http.HttpException; import org.apache.http.entity.ContentType; import org.apache.http.util.Args; +import org.bouncycastle.cms.CMSException; import org.bouncycastle.cms.CMSProcessableByteArray; import org.bouncycastle.cms.CMSSignedData; import org.bouncycastle.cms.CMSSignedDataGenerator; @@ -110,7 +111,7 @@ public class ApplicationPkcs7SignatureEntity extends MimeEntity { } } - private byte[] createSignature(MimeEntity data, CMSSignedDataGenerator signer) throws Exception { + private byte[] createSignature(MimeEntity data, CMSSignedDataGenerator signer) throws IOException, CMSException { try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) { data.writeTo(bos); bos.flush(); @@ -118,8 +119,6 @@ public class ApplicationPkcs7SignatureEntity extends MimeEntity { CMSTypedData contentData = new CMSProcessableByteArray(bos.toByteArray()); CMSSignedData signedData = signer.generate(contentData, false); return signedData.getEncoded(); - } catch (Exception e) { - throw new Exception("", e); } } diff --git a/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/util/EntityUtils.java b/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/util/EntityUtils.java index a077633..b754e8c 100644 --- a/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/util/EntityUtils.java +++ b/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/util/EntityUtils.java @@ -25,6 +25,7 @@ import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.util.concurrent.atomic.AtomicLong; +import org.apache.camel.CamelException; import org.apache.camel.component.as2.api.AS2Header; import org.apache.camel.component.as2.api.AS2MediaType; import org.apache.camel.component.as2.api.entity.ApplicationEDIConsentEntity; @@ -32,6 +33,7 @@ import org.apache.camel.component.as2.api.entity.ApplicationEDIEntity; import org.apache.camel.component.as2.api.entity.ApplicationEDIFACTEntity; import org.apache.camel.component.as2.api.entity.ApplicationEDIX12Entity; import org.apache.camel.component.as2.api.entity.MimeEntity; +import org.apache.commons.codec.DecoderException; import org.apache.commons.codec.binary.Base64InputStream; import org.apache.commons.codec.binary.Base64OutputStream; import org.apache.commons.codec.net.QuotedPrintableCodec; @@ -81,12 +83,12 @@ public final class EntityUtils { return headerString + "; " + parameterName + "=" + parameterValue; } - public static String encode(String data, Charset charset, String encoding) throws Exception { + public static String encode(String data, Charset charset, String encoding) throws CamelException { byte[] encoded = encode(data.getBytes(charset), encoding); return new String(encoded, charset); } - public static byte[] encode(byte[] data, String encoding) throws Exception { + public static byte[] encode(byte[] data, String encoding) throws CamelException { Args.notNull(data, "Data"); if (encoding == null) { @@ -106,11 +108,11 @@ public final class EntityUtils { // Identity encoding return data; default: - throw new Exception("Unknown encoding: " + encoding); + throw new CamelException("Unknown encoding: " + encoding); } } - public static OutputStream encode(OutputStream os, String encoding) throws Exception { + public static OutputStream encode(OutputStream os, String encoding) throws CamelException { Args.notNull(os, "Output Stream"); if (encoding == null) { @@ -129,16 +131,16 @@ public final class EntityUtils { // Identity encoding return os; default: - throw new Exception("Unknown encoding: " + encoding); + throw new CamelException("Unknown encoding: " + encoding); } } - public static String decode(String data, Charset charset, String encoding) throws Exception { + public static String decode(String data, Charset charset, String encoding) throws CamelException, DecoderException { byte[] decoded = decode(data.getBytes(charset), encoding); return new String(decoded, charset); } - public static byte[] decode(byte[] data, String encoding) throws Exception { + public static byte[] decode(byte[] data, String encoding) throws CamelException, DecoderException { Args.notNull(data, "Data"); if (encoding == null) { @@ -156,11 +158,11 @@ public final class EntityUtils { // Identity encoding return data; default: - throw new Exception("Unknown encoding: " + encoding); + throw new CamelException("Unknown encoding: " + encoding); } } - public static InputStream decode(InputStream is, String encoding) throws Exception { + public static InputStream decode(InputStream is, String encoding) throws CamelException { Args.notNull(is, "Input Stream"); if (encoding == null) { @@ -179,13 +181,13 @@ public final class EntityUtils { // Identity encoding return is; default: - throw new Exception("Unknown encoding: " + encoding); + throw new CamelException("Unknown encoding: " + encoding); } } public static ApplicationEDIEntity createEDIEntity( String ediMessage, ContentType ediMessageContentType, String contentTransferEncoding, boolean isMainBody) - throws Exception { + throws CamelException { Args.notNull(ediMessage, "EDI Message"); Args.notNull(ediMessageContentType, "EDI Message Content Type"); String charset = null; @@ -200,7 +202,7 @@ public final class EntityUtils { case AS2MediaType.APPLICATION_EDI_CONSENT: return new ApplicationEDIConsentEntity(ediMessage, charset, contentTransferEncoding, isMainBody); default: - throw new Exception("Invalid EDI entity mime type: " + ediMessageContentType.getMimeType()); + throw new CamelException("Invalid EDI entity mime type: " + ediMessageContentType.getMimeType()); } } @@ -260,7 +262,7 @@ public final class EntityUtils { String bodyPartContent, ContentType contentType, String bodyPartTransferEncoding) - throws Exception { + throws CamelException, DecoderException { Args.notNull(bodyPartContent, "bodyPartContent"); Charset contentCharset = contentType.getCharset(); if (contentCharset == null) {