use of org.apache.http.client.methods.HttpRequestBase in project lucene-solr by apache.
the class HttpSolrClient method httpUriRequest.
/**
* @lucene.experimental
*/
public HttpUriRequestResponse httpUriRequest(final SolrRequest request, final ResponseParser processor) throws SolrServerException, IOException {
HttpUriRequestResponse mrr = new HttpUriRequestResponse();
final HttpRequestBase method = createMethod(request, null);
ExecutorService pool = ExecutorUtil.newMDCAwareFixedThreadPool(1, new SolrjNamedThreadFactory("httpUriRequest"));
try {
MDC.put("HttpSolrClient.url", baseUrl);
mrr.future = pool.submit(() -> executeMethod(method, processor));
} finally {
pool.shutdown();
MDC.remove("HttpSolrClient.url");
}
assert method != null;
mrr.httpUriRequest = method;
return mrr;
}
use of org.apache.http.client.methods.HttpRequestBase in project lucene-solr by apache.
the class CacheHeaderTestBase method getUpdateMethod.
protected HttpRequestBase getUpdateMethod(String method, String... params) throws URISyntaxException {
HttpSolrClient client = (HttpSolrClient) getSolrClient();
HttpRequestBase m = null;
ArrayList<BasicNameValuePair> qparams = new ArrayList<>();
for (int i = 0; i < params.length / 2; i++) {
qparams.add(new BasicNameValuePair(params[i * 2], params[i * 2 + 1]));
}
URI uri = URI.create(client.getBaseURL() + "/update?" + URLEncodedUtils.format(qparams, StandardCharsets.UTF_8));
if ("GET".equals(method)) {
m = new HttpGet(uri);
} else if ("POST".equals(method)) {
m = new HttpPost(uri);
} else if ("HEAD".equals(method)) {
m = new HttpHead(uri);
}
return m;
}
use of org.apache.http.client.methods.HttpRequestBase in project lucene-solr by apache.
the class NoCacheHeaderTest method doCacheControl.
@Override
protected void doCacheControl(String method) throws Exception {
HttpRequestBase m = getSelectMethod(method);
HttpResponse response = getClient().execute(m);
checkResponseBody(method, response);
Header head = response.getFirstHeader("Cache-Control");
assertNull("We got a cache-control header in response", head);
head = response.getFirstHeader("Expires");
assertNull("We got an Expires header in response", head);
}
use of org.apache.http.client.methods.HttpRequestBase in project lucene-solr by apache.
the class CacheHeaderTest method doLastModified.
@Override
protected void doLastModified(String method) throws Exception {
// We do a first request to get the last modified
// This must result in a 200 OK response
HttpRequestBase get = getSelectMethod(method);
HttpResponse response = getClient().execute(get);
checkResponseBody(method, response);
assertEquals("Got no response code 200 in initial request", 200, response.getStatusLine().getStatusCode());
Header head = response.getFirstHeader("Last-Modified");
assertNotNull("We got no Last-Modified header", head);
Date lastModified = DateUtils.parseDate(head.getValue());
// If-Modified-Since tests
get = getSelectMethod(method);
get.addHeader("If-Modified-Since", DateUtils.formatDate(new Date()));
response = getClient().execute(get);
checkResponseBody(method, response);
assertEquals("Expected 304 NotModified response with current date", 304, response.getStatusLine().getStatusCode());
get = getSelectMethod(method);
get.addHeader("If-Modified-Since", DateUtils.formatDate(new Date(lastModified.getTime() - 10000)));
response = getClient().execute(get);
checkResponseBody(method, response);
assertEquals("Expected 200 OK response with If-Modified-Since in the past", 200, response.getStatusLine().getStatusCode());
// If-Unmodified-Since tests
get = getSelectMethod(method);
get.addHeader("If-Unmodified-Since", DateUtils.formatDate(new Date(lastModified.getTime() - 10000)));
response = getClient().execute(get);
checkResponseBody(method, response);
assertEquals("Expected 412 Precondition failed with If-Unmodified-Since in the past", 412, response.getStatusLine().getStatusCode());
get = getSelectMethod(method);
get.addHeader("If-Unmodified-Since", DateUtils.formatDate(new Date()));
response = getClient().execute(get);
checkResponseBody(method, response);
assertEquals("Expected 200 OK response with If-Unmodified-Since and current date", 200, response.getStatusLine().getStatusCode());
}
use of org.apache.http.client.methods.HttpRequestBase in project lucene-solr by apache.
the class CacheHeaderTest method doCacheControl.
@Override
protected void doCacheControl(String method) throws Exception {
if ("POST".equals(method)) {
HttpRequestBase m = getSelectMethod(method);
HttpResponse response = getClient().execute(m);
checkResponseBody(method, response);
Header head = response.getFirstHeader("Cache-Control");
assertNull("We got a cache-control header in response to POST", head);
head = response.getFirstHeader("Expires");
assertNull("We got an Expires header in response to POST", head);
} else {
HttpRequestBase m = getSelectMethod(method);
HttpResponse response = getClient().execute(m);
checkResponseBody(method, response);
Header head = response.getFirstHeader("Cache-Control");
assertNotNull("We got no cache-control header", head);
head = response.getFirstHeader("Expires");
assertNotNull("We got no Expires header in response", head);
}
}
Aggregations