Search in sources :

Example 96 with Header

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;
}
Also used : Header(org.opensaml.soap.soap11.Header) Envelope(org.opensaml.soap.soap11.Envelope) Body(org.opensaml.soap.soap11.Body)

Example 97 with Header

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);
}
Also used : CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) Function(io.reactivex.functions.Function) Headers(okhttp3.Headers) NonNull(io.reactivex.annotations.NonNull) HttpException(retrofit2.HttpException)

Example 98 with Header

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();
}
Also used : Request(okhttp3.Request) Interceptor(okhttp3.Interceptor)

Example 99 with Header

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;
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(org.opensaml.saml.saml2.ecp.Response) Header(org.opensaml.soap.soap11.Header) Envelope(org.opensaml.soap.soap11.Envelope) Body(org.opensaml.soap.soap11.Body)

Example 100 with Header

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());
        }
    }
}
Also used : LazyPath(com.facebook.buck.io.LazyPath) Path(java.nio.file.Path) OutputStream(java.io.OutputStream) Request(okhttp3.Request) HttpResponse(com.facebook.buck.slb.HttpResponse) DataInputStream(java.io.DataInputStream)

Aggregations

Test (org.junit.Test)88 MockResponse (okhttp3.mockwebserver.MockResponse)82 Request (okhttp3.Request)70 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)56 Response (okhttp3.Response)52 IOException (java.io.IOException)50 RequestBody (okhttp3.RequestBody)24 Call (okhttp3.Call)20 OkHttpClient (okhttp3.OkHttpClient)20 Callback (okhttp3.Callback)19 Interceptor (okhttp3.Interceptor)12 FormBody (okhttp3.FormBody)11 ResponseBody (okhttp3.ResponseBody)11 ArrayList (java.util.ArrayList)10 Map (java.util.Map)10 Headers (okhttp3.Headers)10 List (java.util.List)9 JSONObject (org.json.JSONObject)7 File (java.io.File)6 HashMap (java.util.HashMap)6