org.jboss.netty.handler.codec.http2
Class HttpPostRequestEncoder

java.lang.Object
  extended by org.jboss.netty.handler.codec.http2.HttpPostRequestEncoder
All Implemented Interfaces:
org.jboss.netty.handler.stream.ChunkedInput

public class HttpPostRequestEncoder
extends Object
implements org.jboss.netty.handler.stream.ChunkedInput

This encoder will help to encode Request for a FORM as POST.

Author:
The Netty Project, Andy Taylor (andy.taylor@jboss.org), Trustin Lee, Frederic Bregier

Nested Class Summary
static class HttpPostRequestEncoder.ErrorDataEncoderException
          Exception when an error occurs while encoding
 
Constructor Summary
HttpPostRequestEncoder(HttpDataFactory factory, HttpRequest request, boolean multipart)
           
HttpPostRequestEncoder(HttpDataFactory factory, HttpRequest request, boolean multipart, Charset charset)
           
HttpPostRequestEncoder(HttpRequest request, boolean multipart)
           
 
Method Summary
 void addBodyAttribute(String name, String value)
          Add a simple attribute in the body as Name=Value
 void addBodyFileUpload(String name, File file, String contentType, boolean isText)
          Add a file as a FileUpload
 void addBodyFileUploads(String name, File[] file, String[] contentType, boolean[] isText)
          Add a series of Files associated with one File parameter (implied Mixed mode in Multipart)
 void addBodyHttpData(InterfaceHttpData data)
          Add the InterfaceHttpData to the Body list
 void cleanFiles()
          Clean all HttpDatas (on Disk) for the current request.
 void close()
           
 HttpRequest finalizeRequest()
          Finalize the request by preparing the Header in the request and returns the request ready to be sent.
 List<InterfaceHttpData> getBodyListAttributes()
          This method returns a List of all InterfaceHttpData from body part.
 boolean hasNextChunk()
           
 boolean isChunked()
           
 boolean isEndOfInput()
           
 boolean isMultipart()
          True if this request is a Multipart request
 HttpChunk nextChunk()
          Returns the next available HttpChunk.
 void setBodyHttpDatas(List<InterfaceHttpData> datas)
          Set the Body HttpDatas list
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpPostRequestEncoder

public HttpPostRequestEncoder(HttpRequest request,
                              boolean multipart)
                       throws HttpPostRequestEncoder.ErrorDataEncoderException,
                              NullPointerException
Parameters:
request - the request to encode
multipart - True if the FORM is a ENCTYPE="multipart/form-data"
Throws:
NullPointerException - for request
HttpPostRequestEncoder.ErrorDataEncoderException - if the request is not a POST

HttpPostRequestEncoder

public HttpPostRequestEncoder(HttpDataFactory factory,
                              HttpRequest request,
                              boolean multipart)
                       throws HttpPostRequestEncoder.ErrorDataEncoderException,
                              NullPointerException
Parameters:
factory - the factory used to create InterfaceHttpData
request - the request to encode
multipart - True if the FORM is a ENCTYPE="multipart/form-data"
Throws:
NullPointerException - for request and factory
HttpPostRequestEncoder.ErrorDataEncoderException - if the request is not a POST

HttpPostRequestEncoder

public HttpPostRequestEncoder(HttpDataFactory factory,
                              HttpRequest request,
                              boolean multipart,
                              Charset charset)
                       throws HttpPostRequestEncoder.ErrorDataEncoderException,
                              NullPointerException
Parameters:
factory - the factory used to create InterfaceHttpData
request - the request to encode
multipart - True if the FORM is a ENCTYPE="multipart/form-data"
charset - the charset to use as default
Throws:
NullPointerException - for request or charset or factory
HttpPostRequestEncoder.ErrorDataEncoderException - if the request is not a POST
Method Detail

cleanFiles

public void cleanFiles()
Clean all HttpDatas (on Disk) for the current request.


isMultipart

public boolean isMultipart()
True if this request is a Multipart request

Returns:
True if this request is a Multipart request

getBodyListAttributes

public List<InterfaceHttpData> getBodyListAttributes()
This method returns a List of all InterfaceHttpData from body part.

