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