Search in sources :

Example 1 with DolphinRuntimeException

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 + "'");
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) DolphinRuntimeException(com.canoo.platform.core.DolphinRuntimeException) URL(java.net.URL)

Example 2 with DolphinRuntimeException

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();
}
Also used : DolphinRuntimeException(com.canoo.platform.core.DolphinRuntimeException)

Example 3 with DolphinRuntimeException

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");
    }
}
Also used : MissingResourceException(java.util.MissingResourceException) DolphinRuntimeException(com.canoo.platform.core.DolphinRuntimeException) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) Test(org.testng.annotations.Test)

Example 4 with DolphinRuntimeException

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);
    }
}
Also used : DolphinRuntimeException(com.canoo.platform.core.DolphinRuntimeException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 5 with DolphinRuntimeException

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);
    }
}
Also used : ACCEPT_CHARSET_HEADER(com.canoo.dp.impl.platform.core.http.HttpHeaderConstants.ACCEPT_CHARSET_HEADER) ACCEPT_HEADER(com.canoo.dp.impl.platform.core.http.HttpHeaderConstants.ACCEPT_HEADER) HttpHeader(com.canoo.platform.core.http.HttpHeader) DolphinRuntimeException(com.canoo.platform.core.DolphinRuntimeException) HttpException(com.canoo.platform.core.http.HttpException) IOException(java.io.IOException) ConnectionException(com.canoo.platform.core.http.ConnectionException) HttpException(com.canoo.platform.core.http.HttpException) ConnectionException(com.canoo.platform.core.http.ConnectionException) IOException(java.io.IOException) DolphinRuntimeException(com.canoo.platform.core.DolphinRuntimeException)

Aggregations

DolphinRuntimeException (com.canoo.platform.core.DolphinRuntimeException)19 IOException (java.io.IOException)5 URISyntaxException (java.net.URISyntaxException)4 HttpClientConnection (com.canoo.dp.impl.platform.core.http.HttpClientConnection)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 Method (java.lang.reflect.Method)2 MalformedURLException (java.net.MalformedURLException)2 URI (java.net.URI)2 ServletException (javax.servlet.ServletException)2 SimpleDolphinPlatformThreadFactory (com.canoo.dp.impl.platform.core.SimpleDolphinPlatformThreadFactory)1 ACCEPT_CHARSET_HEADER (com.canoo.dp.impl.platform.core.http.HttpHeaderConstants.ACCEPT_CHARSET_HEADER)1 ACCEPT_HEADER (com.canoo.dp.impl.platform.core.http.HttpHeaderConstants.ACCEPT_HEADER)1 ClassInfo (com.canoo.dp.impl.remoting.info.ClassInfo)1 PropertyInfo (com.canoo.dp.impl.remoting.info.PropertyInfo)1 DefaultClasspathScanner (com.canoo.dp.impl.server.scanner.DefaultClasspathScanner)1 PlatformThreadFactory (com.canoo.platform.core.PlatformThreadFactory)1 Subscription (com.canoo.platform.core.functional.Subscription)1 ConnectionException (com.canoo.platform.core.http.ConnectionException)1 HttpException (com.canoo.platform.core.http.HttpException)1 HttpHeader (com.canoo.platform.core.http.HttpHeader)1