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 platform_external_apache-http by android.
the class DefaultRequestDirector method determineRoute.
/**
* Determines the route for a request.
* Called by {@link #execute}
* to determine the route for either the original or a followup request.
*
* @param target the target host for the request.
* Implementations may accept <code>null</code>
* if they can still determine a route, for example
* to a default target or by inspecting the request.
* @param request the request to execute
* @param context the context to use for the execution,
* never <code>null</code>
*
* @return the route the request should take
*
* @throws HttpException in case of a problem
*/
protected HttpRoute determineRoute(HttpHost target, HttpRequest request, HttpContext context) throws HttpException {
if (target == null) {
target = (HttpHost) request.getParams().getParameter(ClientPNames.DEFAULT_HOST);
}
if (target == null) {
// BEGIN android-changed
// If the URI was malformed, make it obvious where there's no host component
String scheme = null;
String host = null;
String path = null;
URI uri;
if (request instanceof HttpUriRequest && (uri = ((HttpUriRequest) request).getURI()) != null) {
scheme = uri.getScheme();
host = uri.getHost();
path = uri.getPath();
}
throw new IllegalStateException("Target host must not be null, or set in parameters." + " scheme=" + scheme + ", host=" + host + ", path=" + path);
// END android-changed
}
return this.routePlanner.determineRoute(target, request, context);
}
use of org.apache.http.client.methods.HttpUriRequest in project platform_external_apache-http by android.
the class AndroidHttpClient method toCurl.
/**
* Generates a cURL command equivalent to the given request.
*/
private static String toCurl(HttpUriRequest request, boolean logAuthToken) throws IOException {
StringBuilder builder = new StringBuilder();
builder.append("curl ");
// add in the method
builder.append("-X ");
builder.append(request.getMethod());
builder.append(" ");
for (Header header : request.getAllHeaders()) {
if (!logAuthToken && (header.getName().equals("Authorization") || header.getName().equals("Cookie"))) {
continue;
}
builder.append("--header \"");
builder.append(header.toString().trim());
builder.append("\" ");
}
URI uri = request.getURI();
// relative URI. We want an absolute URI.
if (request instanceof RequestWrapper) {
HttpRequest original = ((RequestWrapper) request).getOriginal();
if (original instanceof HttpUriRequest) {
uri = ((HttpUriRequest) original).getURI();
}
}
builder.append("\"");
builder.append(uri);
builder.append("\"");
if (request instanceof HttpEntityEnclosingRequest) {
HttpEntityEnclosingRequest entityRequest = (HttpEntityEnclosingRequest) request;
HttpEntity entity = entityRequest.getEntity();
if (entity != null && entity.isRepeatable()) {
if (entity.getContentLength() < 1024) {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
entity.writeTo(stream);
if (isBinaryContent(request)) {
String base64 = Base64.encodeToString(stream.toByteArray(), Base64.NO_WRAP);
builder.insert(0, "echo '" + base64 + "' | base64 -d > /tmp/$$.bin; ");
builder.append(" --data-binary @/tmp/$$.bin");
} else {
String entityString = stream.toString();
builder.append(" --data-ascii \"").append(entityString).append("\"");
}
} else {
builder.append(" [TOO MUCH DATA TO INCLUDE]");
}
}
}
return builder.toString();
}
use of org.apache.http.client.methods.HttpUriRequest in project asterixdb by apache.
the class TestExecutor method executeJSONGet.
public InputStream executeJSONGet(OutputFormat fmt, URI uri) throws Exception {
HttpUriRequest request = constructGetMethod(uri, fmt, new ArrayList<>());
HttpResponse response = executeAndCheckHttpRequest(request);
return response.getEntity().getContent();
}
Aggregations