Search in sources :

Example 1 with OAuthFilter

use of org.openremote.container.web.OAuthFilter in project openremote by openremote.

the class WebsocketIOClient method doConnect.

@Override
protected Future<Boolean> doConnect() {
    if (oAuthGrant != null) {
        LOG.fine("Retrieving OAuth access token: " + getClientUri());
        ResteasyClient client = createClient(executorService, 1, CONNECTION_TIMEOUT_MILLISECONDS, null);
        try {
            OAuthFilter oAuthFilter = new OAuthFilter(client, oAuthGrant);
            authHeaderValue = oAuthFilter.getAuthHeader();
            if (TextUtil.isNullOrEmpty(authHeaderValue)) {
                throw new RuntimeException("Returned access token is null");
            }
            LOG.fine("Retrieved access token via OAuth: " + getClientUri());
        } catch (SocketException | ProcessingException e) {
            LOG.log(Level.SEVERE, "Failed to retrieve OAuth access token for '" + getClientUri() + "': Connection error");
            return CompletableFuture.completedFuture(false);
        } catch (Exception e) {
            LOG.log(Level.SEVERE, "Failed to retrieve OAuth access token: " + getClientUri());
            return CompletableFuture.completedFuture(false);
        } finally {
            if (client != null) {
                client.close();
            }
        }
    }
    return super.doConnect();
}
Also used : SocketException(java.net.SocketException) ResteasyClient(org.jboss.resteasy.client.jaxrs.ResteasyClient) OAuthFilter(org.openremote.container.web.OAuthFilter) SocketException(java.net.SocketException) ProcessingException(javax.ws.rs.ProcessingException) ProcessingException(javax.ws.rs.ProcessingException)

Aggregations

SocketException (java.net.SocketException)1 ProcessingException (javax.ws.rs.ProcessingException)1 ResteasyClient (org.jboss.resteasy.client.jaxrs.ResteasyClient)1 OAuthFilter (org.openremote.container.web.OAuthFilter)1