use of org.apache.http.client.methods.HttpRequestBase in project jmeter by apache.
the class TestHttpWebdav method testGetMethod.
@Test
public void testGetMethod() throws URISyntaxException {
for (String method : VALID_METHODS) {
HttpRequestBase request = new HttpWebdav(method, new URI("http://example.com"));
assertEquals(method, request.getMethod());
}
}
use of org.apache.http.client.methods.HttpRequestBase in project lucene-solr by apache.
the class NoCacheHeaderTest method doETag.
// test ETag
@Override
protected void doETag(String method) throws Exception {
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("ETag");
assertNull("We got an ETag in the response", head);
// If-None-Match tests
// we set a non matching ETag
get = getSelectMethod(method);
get.addHeader("If-None-Match", "\"xyz123456\"");
response = getClient().execute(get);
checkResponseBody(method, response);
assertEquals("If-None-Match: Got no response code 200 in response to non matching ETag", 200, response.getStatusLine().getStatusCode());
// we now set the special star ETag
get = getSelectMethod(method);
get.addHeader("If-None-Match", "*");
response = getClient().execute(get);
checkResponseBody(method, response);
assertEquals("If-None-Match: Got no response 200 for star ETag", 200, response.getStatusLine().getStatusCode());
// If-Match tests
// we set a non matching ETag
get = getSelectMethod(method);
get.addHeader("If-Match", "\"xyz123456\"");
response = getClient().execute(get);
checkResponseBody(method, response);
assertEquals("If-Match: Got no response code 200 in response to non matching ETag", 200, response.getStatusLine().getStatusCode());
// now we set the special star ETag
get = getSelectMethod(method);
get.addHeader("If-Match", "*");
response = getClient().execute(get);
checkResponseBody(method, response);
assertEquals("If-Match: Got no response 200 to star ETag", 200, response.getStatusLine().getStatusCode());
}
use of org.apache.http.client.methods.HttpRequestBase in project lucene-solr by apache.
the class NoCacheHeaderTest method doLastModified.
@SuppressForbidden(reason = "Needs currentTimeMillis for testing caching headers")
@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");
assertNull("We got a Last-Modified header", head);
// 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 200 with If-Modified-Since header. We should never get a 304 here", 200, response.getStatusLine().getStatusCode());
get = getSelectMethod(method);
get.addHeader("If-Modified-Since", DateUtils.formatDate(new Date(System.currentTimeMillis() - 10000)));
response = getClient().execute(get);
checkResponseBody(method, response);
assertEquals("Expected 200 with If-Modified-Since header. We should never get a 304 here", 200, response.getStatusLine().getStatusCode());
// If-Unmodified-Since tests
get = getSelectMethod(method);
get.addHeader("If-Unmodified-Since", DateUtils.formatDate(new Date(System.currentTimeMillis() - 10000)));
response = getClient().execute(get);
checkResponseBody(method, response);
assertEquals("Expected 200 with If-Unmodified-Since header. We should never get a 304 here", 200, 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 with If-Unmodified-Since header. We should never get a 304 here", 200, response.getStatusLine().getStatusCode());
}
use of org.apache.http.client.methods.HttpRequestBase in project jackrabbit by apache.
the class RepositoryServiceImpl method submit.
@Override
public void submit(Batch batch) throws RepositoryException {
if (!(batch instanceof BatchImpl)) {
throw new RepositoryException("Unknown Batch implementation.");
}
BatchImpl batchImpl = (BatchImpl) batch;
if (batchImpl.isEmpty()) {
batchImpl.dispose();
return;
}
HttpRequestBase request = null;
try {
HttpClient client = batchImpl.start();
boolean success = false;
try {
Iterator<HttpRequestBase> it = batchImpl.requests();
while (it.hasNext()) {
request = it.next();
initMethod(request, batchImpl, true);
HttpResponse response = client.execute(request);
if (request instanceof BaseDavRequest) {
((BaseDavRequest) request).checkSuccess(response);
} else {
// use generic HTTP status code checking
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode < 200 || statusCode >= 300) {
throw new DavException(statusCode, "Unexpected status code " + statusCode + " in response to " + request.getMethod() + " request.");
}
}
request.releaseConnection();
}
success = true;
} finally {
// make sure the lock is removed. if any of the methods
// failed the unlock is used to abort any pending changes
// on the server.
batchImpl.end(client, success);
}
} catch (IOException e) {
throw new RepositoryException(e);
} catch (DavException e) {
throw ExceptionConverter.generate(e, request);
} finally {
batchImpl.dispose();
}
}
use of org.apache.http.client.methods.HttpRequestBase in project lucene-solr by apache.
the class CacheHeaderTest method testCacheVetoException.
@Test
public void testCacheVetoException() throws Exception {
HttpRequestBase m = getSelectMethod("GET", "q", "xyz_ignore_exception:solr", "qt", "standard");
// We force an exception from Solr. This should emit "no-cache" HTTP headers
HttpResponse response = getClient().execute(m);
assertFalse(response.getStatusLine().getStatusCode() == 200);
checkVetoHeaders(response, false);
}
Aggregations