Package com.helger.phase4.attachment
Class WSS4JAttachment
java.lang.Object
org.apache.wss4j.common.ext.Attachment
com.helger.phase4.attachment.WSS4JAttachment
- All Implemented Interfaces:
IAS4Attachment
@NotThreadSafe
public class WSS4JAttachment
extends org.apache.wss4j.common.ext.Attachment
implements IAS4Attachment
Special WSS4J attachment with an InputStream provider instead of a fixed
InputStream
Note: cannot be serializable because base class is not serializable and because we're dealing with
Note: cannot be serializable because base class is not serializable and because we're dealing with
InputStreams.- Author:
- bayerlma, Philip Helger
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal voidvoidaddToMimeMultipart(jakarta.mail.internet.MimeMultipart aMimeMultipart) static booleancanBeKeptInMemory(long nBytes) Check if an incoming attachment can be kept in memory, or if a temporary file is needed.static WSS4JAttachmentcreateIncomingFileAttachment(jakarta.mail.internet.MimeBodyPart aBodyPart, AS4ResourceHelper aResHelper) static WSS4JAttachmentcreateOutgoingFileAttachment(byte[] aSrcData, String sContentID, String sFilename, com.helger.commons.mime.IMimeType aMimeType, EAS4CompressionMode eCompressionMode, Charset aCharset, AS4ResourceHelper aResHelper) Quasi constructor.static WSS4JAttachmentcreateOutgoingFileAttachment(AS4OutgoingAttachment aAttachment, AS4ResourceHelper aResHelper) static WSS4JAttachmentcreateOutgoingFileAttachment(File aSrcFile, String sContentID, String sFilename, com.helger.commons.mime.IMimeType aMimeType, EAS4CompressionMode eCompressionMode, Charset aCharset, AS4ResourceHelper aResHelper) Quasi constructor.final CharsetgetCharsetOrDefault(Charset aDefault) Get the specified character set or the provided default value.final EAS4CompressionModefinal com.helger.mail.cte.EContentTransferEncodingcom.helger.commons.io.IHasInputStreamfinal AS4ResourceHelperGet the source stream of the attachment using the default resource helper.getSourceStream(AS4ResourceHelper aResourceHelper) Get the source stream of the attachment using the provided resource helper.final booleanfinal voidoverwriteMimeType(String sMimeType) final WSS4JAttachmentsetCharset(Charset aCharset) final WSS4JAttachmentsetCompressionMode(EAS4CompressionMode eCompressionMode) final WSS4JAttachmentsetContentTransferEncoding(com.helger.mail.cte.EContentTransferEncoding eCTE) final voidsetMimeType(String sMimeType) Deprecated.Do not use this.voidsetSourceStream(InputStream sourceStream) Deprecated.Do not use this, because it can be opened only once.voidsetSourceStreamProvider(com.helger.commons.io.IHasInputStream aISP) voidCreate a random UUID based ID and callAttachment.setId(String)toString()Methods inherited from class org.apache.wss4j.common.ext.Attachment
addHeaders, getHeaders, getId, getMimeType, setIdMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface com.helger.phase4.attachment.IAS4Attachment
getCharset, getId, getMimeType, hasCompressionMode, isRepeatable
-
Field Details
-
CONTENT_DESCRIPTION_ATTACHMENT
- See Also:
-
CONTENT_ID_PREFIX
- See Also:
-
CONTENT_ID_SUFFIX
- See Also:
-
-
Constructor Details
-
WSS4JAttachment
public WSS4JAttachment(@Nonnull @WillNotClose AS4ResourceHelper aResHelper, @Nullable String sMimeType)
-
-
Method Details
-
getResHelper
- Returns:
- The resource helper provided in the constructor. Never
null.
-
setUniqueID
public void setUniqueID()Create a random UUID based ID and callAttachment.setId(String) -
setMimeType
@Deprecated(forRemoval=false) @UnsupportedOperation public final void setMimeType(@Nullable String sMimeType) Deprecated.Do not use this. If you need to use this, useoverwriteMimeType(String)- Overrides:
setMimeTypein classorg.apache.wss4j.common.ext.Attachment
-
overwriteMimeType
-
addHeader
- Overrides:
addHeaderin classorg.apache.wss4j.common.ext.Attachment
-
getUncompressedMimeType
- Specified by:
getUncompressedMimeTypein interfaceIAS4Attachment- Returns:
- The MIME type of the uncompressed attachment. May be
null.
-
getSourceStream
Description copied from interface:IAS4AttachmentGet the source stream of the attachment using the default resource helper.- Specified by:
getSourceStreamin interfaceIAS4Attachment- Overrides:
getSourceStreamin classorg.apache.wss4j.common.ext.Attachment- Returns:
- A non-
nullInputStream on the source.
-
getSourceStream
Description copied from interface:IAS4AttachmentGet the source stream of the attachment using the provided resource helper. This can be helpful, if the source helper is already out of scope.- Specified by:
getSourceStreamin interfaceIAS4Attachment- Parameters:
aResourceHelper- The resource helper to use. May not benull.- Returns:
- A non-
nullInputStream on the source.
-
setSourceStream
@Deprecated(forRemoval=false) @UnsupportedOperation public void setSourceStream(InputStream sourceStream) Deprecated.Do not use this, because it can be opened only once. UsesetSourceStreamProvider(IHasInputStream)instead.- Overrides:
setSourceStreamin classorg.apache.wss4j.common.ext.Attachment
-
getInputStreamProvider
- Specified by:
getInputStreamProviderin interfaceIAS4Attachment
-
setSourceStreamProvider
-
getContentTransferEncoding
- Specified by:
getContentTransferEncodingin interfaceIAS4Attachment- Returns:
- The content transfer encoding to be used. Required for MIME
multipart handling only. May not be
null.
-
setContentTransferEncoding
@Nonnull public final WSS4JAttachment setContentTransferEncoding(@Nonnull com.helger.mail.cte.EContentTransferEncoding eCTE) -
getCompressionMode
- Specified by:
getCompressionModein interfaceIAS4Attachment- Returns:
- The compression mode to use or
nullif the attachment is not compressed.
-
setCompressionMode
@Nonnull public final WSS4JAttachment setCompressionMode(@Nonnull EAS4CompressionMode eCompressionMode) -
getCharsetOrDefault
Description copied from interface:IAS4AttachmentGet the specified character set or the provided default value.- Specified by:
getCharsetOrDefaultin interfaceIAS4Attachment- Parameters:
aDefault- The default value to be returned, if no character set is provided. May benull.- Returns:
- Only
nullif no character set is defined and the provided default value isnull.
-
hasCharset
public final boolean hasCharset()- Specified by:
hasCharsetin interfaceIAS4Attachment- Returns:
trueif a character set is defined,falseif not.
-
setCharset
-
addToMimeMultipart
public void addToMimeMultipart(@Nonnull jakarta.mail.internet.MimeMultipart aMimeMultipart) throws jakarta.mail.MessagingException - Throws:
jakarta.mail.MessagingException
-
customPartProperties
@Nonnull @ReturnsMutableObject public com.helger.commons.collection.impl.ICommonsOrderedMap<String,String> customPartProperties()- Specified by:
customPartPropertiesin interfaceIAS4Attachment- Returns:
- A non-
nullbut maybe empty map of custom PartInfo/PartProperties for the UserMessage.
-
toString
-
createOutgoingFileAttachment
@Nonnull public static WSS4JAttachment createOutgoingFileAttachment(@Nonnull AS4OutgoingAttachment aAttachment, @Nonnull @WillNotClose AS4ResourceHelper aResHelper) throws IOException - Throws:
IOException
-
createOutgoingFileAttachment
@Nonnull public static WSS4JAttachment createOutgoingFileAttachment(@Nonnull File aSrcFile, @Nullable String sContentID, @Nullable String sFilename, @Nonnull com.helger.commons.mime.IMimeType aMimeType, @Nullable EAS4CompressionMode eCompressionMode, @Nullable Charset aCharset, @Nonnull @WillNotClose AS4ResourceHelper aResHelper) throws IOException Quasi constructor. Performs compression internally if necessary.- Parameters:
aSrcFile- Source, uncompressed, unencrypted file.sContentID- Content-ID of the attachment. Ifnulla random ID is created.sFilename- Filename of the attachment. May benullin which case noContent-Dispositionheader is created.aMimeType- Original mime type of the file.eCompressionMode- Optional compression mode to use. May benull.aCharset- The character set to use. May benull(since 0.14.0)aResHelper- The resource manager to use. May not benull.- Returns:
- The newly created attachment instance. Never
null. - Throws:
IOException- In case something goes wrong during compression
-
createOutgoingFileAttachment
@Nonnull public static WSS4JAttachment createOutgoingFileAttachment(@Nonnull byte[] aSrcData, @Nullable String sContentID, @Nullable String sFilename, @Nonnull com.helger.commons.mime.IMimeType aMimeType, @Nullable EAS4CompressionMode eCompressionMode, @Nullable Charset aCharset, @Nonnull AS4ResourceHelper aResHelper) throws IOException Quasi constructor. Performs compression internally.- Parameters:
aSrcData- Source in-memory data, uncompressed, unencrypted.sContentID- Optional content ID ornullto create a random one. Filename of the attachment. May benullin which case noContent-Dispositionheader is created.sFilename- Optional filename to use in the "Content-Disposition" headers. May benull.aMimeType- Original mime type of the file. May not benull.eCompressionMode- Optional compression mode to use. May benull.aCharset- The character set to use. May benull(since 0.14.0)aResHelper- The resource manager to use. May not benull.- Returns:
- The newly created attachment instance. Never
null. - Throws:
IOException- In case something goes wrong during compression
-
canBeKeptInMemory
public static boolean canBeKeptInMemory(long nBytes) Check if an incoming attachment can be kept in memory, or if a temporary file is needed.- Parameters:
nBytes- File size.- Returns:
trueif the size is ≤ than 64 Kilobytes
-
createIncomingFileAttachment
@Nonnull public static WSS4JAttachment createIncomingFileAttachment(@Nonnull jakarta.mail.internet.MimeBodyPart aBodyPart, @Nonnull AS4ResourceHelper aResHelper) throws jakarta.mail.MessagingException, IOException - Throws:
jakarta.mail.MessagingExceptionIOException
-