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