public class ResponseProducer extends Object implements org.apache.http.nio.protocol.HttpAsyncResponseProducer
RequestHandler.handle is invoked by the framework.
To accommodate that, this class has two methods setResponse and setTrigger. Please see those methods for details.| Modifier and Type | Field and Description |
|---|---|
protected org.apache.http.nio.entity.HttpAsyncContentProducer |
contentProducer |
protected org.apache.http.protocol.HttpContext |
context |
protected static org.slf4j.Logger |
Logger |
protected org.apache.http.HttpResponse |
response |
protected String |
role |
protected org.apache.http.nio.protocol.HttpAsyncExchange |
trigger |
| Constructor and Description |
|---|
ResponseProducer(String role,
org.apache.http.protocol.HttpContext context)
Alternate constructor (content producer to be extracted later from the HttpResponse entity).
|
ResponseProducer(String role,
org.apache.http.protocol.HttpContext context,
BufferIOController buffer)
Alternate constructor (content to be produced from the supplied IOControlled buffer.
|
ResponseProducer(String role,
org.apache.http.protocol.HttpContext context,
org.apache.http.nio.entity.HttpAsyncContentProducer contentProducer)
Primary constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Close the content buffer.
|
void |
failed(Exception ex) |
org.apache.http.HttpResponse |
generateResponse()
Someone else always generates the response and invokes one of our
setResponse or setException methods. |
void |
produceContent(org.apache.http.nio.ContentEncoder encoder,
org.apache.http.nio.IOControl ioctrl)
This method is only called if the response has content (which is typically the case).
|
void |
responseCompleted(org.apache.http.protocol.HttpContext context) |
void |
setException(Exception ex)
Send back an appropriate response to the client.
|
boolean |
setResponse(org.apache.http.HttpResponse response)
Determines the HttpResponse that will be sent back to the requesting client.
|
void |
setResponse(int statusCode,
String message)
Send back the specified response to the client
|
boolean |
setTrigger(org.apache.http.nio.protocol.HttpAsyncExchange trigger)
Called from the
RequestHandler.handle method this method keeps track of the supplied trigger. |
protected static final org.slf4j.Logger Logger
protected final org.apache.http.protocol.HttpContext context
protected final String role
protected volatile org.apache.http.nio.entity.HttpAsyncContentProducer contentProducer
protected volatile org.apache.http.HttpResponse response
protected volatile org.apache.http.nio.protocol.HttpAsyncExchange trigger
public ResponseProducer(String role, org.apache.http.protocol.HttpContext context, org.apache.http.nio.entity.HttpAsyncContentProducer contentProducer)
context - The context of this transactionrole - The role played by this producer (e.g. server, proxy, endpoint).contentProducer - The object that will asynchronously produce the content for this response.public ResponseProducer(String role, org.apache.http.protocol.HttpContext context, BufferIOController buffer)
context - The context of this transactionrole - The role played by this producer (e.g. server, proxy, endpoint).buffer - A buffer from which response content may be asynchronously read and sent back to the client.public ResponseProducer(String role, org.apache.http.protocol.HttpContext context)
context - The context of this transactionrole - The role played by this producer (e.g. server, proxy, endpoint).public void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableIOExceptionpublic org.apache.http.HttpResponse generateResponse()
setResponse or setException methods.
This method returns whatever that response was.generateResponse in interface org.apache.http.nio.protocol.HttpAsyncResponseProducerpublic void produceContent(org.apache.http.nio.ContentEncoder encoder,
org.apache.http.nio.IOControl ioctrl)
throws IOException
produceContent in interface org.apache.http.nio.protocol.HttpAsyncResponseProducerIOExceptionpublic void responseCompleted(org.apache.http.protocol.HttpContext context)
responseCompleted in interface org.apache.http.nio.protocol.HttpAsyncResponseProducerpublic void failed(Exception ex)
failed in interface org.apache.http.nio.protocol.HttpAsyncResponseProducerpublic void setException(Exception ex)
public void setResponse(int statusCode,
String message)
public boolean setResponse(org.apache.http.HttpResponse response)
RequestHandler.handle method has already armed us with an HttpAsyncExchange response trigger, then invoke it's submitResponse method.
Otherwise keep track of the response until our setTrigger method is invoked (at which time the trigger's submitResponse method will be called and this response will be sent back to the client).public boolean setTrigger(org.apache.http.nio.protocol.HttpAsyncExchange trigger)
RequestHandler.handle method this method keeps track of the supplied trigger.
If our setResponse method has already been called to specify our response, then we invoke the trigger's submitResponse method to send our response back to the client
Otherwise keep track of the trigger until our setResponse method is invoked (at which time it will invoke the trigger's submitResponse method to send our response back to the client).Copyright © 2015–2024 Frank Stock. All rights reserved.