use of com.dexels.navajo.script.api.FatalException in project navajo by Dexels.
the class Dispatcher method errorHandler.
/**
* Handles errors.
*
* @param access
* @param e
* @param inMessage
* @return the response error Navajo document.
*
* @throws FatalException
*/
private final Navajo errorHandler(Access access, Throwable e, Navajo inMessage) throws FatalException {
String message = "";
if (access != null) {
try {
message = e.getClass().toString() + ": " + e.getMessage() + ", " + e.toString() + ", " + e.getLocalizedMessage();
if (message.equalsIgnoreCase("")) {
message = "Undefined Error";
}
StringWriter swriter = new StringWriter();
PrintWriter writer = new PrintWriter(swriter);
e.printStackTrace(writer);
message += swriter.getBuffer().toString();
message += "\n";
swriter = new StringWriter();
writer = new PrintWriter(swriter);
// Remove some messages that might contain sensitive info.
if (inMessage != null) {
inMessage.removeInternalMessages();
}
inMessage.write(writer);
message += swriter.getBuffer().toString();
} catch (NavajoException tbe) {
throw new FatalException(tbe.getMessage());
}
} else {
// if no access was created, use the throwable message to be able to
// say *anything*
message += e.getMessage();
}
try {
Navajo out = generateErrorMessage(access, message, SystemException.SYSTEM_ERROR, 1, e);
if (access != null) {
access.setOutputDoc(out);
}
return out;
} catch (Exception ne) {
throw new FatalException(ne.getMessage(), ne);
}
}
use of com.dexels.navajo.script.api.FatalException 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.script.api.FatalException in project navajo by Dexels.
the class BaseServiceRunner method execute.
/**
* Handle a request.
*
* @param request
* @param response
* @throws IOException
* @throws ServletException
*/
private final void execute() throws IOException, ServletException {
// BufferedReader r = null;
String instance = myRequest.getInstance();
if (instance != null) {
MDC.put("instance", instance);
myRequest.getInputDocument().getHeader().setHeaderAttribute("instance", instance);
}
try {
Navajo in = getInputNavajo();
in.getHeader().setHeaderAttribute("useComet", "true");
if (in.getHeader().getHeaderAttribute("callback") != null) {
String callback = in.getHeader().getHeaderAttribute("callback");
try {
Navajo callbackNavajo = getLocalClient().handleCallback(getNavajoInstance(), in, callback);
writeOutput(in, callbackNavajo);
} finally {
endTransaction();
}
} else {
boolean continuationFound = false;
try {
String queueId = myQueue.getId();
int queueLength = myQueue.getQueueSize();
ClientInfo clientInfo = getRequest().createClientInfo(scheduledAt, startedAt, queueLength, queueId);
Navajo outDoc = getLocalClient().handleInternal(getNavajoInstance(), in, getRequest().getCert(), clientInfo);
// Do do: Support async services in a more elegant way.
if (!isAborted()) {
writeOutput(in, outDoc);
} else {
logger.warn("Aborted: Can't write output!");
}
} finally {
if (!continuationFound) {
// this will be the responsibility of the next thread,
// who will finish the continuation.
endTransaction();
}
}
}
} catch (Throwable e) {
if (e instanceof FatalException) {
FatalException fe = (FatalException) e;
if (fe.getMessage().equals("500.13")) {
// Server too busy.
throw new ServletException("500.13");
}
}
throw new ServletException(e);
} finally {
MDC.remove("instance");
}
}
use of com.dexels.navajo.script.api.FatalException in project navajo by Dexels.
the class CallCommand method call.
@Descriptor(value = "Call a script without input. It will bypass auth.")
public void call(CommandSession session, @Descriptor(value = "The script to call") String scr) {
String script = scr.replaceAll("/", ".");
Navajo n = NavajoFactory.getInstance().createNavajo();
n.addHeader(NavajoFactory.getInstance().createHeader(n, script, "_internal_", "", -1));
try {
Navajo out = localClient.call(n);
out.write(session.getConsole());
} catch (FatalException e) {
e.printStackTrace(session.getConsole());
}
}
use of com.dexels.navajo.script.api.FatalException in project navajo by Dexels.
the class RestTmlServlet method callDirect.
private final void callDirect(HttpServletRequest request, HttpServletResponse response) throws IOException {
String service = request.getParameter("service");
// String type = request.getParameter("type");
String username = request.getParameter("username");
String password = request.getParameter("password");
logger.info(">in callDirect(): service = " + service + ", username = " + username + " class: " + getClass().getName());
if (service == null) {
// logger.info("Empty service specified, request originating from "
// + request.getRemoteHost());
logger.info("thread = " + Thread.currentThread().hashCode());
logger.info("path = " + request.getPathInfo());
logger.info("query = " + request.getQueryString());
logger.info("protocol = " + request.getProtocol());
logger.info("agent = " + request.getRemoteUser());
logger.info("uri = " + request.getRequestURI());
logger.info("method = " + request.getMethod());
logger.info("contenttype = " + request.getContentType());
logger.info("scheme = " + request.getScheme());
logger.info("server = " + request.getServerName());
logger.info("port = " + request.getServerPort());
logger.info("contentlength = " + request.getContentLength());
Enumeration<String> enm = request.getHeaderNames();
while (enm.hasMoreElements()) {
String key = enm.nextElement();
String header = request.getHeader(key);
logger.info(">>" + key + "=" + header);
}
return;
}
Navajo tbMessage;
try {
tbMessage = constructFromRequest(request);
Header header = constructHeader(tbMessage, service, username, password, -1);
tbMessage.addHeader(header);
LocalClient lc = (LocalClient) getServletContext().getAttribute("localClient");
if (lc == null) {
response.sendError(500, "No navajocontext configured (in NavajoFilterServlet)");
return;
}
Navajo resultMessage = lc.call(tbMessage);
response.setContentType("text/xml");
ServletOutputStream outputStream = response.getOutputStream();
java.io.OutputStreamWriter out = new java.io.OutputStreamWriter(outputStream, "UTF-8");
response.setContentType("text/xml; charset=UTF-8");
writeOutput(resultMessage, out, service);
// resultMessage.write(out);
out.flush();
out.close();
} catch (NavajoException e) {
logger.error("Error: ", e);
} catch (FatalException e) {
logger.error("Error: ", e);
}
}
Aggregations