Search in sources :

Example 1 with HttpClientRequest

use of org.forgerock.http.client.request.HttpClientRequest in project OpenAM by OpenRock.

the class RestletHttpClient method perform.

private HttpClientResponse perform(HttpClientRequest httpClientRequest) throws UnsupportedEncodingException {
    Request request = createRequest(httpClientRequest);
    Client client = new Client(Protocol.HTTP);
    Response response = new Response(request);
    client.handle(request, response);
    return createHttpClientResponse(response);
}
Also used : Response(org.restlet.Response) HttpClientResponse(org.forgerock.http.client.response.HttpClientResponse) SimpleHttpClientResponse(org.forgerock.http.client.response.SimpleHttpClientResponse) Request(org.restlet.Request) HttpClientRequest(org.forgerock.http.client.request.HttpClientRequest) Client(org.restlet.Client)

Example 2 with HttpClientRequest

use of org.forgerock.http.client.request.HttpClientRequest in project OpenAM by OpenRock.

the class RestletHttpClient method getHttpClientResponse.

protected HttpClientResponse getHttpClientResponse(String uri, String body, Map<String, List<Map<String, String>>> requestData, String method) throws UnsupportedEncodingException {
    HttpClientRequest httpClientRequest = httpClientRequestFactory.createRequest();
    httpClientRequest.setMethod(method);
    httpClientRequest.setUri(uri);
    httpClientRequest.setEntity(body);
    if (requestData != null) {
        List<Map<String, String>> cookies = requestData.get("cookies");
        if (cookies != null) {
            for (Map cookie : cookies) {
                httpClientRequest.addCookie((String) cookie.get("domain"), (String) cookie.get("field"), (String) cookie.get("value"));
            }
        }
        List<Map<String, String>> headers = requestData.get("headers");
        if (headers != null) {
            for (Map header : headers) {
                httpClientRequest.addQueryParameter((String) header.get("field"), (String) header.get("value"));
            }
        }
    }
    return perform(httpClientRequest);
}
Also used : HttpClientRequest(org.forgerock.http.client.request.HttpClientRequest)

Example 3 with HttpClientRequest

use of org.forgerock.http.client.request.HttpClientRequest in project OpenAM by OpenRock.

the class RestletHttpClient method createRequest.

private Request createRequest(HttpClientRequest httpClientRequest) throws UnsupportedEncodingException {
    Request request = new Request();
    request.setMethod(Method.valueOf(httpClientRequest.getMethod()));
    request.setResourceRef(httpClientRequest.getUri());
    if (hasEntity(httpClientRequest)) {
        request.setEntity(httpClientRequest.getEntity(), MediaType.ALL);
    }
    if (hasHeaders(httpClientRequest)) {
        addHeadersToRequest(httpClientRequest, request);
    }
    if (hasQueryParameters(httpClientRequest)) {
        addQueryParametersToRequest(httpClientRequest, request);
    }
    if (hasCookies(httpClientRequest)) {
        addCookiesToRequest(httpClientRequest, request);
    }
    return request;
}
Also used : Request(org.restlet.Request) HttpClientRequest(org.forgerock.http.client.request.HttpClientRequest)

Aggregations

HttpClientRequest (org.forgerock.http.client.request.HttpClientRequest)3 Request (org.restlet.Request)2 HttpClientResponse (org.forgerock.http.client.response.HttpClientResponse)1 SimpleHttpClientResponse (org.forgerock.http.client.response.SimpleHttpClientResponse)1 Client (org.restlet.Client)1 Response (org.restlet.Response)1