Search in sources :

Example 51 with Navajo

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

the class JavaNetNavajoClientImpl method readResponse.

private Navajo readResponse(boolean useCompression, HttpURLConnection con) throws IOException {
    // Check for errors.
    Navajo res = null;
    InputStream inr = con.getInputStream();
    InputStream inraw = null;
    if (con.getResponseCode() >= 400) {
        throw new IOException(readErrorStream(con));
    } else {
        if (useCompression) {
            if (forceGzip) {
                inraw = new GZIPInputStream(inr);
            } else {
                String responseEncoding = con.getHeaderField("Content-Encoding");
                if (("jzlib".equals(responseEncoding) || "deflate".equals(responseEncoding))) {
                    inraw = new InflaterInputStream(inr);
                } else {
                    inraw = inr;
                }
            }
        } else {
            inraw = inr;
        }
    }
    if (inraw != null) {
        res = NavajoFactory.getInstance().createNavajo(inraw);
    }
    return res;
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) GZIPInputStream(java.util.zip.GZIPInputStream) BufferedInputStream(java.io.BufferedInputStream) InflaterInputStream(java.util.zip.InflaterInputStream) InputStream(java.io.InputStream) InflaterInputStream(java.util.zip.InflaterInputStream) Navajo(com.dexels.navajo.document.Navajo) IOException(java.io.IOException)

Example 52 with Navajo

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

the class JavaNetNavajoClientImpl method handleException.

private Navajo handleException(Throwable exception, String host) throws ClientException {
    if (!generateConditionErrors) {
        logger.error("Error: ", exception);
        throw new ClientException(-1, -1, exception.getMessage(), exception);
    }
    Navajo n = null;
    if (exception instanceof java.net.UnknownHostException) {
        logger.warn("Connection problem: UnknownHostException exception to {}!", host, exception);
        n = NavajoFactory.getInstance().createNavajo();
        generateConnectionError(n, 7777777, "Unknown host: " + exception.getMessage());
    } else if (exception instanceof java.net.NoRouteToHostException) {
        logger.warn("Connection problem: NoRouteToHostException exception to {}!", host, exception);
        n = NavajoFactory.getInstance().createNavajo();
        generateConnectionError(n, 55555, "No route to host: " + exception.getMessage());
    } else if (exception instanceof java.net.SocketTimeoutException || exception instanceof java.net.ConnectException || exception instanceof java.net.NoRouteToHostException) {
        logger.warn("Connection problem: SocketTimeoutException exception to {}!", host, exception);
        n = NavajoFactory.getInstance().createNavajo();
        generateConnectionError(n, 55555, "Error on getting response data: " + exception.getMessage());
    } else if (exception instanceof javax.net.ssl.SSLHandshakeException) {
        logger.warn("Connection problem: SSLHandshakeException exception to {}!", host, exception);
        n = NavajoFactory.getInstance().createNavajo();
        generateConnectionError(n, 666666, "SSL fout " + exception.getMessage());
    }
    if (n != null) {
        return n;
    }
    logger.warn("Connection problem: Exception {} to {}!", exception.getMessage(), host, exception);
    throw new ClientException(-1, -1, exception.getMessage(), exception);
}
Also used : ClientException(com.dexels.navajo.client.ClientException) Navajo(com.dexels.navajo.document.Navajo)

Example 53 with Navajo

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

the class TestClient method testClientBig.

@Test(timeout = 20000)
@Ignore
public void testClientBig() throws ClientException {
    NavajoClient cl = new JavaNetNavajoClientImpl();
    cl.setAllowCompression(true);
    cl.setForceGzip(true);
    cl.setServerUrls(new String[] { TestConfig.NAVAJO_TEST_SERVER.getValue() });
    cl.setUsername(TestConfig.NAVAJO_TEST_USER.getValue());
    cl.setPassword(TestConfig.NAVAJO_TEST_PASS.getValue());
    cl.useBasicAuthentication(true);
    Navajo nc = NavajoFactory.getInstance().createNavajo();
    Navajo result = cl.doSimpleSend(nc, "club/InitUpdateClub");
    result.getMessage("Club").getProperty("ClubIdentifier").setAnyValue("BBFX31R");
    cl.doSimpleSend(result, "club/ProcessQueryClub");
}
Also used : NavajoClient(com.dexels.navajo.client.NavajoClient) Navajo(com.dexels.navajo.document.Navajo) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 54 with Navajo

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

the class NavajoRemoteContext method callService.

/* (non-Javadoc)
	 * @see com.dexels.navajo.client.context.ClientContext#callService(java.lang.String, com.dexels.navajo.document.Navajo)
	 */
@Override
public void callService(String service, String tenant, String username, String password, Navajo input) throws ClientException {
    if (myClient == null) {
        throw new ClientException(1, -1, "No client has been set up!");
    }
    if (input == null) {
        input = NavajoFactory.getInstance().createNavajo();
    }
    Header outHeader = input.getHeader();
    if (outHeader == null) {
        outHeader = NavajoFactory.getInstance().createHeader(input, service, username, password, -1);
        input.addHeader(outHeader);
    }
    if (debugAll) {
        outHeader.setHeaderAttribute("fullLog", "true");
    }
    long time = System.currentTimeMillis();
    Navajo n = myClient.doSimpleSend(input, service);
    logger.debug("Send complete!");
    n.getHeader().setRPCName(service);
    putNavajo(service, n);
    logger.debug("Call took: {} millis!", System.currentTimeMillis() - time);
}
Also used : Header(com.dexels.navajo.document.Header) ClientException(com.dexels.navajo.client.ClientException) Navajo(com.dexels.navajo.document.Navajo)

Example 55 with Navajo

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

the class TestAsyncService method main.

public static void main(String[] args) throws ClientException {
    TestAsyncService tas = new TestAsyncService();
    NavajoClientFactory.getClient().setUsername("");
    NavajoClientFactory.getClient().setPassword("");
    NavajoClientFactory.getClient().setServerUrl("http://localhost:8080/navajo/KNZB");
    final Navajo n = NavajoClientFactory.getClient().doSimpleSend(null, "InitAsync");
    tas.test(n);
}
Also used : Navajo(com.dexels.navajo.document.Navajo)

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