use of org.talend.sdk.component.form.api.WebException in project component-runtime by Talend.
the class SpringRestClient method toCompletionStage.
// poor man way but we'll enhance it on demand
private <T> CompletableFuture<T> toCompletionStage(final ListenableFuture<ResponseEntity<T>> future) {
final CompletableFuture<T> result = new CompletableFuture<>();
future.addCallback(new ListenableFutureCallback<ResponseEntity<T>>() {
@Override
public void onFailure(final Throwable throwable) {
if (HttpServerErrorException.class.isInstance(throwable)) {
result.completeExceptionally(toException(HttpServerErrorException.class.cast(throwable)));
} else if (RestClientException.class.isInstance(throwable)) {
result.completeExceptionally(toException(RestClientException.class.cast(throwable)));
} else {
result.completeExceptionally(new WebException(throwable, -1, singletonMap("error", throwable.getMessage())));
}
}
@Override
public void onSuccess(final ResponseEntity<T> t) {
result.complete(t.getBody());
}
});
return result;
}
use of org.talend.sdk.component.form.api.WebException in project component-runtime by Talend.
the class SpringRestClient method toException.
private WebException toException(final HttpServerErrorException hsee) {
try {
return new WebException(hsee, hsee.getRawStatusCode(), new HttpMessageConverterExtractor<Map<String, Object>>(mapType.getType(), delegate.getMessageConverters()).extractData(new ClientHttpResponse() {
@Override
public HttpStatus getStatusCode() {
return HttpStatus.OK;
}
@Override
public int getRawStatusCode() {
return 200;
}
@Override
public String getStatusText() {
return "";
}
@Override
public void close() {
// no-op
}
@Override
public InputStream getBody() {
return new ByteArrayInputStream(hsee.getResponseBodyAsByteArray());
}
@Override
public HttpHeaders getHeaders() {
final HttpHeaders json = json();
json.add(HttpHeaders.CONTENT_TYPE, "application/json");
return json;
}
}));
} catch (final IOException e) {
throw new IllegalStateException(e);
}
}
use of org.talend.sdk.component.form.api.WebException in project component-runtime by Talend.
the class WebAppComponentProxy method onException.
private void onException(final AsyncResponse response, final Throwable e) {
final UiActionResult payload;
final int status;
if (WebException.class.isInstance(e)) {
final WebException we = WebException.class.cast(e);
status = we.getStatus();
payload = actionService.map(we);
} else if (CompletionException.class.isInstance(e)) {
final CompletionException actualException = CompletionException.class.cast(e);
log.error(actualException.getMessage(), actualException);
status = Response.Status.BAD_GATEWAY.getStatusCode();
payload = actionService.map(new WebException(actualException, -1, emptyMap()));
} else {
log.error(e.getMessage(), e);
status = Response.Status.BAD_GATEWAY.getStatusCode();
payload = actionService.map(new WebException(e, -1, emptyMap()));
}
response.resume(new WebApplicationException(Response.status(status).entity(payload).build()));
}
Aggregations