Search in sources :

Example 1 with JettyClient

use of com.dexels.navajo.client.stream.jetty.JettyClient in project navajo by Dexels.

the class TestHttp method testBiggerDownload.

@Test
public void testBiggerDownload() throws Exception {
    String url = "https://www.ad.nl/home/rss.xml";
    JettyClient jc = new JettyClient();
    long l = jc.callWithoutBodyToStream(url, e -> e).lift(XML.parseFlowable(10)).flatMap(x -> x).count().blockingGet();
    logger.info("> {}", l);
    Assert.assertTrue(l > 1000);
}
Also used : JettyClient(com.dexels.navajo.client.stream.jetty.JettyClient) Test(org.junit.Test)

Example 2 with JettyClient

use of com.dexels.navajo.client.stream.jetty.JettyClient in project navajo by Dexels.

the class ResourceComponent method activate.

public void activate(Map<String, Object> settings) throws Exception {
    client = new JettyClient();
    String url = (String) settings.get("url");
    String publicurl = (String) settings.get("publicurl");
    this.authorization = (String) settings.get("authorization");
    this.secret = Optional.ofNullable((String) settings.get("secret"));
    if (settings.containsKey("timeout_ms")) {
        timeout = Long.parseLong((String) settings.get("timeout_ms"));
    }
    if (settings.containsKey("timeout_idle_ms")) {
        idle_timeout = Long.parseLong((String) settings.get("timeout_idle_ms"));
    }
    this.url = url.endsWith("/") ? url : url + "/";
    if (publicurl != null) {
        this.publicUrl = publicurl.endsWith("/") ? publicurl : publicurl + "/";
    } else {
        this.publicUrl = url.endsWith("/") ? url : url + "/";
    }
}
Also used : JettyClient(com.dexels.navajo.client.stream.jetty.JettyClient)

Example 3 with JettyClient

use of com.dexels.navajo.client.stream.jetty.JettyClient in project navajo by Dexels.

the class SwiftReactiveImpl method createClientFromURL.

private JettyClient createClientFromURL(String endpoint) throws Exception {
    JettyClient client = new JettyClient();
    this.endpoint = endpoint;
    // }
    return client;
}
Also used : JettyClient(com.dexels.navajo.client.stream.jetty.JettyClient)

Example 4 with JettyClient

use of com.dexels.navajo.client.stream.jetty.JettyClient 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 5 with JettyClient

use of com.dexels.navajo.client.stream.jetty.JettyClient in project navajo by Dexels.

the class ITJettyClient method testNavajoClient.

@Test
public void testNavajoClient() throws Exception {
    JettyClient client = new JettyClient();
    Flowable<NavajoStreamEvent> in = Flowable.<NavajoStreamEvent>empty().compose(StreamDocument.inNavajo(service, Optional.of(username), Optional.of(password)));
    Flowable<byte[]> inStream = in.lift(StreamDocument.serialize()).doOnNext(e -> logger.debug("Sending: {}", new String(e, StandardCharsets.UTF_8)));
    Navajo n = client.callWithBodyToStream(uri, req -> req.header("X-Navajo-Reactive", "true").header("X-Navajo-Service", service).header("X-Navajo-Instance", "").header("X-Navajo-Username", username).header("X-Navajo-Password", password).method(HttpMethod.POST), inStream, "text/xml;charset=utf-8").lift(XML.parseFlowable(5)).concatMap(e -> e).lift(StreamDocument.parse()).concatMap(e -> e).compose(StreamDocument.inNavajo(service, Optional.of(username), Optional.of(password))).toObservable().compose(StreamDocument.domStreamCollector()).blockingFirst();
    StringWriter sw = new StringWriter();
    n.write(sw);
    logger.info("{}", sw);
    client.close();
}
Also used : NavajoReactiveJettyClient(com.dexels.navajo.client.stream.jetty.NavajoReactiveJettyClient) JettyClient(com.dexels.navajo.client.stream.jetty.JettyClient) StringWriter(java.io.StringWriter) Navajo(com.dexels.navajo.document.Navajo) NavajoStreamEvent(com.dexels.navajo.document.stream.events.NavajoStreamEvent) Test(org.junit.Test)

Aggregations

JettyClient (com.dexels.navajo.client.stream.jetty.JettyClient)7 Test (org.junit.Test)4 NavajoReactiveJettyClient (com.dexels.navajo.client.stream.jetty.NavajoReactiveJettyClient)2 Navajo (com.dexels.navajo.document.Navajo)2 NavajoStreamEvent (com.dexels.navajo.document.stream.events.NavajoStreamEvent)2 XML (com.dexels.navajo.document.stream.xml.XML)2 Flowable (io.reactivex.Flowable)2 StringWriter (java.io.StringWriter)2 Assert (org.junit.Assert)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 StreamDocument (com.dexels.navajo.document.stream.StreamDocument)1 XmlEventTypes (com.dexels.navajo.document.stream.xml.XMLEvent.XmlEventTypes)1 TestConfig (com.dexels.navajo.runtime.config.TestConfig)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Optional (java.util.Optional)1 TimeUnit (java.util.concurrent.TimeUnit)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 HttpMethod (org.eclipse.jetty.http.HttpMethod)1