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);
}
}
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);
}
}
}
}
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);
}
}
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);
}
}
Aggregations