public class ScriptResponseProducer extends ResponseProducer
ResponseProducer
specialization is responsible for invoking the JavaScript endpoint to produce a response,
translate that response (if need be) into an asynchronous form, and then send that data back to the client.Modifier and Type | Field and Description |
---|---|
protected static org.slf4j.Logger |
Logger |
contentProducer, context, response, role, trigger
Constructor and Description |
---|
ScriptResponseProducer(ScriptObjectMirror endpoint,
org.apache.http.HttpRequest request,
org.apache.http.protocol.HttpContext context,
BufferIOController buffer)
Primary constructor.
|
Modifier and Type | Method and Description |
---|---|
org.apache.http.HttpResponse |
generateResponse()
Someone else always generates the response and invokes one of our
setResponse or setException methods. |
void |
responseCompleted(org.apache.http.protocol.HttpContext context)
Invoke the endpoint's responseCompleted function, and close out our
ScriptHelper . |
boolean |
setResponse(org.apache.http.HttpResponse response)
Determines the HttpResponse that will be sent back to the requesting client.
|
boolean |
setTrigger(org.apache.http.nio.protocol.HttpAsyncExchange trigger)
Triggers the
generateResponse method and begins responding to the client. |
close, failed, produceContent, setException, setResponse
public ScriptResponseProducer(ScriptObjectMirror endpoint, org.apache.http.HttpRequest request, org.apache.http.protocol.HttpContext context, BufferIOController buffer)
endpoint
- The actual JavaScript endpoint to invoke.request
- The request that was returned earlier by the endpoint's inspectRequest
method.context
- The context of this request / response transaction.buffer
- The buffer from which the response's content data will be asynchronously read and sent back to the client.public org.apache.http.HttpResponse generateResponse()
setResponse
or setException
methods.
This method returns whatever that response was.
This method actually does all the work of this class by invoking the endpoint, and processing it's result.generateResponse
in interface org.apache.http.nio.protocol.HttpAsyncResponseProducer
generateResponse
in class ResponseProducer
public void responseCompleted(org.apache.http.protocol.HttpContext context)
ScriptHelper
.responseCompleted
in interface org.apache.http.nio.protocol.HttpAsyncResponseProducer
responseCompleted
in class ResponseProducer
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).
Because the JavaScript endpoint provides it's data synchronously, our setTrigger
method will not yet have been called
*and* we need to make sure that any response (error or otherwise) has it's HttpEntity
(if any) wrapped into an EntityAsyncContentProducer
so that we can respond to the client in an asynchronous manner.setResponse
in class ResponseProducer
public boolean setTrigger(org.apache.http.nio.protocol.HttpAsyncExchange trigger)
generateResponse
method and begins responding to the client.setTrigger
in class ResponseProducer
Copyright © 2015–2024 Frank Stock. All rights reserved.