Search in sources :

Example 76 with Binary

use of com.dexels.navajo.document.types.Binary 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 77 with Binary

use of com.dexels.navajo.document.types.Binary in project navajo by Dexels.

the class BasePropertyImpl method setValue.

/**
 * @deprecated Not really deprecated but needs a less memory intensive
 *             rewrite.
 * @see com.dexels.navajo.document.Property#setValue(java.net.URL)
 */
@Deprecated
private final void setValue(URL url, Boolean internal) {
    Object old = null;
    if (hasPropertyDataListeners()) {
        old = getTypedValue();
    }
    try {
        if (type.equals(BINARY_PROPERTY)) {
            InputStream in = url.openStream();
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            byte[] data;
            byte[] buffer = new byte[1024];
            int available;
            while ((available = in.read(buffer)) > -1) {
                bos.write(buffer, 0, available);
            }
            bos.flush();
            data = bos.toByteArray();
            bos.close();
            in.close();
            setValue(new Binary(data));
        } else {
            logger.info("-------> setValue(URL) not supported for other property types than BINARY_PROPERTY");
        }
    } catch (Exception e) {
        logger.error("Error: ", e);
    }
    if (hasPropertyDataListeners()) {
        firePropertyChanged(PROPERTY_VALUE, old, getTypedValue(), internal);
    }
}
Also used : InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Binary(com.dexels.navajo.document.types.Binary) PropertyTypeException(com.dexels.navajo.document.PropertyTypeException) NavajoException(com.dexels.navajo.document.NavajoException) ParseException(java.text.ParseException) ExpressionChangedException(com.dexels.navajo.document.ExpressionChangedException) IOException(java.io.IOException)

Example 78 with Binary

use of com.dexels.navajo.document.types.Binary in project navajo by Dexels.

the class CallService method evaluate.

@Override
public Object evaluate() throws TMLExpressionException {
    Operand result = null;
    String serviceName = getStringOperand(0);
    String expression = getOperands().size() == 1 ? null : getStringOperand(1);
    if (getNavajo() == null) {
        throw new TMLExpressionException("No Navajo Request object available.");
    }
    if (getOperands().size() > 2) {
        throw new TMLExpressionException("Invalid number of parameters.");
    }
    try {
        Navajo response = getNavajo().getNavajo(serviceName);
        if (response == null) {
            DispatcherInterface dispatcher = DispatcherFactory.getInstance();
            Navajo input = getNavajo().copy();
            input.getHeader().setRPCName(serviceName);
            response = dispatcher.handle(input, this.getAccess().getTenant(), true);
            getNavajo().addNavajo(serviceName, response);
        }
        if (expression == null) {
            Binary bbb = new Binary();
            OutputStream os = bbb.getOutputStream();
            response.write(os);
            os.flush();
            os.close();
            return bbb;
        } else {
            result = Expression.evaluate(expression, response);
        }
    } catch (Exception ex) {
        logger.error("Error: ", ex);
    }
    if (result != null) {
        return result.value;
    } else {
        return null;
    }
}
Also used : DispatcherInterface(com.dexels.navajo.server.DispatcherInterface) Operand(com.dexels.navajo.document.Operand) OutputStream(java.io.OutputStream) Navajo(com.dexels.navajo.document.Navajo) Binary(com.dexels.navajo.document.types.Binary) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException)

Example 79 with Binary

use of com.dexels.navajo.document.types.Binary in project navajo by Dexels.

the class TestBinary method testEmptyBinary.

@Test
public void testEmptyBinary() {
    Binary b1 = new Binary();
    Assert.assertNull(b1.getData());
}
Also used : Binary(com.dexels.navajo.document.types.Binary) Test(org.junit.Test)

Example 80 with Binary

use of com.dexels.navajo.document.types.Binary in project navajo by Dexels.

the class TestBinary method testBinaryIterator.

@Test
public void testBinaryIterator() {
    NavajoFactory.getInstance().setSandboxMode(false);
    Binary b1 = new Binary(getClass().getResourceAsStream("datasources.xml"));
    int i = 0;
    for (byte[] e : b1.getDataAsIterable(1024)) {
        i += e.length;
    }
    Assert.assertEquals(b1.getLength(), i);
}
Also used : Binary(com.dexels.navajo.document.types.Binary) Test(org.junit.Test)

Aggregations

Binary (com.dexels.navajo.document.types.Binary)139 Test (org.junit.Test)38 IOException (java.io.IOException)32 TMLExpressionException (com.dexels.navajo.expression.api.TMLExpressionException)26 File (java.io.File)25 Ignore (org.junit.Ignore)17 Property (com.dexels.navajo.document.Property)16 URL (java.net.URL)16 UserException (com.dexels.navajo.script.api.UserException)14 OutputStream (java.io.OutputStream)13 FileOutputStream (java.io.FileOutputStream)12 Navajo (com.dexels.navajo.document.Navajo)11 MappableException (com.dexels.navajo.script.api.MappableException)11 FileInputStream (java.io.FileInputStream)9 InputStream (java.io.InputStream)9 Message (com.dexels.navajo.document.Message)8 StringWriter (java.io.StringWriter)8 OutputStreamWriter (java.io.OutputStreamWriter)7 NavajoException (com.dexels.navajo.document.NavajoException)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6