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