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