Search in sources :

Example 61 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 62 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 63 with HttpUriRequest

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

Example 64 with HttpUriRequest

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();
}
Also used : HttpRequest(org.apache.http.HttpRequest) HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) Header(org.apache.http.Header) AbstractHttpEntity(org.apache.http.entity.AbstractHttpEntity) HttpEntity(org.apache.http.HttpEntity) HttpEntityEnclosingRequest(org.apache.http.HttpEntityEnclosingRequest) RequestWrapper(org.apache.http.impl.client.RequestWrapper) ByteArrayOutputStream(java.io.ByteArrayOutputStream) URI(java.net.URI)

Example 65 with HttpUriRequest

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

Aggregations

HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)183 Test (org.junit.Test)62 TestRequest (com.android.volley.mock.TestRequest)52 HttpGet (org.apache.http.client.methods.HttpGet)44 URI (java.net.URI)41 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)21 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 HttpParams (org.apache.http.params.HttpParams)10