use of com.dexels.navajo.reactive.api.ReactiveResolvedParameters in project navajo by Dexels.
the class HttpPushStreamTransformer method execute.
@Override
public FlowableTransformer<DataItem, DataItem> execute(StreamScriptContext context, Optional<ImmutableMessage> current, ImmutableMessage param) {
ReactiveResolvedParameters resolved = parameters.resolve(context, current, param, metadata);
String name = resolved.paramString("name");
String id = resolved.paramString("id");
String bucket = resolved.paramString("bucket");
String type = resolved.optionalString("type").orElse("application/octetstream");
return flow -> {
Flowable<byte[]> in = flow.map(f -> f.data());
return HttpResourceFactory.getInstance().getHttpResource(name).put(context.getTenant(), bucket, id, type, in).map(status -> ImmutableFactory.empty().with("code", status, Property.INTEGER_PROPERTY)).map(DataItem::of).toFlowable();
};
}
use of com.dexels.navajo.reactive.api.ReactiveResolvedParameters 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.reactive.api.ReactiveResolvedParameters 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));
};
}
use of com.dexels.navajo.reactive.api.ReactiveResolvedParameters in project navajo by Dexels.
the class HttpPushTransformer method execute.
@Override
public FlowableTransformer<DataItem, DataItem> execute(StreamScriptContext context, Optional<ImmutableMessage> current, ImmutableMessage param) {
ReactiveResolvedParameters resolved = parameters.resolve(context, current, param, metadata);
String name = resolved.paramString("name");
int parallel = resolved.optionalInteger("parallel").orElse(1);
HttpResource res = HttpResourceFactory.getInstance().getHttpResource(name);
return flow -> {
if (res == null) {
throw new NullPointerException("Missing http resource: " + name);
}
return flow.map(f -> f.message()).observeOn(Schedulers.io()).map(msg -> {
ReactiveResolvedParameters resInMsg = parameters.resolve(context, Optional.of(msg), ImmutableFactory.empty(), metadata);
String id = resInMsg.paramString("id");
String bucket = resInMsg.paramString("bucket");
String property = resInMsg.paramString("property");
Binary bin = (Binary) msg.columnValue(property);
return res.put(context.getTenant(), bucket, id, bin).map(e -> e.toMessage()).toFlowable();
}).flatMap(f -> f, parallel).map(DataItem::of);
};
}
Aggregations