Search in sources :

Example 6 with ClientException

use of com.dexels.navajo.client.ClientException in project navajo by Dexels.

the class LocalNavajoContext method callService.

@Override
public void callService(String service, String tenant, String username, String password, Navajo input) throws ClientException {
    if (input == null) {
        input = NavajoFactory.getInstance().createNavajo();
        input.addHeader(NavajoFactory.getInstance().createHeader(input, service, username, password, -1));
    } else {
        if (input.getHeader() == null) {
            input.addHeader(NavajoFactory.getInstance().createHeader(input, service, username, password, -1));
        } else {
            input.getHeader().setRPCName(service);
            input.getHeader().setRPCUser(getUsername());
            input.getHeader().setRPCPassword(getPassword());
        }
    }
    try {
        LocalClient lc = tenant == null ? localClients.get(DEFAULT_TENANT) : localClients.get(tenant);
        Navajo result = lc.call(input);
        result.getHeader().setRPCName(service);
        putNavajo(service, result);
    } catch (FatalException e) {
        throw (new ClientException(0, -1, "Error calling local client", e));
    }
}
Also used : FatalException(com.dexels.navajo.script.api.FatalException) LocalClient(com.dexels.navajo.script.api.LocalClient) Navajo(com.dexels.navajo.document.Navajo) ClientException(com.dexels.navajo.client.ClientException)

Example 7 with ClientException

use of com.dexels.navajo.client.ClientException in project navajo by Dexels.

the class ServerAsyncRunner method poll.

private void poll(Navajo temp) throws ClientException {
    Header head = temp.getHeader();
    if (head == null) {
        logger.warn("Received no header. returning and killing thread");
        throw new ClientException(-1, -1, "No async header!");
    }
    if (isFinished(temp)) {
        // Really dont know what I should pass to getCallBackPointer
        if (myListener != null) {
            myListener.setProgress(head.getCallBackPointer(null), 100);
            myListener.receiveServerAsync(temp, myMethod, head.getCallBackPointer(null), myClientId);
        }
        registry.deRegisterAsyncRunner(myClientId);
        myNavajo.removeHeader();
        this.iterate = false;
    } else {
        if (myListener != null) {
            myListener.setProgress(head.getCallBackPointer(null), head.getCallBackProgress());
        }
    }
    checkPollingInterval(head.getCallBackProgress());
    sleep();
}
Also used : Header(com.dexels.navajo.document.Header) ClientException(com.dexels.navajo.client.ClientException)

Example 8 with ClientException

use of com.dexels.navajo.client.ClientException in project navajo by Dexels.

the class ServerAsyncRunner method startAsync.

/**
 * Start the ServerAsyncRunner
 * @throws ClientException
 * @return String
 */
public String startAsync() throws ClientException {
    if (myNavajo.getHeader() != null) {
        myNavajo.removeHeader();
    }
    myResult = doSimpleSend(myNavajo, myMethod);
    Header resultHead = myResult.getHeader();
    if (resultHead != null) {
        if (myListener != null) {
            myListener.serviceStarted(resultHead.getCallBackPointer(null));
            start();
            return resultHead.getCallBackPointer(null);
        }
    } else {
        logger.info("Received no header. returning and killing thread");
        throw new ClientException(-1, -1, "No async header!");
    }
    return null;
}
Also used : Header(com.dexels.navajo.document.Header) ClientException(com.dexels.navajo.client.ClientException)

Example 9 with ClientException

use of com.dexels.navajo.client.ClientException 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)9 Navajo (com.dexels.navajo.document.Navajo)6 Header (com.dexels.navajo.document.Header)3 IOException (java.io.IOException)2 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 FatalException (com.dexels.navajo.script.api.FatalException)1 LocalClient (com.dexels.navajo.script.api.LocalClient)1 InterruptedIOException (java.io.InterruptedIOException)1 OutputStream (java.io.OutputStream)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 UnknownHostException (java.net.UnknownHostException)1 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)1 ServletException (javax.servlet.ServletException)1 NoHttpResponseException (org.apache.http.NoHttpResponseException)1 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)1 HttpPost (org.apache.http.client.methods.HttpPost)1