use of okhttp3.internal.http2.Header in project ddf by codice.
the class SamlProtocol method createSoapMessage.
public static Envelope createSoapMessage(SignableSAMLObject signableSAMLObject) {
Body body = soapBodyBuilder.buildObject();
body.getUnknownXMLObjects().add(signableSAMLObject);
Envelope envelope = soapEnvelopeBuilder.buildObject();
envelope.setBody(body);
Header header = soapHeaderBuilder.buildObject();
envelope.setHeader(header);
return envelope;
}
use of okhttp3.internal.http2.Header in project Varis-Android by dkhmelenko.
the class BuildsDetailsPresenter method startLoadingLog.
/**
* Starts loading log file
*
* @param jobId Job ID
*/
public void startLoadingLog(long jobId) {
mJobId = jobId;
String accessToken = AppSettings.getAccessToken();
Single<String> responseSingle;
if (TextUtils.isEmpty(accessToken)) {
responseSingle = mRawClient.getApiService().getLog(String.valueOf(mJobId));
} else {
String auth = String.format("token %1$s", AppSettings.getAccessToken());
responseSingle = mRawClient.getApiService().getLog(auth, String.valueOf(mJobId));
}
Disposable subscription = responseSingle.subscribeOn(Schedulers.io()).map(s -> mRawClient.getLogUrl(mJobId)).onErrorResumeNext(new Function<Throwable, SingleSource<String>>() {
@Override
public SingleSource<String> apply(@NonNull Throwable throwable) throws Exception {
String redirectUrl = "";
HttpException httpException = (HttpException) throwable;
Headers headers = httpException.response().headers();
for (String header : headers.names()) {
if (header.equals("Location")) {
redirectUrl = headers.get(header);
break;
}
}
return Single.just(redirectUrl);
}
}).retry(LOAD_LOG_MAX_ATTEMPT).observeOn(AndroidSchedulers.mainThread()).subscribe((logUrl, throwable) -> {
if (throwable == null) {
getView().setLogUrl(logUrl);
} else {
getView().showLogError();
getView().showLoadingError(throwable.getMessage());
}
});
mSubscriptions.add(subscription);
}
use of okhttp3.internal.http2.Header in project Varis-Android by dkhmelenko.
the class TravisRestClient method getHttpClient.
private OkHttpClient getHttpClient() {
final String userAgent = String.format("TravisClient/%1$s", PackageUtils.getAppVersion());
return mOkHttpClient.newBuilder().addInterceptor(new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
Request original = chain.request();
Request.Builder request = original.newBuilder().header("User-Agent", userAgent).header("Accept", "application/vnd.travis-ci.2+json");
String accessToken = AppSettings.getAccessToken();
if (!TextUtils.isEmpty(accessToken)) {
String headerValue = String.format("token %1$s", accessToken);
request.addHeader("Authorization", headerValue);
}
return chain.proceed(request.build());
}
}).build();
}
use of okhttp3.internal.http2.Header in project cas by apereo.
the class SamlProfileSamlSoap11ResponseBuilder method buildResponse.
@Override
protected Envelope buildResponse(final Assertion assertion, final org.jasig.cas.client.validation.Assertion casAssertion, final AuthnRequest authnRequest, final SamlRegisteredService service, final SamlRegisteredServiceServiceProviderMetadataFacade adaptor, final HttpServletRequest request, final HttpServletResponse response) throws SamlException {
final Response ecpResponse = newEcpResponse(adaptor.getAssertionConsumerService().getLocation());
final Header header = newSoapObject(Header.class);
header.getUnknownXMLObjects().add(ecpResponse);
final Body body = newSoapObject(Body.class);
final org.opensaml.saml.saml2.core.Response saml2Response = (org.opensaml.saml.saml2.core.Response) saml2ResponseBuilder.build(authnRequest, request, response, casAssertion, service, adaptor);
body.getUnknownXMLObjects().add(saml2Response);
final Envelope envelope = newSoapObject(Envelope.class);
envelope.setHeader(header);
envelope.setBody(body);
return envelope;
}
use of okhttp3.internal.http2.Header in project buck by facebook.
the class HttpArtifactCache method fetchImpl.
@Override
protected CacheResult fetchImpl(RuleKey ruleKey, LazyPath output, final Finished.Builder eventBuilder) throws IOException {
Request.Builder requestBuilder = new Request.Builder().get();
try (HttpResponse response = fetchClient.makeRequest("/artifacts/key/" + ruleKey.toString(), requestBuilder)) {
eventBuilder.getFetchBuilder().setResponseSizeBytes(response.contentLength());
try (DataInputStream input = new DataInputStream(new FullyReadOnCloseInputStream(response.getBody()))) {
if (response.statusCode() == HttpURLConnection.HTTP_NOT_FOUND) {
LOG.info("fetch(%s, %s): cache miss", response.requestUrl(), ruleKey);
return CacheResult.miss();
}
if (response.statusCode() != HttpURLConnection.HTTP_OK) {
String msg = String.format("unexpected server response: [%d:%s]", response.statusCode(), response.statusMessage());
reportFailure("fetch(%s, %s): %s", response.requestUrl(), ruleKey, msg);
eventBuilder.getFetchBuilder().setErrorMessage(msg);
return CacheResult.error(name, msg);
}
// Setup a temporary file, which sits next to the destination, to write to and
// make sure all parent dirs exist.
Path file = output.get();
projectFilesystem.createParentDirs(file);
Path temp = projectFilesystem.createTempFile(file.getParent(), file.getFileName().toString(), ".tmp");
FetchResponseReadResult fetchedData;
try (OutputStream tempFileOutputStream = projectFilesystem.newFileOutputStream(temp)) {
fetchedData = HttpArtifactCacheBinaryProtocol.readFetchResponse(input, tempFileOutputStream);
}
eventBuilder.setTarget(ArtifactCacheEvent.getTarget(fetchedData.getMetadata())).getFetchBuilder().setResponseSizeBytes(fetchedData.getResponseSizeBytes()).setArtifactContentHash(fetchedData.getArtifactOnlyHashCode().toString());
// Verify that we were one of the rule keys that stored this artifact.
if (!fetchedData.getRuleKeys().contains(ruleKey)) {
String msg = "incorrect key name";
reportFailure("fetch(%s, %s): %s", response.requestUrl(), ruleKey, msg);
eventBuilder.getFetchBuilder().setErrorMessage(msg);
return CacheResult.error(name, msg);
}
// the HTTP header. If it's incorrect, log this and return a miss.
if (!fetchedData.getExpectedHashCode().equals(fetchedData.getActualHashCode())) {
String msg = "artifact had invalid checksum";
reportFailure("fetch(%s, %s): %s", response.requestUrl(), ruleKey, msg);
projectFilesystem.deleteFileAtPath(temp);
eventBuilder.getFetchBuilder().setErrorMessage(msg);
return CacheResult.error(name, msg);
}
// Finally, move the temp file into it's final place.
projectFilesystem.move(temp, file, StandardCopyOption.REPLACE_EXISTING);
LOG.info("fetch(%s, %s): cache hit", response.requestUrl(), ruleKey);
return CacheResult.hit(name, fetchedData.getMetadata(), fetchedData.getResponseSizeBytes());
}
}
}
Aggregations