Search in sources :

Example 6 with LocalClient

use of com.dexels.navajo.script.api.LocalClient in project navajo by Dexels.

the class TmlContinuationMultitenantServlet method service.

@Override
protected void service(final HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    try {
        if (useReactiveEndpoint(req)) {
            reactiveHttpServlet.service(req, resp);
            return;
        }
        String instance = determineTenantFromRequest(req);
        LocalClient localClient = getLocalClient();
        if (localClient == null) {
            localClient = getLocalClient(req);
        }
        TmlRunnable runner = TmlRunnableBuilder.prepareRunnable(req, resp, localClient, instance, requestTimeout);
        if (runner != null) {
            getTmlScheduler().submit(runner, false);
        }
    } 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) TmlRunnable(com.dexels.navajo.script.api.TmlRunnable)

Example 7 with LocalClient

use of com.dexels.navajo.script.api.LocalClient in project navajo by Dexels.

the class TmlContinuationMultitenantServlet 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 8 with LocalClient

use of com.dexels.navajo.script.api.LocalClient 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);
    }
}
Also used : Header(com.dexels.navajo.document.Header) ServletOutputStream(javax.servlet.ServletOutputStream) FatalException(com.dexels.navajo.script.api.FatalException) LocalClient(com.dexels.navajo.script.api.LocalClient) NavajoException(com.dexels.navajo.document.NavajoException) 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