com.infoengine.soap
Class SOAPAttachmentOutputStream

java.lang.Object
  extended byjava.io.OutputStream
      extended bycom.infoengine.object.IeMultipartOutputStream
          extended bycom.infoengine.soap.SOAPAttachmentOutputStream
All Implemented Interfaces:
javax.activation.DataSource

public class SOAPAttachmentOutputStream
extends IeMultipartOutputStream
implements javax.activation.DataSource

this class is used to catch bytes from SOAP method invocation to be returned to a SOAP client as an attachment. bytes are buffered in memory while waiting to be written to the SOAP MIME stream. if the number of bytes written here exceeds a configurable threshold then the bytes will be temporarily redirected to a file. the threshold can be configured by setting the com.infoengine.soap.attachment.download.threshold System property. the property value must be a valid integer number of bytes. the default threshold is 100K.


Nested Class Summary
(package private)  class SOAPAttachmentOutputStream.TemporaryFileInputStream
          an extension to FileInputStream that deletes the underlying file when the stream is closed.
 
Nested classes inherited from class com.infoengine.object.IeMultipartOutputStream
 
Field Summary
private  int bytesWritten
           
private  String contentType
           
private  InputStream dataSourceInput
           
private static int DEFAULT_THRESHOLD
           
private  String name
           
private  OutputStream os
           
private  File overflowFile
           
private  boolean streamClosed
           
private  int threshold
           
 
Fields inherited from class com.infoengine.object.IeMultipartOutputStream
boundary, contentLength, encoding, eof, forceEncoding, out
 
Constructor Summary
SOAPAttachmentOutputStream()
          create a SOAPAttachmentOutputStream that is used to catch bytes destined to be a SOAP attachment sent to a SOAP client
 
Method Summary
 void close()
          close the underlying stream
 boolean eofWritten()
          return the flag that determines if the eof was written
 void flush()
          flush the underlying stream
 String getContentType()
          get the content-type associated with this DataSource
 javax.activation.DataSource getDataSource()
          get a javax.activation.DataSource implementation if there is some data to be supplied
 InputStream getInputStream()
          get a stream that can be used to read the data from this DataSource.
 String getName()
          get the name associated with this DataSource
 OutputStream getOutputStream()
          this DataSource implementation does not support writing to writing only via exposed OutputStream methods
protected  void initialize(String contentType, int contentLength, String boundary)
           
protected  void initialize(String contentType, String boundary)
           
 void print(String data)
          Prints a string to the output stream.
 void println(String data)
          Prints a string to the output stream with a CR/LF sequence appended.
 void setCharacterSet(String encoding)
          since this class is only concerned with binary data this method is a no-op
 void setForceEncoding(String encoding)
          since this class is only concerned with binary data this method is a no-op
private  void startOverFlow()
          when the number of bytes written to this stream exceeds the configured threshold this method will be called to begin writing the data to file to avoid memory related issues.
 void write(byte[] b)
          write an array of bytes to the underlying stream has same effect as write ( b, 0, b.length )
 void write(byte[] b, int off, int len)
          write an array of bytes or a subset of an aray of bytes to the underlying stream
 void write(int b)
          write a single byte to the underlying stream
 void write(String name, String filename, String contentType)
          set the name, filename and contentType associated with this multipart stream
 void write(String data, String name, String filename, String contentType)
          Writes one content object of a MIME multipart object to the output stream.
 void writeBlob(InputStream content, String name, String filename, String contentType)
          write the data on content with the associated MIME info
 void writeBlob(InputStream content, String name, String filename, String contentType, boolean flag)
          Writes one content object of a MIME multipart object to the output stream.
 void writeEOF()
          write end boundary.
 void writeRequest(IeRequest request)
          Writes an Info*Engine request object to the output stream.
 void writeRequest(IeRequest request, String contentType)
          Writes an Info*Engine request object to the output stream serializing according to contentType.
 void writeRequest(IeRequest request, String contentType, boolean exception)
          Writes an Info*Engine request object to the output stream serializing according to contentType.
 void writeVdb(IeCollection vdb, String contentType)
          Writes an Info*Engine VDB object to the output stream serializing according to contentType.
 void writeVdb(IeCollection vdb, String contentType, boolean exception)
          Writes an Info*Engine VDB object to the output stream serializing according to contentType.
 
Methods inherited from class com.infoengine.object.IeMultipartOutputStream
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_THRESHOLD

