Search in sources :

Example 1 with XML

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();
}
Also used : NavajoReactiveJettyClient(com.dexels.navajo.client.stream.jetty.NavajoReactiveJettyClient) JettyClient(com.dexels.navajo.client.stream.jetty.JettyClient) Logger(org.slf4j.Logger) ByteArrayOutputStream(java.io.ByteArrayOutputStream) StringWriter(java.io.StringWriter) LoggerFactory(org.slf4j.LoggerFactory) NavajoReactiveJettyClient(com.dexels.navajo.client.stream.jetty.NavajoReactiveJettyClient) Test(org.junit.Test) StandardCharsets(java.nio.charset.StandardCharsets) HttpMethod(org.eclipse.jetty.http.HttpMethod) NavajoStreamEvent(com.dexels.navajo.document.stream.events.NavajoStreamEvent) Flowable(io.reactivex.Flowable) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Optional(java.util.Optional) XML(com.dexels.navajo.document.stream.xml.XML) JettyClient(com.dexels.navajo.client.stream.jetty.JettyClient) StreamDocument(com.dexels.navajo.document.stream.StreamDocument) TestConfig(com.dexels.navajo.runtime.config.TestConfig) Assert(org.junit.Assert) Navajo(com.dexels.navajo.document.Navajo) ByteArrayOutputStream(java.io.ByteArrayOutputStream) NavajoStreamEvent(com.dexels.navajo.document.stream.events.NavajoStreamEvent) Test(org.junit.Test)

Example 2 with XML

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();
}
Also used : Arrays(java.util.Arrays) GZIPInputStream(java.util.zip.GZIPInputStream) BufferedInputStream(java.io.BufferedInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) StreamCompress(com.dexels.navajo.document.stream.StreamCompress) BufferedOutputStream(java.io.BufferedOutputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) Flowable(io.reactivex.Flowable) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) XML(com.dexels.navajo.document.stream.xml.XML) Observable(io.reactivex.Observable) Subscriber(org.reactivestreams.Subscriber) OutputStream(java.io.OutputStream) XMLEvent(com.dexels.navajo.document.stream.xml.XMLEvent) IOException(java.io.IOException) Test(org.junit.Test) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) TimeUnit(java.util.concurrent.TimeUnit) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) Disposable(io.reactivex.disposables.Disposable) Ignore(org.junit.Ignore) Subscription(org.reactivestreams.Subscription) StreamDocument(com.dexels.navajo.document.stream.StreamDocument) Assert(org.junit.Assert) Bytes(com.github.davidmoten.rx2.Bytes) InputStream(java.io.InputStream) GZIPInputStream(java.util.zip.GZIPInputStream) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) File(java.io.File) Test(org.junit.Test)

Example 3 with XML

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?)
}
Also used : JettyClient(com.dexels.navajo.client.stream.jetty.JettyClient) TimeUnit(java.util.concurrent.TimeUnit) Logger(org.slf4j.Logger) Flowable(io.reactivex.Flowable) XmlEventTypes(com.dexels.navajo.document.stream.xml.XMLEvent.XmlEventTypes) LoggerFactory(org.slf4j.LoggerFactory) XML(com.dexels.navajo.document.stream.xml.XML) Test(org.junit.Test) JettyClient(com.dexels.navajo.client.stream.jetty.JettyClient) Assert(org.junit.Assert) Test(org.junit.Test)

Example 4 with XML

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;
}
Also used : ReactiveResolvedParameters(com.dexels.navajo.reactive.api.ReactiveResolvedParameters) Type(com.dexels.navajo.document.stream.DataItem.Type) ReactiveParameters(com.dexels.navajo.reactive.api.ReactiveParameters) DataItem(com.dexels.navajo.document.stream.DataItem) StreamScriptContext(com.dexels.navajo.document.stream.api.StreamScriptContext) ImmutableFactory(com.dexels.immutable.factory.ImmutableFactory) SourceMetadata(com.dexels.navajo.reactive.api.SourceMetadata) HttpMethod(org.eclipse.jetty.http.HttpMethod) NavajoStreamEvent(com.dexels.navajo.document.stream.events.NavajoStreamEvent) ReactiveResolvedParameters(com.dexels.navajo.reactive.api.ReactiveResolvedParameters) Flowable(io.reactivex.Flowable) Optional(java.util.Optional) XML(com.dexels.navajo.document.stream.xml.XML) JettyClient(com.dexels.navajo.client.stream.jetty.JettyClient) StreamDocument(com.dexels.navajo.document.stream.StreamDocument) ImmutableMessage(com.dexels.immutable.api.ImmutableMessage) ReactiveSource(com.dexels.navajo.reactive.api.ReactiveSource) DataItem(com.dexels.navajo.document.stream.DataItem) NavajoStreamEvent(com.dexels.navajo.document.stream.events.NavajoStreamEvent)

Example 5 with XML

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));
    };
}
Also used : ReactiveResolvedParameters(com.dexels.navajo.reactive.api.ReactiveResolvedParameters) ReactiveTransformer(com.dexels.navajo.reactive.api.ReactiveTransformer) ReactiveParameters(com.dexels.navajo.reactive.api.ReactiveParameters) DataItem(com.dexels.navajo.document.stream.DataItem) TransformerMetadata(com.dexels.navajo.reactive.api.TransformerMetadata) StreamScriptContext(com.dexels.navajo.document.stream.api.StreamScriptContext) FlowableTransformer(io.reactivex.FlowableTransformer) NavajoStreamEvent(com.dexels.navajo.document.stream.events.NavajoStreamEvent) ReactiveResolvedParameters(com.dexels.navajo.reactive.api.ReactiveResolvedParameters) Flowable(io.reactivex.Flowable) Optional(java.util.Optional) XML(com.dexels.navajo.document.stream.xml.XML) JettyClient(com.dexels.navajo.client.stream.jetty.JettyClient) StreamDocument(com.dexels.navajo.document.stream.StreamDocument) ImmutableMessage(com.dexels.immutable.api.ImmutableMessage) Flowable(io.reactivex.Flowable)

Aggregations

XML (com.dexels.navajo.document.stream.xml.XML)5 Flowable (io.reactivex.Flowable)5 JettyClient (com.dexels.navajo.client.stream.jetty.JettyClient)4 StreamDocument (com.dexels.navajo.document.stream.StreamDocument)4 NavajoStreamEvent (com.dexels.navajo.document.stream.events.NavajoStreamEvent)3 Optional (java.util.Optional)3 Assert (org.junit.Assert)3 Test (org.junit.Test)3 ImmutableMessage (com.dexels.immutable.api.ImmutableMessage)2 DataItem (com.dexels.navajo.document.stream.DataItem)2 StreamScriptContext (com.dexels.navajo.document.stream.api.StreamScriptContext)2 ReactiveParameters (com.dexels.navajo.reactive.api.ReactiveParameters)2 ReactiveResolvedParameters (com.dexels.navajo.reactive.api.ReactiveResolvedParameters)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 TimeUnit (java.util.concurrent.TimeUnit)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 ImmutableFactory (com.dexels.immutable.factory.ImmutableFactory)1 NavajoReactiveJettyClient (com.dexels.navajo.client.stream.jetty.NavajoReactiveJettyClient)1 Navajo (com.dexels.navajo.document.Navajo)1 Type (com.dexels.navajo.document.stream.DataItem.Type)1