SMILA (incubation) API documentation

org.eclipse.smila.http.server.json
Class JsonBulkRequestHandler

java.lang.Object
  extended by org.eclipse.smila.http.server.util.ARequestHandler
      extended by org.eclipse.smila.http.server.json.JsonBulkRequestHandler
All Implemented Interfaces:
HttpHandler, RequestHandler
Direct Known Subclasses:
BulkbuilderBurstHandler

public abstract class JsonBulkRequestHandler
extends ARequestHandler

JSON bulk request handler.


Field Summary
protected static DataFactory FACTORY
          Record/Any factory.
 
Constructor Summary
JsonBulkRequestHandler()
           
 
Method Summary
abstract  void end(java.lang.String method, java.lang.String requestUri)
          Called after processing and finishing is done.
abstract  java.lang.Object finish(java.lang.String method, java.lang.String requestUri)
          Called after the complete input bulk has been processed successfully.
protected  int getErrorStatus(java.lang.String method, java.lang.String requestUri, java.lang.Throwable ex)
          Gets the HTTP error status code depending on the method, request URI and throwable.
protected  java.lang.String getRequestHost()
           
protected  int getSuccessStatus(java.lang.String method, java.lang.String requestUri, java.lang.Object resultObject)
          Gets the ACCEPTED (202) HTTP status code.
 void handle(HttpExchange exchange)
          Handles a HttpExchange containing a HttpRequest.
protected  boolean isValidMethod(java.lang.String method, java.lang.String requestUri)
          Checks if the given HTTP method is allowed for the request URI.
abstract  void process(java.lang.String method, java.lang.String requestUri, Record inputRecord)
          process input record and return result record.
abstract  void start(java.lang.String method, java.lang.String requestUri)
          Called before processing.
protected  boolean writeErrorResult(HttpExchange exchange, java.lang.Throwable error)
          Writes the error result.
protected  void writeResultObject(java.io.OutputStream responseStream, java.lang.Object resultObject)
          write result object.
protected  boolean writeSuccessResult(HttpExchange exchange, java.lang.Object resultObject)
          Writes a success status code.
 
Methods inherited from class org.eclipse.smila.http.server.util.ARequestHandler
activate, getDynamicUriParts, getRootContextPath, getStaticUriParts, getUriPattern, matches, urlDecode
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FACTORY

protected static final DataFactory FACTORY
Record/Any factory. Helper shortcut for subclasses.

Constructor Detail

JsonBulkRequestHandler

public JsonBulkRequestHandler()
Method Detail

process

public abstract void process(java.lang.String method,
                             java.lang.String requestUri,
                             Record inputRecord)
                      throws java.lang.Exception
process input record and return result record.

Parameters:
method - the HTTP method of this request.
requestUri - the request URI
inputRecord - input Record, may be null
Throws:
java.lang.Exception - any failure during processing.

finish

public abstract java.lang.Object finish(java.lang.String method,
                                        java.lang.String requestUri)
                                 throws java.lang.Exception
Called after the complete input bulk has been processed successfully.

Parameters:
method - the request method.
requestUri - the request URI.
Returns:
result object, may be null.
Throws:
java.lang.Exception - any failure during finishing.

start

public abstract void start(java.lang.String method,
                           java.lang.String requestUri)
                    throws java.lang.Exception
Called before processing.

Parameters:
method - the request method.
requestUri - the request URI.
Throws:
java.lang.Exception - any failure during processing.

end

public abstract void end(java.lang.String method,
                         java.lang.String requestUri)
                  throws java.lang.Exception
Called after processing and finishing is done. This method can be used to clean up resources.

Parameters:
method - the request method.
requestUri - the request URI.
Throws:
java.lang.Exception

handle

public void handle(HttpExchange exchange)
Handles a HttpExchange containing a HttpRequest.

Parameters:
exchange - the HttpExchange object

isValidMethod

protected boolean isValidMethod(java.lang.String method,
                                java.lang.String requestUri)
Checks if the given HTTP method is allowed for the request URI. Currently only POST is allowed.

Parameters:
method - the HTTP method.
requestUri - the Request URI.
Returns:
'true' if the method is allowed (POST), 'false' if not.

writeSuccessResult

protected boolean writeSuccessResult(HttpExchange exchange,
                                     java.lang.Object resultObject)
                              throws java.io.IOException
Writes a success status code.

Parameters:
exchange - the HttpExchange
resultObject - result object, may be null.
Returns:
true, if the "Connection" request header equals "close"
Throws:
java.io.IOException

getSuccessStatus

protected int getSuccessStatus(java.lang.String method,
                               java.lang.String requestUri,
                               java.lang.Object resultObject)
Gets the ACCEPTED (202) HTTP status code.

Parameters:
method - ignored
requestUri - ignored
resultObject - result object, may be null.
Returns:
the ACCEPTED (202) HTTP status code.

writeResultObject

protected void writeResultObject(java.io.OutputStream responseStream,
                                 java.lang.Object resultObject)
                          throws java.io.IOException
write result object. The default implementation writes back single Record results. Subclasses that produce different result types must override this method.

Parameters:
responseStream - response stream
resultObject - result object.
Throws:
java.io.IOException - error writing result

writeErrorResult

protected boolean writeErrorResult(HttpExchange exchange,
                                   java.lang.Throwable error)
                            throws java.io.IOException
Writes the error result.

Parameters:
exchange - the HttpExchange object.
error - the error to be written
Returns:
true, if the "Connection" request header equals "close"
Throws:
java.io.IOException - could not write the error to the response stream.

getErrorStatus

protected int getErrorStatus(java.lang.String method,
                             java.lang.String requestUri,
                             java.lang.Throwable ex)
Gets the HTTP error status code depending on the method, request URI and throwable.

See Also:
JsonHttpUtils.getErrorStatus(Throwable)

getRequestHost

protected java.lang.String getRequestHost()
Returns:
the host as stated in the request.

SMILA (incubation) API documentation