Search in sources :

Example 11 with Route

use of com.google.cloud.compute.v1.Route in project openhab-android by openhab.

the class MjpegStreamer method httpRequest.

public InputStream httpRequest(String url, final String usr, final String pwd) {
    Request request = new Request.Builder().url(url).build();
    OkHttpClient client = new OkHttpClient.Builder().authenticator(new Authenticator() {

        @Override
        public Request authenticate(Route route, Response response) throws IOException {
            Log.d(TAG, "Authenticating for response: " + response);
            Log.d(TAG, "Challenges: " + response.challenges());
            // Get username/password from preferences
            String credential = Credentials.basic(usr, pwd);
            return response.request().newBuilder().header("Authorization", credential).build();
        }
    }).build();
    try {
        Log.d(TAG, "1. Sending http request");
        Response response = client.newCall(request).execute();
        Log.d(TAG, "2. Request finished, status = " + response.code());
        if (response.code() == 401) {
            // You must turn off camera User Access Control before this will work
            return null;
        }
        return response.body().byteStream();
    } catch (IOException e) {
        Log.e(TAG, "Request failed-IOException", e);
    // Error connecting to camera
    }
    return null;
}
Also used : Response(okhttp3.Response) OkHttpClient(okhttp3.OkHttpClient) Request(okhttp3.Request) IOException(java.io.IOException) Authenticator(okhttp3.Authenticator) Route(okhttp3.Route)

Example 12 with Route

use of com.google.cloud.compute.v1.Route in project hub-fortify-ssc-integration-service by blackducksoftware.

the class FortifyService method getHeader.

public static Builder getHeader(final PropertyConstants propertyConstants, final String token) {
    final HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
    if (propertyConstants.getLogLevel().equalsIgnoreCase("INFO")) {
        logging.setLevel(Level.BASIC);
    } else {
        logging.setLevel(Level.BODY);
    }
    final OkHttpClient.Builder okBuilder = new OkHttpClient.Builder();
    okBuilder.authenticator(new Authenticator() {

        @Override
        public Request authenticate(final Route route, final Response response) throws IOException {
            if (token.equals(response.request().header("Authorization"))) {
                try {
                    FortifyExceptionUtil.verifyFortifyResponseCode(response.code(), "Unauthorized access of Fortify Api");
                } catch (final IntegrationException e) {
                    throw new IOException(e);
                }
                return null;
            }
            return response.request().newBuilder().header("Authorization", token).build();
        }
    });
    okBuilder.addInterceptor(logging);
    return okBuilder;
}
Also used : Builder(okhttp3.OkHttpClient.Builder) Response(okhttp3.Response) OkHttpClient(okhttp3.OkHttpClient) IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) Builder(okhttp3.OkHttpClient.Builder) Request(okhttp3.Request) IOException(java.io.IOException) HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor) Authenticator(okhttp3.Authenticator) Route(okhttp3.Route)

Example 13 with Route

use of com.google.cloud.compute.v1.Route in project hub-fortify-ssc-integration-service by blackducksoftware.

the class FortifyUnifiedLoginTokenApi method getHeader.

private static Builder getHeader(final PropertyConstants propertyConstants) {
    final HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
    if (propertyConstants.getLogLevel().equalsIgnoreCase("INFO")) {
        logging.setLevel(Level.BASIC);
    } else {
        logging.setLevel(Level.BODY);
    }
    final OkHttpClient.Builder okBuilder = new OkHttpClient.Builder();
    okBuilder.authenticator(new Authenticator() {

        @Override
        public Request authenticate(final Route route, final Response response) throws IOException {
            final String credential = Credentials.basic(propertyConstants.getFortifyUserName(), propertyConstants.getFortifyPassword());
            if (credential.equals(response.request().header("Authorization"))) {
                try {
                    FortifyExceptionUtil.verifyFortifyResponseCode(response.code(), "Unauthorized access of Fortify Api");
                } catch (final IntegrationException e) {
                    throw new IOException(e);
                }
                return null;
            }
            return response.request().newBuilder().header("Authorization", credential).build();
        }
    });
    okBuilder.addInterceptor(logging);
    return okBuilder;
}
Also used : Builder(okhttp3.OkHttpClient.Builder) UnifiedLoginTokenResponse(com.blackducksoftware.integration.fortify.model.UnifiedLoginTokenResponse) Response(okhttp3.Response) OkHttpClient(okhttp3.OkHttpClient) IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) Builder(okhttp3.OkHttpClient.Builder) Request(okhttp3.Request) IOException(java.io.IOException) HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor) Authenticator(okhttp3.Authenticator) Route(okhttp3.Route)

Example 14 with Route

use of com.google.cloud.compute.v1.Route in project autorest-clientruntime-for-java by Azure.

the class AzureTokenCredentials method applyCredentialsFilter.

@Override
public void applyCredentialsFilter(OkHttpClient.Builder clientBuilder) {
    clientBuilder.interceptors().add(new AzureTokenCredentialsInterceptor(this));
    clientBuilder.authenticator(new Authenticator() {

        @Override
        public Request authenticate(Route route, Response response) throws IOException {
            String authenticateHeader = response.header("WWW-Authenticate");
            if (authenticateHeader != null && !authenticateHeader.isEmpty()) {
                Pattern pattern = Pattern.compile("resource=\"([a-zA-Z0-9.:/-_]+)\"");
                Matcher matcher = pattern.matcher(authenticateHeader);
                if (matcher.find()) {
                    String resource = matcher.group(1);
                    return response.request().newBuilder().header("Authorization", "Bearer " + getToken(resource)).build();
                }
            }
            // Otherwise cannot satisfy the challenge
            return null;
        }
    });
}
Also used : Response(okhttp3.Response) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) Request(okhttp3.Request) IOException(java.io.IOException) Authenticator(okhttp3.Authenticator) Route(okhttp3.Route)

Example 15 with Route

use of com.google.cloud.compute.v1.Route in project bgpcep by opendaylight.

the class ComplexRouteEntry method createRoute.

@Override
public Route createRoute(final RIBSupport ribSup, final Identifier routeKey, final long pathId, final AddPathBestPath path) {
    final OffsetMap map = getOffsets();
    final Route route = map.getValue(this.values, map.offsetOf(path.getRouteKey()));
    return ribSup.createRoute(route, routeKey, pathId, path.getAttributes());
}
Also used : OffsetMap(org.opendaylight.protocol.bgp.mode.impl.add.OffsetMap) Route(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.Route)

Aggregations

Route (okhttp3.Route)30 Response (okhttp3.Response)16 Authenticator (okhttp3.Authenticator)14 Request (okhttp3.Request)12 IOException (java.io.IOException)10 OkHttpClient (okhttp3.OkHttpClient)10 InetSocketAddress (java.net.InetSocketAddress)9 Route (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.Route)9 Proxy (java.net.Proxy)7 Route (io.fabric8.knative.serving.v1.Route)6 RouteBuilder (io.fabric8.knative.serving.v1.RouteBuilder)6 Test (org.junit.Test)6 Test (org.junit.jupiter.api.Test)6 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)6 KeyedInstanceIdentifier (org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier)6 Address (okhttp3.Address)5 Connection (okhttp3.Connection)5 RIBSupport (org.opendaylight.protocol.bgp.rib.spi.RIBSupport)5 Identifier (org.opendaylight.yangtools.yang.binding.Identifier)5 Builder (okhttp3.OkHttpClient.Builder)4