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();
}
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;
}
}
Aggregations