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