private static final int DEFAULT_THRESHOLD
See Also:
Constant Field Values

threshold

private int threshold

bytesWritten

private int bytesWritten

dataSourceInput

private InputStream dataSourceInput

os

private OutputStream os

name

private String name

contentType

private String contentType

overflowFile

private File overflowFile

streamClosed

private boolean streamClosed
Constructor Detail

SOAPAttachmentOutputStream

public SOAPAttachmentOutputStream()
                           throws IOException
create a SOAPAttachmentOutputStream that is used to catch bytes destined to be a SOAP attachment sent to a SOAP client

Method Detail

close

public void close()
           throws IOException
close the underlying stream

Overrides:
close in class IeMultipartOutputStream
Throws:
IOException - if buffered output is not flushed successfully.

eofWritten

public boolean eofWritten()
return the flag that determines if the eof was written

Overrides:
eofWritten in class IeMultipartOutputStream
Returns:
true if end of file written.
See Also:
writeEOF()

flush

public void flush()
           throws IOException
flush the underlying stream

Overrides:
flush in class IeMultipartOutputStream
Throws:
IOException - if buffered output is not flushed successfully.

initialize

protected void initialize(String contentType,
                          String boundary)
Overrides:
initialize in class IeMultipartOutputStream

initialize

protected void initialize(String contentType,
                          int contentLength,
                          String boundary)
Overrides:
initialize in class IeMultipartOutputStream

setCharacterSet

public void setCharacterSet(String encoding)
since this class is only concerned with binary data this method is a no-op

Overrides:
setCharacterSet in class IeMultipartOutputStream
Parameters:
encoding - The character set encoding name.

setForceEncoding

public void setForceEncoding(String encoding)
since this class is only concerned with binary data this method is a no-op

Overrides:
setForceEncoding in class IeMultipartOutputStream
Parameters:
encoding - The character set encoding name.

write

public void write(byte[] b)
           throws IOException
write an array of bytes to the underlying stream has same effect as write ( b, 0, b.length )

Overrides:
write in class IeMultipartOutputStream
Parameters:
b - the bytes to write
Throws:
IOException - if the array is not written successfully.

write

public void write(int b)
           throws IOException
write a single byte to the underlying stream

Overrides:
write in class IeMultipartOutputStream
Parameters:
b - the byte to write
Throws:
IOException - if the segment is not written successfully.

write

public void write(byte[] b,
                  int off,
                  int len)
           throws IOException
write an array of bytes or a subset of an aray of bytes to the underlying stream

Overrides:
write in class IeMultipartOutputStream
Parameters:
b - - the array of bytes to write
off - - the offset into the byte array to start writing at
len - - the number of bytes to write
Throws:
IOException - if the segment is not written successfully.

write

public void write(String name,
                  String filename,
                  String contentType)
set the name, filename and contentType associated with this multipart stream

Overrides:
write in class IeMultipartOutputStream
Parameters:
name - - the MIME part name
filename - - the MIME part filename
contentType - - the MIME part content-type

writeBlob

public void writeBlob(InputStream content,
                      String name,
                      String filename,
                      String contentType)
               throws IOException
write the data on content with the associated MIME info

Overrides:
writeBlob in class IeMultipartOutputStream
Parameters:
content - - the input stream to read the data from
name - - the MIME part name
filename - - the MIME part filename
contentType - - the MIME part content-type
Throws:
IOException - if the content object is not written successfully.

writeBlob

public void writeBlob(InputStream content,
                      String name,
                      String filename,
                      String contentType,
                      boolean flag)
               throws IOException
Description copied from class: IeMultipartOutputStream
Writes one content object of a MIME multipart object to the output stream.

Overrides:
writeBlob in class IeMultipartOutputStream
Parameters:
content - The input stream containing the bytes to be written to the output stream as the content data.
name - The name to be specified in the Content-Disposition header of the content object.
filename - The filename to be specified in the Content-Disposition header of the content object.
contentType - The MIME content type to be specified in the Content-Type header of the content object.
flag - Ignored.
Throws:
IOException - if the content object is not written successfully.
See Also:
writeBlob

writeEOF

public void writeEOF()
write end boundary. since I*E only supports single BLOB download and this stream as a result only cares about one stream of binary data this simply sets a flag to be returned get eofWritten();

Overrides:
writeEOF in class IeMultipartOutputStream
See Also:
eofWritten()

getDataSource

public javax.activation.DataSource getDataSource()
get a javax.activation.DataSource implementation if there is some data to be supplied

