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