Search in sources :

Example 11 with RequestArguments

use of com.tvd12.ezyhttp.server.core.request.RequestArguments in project ezyhttp by youngmonkeys.

the class BlockingServlet method handleException.

protected void handleException(HttpMethod method, RequestArguments arguments, Exception e) {
    UncaughtExceptionHandler handler = getUncaughtExceptionHandler(e.getClass());
    HttpServletRequest request = arguments.getRequest();
    HttpServletResponse response = arguments.getResponse();
    Exception exception = e;
    if (handler != null) {
        try {
            Object result = handler.handleException(arguments, e);
            if (result != null) {
                String responseContentType = handler.getResponseContentType();
                if (responseContentType != null) {
                    response.setContentType(responseContentType);
                }
                handleResponseData(request, response, result);
            } else {
                handleError(method, request, response, HttpServletResponse.SC_BAD_REQUEST);
            }
            exception = null;
        } catch (Exception ex) {
            exception = ex;
        }
    }
    if (exception != null) {
        handleError(method, request, response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, exception);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) UncaughtExceptionHandler(com.tvd12.ezyhttp.server.core.handler.UncaughtExceptionHandler) ServletException(javax.servlet.ServletException) DeserializeValueException(com.tvd12.ezyhttp.core.exception.DeserializeValueException) IOException(java.io.IOException) HttpRequestException(com.tvd12.ezyhttp.core.exception.HttpRequestException)

Example 12 with RequestArguments

use of com.tvd12.ezyhttp.server.core.request.RequestArguments in project ezyhttp by youngmonkeys.

the class FileUploadService method download.

public void download(RequestArguments requestArguments, String file) throws Exception {
    ResourceRequestHandler handler = new ResourceRequestHandler("files/" + file, "files/" + file, EzyFileUtil.getFileExtension(file), resourceDownloadManager);
    handler.handle(requestArguments);
}
Also used : ResourceRequestHandler(com.tvd12.ezyhttp.server.core.handler.ResourceRequestHandler)

Aggregations

RequestArguments (com.tvd12.ezyhttp.server.core.request.RequestArguments)7 AsyncContext (javax.servlet.AsyncContext)6 Test (org.testng.annotations.Test)6 HttpServletResponse (javax.servlet.http.HttpServletResponse)5 ResourceRequestHandler (com.tvd12.ezyhttp.server.core.handler.ResourceRequestHandler)4 HttpBadRequestException (com.tvd12.ezyhttp.core.exception.HttpBadRequestException)3 ResourceDownloadManager (com.tvd12.ezyhttp.core.resources.ResourceDownloadManager)3 ServletOutputStream (javax.servlet.ServletOutputStream)3 DeserializeBodyException (com.tvd12.ezyhttp.core.exception.DeserializeBodyException)2 DeserializeCookieException (com.tvd12.ezyhttp.core.exception.DeserializeCookieException)2 DeserializeHeaderException (com.tvd12.ezyhttp.core.exception.DeserializeHeaderException)2 DeserializeParameterException (com.tvd12.ezyhttp.core.exception.DeserializeParameterException)2 DeserializePathVariableException (com.tvd12.ezyhttp.core.exception.DeserializePathVariableException)2 DeserializeValueException (com.tvd12.ezyhttp.core.exception.DeserializeValueException)2 HttpRequestException (com.tvd12.ezyhttp.core.exception.HttpRequestException)2 SimpleRequestArguments (com.tvd12.ezyhttp.server.core.request.SimpleRequestArguments)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 OutputStream (java.io.OutputStream)2 ServletException (javax.servlet.ServletException)2