Search in sources :

Example 41 with HttpRequestBase

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());
    }
}
Also used : HttpRequestBase(org.apache.http.client.methods.HttpRequestBase) URI(java.net.URI) Test(org.junit.Test)

Example 42 with HttpRequestBase

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());
}
Also used : HttpRequestBase(org.apache.http.client.methods.HttpRequestBase) Header(org.apache.http.Header) HttpResponse(org.apache.http.HttpResponse)

Example 43 with HttpRequestBase

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());
}
Also used : HttpRequestBase(org.apache.http.client.methods.HttpRequestBase) Header(org.apache.http.Header) HttpResponse(org.apache.http.HttpResponse) Date(java.util.Date) SuppressForbidden(org.apache.solr.common.util.SuppressForbidden)

Example 44 with HttpRequestBase

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();
    }
}
Also used : HttpRequestBase(org.apache.http.client.methods.HttpRequestBase) DavException(org.apache.jackrabbit.webdav.DavException) HttpClient(org.apache.http.client.HttpClient) HttpResponse(org.apache.http.HttpResponse) RepositoryException(javax.jcr.RepositoryException) BaseDavRequest(org.apache.jackrabbit.webdav.client.methods.BaseDavRequest) IOException(java.io.IOException)

Example 45 with HttpRequestBase

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);
}
Also used : HttpRequestBase(org.apache.http.client.methods.HttpRequestBase) HttpResponse(org.apache.http.HttpResponse) Test(org.junit.Test)

Aggregations

HttpRequestBase (org.apache.http.client.methods.HttpRequestBase)63 HttpResponse (org.apache.http.HttpResponse)28 HttpGet (org.apache.http.client.methods.HttpGet)20 IOException (java.io.IOException)18 Header (org.apache.http.Header)13 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)13 HttpPost (org.apache.http.client.methods.HttpPost)13 HttpEntity (org.apache.http.HttpEntity)10 StringEntity (org.apache.http.entity.StringEntity)10 URI (java.net.URI)9 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)9 Test (org.junit.Test)9 InputStream (java.io.InputStream)7 URISyntaxException (java.net.URISyntaxException)7 ArrayList (java.util.ArrayList)7 HttpHead (org.apache.http.client.methods.HttpHead)7 HttpPut (org.apache.http.client.methods.HttpPut)6 HttpEntityEnclosingRequest (org.apache.http.HttpEntityEnclosingRequest)5 HttpEntityEnclosingRequestBase (org.apache.http.client.methods.HttpEntityEnclosingRequestBase)5 HashMap (java.util.HashMap)4