use of org.glassfish.jersey.media.multipart.FormDataMultiPart in project pulsar by apache.
the class FunctionsImpl method triggerFunctionAsync.
@Override
public CompletableFuture<String> triggerFunctionAsync(String tenant, String namespace, String function, String topic, String triggerValue, String triggerFile) {
final FormDataMultiPart mp = new FormDataMultiPart();
if (triggerFile != null) {
mp.bodyPart(new FileDataBodyPart("dataStream", new File(triggerFile), MediaType.APPLICATION_OCTET_STREAM_TYPE));
}
if (triggerValue != null) {
mp.bodyPart(new FormDataBodyPart("data", triggerValue, MediaType.TEXT_PLAIN_TYPE));
}
if (topic != null && !topic.isEmpty()) {
mp.bodyPart(new FormDataBodyPart("topic", topic, MediaType.TEXT_PLAIN_TYPE));
}
WebTarget path = functions.path(tenant).path(namespace).path(function).path("trigger");
final CompletableFuture<String> future = new CompletableFuture<>();
try {
request(path).async().post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA), new InvocationCallback<String>() {
@Override
public void completed(String response) {
future.complete(response);
}
@Override
public void failed(Throwable throwable) {
log.warn("[{}] Failed to perform http post request: {}", path.getUri(), throwable.getMessage());
future.completeExceptionally(getApiException(throwable.getCause()));
}
});
} catch (PulsarAdminException cae) {
future.completeExceptionally(cae);
}
return future;
}
use of org.glassfish.jersey.media.multipart.FormDataMultiPart in project pulsar by apache.
the class FunctionsImpl method updateFunctionWithUrlAsync.
@Override
public CompletableFuture<Void> updateFunctionWithUrlAsync(FunctionConfig functionConfig, String pkgUrl, UpdateOptions updateOptions) {
final CompletableFuture<Void> future = new CompletableFuture<>();
try {
final FormDataMultiPart mp = new FormDataMultiPart();
mp.bodyPart(new FormDataBodyPart("url", pkgUrl, MediaType.TEXT_PLAIN_TYPE));
mp.bodyPart(new FormDataBodyPart("functionConfig", ObjectMapperFactory.getThreadLocal().writeValueAsString(functionConfig), MediaType.APPLICATION_JSON_TYPE));
UpdateOptionsImpl options = (UpdateOptionsImpl) updateOptions;
if (options != null) {
mp.bodyPart(new FormDataBodyPart("updateOptions", ObjectMapperFactory.getThreadLocal().writeValueAsString(options), MediaType.APPLICATION_JSON_TYPE));
}
WebTarget path = functions.path(functionConfig.getTenant()).path(functionConfig.getNamespace()).path(functionConfig.getName());
return asyncPutRequest(path, Entity.entity(mp, MediaType.MULTIPART_FORM_DATA));
} catch (Exception e) {
future.completeExceptionally(getApiException(e));
}
return future;
}
use of org.glassfish.jersey.media.multipart.FormDataMultiPart in project pulsar by apache.
the class SinksImpl method createSinkWithUrlAsync.
@Override
public CompletableFuture<Void> createSinkWithUrlAsync(SinkConfig sinkConfig, String pkgUrl) {
final FormDataMultiPart mp = new FormDataMultiPart();
mp.bodyPart(new FormDataBodyPart("url", pkgUrl, MediaType.TEXT_PLAIN_TYPE));
mp.bodyPart(new FormDataBodyPart("sinkConfig", new Gson().toJson(sinkConfig), MediaType.APPLICATION_JSON_TYPE));
CompletableFuture<Void> validationFuture = new CompletableFuture<>();
if (!validateSinkName(sinkConfig.getTenant(), sinkConfig.getNamespace(), sinkConfig.getName(), validationFuture)) {
return validationFuture;
}
WebTarget path = sink.path(sinkConfig.getTenant()).path(sinkConfig.getNamespace()).path(sinkConfig.getName());
return asyncPostRequest(path, Entity.entity(mp, MediaType.MULTIPART_FORM_DATA));
}
use of org.glassfish.jersey.media.multipart.FormDataMultiPart in project pulsar by apache.
the class SourcesImpl method createSourceWithUrlAsync.
@Override
public CompletableFuture<Void> createSourceWithUrlAsync(SourceConfig sourceConfig, String pkgUrl) {
final FormDataMultiPart mp = new FormDataMultiPart();
mp.bodyPart(new FormDataBodyPart("url", pkgUrl, MediaType.TEXT_PLAIN_TYPE));
mp.bodyPart(new FormDataBodyPart("sourceConfig", new Gson().toJson(sourceConfig), MediaType.APPLICATION_JSON_TYPE));
WebTarget path = source.path(sourceConfig.getTenant()).path(sourceConfig.getNamespace()).path(sourceConfig.getName());
return asyncPostRequest(path, Entity.entity(mp, MediaType.MULTIPART_FORM_DATA));
}
use of org.glassfish.jersey.media.multipart.FormDataMultiPart in project pulsar by apache.
the class SourcesImpl method updateSourceWithUrlAsync.
@Override
public CompletableFuture<Void> updateSourceWithUrlAsync(SourceConfig sourceConfig, String pkgUrl, UpdateOptions updateOptions) {
final CompletableFuture<Void> future = new CompletableFuture<>();
try {
final FormDataMultiPart mp = new FormDataMultiPart();
mp.bodyPart(new FormDataBodyPart("url", pkgUrl, MediaType.TEXT_PLAIN_TYPE));
mp.bodyPart(new FormDataBodyPart("sourceConfig", new Gson().toJson(sourceConfig), MediaType.APPLICATION_JSON_TYPE));
UpdateOptionsImpl options = (UpdateOptionsImpl) updateOptions;
if (options != null) {
mp.bodyPart(new FormDataBodyPart("updateOptions", ObjectMapperFactory.getThreadLocal().writeValueAsString(options), MediaType.APPLICATION_JSON_TYPE));
}
WebTarget path = source.path(sourceConfig.getTenant()).path(sourceConfig.getNamespace()).path(sourceConfig.getName());
return asyncPutRequest(path, Entity.entity(mp, MediaType.MULTIPART_FORM_DATA));
} catch (Exception e) {
future.completeExceptionally(getApiException(e));
}
return future;
}
Aggregations