use of com.dexels.navajo.script.api.LocalClient in project navajo by Dexels.
the class TmlStandardServlet method doPost.
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
final LocalClient lc = (LocalClient) getServletContext().getAttribute("localClient");
if (lc == null) {
resp.sendError(500, "No local client registered in servlet context");
return;
}
Object certObject = req.getAttribute("javax.servlet.request.X509Certificate");
String recvEncoding = req.getHeader("Content-Encoding");
String sendEncoding = req.getHeader("Accept-Encoding");
AsyncRequest request = new BaseRequestImpl(req, resp, sendEncoding, recvEncoding, certObject, "default");
TmlStandardRunner tr = new TmlStandardRunner(request, lc);
getTmlScheduler().run(tr);
// TODO broken? fix
// getTmlScheduler().run(request.instantiateRunnable());
}
use of com.dexels.navajo.script.api.LocalClient in project navajo by Dexels.
the class TmlHttpServlet method handleTransaction.
@SuppressWarnings({ "rawtypes", "unchecked" })
private Navajo handleTransaction(String instance, DispatcherInterface dis, Navajo in, Object certObject, ClientInfo clientInfo) throws FatalException {
//
if (this.bundleContext != null) {
// OSGi environment:
ServiceReference sr = bundleContext.getServiceReference(LocalClient.class.getName());
if (sr == null) {
logger.warn("Resolving localclient service failed. Falling back to regular.");
return fallbackHandleTransaction(dis, in, certObject, clientInfo);
}
LocalClient lc = (LocalClient) bundleContext.getService(sr);
Navajo nn = lc.handleInternal(instance, in, certObject, clientInfo);
bundleContext.ungetService(sr);
lc = null;
return nn;
}
return fallbackHandleTransaction(dis, in, certObject, clientInfo);
}
use of com.dexels.navajo.script.api.LocalClient 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.LocalClient in project navajo by Dexels.
the class NavajoFilterServlet method getLocalClient.
protected LocalClient getLocalClient(final HttpServletRequest req) throws ServletException {
LocalClient tempClient = localClient;
if (localClient == null) {
tempClient = (LocalClient) req.getServletContext().getAttribute("localClient");
}
final LocalClient lc = tempClient;
if (lc == null) {
logger.error("No localclient found");
throw new ServletException("No local client registered in servlet context");
}
return lc;
}
use of com.dexels.navajo.script.api.LocalClient in project navajo by Dexels.
the class NavajoFilterServlet method service.
@Override
protected void service(final HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
try {
String instance = determineInstanceFromRequest(req);
LocalClient localClient = getLocalClient();
if (localClient == null) {
localClient = getLocalClient(req);
}
logger.info("Instance determined from request: " + instance);
Navajo input = buildRequest(getInitParameter("inputFilterClass"), req);
Navajo result = localClient.call(instance, input);
responseWrapper.processResponse(req, input, result, resp);
} catch (Throwable e) {
if (e instanceof ServletException) {
throw (ServletException) e;
}
logger.error("Servlet call failed dramatically", e);
}
}
Aggregations