use of com.dexels.navajo.document.stream.events.NavajoStreamEvent in project navajo by Dexels.
the class StreamDocument method messageWithPath.
public static FlowableOperator<NavajoStreamEvent, NavajoStreamEvent> messageWithPath(final String messagePath, final Function<Msg, Msg> operation, boolean filterOthers) {
return new BaseFlowableOperator<NavajoStreamEvent, NavajoStreamEvent>(1) {
@Override
public Subscriber<? super NavajoStreamEvent> apply(Subscriber<? super NavajoStreamEvent> child) throws Exception {
return new Subscriber<NavajoStreamEvent>() {
private final Stack<String> pathStack = new Stack<>();
@Override
public void onComplete() {
operatorComplete(child);
}
@Override
public void onError(Throwable e) {
operatorError(e, child);
}
@Override
public void onNext(NavajoStreamEvent event) {
switch(event.type()) {
case MESSAGE_STARTED:
pathStack.push(event.path());
// operatorRequest(1);
break;
case ARRAY_ELEMENT_STARTED:
// operatorRequest(1);
break;
case MESSAGE:
if (matches(messagePath, pathStack)) {
Msg transformed;
try {
transformed = operation.apply((Msg) event.body());
operatorNext(event, e -> {
return Events.message(transformed, event.path(), event.attributes());
}, child);
} catch (Exception e1) {
logger.error("Unexpected error: ", e1);
}
return;
}
pathStack.pop();
break;
case ARRAY_ELEMENT:
if (matches(messagePath, pathStack)) {
Msg transformed;
try {
transformed = operation.apply((Msg) event.body());
operatorNext(event, e -> {
return Events.arrayElement(transformed, event.attributes());
}, child);
} catch (Exception e1) {
logger.error("Very unexpected exception: ", e1);
e1.printStackTrace();
}
return;
}
break;
// TODO Support these?
case ARRAY_STARTED:
pathStack.push(event.path());
break;
case ARRAY_DONE:
pathStack.pop();
break;
default:
break;
}
if (!filterOthers) {
operatorNext(event, e -> e, child);
} else {
operatorRequest(1);
}
}
private boolean matches(String path, Stack<String> pathStack) {
String joined = String.join("/", pathStack);
return path.equals(joined);
}
@Override
public void onSubscribe(Subscription s) {
operatorSubscribe(s, child);
}
};
}
};
}
use of com.dexels.navajo.document.stream.events.NavajoStreamEvent 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();
}
use of com.dexels.navajo.document.stream.events.NavajoStreamEvent 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.events.NavajoStreamEvent 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