|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||

java.lang.Objectorg.xlightweb.BodyForwarder
public class BodyForwarder
Implementation base of a body forwarder. This class handles closing of he data source and exceptions by forwarding the body data. Example:
class ForwardHandler implements IHttpRequestHandler {
private HttpClient httpClient = ...
// will be called if request header is received (Default-InvokeOn is HEADER_RECEIVED)
public void onRequest(IHttpExchange exchange) throws IOException {
IHttpRequestHeader requestHeader = exchange.getRequest().getRequestHeader();
NonBlockingBodyDataSource requestBodyChannel = exchange.getRequest().getNonBlockingBody();
// forwards the request (header)
BodyDataSink dataSink = httpClient.send(requestHeader);
// defines the body forwarder
BodyForwarder bodyForwarder = new BodyForwarder(requestBodyChannel, dataSink) {
public void onData(NonBlockingBodyDataSource bodyDataSource, BodyDataSink bodyDataSink) throws BufferUnderflowException, IOException {
int available = bodyDataSink.available();
ByteBuffer[] data = bodyDataSink.readByteBufferByLength(available);
for (ByteBuffer byteBuffer : data) {
ByteBuffer copy = byteBuffer.duplicate();
// ...
}
bodyDataSink.write(data);
}
};
// assign the body forwarder to the body data source
requestBodyChannel.setDataHandler(bodyForwarder);
}
}
| Field Summary |
|---|
| Fields inherited from interface org.xlightweb.IBodyDataHandler |
|---|
DEFAULT_EXECUTION_MODE |
| Constructor Summary | |
|---|---|
BodyForwarder(NonBlockingBodyDataSource bodyDataSource,
BodyDataSink bodyDataSink)
constructor |
|
| Method Summary | |
|---|---|
void |
onComplete()
call back which will be executed, if the body data source's end of data is reached |
boolean |
onData(NonBlockingBodyDataSource bodyDataSource)
call back. |
void |
onData(NonBlockingBodyDataSource bodyDataSource,
BodyDataSink bodyDataSink)
call back method which will be called if the body data source contains a least one byte |
void |
onException(Exception e)
call back which will be executed, if an exception is occurred |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public BodyForwarder(NonBlockingBodyDataSource bodyDataSource,
BodyDataSink bodyDataSink)
bodyDataSource - the body data sourcebodyDataSink - the body data sink| Method Detail |
|---|
public final boolean onData(NonBlockingBodyDataSource bodyDataSource)
throws BufferUnderflowException
onData in interface IBodyDataHandlerbodyDataSource - the body
BufferUnderflowException - if more incoming data is required to process (e.g. delimiter hasn't yet received -> readByDelimiter methods or size of the available, received data is smaller than the required size -> readByLength). The BufferUnderflowException will be swallowed by the framework
public void onData(NonBlockingBodyDataSource bodyDataSource,
BodyDataSink bodyDataSink)
throws BufferUnderflowException,
IOException
bodyDataSource - the body data sourcebodyDataSink - the body data sink
BufferUnderflowException - if not enough data is available
IOException - if an exception occurspublic void onException(Exception e)
e - the excptionpublic void onComplete()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||