use of com.dexels.navajo.document.stream.xml.XML in project navajo by Dexels.
the class ITJettyClient method testJettyCLient.
@Test
public void testJettyCLient() throws Exception {
JettyClient jc = new JettyClient();
Flowable<byte[]> in = Flowable.<NavajoStreamEvent>empty().compose(StreamDocument.inNavajo(service, Optional.of(username), Optional.of(password))).lift(StreamDocument.serialize());
byte[] result = jc.callWithBodyToStream(uri, req -> req.header("X-Navajo-Reactive", "true").header("X-Navajo-Service", service).header("X-Navajo-Username", username).header("X-Navajo-Password", password).header("Accept-Encoding", null).method(HttpMethod.POST), in, "text/xml;charset=utf-8").reduce(new ByteArrayOutputStream(), (stream, b) -> {
stream.write(b);
return stream;
}).map(stream -> stream.toByteArray()).blockingGet();
logger.info("result: {}", new String(result));
Assert.assertTrue(result.length > 5000);
jc.close();
}
use of com.dexels.navajo.document.stream.xml.XML in project navajo by Dexels.
the class TestRx method repro.
@Test
public void repro() throws IOException {
File compressed = File.createTempFile("dump", ".xml.deflated");
File uncompressed = File.createTempFile("dump", ".xml");
InputStream resourceAsStream = TestRx.class.getClassLoader().getResourceAsStream("tml_with_binary.xml");
Bytes.from(resourceAsStream, 8192).doOnSubscribe(e -> System.err.println("Ataaaa")).doOnNext(b -> System.err.println("Bytes: " + b.length)).subscribe(StreamDocument.dumpToFile(uncompressed.getAbsolutePath()));
System.err.println("Uncompressed file at: " + uncompressed.getAbsolutePath());
Bytes.from(TestRx.class.getClassLoader().getResourceAsStream("tml_with_binary.xml"), 8192).compose(StreamCompress.deflate()).subscribe(StreamDocument.dumpToFile(compressed.getAbsolutePath()));
System.err.println("Compressed file at: " + compressed.getAbsolutePath());
// 1,560
Assert.assertTrue(uncompressed.exists());
System.err.println("Compressed: " + compressed.length());
System.err.println("Uncompressed: " + uncompressed.length());
Assert.assertTrue(uncompressed.length() == 5258);
Assert.assertTrue(compressed.length() < uncompressed.length());
// compressed.delete();
// uncompressed.delete();
}
use of com.dexels.navajo.document.stream.xml.XML in project navajo by Dexels.
the class TestHttp method testHttpGet.
@Test
public void testHttpGet() throws Exception {
JettyClient jc = new JettyClient();
// jc.c
String weather = jc.callWithoutBodyToStream("http://api.openweathermap.org/data/2.5/weather?q=Amsterdam&APPID=c9a22840a45f9da6f235c718475c4f08&mode=xml", e -> e).lift(XML.parseFlowable(10)).flatMap(x -> x).filter(e -> e.getType() == XmlEventTypes.START_ELEMENT).filter(e -> e.getText().equals("weather")).firstElement().map(xml -> xml.getAttributes().get("value")).blockingGet();
logger.info("Weather: {}", weather);
// Not really a good unit test (... or is it?)
}
use of com.dexels.navajo.document.stream.xml.XML in project navajo by Dexels.
the class CallRemoteSource method execute.
@Override
public Flowable<DataItem> execute(StreamScriptContext context, Optional<ImmutableMessage> current, ImmutableMessage param) {
ReactiveResolvedParameters resolved = params.resolve(context, current, ImmutableFactory.empty(), metadata);
String server = resolved.paramString("server");
String username = resolved.paramString("username");
String password = resolved.paramString("password");
final String service = resolved.paramString("service");
Flowable<NavajoStreamEvent> flow = client.callWithBodyToStream(server, e -> e.header("X-Navajo-Username", username).header("X-Navajo-Password", password).header("X-Navajo-Service", service).method(HttpMethod.POST), Flowable.<NavajoStreamEvent>empty().compose(StreamDocument.inNavajo(service, Optional.of(username), Optional.of(password))).lift(StreamDocument.serialize()), "text/xml").lift(XML.parseFlowable(10)).concatMap(e -> e).lift(StreamDocument.parse()).concatMap(e -> e).filter(e -> e.type() != NavajoStreamEvent.NavajoEventTypes.NAVAJO_STARTED && e.type() != NavajoStreamEvent.NavajoEventTypes.NAVAJO_DONE);
Flowable<DataItem> fw = Flowable.just(DataItem.ofEventStream(flow));
return fw;
}
use of com.dexels.navajo.document.stream.xml.XML in project navajo by Dexels.
the class CallRemoteTransformer method execute.
@Override
public FlowableTransformer<DataItem, DataItem> execute(StreamScriptContext context, Optional<ImmutableMessage> current, ImmutableMessage param) {
ReactiveResolvedParameters resolved = parameters.resolve(context, current, param, metadata);
String server = resolved.paramString("server");
String username = resolved.paramString("username");
String password = resolved.paramString("password");
final String service = resolved.paramString("service");
return flow -> {
Flowable<NavajoStreamEvent> result = client.callWithBodyToStream(server, e -> e.header("X-Navajo-Username", username).header("X-Navajo-Password", password).header("X-Navajo-Service", service), flow.map(di -> di.eventStream()).concatMap(e -> e).lift(StreamDocument.serialize()), "text/xml").lift(XML.parseFlowable(10)).concatMap(e -> e).lift(StreamDocument.parse()).concatMap(e -> e).filter(e -> e.type() != NavajoStreamEvent.NavajoEventTypes.NAVAJO_STARTED && e.type() != NavajoStreamEvent.NavajoEventTypes.NAVAJO_DONE);
return Flowable.just(DataItem.ofEventStream(result));
};
}
Aggregations