Search in sources :

Example 1 with OutputCallback

use of com.dexels.navajo.client.nql.OutputCallback 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
}
Also used : ServletException(javax.servlet.ServletException) NqlContextApi(com.dexels.navajo.client.nql.NqlContextApi) NavajoRemoteContext(com.dexels.navajo.client.context.NavajoRemoteContext) OutputStream(java.io.OutputStream) NavajoException(com.dexels.navajo.document.NavajoException) IOException(java.io.IOException) ClientException(com.dexels.navajo.client.ClientException) OutputCallback(com.dexels.navajo.client.nql.OutputCallback)

Aggregations

ClientException (com.dexels.navajo.client.ClientException)1 NavajoRemoteContext (com.dexels.navajo.client.context.NavajoRemoteContext)1 NqlContextApi (com.dexels.navajo.client.nql.NqlContextApi)1 OutputCallback (com.dexels.navajo.client.nql.OutputCallback)1 NavajoException (com.dexels.navajo.document.NavajoException)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 ServletException (javax.servlet.ServletException)1