use of com.dexels.navajo.client.context.NavajoRemoteContext in project navajo by Dexels.
the class NqlServlet method doGet.
@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
String username = req.getParameter("username");
String password = req.getParameter("password");
String server = req.getParameter("server");
String query = req.getParameter("query");
String ping = req.getParameter("ping");
String tenant = req.getParameter("tenant");
if (tenant == null) {
// Fall back to header
tenant = req.getHeader("X-Navajo-Instance");
}
if (ping != null) {
if (!checkPing(username, resp)) {
throw new ServletException("ping failed.");
}
return;
}
NavajoRemoteContext nrc = new NavajoRemoteContext();
nrc.setupClient(server, username, password, req.getServerName(), req.getServerPort(), req.getContextPath(), "/PostmanLegacy");
// new NQLContext();
NqlContextApi nc = getNqlContext();
nc.setNavajoContext(getClientContext());
try {
nc.executeCommand(query, tenant, username, password, new OutputCallback() {
@Override
public void setOutputType(String mime) {
resp.setContentType(mime);
}
@Override
public void setContentLength(long l) {
resp.setContentLength((int) l);
resp.setHeader("Accept-Ranges", "none");
resp.setHeader("Connection", "close");
}
@Override
public OutputStream getOutputStream() {
try {
return resp.getOutputStream();
} catch (IOException e) {
logger.error("Error: ", e);
return null;
}
}
});
} catch (ClientException e) {
logger.error("Error: ", e);
} catch (NavajoException e) {
logger.error("Error: ", e);
}
resp.getOutputStream().flush();
resp.getOutputStream().close();
// String
}
Aggregations