Search in sources :

Example 1 with ManualAsyncClient

use of com.dexels.navajo.client.async.ManualAsyncClient 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 2 with ManualAsyncClient

use of com.dexels.navajo.client.async.ManualAsyncClient in project navajo by Dexels.

the class ITAsyncClient method testPost.

@Test
public void testPost() throws Exception {
    final ManualAsyncClient ac = new AsyncClientImpl();
    String service = "ProcessPrintGenericBirt";
    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(getClass().getResourceAsStream("test.xml"));
    final NavajoResponseHandler showOutput = new NavajoResponseHandler() {

        @Override
        public void onResponse(Navajo n) {
            logger.info("Navajo finished!");
            try {
                StringWriter sw = new StringWriter();
                n.write(sw);
                Binary b = (Binary) n.getMessage("Result").getProperty("Data").getTypedValue();
                BinaryOpenerFactory.getInstance().open(b);
                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;
        }
    };
    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) Binary(com.dexels.navajo.document.types.Binary) Test(org.junit.Test)

Example 3 with ManualAsyncClient

use of com.dexels.navajo.client.async.ManualAsyncClient in project navajo by Dexels.

the class ITAsyncClient method test.

@Test
@Ignore
public void test() throws Exception {
    final ManualAsyncClient ac = new AsyncClientImpl();
    ac.setClientCertificate("SunX509", "JKS", getClass().getClassLoader().getResourceAsStream("client.jks"), "password".toCharArray());
// TODO make actual test
}
Also used : ManualAsyncClient(com.dexels.navajo.client.async.ManualAsyncClient) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 4 with ManualAsyncClient

use of com.dexels.navajo.client.async.ManualAsyncClient in project navajo by Dexels.

the class NavajoMap method setDoSend.

/**
 * Use this method to call another Navajo webservice. If server is not specified, the Navajo server that is used to handle this request is also used to
 * handle the new request.
 *
 * @param method
 * @throws UserException
 */
public void setDoSend(String method, Navajo od) throws UserException, ConditionErrorException, SystemException {
    if (serviceCalled) {
        logger.warn("DO NOT USE A NAVAJOMAP TO CALL A SECOND WEBSERVICE, USE NEW NAVAJOMAP INSTEAD");
    }
    // Reset current msgPointer when performing new doSend.
    msgPointer = null;
    setMethod(method);
    this.outDoc = od;
    this.username = (username == null) ? this.access.rpcUser : username;
    this.password = (password == null) ? this.access.rpcPwd : password;
    this.method = method;
    if (password == null)
        password = "";
    try {
        if (this.resource != null) {
            serviceCalled = true;
            AsyncClient ac = NavajoClientResourceManager.getInstance().getAsyncClient(this.resource);
            if (ac == null) {
                throw new UserException(-1, "No external resource found for: " + this.resource);
            }
            ac.callService(outDoc, method, this);
        } else if (server != null) {
            // External request.
            try {
                ManualAsyncClient ac = AsyncClientFactory.getManualInstance();
                if (ac == null) {
                    logger.warn("unable to find async client - cannot perform navajomap call!");
                    throw new UserException(-1, "AsyncClient null");
                }
                String server = this.server.startsWith("http") ? this.server : "http://" + this.server;
                Integer timeout = null;
                if (serverTimeout > -1) {
                    timeout = serverTimeout;
                }
                ac.callService(server, username, password, outDoc, method, this, timeout);
            } catch (Exception e) {
                throw new UserException(-1, e.getMessage(), e);
            }
            serviceCalled = true;
        } else // Internal request.
        {
            inDoc = null;
            serviceFinished = false;
            if (block) {
                this.run();
            } else {
                SchedulerRegistry.submit(this, lowPriority);
            }
            serviceCalled = true;
            if (getException() != null) {
                if (getException() instanceof ConditionErrorException) {
                    throw (ConditionErrorException) getException();
                } else if (getException() instanceof UserException) {
                    throw (UserException) getException();
                } else if (getException() instanceof SystemException) {
                    throw (SystemException) getException();
                } else {
                    throw new SystemException(-1, "", getException());
                }
            }
        }
    } catch (NavajoException | IOException e) {
        throw new SystemException("Error connecting to remote server", e);
    }
}
Also used : ConditionErrorException(com.dexels.navajo.server.ConditionErrorException) ManualAsyncClient(com.dexels.navajo.client.async.ManualAsyncClient) SystemException(com.dexels.navajo.script.api.SystemException) NavajoException(com.dexels.navajo.document.NavajoException) UserException(com.dexels.navajo.script.api.UserException) IOException(java.io.IOException) AsyncClient(com.dexels.navajo.client.async.AsyncClient) ManualAsyncClient(com.dexels.navajo.client.async.ManualAsyncClient) NavajoException(com.dexels.navajo.document.NavajoException) AuthorizationException(com.dexels.navajo.script.api.AuthorizationException) UserException(com.dexels.navajo.script.api.UserException) MappableException(com.dexels.navajo.script.api.MappableException) IOException(java.io.IOException) SystemException(com.dexels.navajo.script.api.SystemException) ConditionErrorException(com.dexels.navajo.server.ConditionErrorException)

Aggregations

ManualAsyncClient (com.dexels.navajo.client.async.ManualAsyncClient)4 NavajoException (com.dexels.navajo.document.NavajoException)3 Test (org.junit.Test)3 NavajoResponseHandler (com.dexels.navajo.client.NavajoResponseHandler)2 Navajo (com.dexels.navajo.document.Navajo)2 StringWriter (java.io.StringWriter)2 Ignore (org.junit.Ignore)2 AsyncClient (com.dexels.navajo.client.async.AsyncClient)1 Binary (com.dexels.navajo.document.types.Binary)1 AuthorizationException (com.dexels.navajo.script.api.AuthorizationException)1 MappableException (com.dexels.navajo.script.api.MappableException)1 SystemException (com.dexels.navajo.script.api.SystemException)1 UserException (com.dexels.navajo.script.api.UserException)1 ConditionErrorException (com.dexels.navajo.server.ConditionErrorException)1 IOException (java.io.IOException)1