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);
}
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);
}
}
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;
}
}
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());
}
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);
}
Aggregations