Search in sources :

Example 31 with BasicHttpContext

use of org.apache.http.protocol.BasicHttpContext in project oxCore by GluuFederation.

the class WebDavDocumentStoreProvider method saveDocument.

@Override
public boolean saveDocument(String path, String documentContent, Charset charset) {
    if (true) {
        log.debug("Save document: '{}'", path);
        String normalizedPath = getNormalizedPath(path);
        try {
            HttpPut method = new HttpPut(baseServerUrl + "/" + normalizedPath);
            HttpEntity entity = new StringEntity(documentContent, charset);
            method.setEntity(entity);
            HttpContext requestLocalContext = new BasicHttpContext(context);
            HttpResponse response = httpClient.execute(method, requestLocalContext);
            int statusCode = response.getStatusLine().getStatusCode();
            return statusCode == HttpStatus.SC_CREATED || statusCode == HttpStatus.SC_NO_CONTENT;
        } catch (IOException ex) {
            log.error("Failed to write document to file '{}'", path, ex);
        }
        return false;
    } else {
        log.debug("Save document: '{}'", path);
        String normalizedPath = getNormalizedPath(path);
        try {
            String url = baseServerUrl + "/" + normalizedPath;
            client.put(url, IOUtils.toInputStream(documentContent));
            return true;
        } catch (IOException ex) {
            log.error("Failed to write document to file '{}'", path, ex);
        }
        return false;
    }
}
Also used : StringEntity(org.apache.http.entity.StringEntity) HttpEntity(org.apache.http.HttpEntity) BasicHttpContext(org.apache.http.protocol.BasicHttpContext) BasicHttpContext(org.apache.http.protocol.BasicHttpContext) HttpContext(org.apache.http.protocol.HttpContext) HttpResponse(org.apache.http.HttpResponse) IOException(java.io.IOException) HttpPut(org.apache.http.client.methods.HttpPut)

Example 32 with BasicHttpContext

use of org.apache.http.protocol.BasicHttpContext in project oxCore by GluuFederation.

the class WebDavDocumentStoreProvider method saveDocumentStream.

@Override
public boolean saveDocumentStream(String path, InputStream documentStream) {
    log.debug("Save document from stream: '{}'", path);
    String normalizedPath = getNormalizedPath(path);
    try {
        HttpPut method = new HttpPut(baseServerUrl + "/" + normalizedPath);
        HttpEntity entity = new InputStreamEntity(documentStream);
        method.setEntity(entity);
        HttpContext requestLocalContext = new BasicHttpContext(context);
        HttpResponse response = httpClient.execute(method, requestLocalContext);
        return response.getStatusLine().getStatusCode() == HttpStatus.SC_CREATED;
    } catch (IOException ex) {
        log.error("Failed to write document from stream to file '{}'", path, ex);
    }
    return false;
}
Also used : HttpEntity(org.apache.http.HttpEntity) BasicHttpContext(org.apache.http.protocol.BasicHttpContext) BasicHttpContext(org.apache.http.protocol.BasicHttpContext) HttpContext(org.apache.http.protocol.HttpContext) HttpResponse(org.apache.http.HttpResponse) IOException(java.io.IOException) HttpPut(org.apache.http.client.methods.HttpPut) InputStreamEntity(org.apache.http.entity.InputStreamEntity)

Example 33 with BasicHttpContext

use of org.apache.http.protocol.BasicHttpContext in project gocd by gocd.

the class GoHttpClientHttpInvokerRequestExecutor method doExecuteRequest.

@Override
protected RemoteInvocationResult doExecuteRequest(HttpInvokerClientConfiguration config, ByteArrayOutputStream baos) throws Exception {
    HttpPost postMethod = new HttpPost(config.getServiceUrl());
    ByteArrayEntity entity = new ByteArrayEntity(baos.toByteArray());
    entity.setContentType(getContentType());
    postMethod.setEntity(entity);
    BasicHttpContext context = null;
    postMethod.setHeader("X-Agent-GUID", defaultAgentRegistry.uuid());
    postMethod.setHeader("Authorization", defaultAgentRegistry.token());
    try (CloseableHttpResponse response = goAgentServerHttpClient.execute(postMethod, context)) {
        validateResponse(response);
        try (InputStream responseBody = getResponseBody(response)) {
            return readRemoteInvocationResult(responseBody, config.getCodebaseUrl());
        }
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) ByteArrayEntity(org.apache.http.entity.ByteArrayEntity) BasicHttpContext(org.apache.http.protocol.BasicHttpContext) GZIPInputStream(java.util.zip.GZIPInputStream) InputStream(java.io.InputStream) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse)

Example 34 with BasicHttpContext

use of org.apache.http.protocol.BasicHttpContext in project warn-report by saaavsaaa.

the class WebRequestClient method setCookies.

private static void setCookies(Cookie[] cookies) {
    // 创建一个本地上下文信息
    HttpContext localContext = new BasicHttpContext();
    for (Cookie one : cookies) {
        cs.addCookie(one);
    }
    // 在本地上下问中绑定一个本地存储
    localContext.setAttribute(HttpClientContext.COOKIE_STORE, cs);
}
Also used : BasicClientCookie(org.apache.http.impl.cookie.BasicClientCookie) Cookie(org.apache.http.cookie.Cookie) BasicHttpContext(org.apache.http.protocol.BasicHttpContext) BasicHttpContext(org.apache.http.protocol.BasicHttpContext) HttpContext(org.apache.http.protocol.HttpContext)

Example 35 with BasicHttpContext

use of org.apache.http.protocol.BasicHttpContext in project warn-report by saaavsaaa.

the class WebRequestClient method setCookies.

private static void setCookies(Cookie[] cookies) {
    // 创建一个本地上下文信息
    HttpContext localContext = new BasicHttpContext();
    for (Cookie one : cookies) {
        cs.addCookie(one);
    }
    // 在本地上下问中绑定一个本地存储
    localContext.setAttribute(HttpClientContext.COOKIE_STORE, cs);
}
Also used : BasicClientCookie(org.apache.http.impl.cookie.BasicClientCookie) Cookie(org.apache.http.cookie.Cookie) BasicHttpContext(org.apache.http.protocol.BasicHttpContext) BasicHttpContext(org.apache.http.protocol.BasicHttpContext) HttpContext(org.apache.http.protocol.HttpContext)

Aggregations

BasicHttpContext (org.apache.http.protocol.BasicHttpContext)60 HttpContext (org.apache.http.protocol.HttpContext)37 IOException (java.io.IOException)24 HttpResponse (org.apache.http.HttpResponse)21 HttpGet (org.apache.http.client.methods.HttpGet)19 BasicCookieStore (org.apache.http.impl.client.BasicCookieStore)14 HttpHost (org.apache.http.HttpHost)11 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)11 HttpEntity (org.apache.http.HttpEntity)10 HttpPost (org.apache.http.client.methods.HttpPost)10 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)10 Header (org.apache.http.Header)8 BasicScheme (org.apache.http.impl.auth.BasicScheme)8 InputStream (java.io.InputStream)7 AuthScope (org.apache.http.auth.AuthScope)7 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)7 URI (java.net.URI)6 ArrayList (java.util.ArrayList)6 GZIPInputStream (java.util.zip.GZIPInputStream)6 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)6