Search in sources :

Example 96 with Navajo

use of com.dexels.navajo.document.Navajo in project navajo by Dexels.

the class TmlHttpServlet method callDirect.

private final void callDirect(HttpServletRequest request, HttpServletResponse response) {
    String service = request.getParameter("service");
    if (service == null) {
        logRequestParams(request);
        return;
    }
    final String instance = determineInstanceFromRequest(request);
    // PrintWriter out = response.getWriter();
    Navajo tbMessage = null;
    DispatcherInterface dis = null;
    dis = DispatcherFactory.getInstance();
    try {
        tbMessage = constructFromRequest(request);
        Navajo resultMessage = handleTransaction(instance, dis, tbMessage, null, null);
        sendResponse(request, response, resultMessage);
        statLogger.info("direct legacy call");
    } catch (Exception ce) {
        logger.error("Error: ", ce);
    } finally {
        dis = null;
    }
}
Also used : DispatcherInterface(com.dexels.navajo.server.DispatcherInterface) Navajo(com.dexels.navajo.document.Navajo) FatalException(com.dexels.navajo.script.api.FatalException) ServletException(javax.servlet.ServletException) NavajoException(com.dexels.navajo.document.NavajoException) IOException(java.io.IOException)

Example 97 with Navajo

use of com.dexels.navajo.document.Navajo 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 98 with Navajo

use of com.dexels.navajo.document.Navajo in project navajo by Dexels.

the class TmlRunnableBuilder method constructRequest.

private static AsyncRequest constructRequest(final HttpServletRequest req, HttpServletResponse resp, String instance) throws IOException {
    Object certObject = req.getAttribute("javax.servlet.request.X509Certificate");
    String contentEncoding = req.getHeader("Content-Encoding");
    String acceptEncoding = req.getHeader("Accept-Encoding");
    AsyncRequest request = null;
    if ("POST".equals(req.getMethod())) {
        request = new BaseRequestImpl(req, resp, acceptEncoding, contentEncoding, certObject, instance);
    } else {
        Navajo in = TmlHttpServlet.constructFromRequest(req);
        request = new BaseRequestImpl(in, req, resp, instance);
    }
    return request;
}
Also used : BaseRequestImpl(com.dexels.navajo.server.listener.http.impl.BaseRequestImpl) AsyncRequest(com.dexels.navajo.script.api.AsyncRequest) Navajo(com.dexels.navajo.document.Navajo)

Example 99 with Navajo

use of com.dexels.navajo.document.Navajo in project navajo by Dexels.

the class ITAsyncClient method testAsync.

@Test
@Ignore
public void testAsync() throws Exception {
    final ManualAsyncClient ac = new AsyncClientImpl();
    String service = "club/InitUpdateClub";
    System.err.println(TestConfig.NAVAJO_TEST_SERVER.getValue());
    ac.setServer(TestConfig.NAVAJO_TEST_SERVER.getValue());
    ac.setUsername(TestConfig.NAVAJO_TEST_USER.getValue());
    ac.setPassword(TestConfig.NAVAJO_TEST_PASS.getValue());
    Navajo input = NavajoFactory.getInstance().createNavajo();
    final NavajoResponseHandler showOutput = new NavajoResponseHandler() {

        @Override
        public void onResponse(Navajo n) {
            logger.info("Navajo finished!");
            try {
                StringWriter sw = new StringWriter();
                n.write(sw);
                logger.info("Response2 : {}", sw);
            } catch (NavajoException e) {
                logger.error("Error: ", e);
            }
        }

        @Override
        public void onFail(Throwable t) {
            logger.error("whoops: ", t);
        }

        @Override
        public Throwable getCaughtException() {
            return null;
        }
    };
    for (int i = 0; i < 10; i++) {
        ac.callService(input, service, showOutput);
        logger.info("Exchange sent");
    }
    Thread.sleep(10000);
}
Also used : ManualAsyncClient(com.dexels.navajo.client.async.ManualAsyncClient) StringWriter(java.io.StringWriter) NavajoException(com.dexels.navajo.document.NavajoException) NavajoResponseHandler(com.dexels.navajo.client.NavajoResponseHandler) Navajo(com.dexels.navajo.document.Navajo) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 100 with Navajo

use of com.dexels.navajo.document.Navajo in project navajo by Dexels.

the class ServerAsyncRunner method run.

/**
 * Main thread
 */
@Override
public void run() {
    try {
        prevTime = System.currentTimeMillis();
        while (isIterating()) {
            if (kill) {
                logger.warn("Kill called in ServerAsyncRunner...");
                myResult.getHeader().setCallBackInterrupt("kill");
                setIterating(false);
            }
            if (myPollingInterval > 0) {
                myNavajo.removeHeader();
                myNavajo.addHeader(myResult.getHeader());
                Navajo temp = doSimpleSend(myNavajo, myMethod);
                if (temp.getMessage("ConditionErrors") != null) {
                    logger.warn("Had ConditionErrors in Asyncsend.. ");
                    killServerAsyncSend();
                } else {
                    poll(temp);
                }
            }
        }
    } catch (ClientException ex) {
        logger.debug("oooops");
        myListener.handleException(ex);
        return;
    }
    if (myListener != null) {
        myListener.handleException(new ClientException(-1, -1, "Operation aborted"));
    }
}
Also used : Navajo(com.dexels.navajo.document.Navajo) ClientException(com.dexels.navajo.client.ClientException)

Aggregations

Navajo (com.dexels.navajo.document.Navajo)258 Message (com.dexels.navajo.document.Message)131 Test (org.junit.Test)109 Property (com.dexels.navajo.document.Property)86 NavajoException (com.dexels.navajo.document.NavajoException)31 Access (com.dexels.navajo.script.api.Access)30 IOException (java.io.IOException)28 StringWriter (java.io.StringWriter)27 TMLExpressionException (com.dexels.navajo.expression.api.TMLExpressionException)26 FunctionInterface (com.dexels.navajo.expression.api.FunctionInterface)25 ImmutableMessage (com.dexels.immutable.api.ImmutableMessage)22 Selection (com.dexels.navajo.document.Selection)22 Header (com.dexels.navajo.document.Header)20 Operand (com.dexels.navajo.document.Operand)20 InputStream (java.io.InputStream)17 UserException (com.dexels.navajo.script.api.UserException)16 Optional (java.util.Optional)16 FatalException (com.dexels.navajo.script.api.FatalException)14 SystemException (com.dexels.navajo.script.api.SystemException)14 ContextExpression (com.dexels.navajo.expression.api.ContextExpression)13