Search in sources :

Example 16 with DolphinRuntimeException

use of com.canoo.platform.core.DolphinRuntimeException in project dolphin-platform by canoo.

the class HttpClientImpl method request.

@Override
public HttpCallRequestBuilder request(final URI url, final RequestMethod method) {
    try {
        Assert.requireNonNull(url, "url");
        Assert.requireNonNull(method, "method");
        final HttpClientConnection clientConnection = new HttpClientConnection(httpURLConnectionFactory, url, method);
        return new HttpCallRequestBuilderImpl(clientConnection, gson, requestHandlers, responseHandlers, configuration);
    } catch (final IOException e) {
        throw new DolphinRuntimeException("HTTP error", e);
    }
}
Also used : HttpClientConnection(com.canoo.dp.impl.platform.core.http.HttpClientConnection) DolphinRuntimeException(com.canoo.platform.core.DolphinRuntimeException) IOException(java.io.IOException)

Example 17 with DolphinRuntimeException

use of com.canoo.platform.core.DolphinRuntimeException in project dolphin-platform by canoo.

the class HttpClientCookieHandler method updateCookiesFromResponse.

public void updateCookiesFromResponse(final HttpURLConnection connection) throws URISyntaxException {
    Assert.requireNonNull(connection, "connection");
    LOG.debug("adding cookies from response to cookie store");
    final Map<String, List<String>> headerFields = connection.getHeaderFields();
    final List<String> cookiesHeader = headerFields.get(SET_COOKIE_HEADER);
    if (cookiesHeader != null) {
        LOG.debug("found '{}' header field", SET_COOKIE_HEADER);
        for (String cookie : cookiesHeader) {
            if (cookie == null || cookie.isEmpty()) {
                continue;
            }
            LOG.debug("will parse '{}' header content '{}'", cookie);
            final List<HttpCookie> cookies = new ArrayList<>();
            try {
                cookies.addAll(HttpCookie.parse(cookie));
            } catch (final Exception e) {
                throw new DolphinRuntimeException("Can not convert '" + SET_COOKIE_HEADER + "' response header field to http cookies. Bad content: " + cookie, e);
            }
            LOG.debug("Found {} http cookies in header", cookies.size());
            for (final HttpCookie httpCookie : cookies) {
                LOG.trace("Found Cookie '{}' for Domain '{}' at Ports '{}' with Path '{}", httpCookie.getValue(), httpCookie.getDomain(), httpCookie.getPortlist(), httpCookie.getPath());
                cookieStore.add(connection.getURL().toURI(), httpCookie);
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) DolphinRuntimeException(com.canoo.platform.core.DolphinRuntimeException) ArrayList(java.util.ArrayList) List(java.util.List) HttpCookie(java.net.HttpCookie) URISyntaxException(java.net.URISyntaxException) DolphinRuntimeException(com.canoo.platform.core.DolphinRuntimeException)

Example 18 with DolphinRuntimeException

use of com.canoo.platform.core.DolphinRuntimeException in project dolphin-platform by canoo.

the class ClientSessionRequestHandler method handle.

@Override
public void handle(final HttpURLConnection request) {
    Assert.requireNonNull(request, "request");
    final String clientId;
    try {
        clientId = clientSessionStore.getClientIdentifierForUrl(request.getURL().toURI());
        if (clientId != null) {
            LOG.debug("Adding client id {} to http request at {}", clientId, request.getURL());
            request.setRequestProperty(PlatformConstants.CLIENT_ID_HTTP_HEADER_NAME, clientId);
        } else {
            LOG.debug("Request to application at {} without client id. PlatformClient id not defined until now.", request.getURL());
        }
    } catch (URISyntaxException e) {
        LOG.error("Exception while converting to request URL {} to URI", request.getURL());
        throw new DolphinRuntimeException("Exception while converting URL " + request.getURL() + "to URI", e);
    }
}
Also used : DolphinRuntimeException(com.canoo.platform.core.DolphinRuntimeException) URISyntaxException(java.net.URISyntaxException)

Example 19 with DolphinRuntimeException

use of com.canoo.platform.core.DolphinRuntimeException in project dolphin-platform by canoo.

the class DolphinPlatformApplication method init.

/**
 * Creates the connection to the Dolphin Platform server. If this method will be overridden always call the super method.
 *
 * @throws Exception a exception if the connection can't be created
 */
@Override
public final void init() throws Exception {
    FxToolkit.init();
    applicationInit();
    PlatformClient.getClientConfiguration().setUncaughtExceptionHandler((Thread thread, Throwable exception) -> {
        PlatformClient.getClientConfiguration().getUiExecutor().execute(() -> {
            Assert.requireNonNull(thread, "thread");
            Assert.requireNonNull(exception, "exception");
            if (connectInProgress.get()) {
                runtimeExceptionsAtInitialization.add(new DolphinRuntimeException(thread, "Unhandled error in Dolphin Platform background thread", exception));
            } else {
                onRuntimeError(primaryStage, new DolphinRuntimeException(thread, "Unhandled error in Dolphin Platform background thread", exception));
            }
        });
    });
    try {
        clientContext = createClientContext();
        Assert.requireNonNull(clientContext, "clientContext");
        connectInProgress.set(true);
        clientContext.connect().get(30_000, TimeUnit.MILLISECONDS);
    } catch (ClientInitializationException e) {
        initializationException = e;
    } catch (Exception e) {
        initializationException = new ClientInitializationException("Can not initialize Dolphin Platform Context", e);
    } finally {
        connectInProgress.set(false);
    }
}
Also used : DolphinRuntimeException(com.canoo.platform.core.DolphinRuntimeException) ClientInitializationException(com.canoo.platform.remoting.client.ClientInitializationException) MalformedURLException(java.net.MalformedURLException) ClientInitializationException(com.canoo.platform.remoting.client.ClientInitializationException) 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