use of com.canoo.platform.core.DolphinRuntimeException in project dolphin-platform by canoo.
the class URLTemplate method create.
public URL create(final Map<String, String> variables) {
Assert.requireNonNull(variables, "variables");
final String url = variables.keySet().stream().reduce(urlRepresentation, (base, key) -> replace(base, key, variables.get(key)));
try {
return new URL(url);
} catch (final MalformedURLException e) {
throw new DolphinRuntimeException("Can not create url for '" + url + "'");
}
}
use of com.canoo.platform.core.DolphinRuntimeException in project dolphin-platform by canoo.
the class DolphinPlatformApplication method onInitializationError.
protected void onInitializationError(Stage primaryStage, ClientInitializationException initializationException, Iterable<DolphinRuntimeException> possibleCauses) {
LOG.error("Dolphin Platform initialization error", initializationException);
for (DolphinRuntimeException cause : possibleCauses) {
LOG.error("Possible cause", cause);
}
Platform.exit();
}
use of com.canoo.platform.core.DolphinRuntimeException in project dolphin-platform by canoo.
the class ReflectionHelperTest method testInvokePrivilegedException.
@Test
public void testInvokePrivilegedException() throws NoSuchMethodException {
final Method method = ReflectionHelper.getMethod(ReflectionHelperTest.class, "fail").get();
try {
ReflectionHelper.invokePrivileged(method, this);
Assert.fail();
} catch (DolphinRuntimeException e) {
Assert.assertEquals(e.getCause().getClass(), InvocationTargetException.class);
final InvocationTargetException invocationTargetException = (InvocationTargetException) e.getCause();
Assert.assertEquals(invocationTargetException.getCause().getClass(), MissingResourceException.class);
final MissingResourceException missingResourceException = (MissingResourceException) invocationTargetException.getCause();
Assert.assertEquals(missingResourceException.getClassName(), "Class");
Assert.assertEquals(missingResourceException.getKey(), "Key");
Assert.assertEquals(missingResourceException.getMessage(), "FAIL");
}
}
use of com.canoo.platform.core.DolphinRuntimeException in project dolphin-platform by canoo.
the class HttpCallRequestBuilder method withContent.
default HttpCallResponseBuilder withContent(final String content, final String contentType) {
Assert.requireNonNull(content, "content");
withHeader("charset", CHARSET);
try {
return withContent(content.getBytes(CHARSET), contentType);
} catch (UnsupportedEncodingException e) {
throw new DolphinRuntimeException("Encoding error", e);
}
}
use of com.canoo.platform.core.DolphinRuntimeException in project dolphin-platform by canoo.
the class HttpCallResponseBuilderImpl method handleRequest.
private <R> HttpResponse<R> handleRequest(final ResponseContentConverter<R> converter) throws HttpException {
Assert.requireNonNull(converter, "converter");
if (handled.get()) {
throw new DolphinRuntimeException("Http call already handled");
}
handled.set(true);
requestHandlers.forEach(h -> h.handle(connection.getConnection()));
final byte[] rawBytes = dataProvider.get();
try {
connection.writeRequestContent(rawBytes);
} catch (final IOException e) {
throw new ConnectionException("Can not connect to server", e);
}
try {
int responseCode = connection.readResponseCode();
final byte[] rawContent = connection.readResponseContent();
responseHandlers.forEach(h -> h.handle(connection.getConnection()));
final R content = converter.convert(rawContent);
final List<HttpHeader> headers = connection.getResponseHeaders();
return new HttpResponseImpl<R>(headers, responseCode, rawContent, content);
} catch (IOException e) {
throw new ConnectionException("No response from server", e);
} catch (Exception e) {
throw new HttpException("Can not handle response", e);
}
}
Aggregations