Search in sources :

Example 1 with JsonResponseBuilder

use of org.apache.storm.daemon.common.JsonResponseBuilder in project storm by apache.

the class AuthorizedUserFilter method makeResponse.

/**
 * makeResponse.
 * @param ex ex
 * @param request request
 * @param statusCode statusCode
 * @return error response
 */
public static Response makeResponse(Exception ex, ContainerRequestContext request, int statusCode) {
    String callback = null;
    if (request.getMediaType() != null && request.getMediaType().equals(MediaType.APPLICATION_JSON_TYPE)) {
        try {
            String json = IOUtils.toString(request.getEntityStream(), Charsets.UTF_8);
            InputStream in = IOUtils.toInputStream(json);
            request.setEntityStream(in);
            Map<String, Object> requestBody = (Map<String, Object>) JSONValue.parse(json);
            if (requestBody.containsKey(StormApiResource.callbackParameterName)) {
                callback = String.valueOf(requestBody.get(StormApiResource.callbackParameterName));
            }
        } catch (IOException e) {
            LOG.error("Exception while trying to get callback ", e);
        }
    }
    return new JsonResponseBuilder().setData(UIHelpers.exceptionToJson(ex, statusCode)).setCallback(callback).setStatus(statusCode).build();
}
Also used : JsonResponseBuilder(org.apache.storm.daemon.common.JsonResponseBuilder) InputStream(java.io.InputStream) IOException(java.io.IOException) Map(java.util.Map)

Example 2 with JsonResponseBuilder

use of org.apache.storm.daemon.common.JsonResponseBuilder in project storm by apache.

the class LogviewerResource method search.

/**
 * Handles '/search' (searching from specific worker or daemon log file) request.
 */
@GET
@Path("/search")
public Response search(@Context HttpServletRequest request) throws IOException {
    numSearchLogRequests.mark();
    String user = httpCredsHandler.getUserName(request);
    boolean isDaemon = StringUtils.equals(request.getParameter("is-daemon"), "yes");
    String file = request.getParameter("file");
    String decodedFileName = Utils.urlDecodeUtf8(file);
    String searchString = request.getParameter("search-string");
    String numMatchesStr = request.getParameter("num-matches");
    String startByteOffset = request.getParameter("start-byte-offset");
    String callback = request.getParameter(StormApiResource.callbackParameterName);
    String origin = request.getHeader("Origin");
    try (Timer.Context t = searchLogRequestDuration.time()) {
        return logSearchHandler.searchLogFile(decodedFileName, user, isDaemon, searchString, numMatchesStr, startByteOffset, callback, origin);
    } catch (InvalidRequestException e) {
        LOG.error(e.getMessage(), e);
        int statusCode = 400;
        return new JsonResponseBuilder().setData(UIHelpers.exceptionToJson(e, statusCode)).setCallback(callback).setStatus(statusCode).build();
    } catch (IOException e) {
        numSearchExceptions.mark();
        throw e;
    }
}
Also used : JsonResponseBuilder(org.apache.storm.daemon.common.JsonResponseBuilder) Timer(com.codahale.metrics.Timer) InvalidRequestException(org.apache.storm.daemon.ui.InvalidRequestException) IOException(java.io.IOException) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Aggregations

IOException (java.io.IOException)2 JsonResponseBuilder (org.apache.storm.daemon.common.JsonResponseBuilder)2 Timer (com.codahale.metrics.Timer)1 InputStream (java.io.InputStream)1 Map (java.util.Map)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 InvalidRequestException (org.apache.storm.daemon.ui.InvalidRequestException)1