@JsOverlay public final void send(ArrayBufferView data) { send(Js.<XMLHttpRequest.SendDataUnionType>uncheckedCast(data)); }
private XMLHttpRequest newXhr(String url, HttpMethod method, Operation operation, OnError error, OnLoad onLoad) { XMLHttpRequest xhr = new XMLHttpRequest(); // The order of the XHR methods is important! Do not rearrange the code unless you know what you're doing! xhr.onload = event -> onLoad.onLoad(xhr); xhr.addEventListener("error", //NON-NLS event -> handleErrorCodes(url, (int) xhr.status, operation, error), false); xhr.open(method.name(), url, true); xhr.setRequestHeader(X_MANAGEMENT_CLIENT_NAME.header(), HEADER_MANAGEMENT_CLIENT_VALUE); String bearerToken = getBearerToken(); if (bearerToken != null) { xhr.setRequestHeader("Authorization", "Bearer " + bearerToken); } xhr.withCredentials = true; return xhr; }
public FileItem cancel() { if (request != null) { canceled = true; request.abort(); } return this; }
}; request.addEventListener("readystatechange", evt -> { if (request.readyState == 4) { if (request.status == 200) request.open("post", options.getUrl()); FormData formData = new FormData(); formData.append(file.name, file); beforeUploadHandlers.forEach(handler -> handler.onBeforeUpload(request)); request.send(formData);
Map<String, String> headers = new HashMap<>(); for (Param h : headerParams) headers.put(h.k, Objects.toString(h.v)); for (Map.Entry<String, String> h : headers.entrySet()) xhr.setRequestHeader(h.getKey(), h.getValue()); }; em.setCancellable(() -> { if (xhr.readyState != XMLHttpRequest.DONE) xhr.abort(); }); xhr.setRequestHeader(CONTENT_TYPE, MULTIPART_FORM_DATA); FormData form = new FormData(); formParams.forEach(p -> form.append(p.k, Objects.toString(p.v))); xhr.send(form); } else { if (!headers.containsKey(CONTENT_TYPE)) xhr.setRequestHeader(CONTENT_TYPE, APPLICATION_JSON); if (!headers.containsKey(ACCEPT)) xhr.setRequestHeader(ACCEPT, APPLICATION_JSON); if (data != null) xhr.send(Global.JSON.stringify(data)); else xhr.send();
@JsIgnore public void download(Operation operation, Consumer<String> success) { Operation downloadOperation = runAs(operation); String url = downloadUrl(downloadOperation); XMLHttpRequest request = newXhr(url, GET, downloadOperation, exceptionCallback, xhr -> { int status = (int) xhr.status; String responseText = xhr.responseText; if (status == 200) { success.accept(responseText); } else { handleErrorCodes(url, status, downloadOperation, exceptionCallback); } }); request.setRequestHeader(ACCEPT.header(), APPLICATION_DMR_ENCODED); request.setRequestHeader(CONTENT_TYPE.header(), APPLICATION_DMR_ENCODED); request.send(); // Downloads are not supported in macros! }
public FileItem(File file, UploadOptions options) { this.file = file; this.options = options; initFileImage(); initFileTitle(); initFileSizeParagraph(); initFooter(); initProgress(); initThumbnail(); if (isExceedsMaxFile()) { invalidate("File is too large, maximum file size is " + formatSize(options.getMaxFileSize())); } request =new XMLHttpRequest(); init(this); }
}; request.addEventListener("readystatechange", evt -> { if (request.readyState == 4) { if (request.status == 200) request.open("post", options.getUrl()); FormData formData = new FormData(); formData.append(file.name, file); beforeUploadHandlers.forEach(handler -> handler.onBeforeUpload(request)); request.send(formData);
private Single<ModelNode> dmr(Operation operation) { Operation dmrOperation = runAs(operation); // runAs might mutate the operation, so do it synchronously boolean get = GetOperation.isSupported(dmrOperation.getName()); String url = get ? operationUrl(dmrOperation) : endpoints.dmr(); HttpMethod method = get ? GET : POST; // ^-- those eager fields are useful if we don't want to evaluate it on each Single subscription return Single.fromEmitter(emitter -> { // in general, code inside the RX type should be able to be executed multiple times and always returns // the same result, so we need to be careful to not mutate anything (like the operation). This is useful // for example if we want to use the retry operator which will try again (subscribe again) if it fails. XMLHttpRequest xhr = newDmrXhr(url, method, dmrOperation, new DmrPayloadProcessor(), emitter::onSuccess, (op, fail) -> emitter.onError(new DispatchFailure(fail, operation)), (op, error) -> emitter.onError(error)); xhr.setRequestHeader(ACCEPT.header(), APPLICATION_DMR_ENCODED); xhr.setRequestHeader(CONTENT_TYPE.header(), APPLICATION_DMR_ENCODED); if (get) { xhr.send(); } else { xhr.send(dmrOperation.toBase64String()); } recordOperation(operation); }); }
public FileItem(File file, UploadOptions options) { this.file = file; this.options = options; initFileImage(); initFileTitle(); initFileSizeParagraph(); initFooter(); initProgress(); initThumbnail(); if (isExceedsMaxFile()) { invalidate("File is too large, maximum file size is " + formatSize(options.getMaxFileSize())); } request =new XMLHttpRequest(); init(this); }
@JsOverlay public final void send(Document data) { send(Js.<XMLHttpRequest.SendDataUnionType>uncheckedCast(data)); }
public FileItem cancel() { if (request != null) { canceled = true; request.abort(); } return this; }
@JsOverlay public final void send(String data) { send(Js.<XMLHttpRequest.SendDataUnionType>uncheckedCast(data)); }
@JsOverlay public final void send(String data) { send(Js.<XMLHttpRequest.SendDataUnionType>uncheckedCast(data)); }
@JsOverlay public final void send(ArrayBuffer data) { send(Js.<XMLHttpRequest.SendDataUnionType>uncheckedCast(data)); }
@JsOverlay public final void send(Blob data) { send(Js.<XMLHttpRequest.SendDataUnionType>uncheckedCast(data)); }
@JsOverlay public final void send(ArrayBuffer data) { send(Js.<XMLHttpRequest.SendDataUnionType>uncheckedCast(data)); }
@JsOverlay public final void send(ArrayBufferView data) { send(Js.<XMLHttpRequest.SendDataUnionType>uncheckedCast(data)); }
@JsOverlay public final void send(Blob data) { send(Js.<XMLHttpRequest.SendDataUnionType>uncheckedCast(data)); }
@JsOverlay public final void send(Document data) { send(Js.<XMLHttpRequest.SendDataUnionType>uncheckedCast(data)); }