Search in sources :

Example 51 with HttpUriRequest

use of org.apache.http.client.methods.HttpUriRequest in project perun by CESNET.

the class PublicationSystemStrategyIntegrationTest method contactPublicationSystemOBDTest.

@Test
public void contactPublicationSystemOBDTest() throws Exception {
    System.out.println("PublicationSystemStrategyIntegrationTest.contactPublicationSystemOBDTest");
    PublicationSystem publicationSystem = getCabinetManager().getPublicationSystemByNamespace("zcu");
    assertNotNull(publicationSystem);
    PublicationSystemStrategy prezentator = (PublicationSystemStrategy) Class.forName(publicationSystem.getType()).newInstance();
    assertNotNull(prezentator);
    PublicationSystemStrategy obd = (PublicationSystemStrategy) Class.forName(publicationSystem.getType()).newInstance();
    assertNotNull(obd);
    String authorId = "Sitera,Jiří";
    int yearSince = 2006;
    int yearTill = 2009;
    HttpUriRequest request = obd.getHttpRequest(authorId, yearSince, yearTill, publicationSystem);
    try {
        HttpResponse response = obd.execute(request);
        assertNotNull(response);
    } catch (CabinetException ex) {
        if (!ex.getType().equals(ErrorCodes.HTTP_IO_EXCEPTION)) {
            fail("Different exception code, was: " + ex.getType() + ", but expected: HTTP_IO_EXCEPTION.");
        // fail if different error
        } else {
            System.out.println("-- Test silently skipped because of HTTP_IO_EXCEPTION");
        }
    }
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) HttpResponse(org.apache.http.HttpResponse) PublicationSystem(cz.metacentrum.perun.cabinet.model.PublicationSystem) CabinetException(cz.metacentrum.perun.cabinet.bl.CabinetException) CabinetBaseIntegrationTest(cz.metacentrum.perun.cabinet.CabinetBaseIntegrationTest) Test(org.junit.Test)

Example 52 with HttpUriRequest

use of org.apache.http.client.methods.HttpUriRequest in project perun by CESNET.

the class MUStrategyUnitTest method getHttpRequest.

@Test
public void getHttpRequest() throws Exception {
    System.out.println("MUStrategyUnitTest.getHttpRequest");
    PublicationSystem ps = new PublicationSystem();
    ps.setLoginNamespace("mu");
    ps.setUsername("test");
    ps.setPassword("test");
    ps.setUrl("http://www.seznam.cz");
    HttpUriRequest result = muStrategy.getHttpRequest("1", 2009, 2010, ps);
    assert result != null;
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) PublicationSystem(cz.metacentrum.perun.cabinet.model.PublicationSystem) Test(org.junit.Test)

Example 53 with HttpUriRequest

use of org.apache.http.client.methods.HttpUriRequest in project SeaStar by 13120241790.

the class RetryHandler method retryRequest.

@Override
public boolean retryRequest(IOException exception, int executionCount, HttpContext context) {
    boolean retry = true;
    Boolean b = (Boolean) context.getAttribute(ExecutionContext.HTTP_REQ_SENT);
    boolean sent = (b != null && b);
    if (executionCount > maxRetries) {
        // Do not retry if over max retry count
        retry = false;
    } else if (isInList(exceptionBlacklist, exception)) {
        // immediately cancel retry if the error is blacklisted
        retry = false;
    } else if (isInList(exceptionWhitelist, exception)) {
        // immediately retry if error is whitelisted
        retry = true;
    } else if (!sent) {
        // for most other errors, retry only if request hasn't been fully sent yet
        retry = true;
    }
    if (retry) {
        // resend all idempotent requests
        HttpUriRequest currentReq = (HttpUriRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST);
        if (currentReq == null) {
            return false;
        }
        String requestType = currentReq.getMethod();
        retry = !requestType.equals("POST");
    }
    if (retry) {
        SystemClock.sleep(retrySleepTimeMS);
    } else {
        exception.printStackTrace();
    }
    return retry;
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest)

Example 54 with HttpUriRequest

use of org.apache.http.client.methods.HttpUriRequest in project nhin-d by DirectProject.

the class SecuredServiceRequestBase method call.

/**
     * {@inheritDoc}}
     */
@Override
public T call() throws E, IOException, ServiceException {
    HttpUriRequest request = createRequest();
    assert request != null;
    request = securityManager.createAuthenticatedRequest(request);
    final HttpResponse response = httpClient.execute(request);
    try {
        final int statusCode = response.getStatusLine().getStatusCode();
        return interpretResponse(statusCode, response);
    } finally {
        closeConnection(response);
    }
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) HttpResponse(org.apache.http.HttpResponse)

Example 55 with HttpUriRequest

use of org.apache.http.client.methods.HttpUriRequest in project opennms by OpenNMS.

the class JUnitHttpServerTest method testBasicAuthSuccess.

@Test
@JUnitHttpServer(port = 9162, basicAuth = true, webapps = { @Webapp(context = "/testContext", path = "src/test/resources/test-webapp") })
public void testBasicAuthSuccess() throws Exception {
    final HttpUriRequest method = new HttpGet("http://localhost:9162/testContext/monkey");
    m_clientWrapper.addBasicCredentials("admin", "istrator");
    final HttpResponse response = m_clientWrapper.execute(method);
    final String responseString = EntityUtils.toString(response.getEntity());
    LOG.debug("got response:\n{}", responseString);
    assertEquals(200, response.getStatusLine().getStatusCode());
    assertTrue(responseString.contains("You are reading this from a servlet!"));
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) HttpResponse(org.apache.http.HttpResponse) Test(org.junit.Test) JUnitHttpServer(org.opennms.core.test.http.annotations.JUnitHttpServer)

Aggregations

HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)185 Test (org.junit.Test)62 TestRequest (com.android.volley.mock.TestRequest)52 HttpGet (org.apache.http.client.methods.HttpGet)45 URI (java.net.URI)43 HttpResponse (org.apache.http.HttpResponse)41 HttpEntity (org.apache.http.HttpEntity)38 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)36 HttpPost (org.apache.http.client.methods.HttpPost)22 IOException (java.io.IOException)19 Header (org.apache.http.Header)18 JSONObject (org.json.JSONObject)18 BufferedReader (java.io.BufferedReader)17 InputStreamReader (java.io.InputStreamReader)17 PrintWriter (java.io.PrintWriter)17 StringWriter (java.io.StringWriter)17 HttpHost (org.apache.http.HttpHost)13 HttpPut (org.apache.http.client.methods.HttpPut)12 HttpEntityEnclosingRequest (org.apache.http.HttpEntityEnclosingRequest)11 StringEntity (org.apache.http.entity.StringEntity)10