Search in sources :

Example 1 with LocalClient

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());
}
Also used : BaseRequestImpl(com.dexels.navajo.server.listener.http.impl.BaseRequestImpl) AsyncRequest(com.dexels.navajo.script.api.AsyncRequest) LocalClient(com.dexels.navajo.script.api.LocalClient)

Example 2 with LocalClient

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);
}
Also used : LocalClient(com.dexels.navajo.script.api.LocalClient) Navajo(com.dexels.navajo.document.Navajo) ServiceReference(org.osgi.framework.ServiceReference)

Example 3 with LocalClient

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));
    }
}
Also used : FatalException(com.dexels.navajo.script.api.FatalException) LocalClient(com.dexels.navajo.script.api.LocalClient) Navajo(com.dexels.navajo.document.Navajo) ClientException(com.dexels.navajo.client.ClientException)

Example 4 with LocalClient

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;
}
Also used : ServletException(javax.servlet.ServletException) LocalClient(com.dexels.navajo.script.api.LocalClient)

Example 5 with LocalClient

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);
    }
}
Also used : ServletException(javax.servlet.ServletException) LocalClient(com.dexels.navajo.script.api.LocalClient) Navajo(com.dexels.navajo.document.Navajo)

Aggregations

LocalClient (com.dexels.navajo.script.api.LocalClient)8 Navajo (com.dexels.navajo.document.Navajo)4 ServletException (javax.servlet.ServletException)4 FatalException (com.dexels.navajo.script.api.FatalException)2 ClientException (com.dexels.navajo.client.ClientException)1 Header (com.dexels.navajo.document.Header)1 NavajoException (com.dexels.navajo.document.NavajoException)1 AsyncRequest (com.dexels.navajo.script.api.AsyncRequest)1 TmlRunnable (com.dexels.navajo.script.api.TmlRunnable)1 BaseRequestImpl (com.dexels.navajo.server.listener.http.impl.BaseRequestImpl)1 ServletOutputStream (javax.servlet.ServletOutputStream)1 ServiceReference (org.osgi.framework.ServiceReference)1