Search in sources :

Example 1 with ClientException

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

the class ServerAsyncRunner method run.

/**
 * Main thread
 */
@Override
public void run() {
    try {
        prevTime = System.currentTimeMillis();
        while (isIterating()) {
            if (kill) {
                logger.warn("Kill called in ServerAsyncRunner...");
                myResult.getHeader().setCallBackInterrupt("kill");
                setIterating(false);
            }
            if (myPollingInterval > 0) {
                myNavajo.removeHeader();
                myNavajo.addHeader(myResult.getHeader());
                Navajo temp = doSimpleSend(myNavajo, myMethod);
                if (temp.getMessage("ConditionErrors") != null) {
                    logger.warn("Had ConditionErrors in Asyncsend.. ");
                    killServerAsyncSend();
                } else {
                    poll(temp);
                }
            }
        }
    } catch (ClientException ex) {
        logger.debug("oooops");
        myListener.handleException(ex);
        return;
    }
    if (myListener != null) {
        myListener.handleException(new ClientException(-1, -1, "Operation aborted"));
    }
}
Also used : Navajo(com.dexels.navajo.document.Navajo) ClientException(com.dexels.navajo.client.ClientException)

Example 2 with ClientException

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

the class JavaNetNavajoClientImpl method handleException.

private Navajo handleException(Throwable exception, String host) throws ClientException {
    if (!generateConditionErrors) {
        logger.error("Error: ", exception);
        throw new ClientException(-1, -1, exception.getMessage(), exception);
    }
    Navajo n = null;
    if (exception instanceof java.net.UnknownHostException) {
        logger.warn("Connection problem: UnknownHostException exception to {}!", host, exception);
        n = NavajoFactory.getInstance().createNavajo();
        generateConnectionError(n, 7777777, "Unknown host: " + exception.getMessage());
    } else if (exception instanceof java.net.NoRouteToHostException) {
        logger.warn("Connection problem: NoRouteToHostException exception to {}!", host, exception);
        n = NavajoFactory.getInstance().createNavajo();
        generateConnectionError(n, 55555, "No route to host: " + exception.getMessage());
    } else if (exception instanceof java.net.SocketTimeoutException || exception instanceof java.net.ConnectException || exception instanceof java.net.NoRouteToHostException) {
        logger.warn("Connection problem: SocketTimeoutException exception to {}!", host, exception);
        n = NavajoFactory.getInstance().createNavajo();
        generateConnectionError(n, 55555, "Error on getting response data: " + exception.getMessage());
    } else if (exception instanceof javax.net.ssl.SSLHandshakeException) {
        logger.warn("Connection problem: SSLHandshakeException exception to {}!", host, exception);
        n = NavajoFactory.getInstance().createNavajo();
        generateConnectionError(n, 666666, "SSL fout " + exception.getMessage());
    }
    if (n != null) {
        return n;
    }
    logger.warn("Connection problem: Exception {} to {}!", exception.getMessage(), host, exception);
    throw new ClientException(-1, -1, exception.getMessage(), exception);
}
Also used : ClientException(com.dexels.navajo.client.ClientException) Navajo(com.dexels.navajo.document.Navajo)

Example 3 with ClientException

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

the class NavajoRemoteContext method callService.

/* (non-Javadoc)
	 * @see com.dexels.navajo.client.context.ClientContext#callService(java.lang.String, com.dexels.navajo.document.Navajo)
	 */
@Override
public void callService(String service, String tenant, String username, String password, Navajo input) throws ClientException {
    if (myClient == null) {
        throw new ClientException(1, -1, "No client has been set up!");
    }
    if (input == null) {
        input = NavajoFactory.getInstance().createNavajo();
    }
    Header outHeader = input.getHeader();
    if (outHeader == null) {
        outHeader = NavajoFactory.getInstance().createHeader(input, service, username, password, -1);
        input.addHeader(outHeader);
    }
    if (debugAll) {
        outHeader.setHeaderAttribute("fullLog", "true");
    }
    long time = System.currentTimeMillis();
    Navajo n = myClient.doSimpleSend(input, service);
    logger.debug("Send complete!");
    n.getHeader().setRPCName(service);
    putNavajo(service, n);
    logger.debug("Call took: {} millis!", System.currentTimeMillis() - time);
}
Also used : Header(com.dexels.navajo.document.Header) ClientException(com.dexels.navajo.client.ClientException) Navajo(com.dexels.navajo.document.Navajo)

Example 4 with ClientException

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

the class ApacheNavajoClientImpl method doTransaction.

