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 InputStreams.
Author:
bayerlma, Philip Helger
  • Field Details

  • Constructor Details

  • Method Details

    • getResHelper

      @Nonnull public final AS4ResourceHelper getResHelper()
      Returns:
      The resource helper provided in the constructor. Never null.
    • setUniqueID

      public void setUniqueID()
      Create a random UUID based ID and call Attachment.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, use overwriteMimeType(String)
      Overrides:
      setMimeType in class org.apache.wss4j.common.ext.Attachment
    • overwriteMimeType

      public final void overwriteMimeType(@Nullable String sMimeType)
    • addHeader

      public final void addHeader(String sName, String sValue)
      Overrides:
      addHeader in class org.apache.wss4j.common.ext.Attachment
    • getUncompressedMimeType

      @Nullable public String getUncompressedMimeType()
      Specified by:
      getUncompressedMimeType in interface IAS4Attachment
      Returns:
      The MIME type of the uncompressed attachment. May be null. This is only set, if compression was active. Otherwise use IAS4Attachment.getMimeType().
      See Also:
    • getSourceStream

      @Nonnull public InputStream getSourceStream()
      Description copied from interface: IAS4Attachment
      Get the source stream of the attachment using the default resource helper. The streams retrieved by this method are automatically closed when the respective resource helper goes out of scope.
      Specified by:
      getSourceStream in interface IAS4Attachment
      Overrides:
      getSourceStream in class org.apache.wss4j.common.ext.Attachment
      Returns:
      A non-null InputStream on the source.
    • getSourceStream

      @Nonnull public InputStream getSourceStream(@Nonnull AS4ResourceHelper aResourceHelper)
      Description copied from interface: IAS4Attachment
      Get the source stream of the attachment using the provided resource helper, to automatically close the stream at the end of the message. This can be helpful, if the source helper is already out of scope.
      Specified by:
      getSourceStream in interface IAS4Attachment
      Parameters:
      aResourceHelper - The resource helper to use. May not be null.
      Returns:
      A non-null InputStream 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. Use setSourceStreamProvider(IHasInputStream) instead.
      Overrides:
      setSourceStream in class org.apache.wss4j.common.ext.Attachment
    • getInputStreamProvider

      @Nullable public com.helger.commons.io.IHasInputStream getInputStreamProvider()
      Description copied from interface: IAS4Attachment
      This is primarily an internal method. If you use it, you need to make sure to close the streams yourself if you open them.
      Specified by:
      getInputStreamProvider in interface IAS4Attachment
      Returns:
      The internal input stream provider. May be null.
    • setSourceStreamProvider

      public void setSourceStreamProvider(@Nonnull com.helger.commons.io.IHasInputStream aISP)
    • getContentTransferEncoding

      @Nonnull public final com.helger.mail.cte.EContentTransferEncoding getContentTransferEncoding()
      Specified by:
      getContentTransferEncoding in interface IAS4Attachment
      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

      @Nullable public final EAS4CompressionMode getCompressionMode()
      Specified by:
      getCompressionMode in interface IAS4Attachment
      Returns:
      The compression mode to use or null if the attachment is not compressed.
    • setCompressionMode

      @Nonnull public final WSS4JAttachment setCompressionMode(@Nonnull EAS4CompressionMode eCompressionMode)
    • getCharsetOrDefault

      @Nullable public final Charset getCharsetOrDefault(@Nullable Charset aDefault)
      Description copied from interface: IAS4Attachment
      Get the specified character set or the provided default value.
      Specified by:
      getCharsetOrDefault in interface IAS4Attachment
      Parameters:
      aDefault - The default value to be returned, if no character set is provided. May be null.
      Returns:
      Only null if no character set is defined and the provided default value is null.
    • hasCharset

      public final boolean hasCharset()
      Specified by:
      hasCharset in interface IAS4Attachment
      Returns:
      true if a character set is defined, false if not.
    • setCharset

      @Nonnull public final WSS4JAttachment setCharset(@Nullable Charset aCharset)
    • 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:
      customPartProperties in interface IAS4Attachment
      Returns:
      A non-null but maybe empty map of custom PartInfo/PartProperties for the UserMessage.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • 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. If null a random ID is created.
      sFilename - Filename of the attachment. May be null in which case no Content-Disposition header is created.
      aMimeType - Original mime type of the file.
      eCompressionMode - Optional compression mode to use. May be null.
      aCharset - The character set to use. May be null (since 0.14.0)
      aResHelper - The resource manager to use. May not be null.
      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 or null to create a random one. Filename of the attachment. May be null in which case no Content-Disposition header is created.
      sFilename - Optional filename to use in the "Content-Disposition" headers. May be null.
      aMimeType - Original mime type of the file. May not be null.
      eCompressionMode - Optional compression mode to use. May be null.
      aCharset - The character set to use. May be null (since 0.14.0)
      aResHelper - The resource manager to use. May not be null.
      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:
      true if 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.MessagingException
      IOException