Returns:
the list of InterfaceHttpData from Body part

setBodyHttpDatas

public void setBodyHttpDatas(List<InterfaceHttpData> datas)
                      throws NullPointerException,
                             HttpPostRequestEncoder.ErrorDataEncoderException
Set the Body HttpDatas list

Parameters:
datas -
Throws:
NullPointerException - for datas
HttpPostRequestEncoder.ErrorDataEncoderException - if the encoding is in error or if the finalize were already done

addBodyAttribute

public void addBodyAttribute(String name,
                             String value)
                      throws NullPointerException,
                             HttpPostRequestEncoder.ErrorDataEncoderException
Add a simple attribute in the body as Name=Value

Parameters:
name - name of the parameter
value - the value of the parameter
Throws:
NullPointerException - for name
HttpPostRequestEncoder.ErrorDataEncoderException - if the encoding is in error or if the finalize were already done

addBodyFileUpload

public void addBodyFileUpload(String name,
                              File file,
                              String contentType,
                              boolean isText)
                       throws NullPointerException,
                              HttpPostRequestEncoder.ErrorDataEncoderException
Add a file as a FileUpload

Parameters:
name - the name of the parameter
file - the file to be uploaded (if not Multipart mode, only the filename will be included)
contentType - the associated contentType for the File
isText - True if this file should be transmitted in Text format (else binary)
Throws:
NullPointerException - for name and file
HttpPostRequestEncoder.ErrorDataEncoderException - if the encoding is in error or if the finalize were already done

addBodyFileUploads

public void addBodyFileUploads(String name,
                               File[] file,
                               String[] contentType,
                               boolean[] isText)
                        throws NullPointerException,
                               HttpPostRequestEncoder.ErrorDataEncoderException
Add a series of Files associated with one File parameter (implied Mixed mode in Multipart)

Parameters:
name - the name of the parameter
file - the array of files
contentType - the array of content Types associated with each file
isText - the array of isText attribute (False meaning binary mode) for each file
Throws:
NullPointerException - also throws if array have different sizes
HttpPostRequestEncoder.ErrorDataEncoderException - if the encoding is in error or if the finalize were already done

addBodyHttpData

public void addBodyHttpData(InterfaceHttpData data)
                     throws NullPointerException,
                            HttpPostRequestEncoder.ErrorDataEncoderException
Add the InterfaceHttpData to the Body list

Parameters:
data -
Throws:
NullPointerException - for data
HttpPostRequestEncoder.ErrorDataEncoderException - if the encoding is in error or if the finalize were already done

finalizeRequest

public HttpRequest finalizeRequest()
                            throws HttpPostRequestEncoder.ErrorDataEncoderException
Finalize the request by preparing the Header in the request and returns the request ready to be sent.
Once finalized, no data must be added.
If the request does not need chunk (isChunked() == false), this request is the only object to send to the remote server.

Returns:
the request object (chunked or not according to size of body)
Throws:
HttpPostRequestEncoder.ErrorDataEncoderException - if the encoding is in error or if the finalize were already done

isChunked

public boolean isChunked()
Returns:
True if the request is by Chunk

close

public void close()
           throws Exception
Specified by:
close in interface org.jboss.netty.handler.stream.ChunkedInput
Throws:
Exception

hasNextChunk

public boolean hasNextChunk()
                     throws Exception
Specified by:
hasNextChunk in interface org.jboss.netty.handler.stream.ChunkedInput
Throws:
Exception

nextChunk

public HttpChunk nextChunk()
                    throws HttpPostRequestEncoder.ErrorDataEncoderException
Returns the next available HttpChunk. The caller is responsible to test if this chunk is the last one (isLast()), in order to stop calling this method.

Specified by:
nextChunk in interface org.jboss.netty.handler.stream.ChunkedInput
Returns:
the next available HttpChunk
Throws:
HttpPostRequestEncoder.ErrorDataEncoderException - if the encoding is in error

isEndOfInput

public boolean isEndOfInput()
                     throws Exception
Specified by:
isEndOfInput in interface org.jboss.netty.handler.stream.ChunkedInput
Throws:
Exception


Copyright © 2009-2012 Frederic Bregier. All Rights Reserved.