@Override
protected Navajo doTransaction(Navajo d, boolean useCompression, int retries, int exceptionCount) throws ClientException {
    URI uri;
    Navajo n = null;
    try {
        uri = new URI(getCurrentHost());
    } catch (URISyntaxException e) {
        logger.error("Syntax exception!", e);
        throw new ClientException("Invalid host");
    }
    long timeStamp = System.currentTimeMillis();
    try {
        HttpPost httppost = new HttpPost(uri);
        if (bearerToken != null) {
            httppost.setHeader("Authorization", "Bearer " + bearerToken);
        } else if (useBasicAuth) {
            String header = Base64.encodeBase64URLSafeString((username + ":" + password).getBytes());
            httppost.setHeader("Authorization", "Basic " + header);
        }
        appendHeaderToHttp(httppost, d.getHeader());
        NavajoRequestEntity reqEntity = new NavajoRequestEntity(d, useCompression, forceGzip);
        httppost.setEntity(reqEntity);
        CloseableHttpResponse response = httpclient.execute(httppost);
        try {
            if (response.getStatusLine().getStatusCode() >= 400) {
                throw new IOException(response.getStatusLine().getReasonPhrase());
            }
            n = parseResponse(response);
        } finally {
            response.close();
        }
    } catch (Throwable t) {
        // Check if we should attempt a retry.
        logger.error("Problem: ", t);
        if (retryRequest(t, retries)) {
            try {
                Thread.sleep((long) ((exceptionCount + 1) * SLEEPTIME_PER_EXCEPTION));
            } catch (InterruptedException e) {
                logger.error("Error: ", e);
            }
            n = doTransaction(d, useCompression, --retries, ++exceptionCount);
        } else {
            n = handleException(t, getCurrentHost(), timeStamp);
        }
    } finally {
    // Don't close to allow connection reuse
    }
    if (n == null) {
        throw new ClientException(-1, -1, "Empty Navajo received");
    }
    return n;
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) Navajo(com.dexels.navajo.document.Navajo) URISyntaxException(java.net.URISyntaxException) ClientException(com.dexels.navajo.client.ClientException) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) URI(java.net.URI)

Example 5 with ClientException

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

the class ApacheNavajoClientImpl method handleException.

protected Navajo handleException(Throwable exception, String host, long timeStamp) throws ClientException {
    if (!generateConditionErrors) {
        logger.error("Error: ", exception);
        throw new ClientException(-1, -1, exception.getMessage(), exception);
    }
    logger.error("Error: ", exception);
    Navajo n = null;
    if (exception instanceof java.net.UnknownHostException || exception instanceof org.apache.http.conn.HttpHostConnectException) {
        logger.warn("Connection problem: UnknownHostException exception to {}!", host, exception);
        n = NavajoFactory.getInstance().createNavajo();
        generateConnectionError(n, 7777777, "Unknown host: " + exception.getMessage());
    } else if (exception instanceof java.net.NoRouteToHostException) {
        logger.warn("Connection problem: NoRouteToHostException exception to {}!", host, exception);
        n = NavajoFactory.getInstance().createNavajo();
        generateConnectionError(n, 55555, "No route to host: " + exception.getMessage());
    } else if (exception instanceof org.apache.http.NoHttpResponseException) {
        logger.warn("Connection problem: NoHttpResponseException exception to {}!  after {}ms", host, (System.currentTimeMillis() - timeStamp), exception);
        n = NavajoFactory.getInstance().createNavajo();
        generateConnectionError(n, 55555, "Error on getting response data: " + exception.getMessage());
    } else if (exception instanceof java.net.SocketTimeoutException) {
        logger.warn("Connection problem: SocketTimeoutException exception to {}! after {}ms", host, (System.currentTimeMillis() - timeStamp), exception);
        n = NavajoFactory.getInstance().createNavajo();
        generateConnectionError(n, 55555, "Error on getting response data: " + exception.getMessage());
    } else if (exception instanceof org.apache.http.conn.ConnectTimeoutException) {
        logger.warn("Connection problem: ConnectTimeoutException exception to {}! after {}ms", host, (System.currentTimeMillis() - timeStamp), exception);
        n = NavajoFactory.getInstance().createNavajo();
        generateConnectionError(n, 55555, "Connect time-out: " + exception.getMessage());
    } else if (exception instanceof javax.net.ssl.SSLHandshakeException) {
        logger.warn("Connection problem: SSLHandshakeException exception to {}!", host, exception);
        n = NavajoFactory.getInstance().createNavajo();
        generateConnectionError(n, 666666, "SSL fout " + exception.getMessage());
    } else if (exception instanceof java.net.SocketException) {
        logger.warn("Connection problem: SocketException {} exception to {}! ", exception.getMessage(), host, exception);
        n = NavajoFactory.getInstance().createNavajo();
        generateConnectionError(n, 55555, "SocketException: " + exception.getMessage());
    }
    if (n != null) {
        return n;
    }
    logger.warn("Connection problem: Exception {} to {}!", exception.getMessage(), host, exception);
    throw new ClientException(-1, -1, exception.getMessage(), exception);
}
Also used : NoHttpResponseException(org.apache.http.NoHttpResponseException) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) Navajo(com.dexels.navajo.document.Navajo) UnknownHostException(java.net.UnknownHostException) ClientException(com.dexels.navajo.client.ClientException)

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