Returns:
DataSource

startOverFlow

private void startOverFlow()
                    throws IOException
when the number of bytes written to this stream exceeds the configured threshold this method will be called to begin writing the data to file to avoid memory related issues.

Throws:
IOException

getContentType

public String getContentType()
get the content-type associated with this DataSource

Specified by:
getContentType in interface javax.activation.DataSource
Returns:
content type

getInputStream

public InputStream getInputStream()
                           throws IOException
get a stream that can be used to read the data from this DataSource. will return null if no data was written

Specified by:
getInputStream in interface javax.activation.DataSource
Returns:
InputStream
Throws:
IOException

getName

public String getName()
get the name associated with this DataSource

Specified by:
getName in interface javax.activation.DataSource
Returns:
string name

getOutputStream

public OutputStream getOutputStream()
                             throws IOException
this DataSource implementation does not support writing to writing only via exposed OutputStream methods

Specified by:
getOutputStream in interface javax.activation.DataSource
Throws:
UnsupportedOperationException
IOException

writeRequest

public void writeRequest(IeRequest request)
Description copied from class: IeMultipartOutputStream
Writes an Info*Engine request object to the output stream. will use a default serialization type of application/java-serialized-object

Overrides:
writeRequest in class IeMultipartOutputStream
Parameters:
request - The Info*Engine request object to be written.

writeRequest

public void writeRequest(IeRequest request,
                         String contentType)
Description copied from class: IeMultipartOutputStream
Writes an Info*Engine request object to the output stream serializing according to contentType.

Overrides:
writeRequest in class IeMultipartOutputStream
Parameters:
request - The Info*Engine request object to be written.
contentType - The MIME content type to associate with the request. Currently accepts text/xml or application/java-serialized-object. If null, will use application/java-serialized-object.

writeRequest

public void writeRequest(IeRequest request,
                         String contentType,
                         boolean exception)
Description copied from class: IeMultipartOutputStream
Writes an Info*Engine request object to the output stream serializing according to contentType.

Overrides:
writeRequest in class IeMultipartOutputStream
Parameters:
request - The Info*Engine request object to be written.
contentType - The MIME content type to associate with the request. Currently accepts text/xml or application/java-serialized-object. If null, will use application/java-serialized-object.
exception - States whether this request is the result of an exception or not. If true the MIME part for the request will be named "exception". If false the MIME part will be named "request".

writeVdb

public void writeVdb(IeCollection vdb,
                     String contentType)
Description copied from class: IeMultipartOutputStream
Writes an Info*Engine VDB object to the output stream serializing according to contentType.

Overrides:
writeVdb in class IeMultipartOutputStream
Parameters:
vdb - The Info*Engine VDB object to be written.
contentType - The MIME content type to associate with the request. Currently accepts text/xml or application/java-serialized-object. If null, will use text/xml.

writeVdb

public void writeVdb(IeCollection vdb,
                     String contentType,
                     boolean exception)
Description copied from class: IeMultipartOutputStream
Writes an Info*Engine VDB object to the output stream serializing according to contentType.

Overrides:
writeVdb in class IeMultipartOutputStream
Parameters:
vdb - The Info*Engine VDB object to be written.
contentType - The MIME content type to associate with the request. Currently accepts text/xml or application/java-serialized-object. If null, will use text/xml.
exception - States whether this VDB is the result of an exception or not. If true the MIME part for the VDB will be named "exception". If false the MIME part will be named "object".

print

public void print(String data)
Description copied from class: IeMultipartOutputStream
Prints a string to the output stream.

Overrides:
print in class IeMultipartOutputStream
Parameters:
data - The string to be written.

println

public void println(String data)
Description copied from class: IeMultipartOutputStream
Prints a string to the output stream with a CR/LF sequence appended.

Overrides:
println in class IeMultipartOutputStream
Parameters:
data - The string to be written.

write

public void write(String data,
                  String name,
                  String filename,
                  String contentType)
           throws IOException
Description copied from class: IeMultipartOutputStream
Writes one content object of a MIME multipart object to the output stream.

Overrides:
write in class IeMultipartOutputStream
Parameters:
data - The string to be written to the output stream as the content data.
name - The name to be specified in the Content-Disposition header of the content object.
filename - The filename to be specified in the Content-Disposition header of the content object.
contentType - The MIME content type to be specified in the Content-Type header of the content object.
Throws:
IOException - if the content object is not written successfully.