Search in sources :

Example 51 with Request

use of org.forgerock.http.protocol.Request in project OpenAM by OpenRock.

the class LogWriter method sendEvent.

private static void sendEvent(String topic, JsonValue eventJson, String sessionId, String baseUrl) throws HttpApplicationException, URISyntaxException {
    Client client = new Client(new HttpClientHandler());
    Request request = new Request();
    request.setMethod("POST");
    if (eventJson.isDefined(EVENT_REALM)) {
        String realm = eventJson.get(EVENT_REALM).asString();
        baseUrl = baseUrl + "/json/realm-audit" + (realm.endsWith("/") ? realm : realm + "/");
    } else {
        baseUrl = baseUrl + "/json/global-audit/";
    }
    request.setUri(baseUrl + topic + "?_action=create");
    request.getHeaders().add(SystemProperties.get("com.iplanet.am.cookie.name"), sessionId);
    request.getHeaders().add(new AcceptApiVersionHeader(version(1), version(1)));
    request.getEntity().setJson(eventJson.getObject());
    client.send(request).then(WARN_OF_FAILURES_FUNCTION);
}
Also used : Request(org.forgerock.http.protocol.Request) Client(org.forgerock.http.Client) AcceptApiVersionHeader(org.forgerock.http.header.AcceptApiVersionHeader) HttpClientHandler(org.forgerock.http.handler.HttpClientHandler)

Aggregations

Request (org.forgerock.http.protocol.Request)51 Test (org.testng.annotations.Test)45 Context (org.forgerock.services.context.Context)36 RootContext (org.forgerock.services.context.RootContext)33 AttributesContext (org.forgerock.services.context.AttributesContext)30 ReadRequest (org.forgerock.json.resource.ReadRequest)29 ActionRequest (org.forgerock.json.resource.ActionRequest)21 CreateRequest (org.forgerock.json.resource.CreateRequest)21 DeleteRequest (org.forgerock.json.resource.DeleteRequest)21 PatchRequest (org.forgerock.json.resource.PatchRequest)21 QueryRequest (org.forgerock.json.resource.QueryRequest)21 UpdateRequest (org.forgerock.json.resource.UpdateRequest)21 UriRouterContext (org.forgerock.http.routing.UriRouterContext)19 Response (org.forgerock.http.protocol.Response)14 SessionContext (org.forgerock.http.session.SessionContext)11 Handler (org.forgerock.http.Handler)10 RequestAuditContext (org.forgerock.services.context.RequestAuditContext)9 HttpServletRequest (javax.servlet.http.HttpServletRequest)8 HttpContext (org.forgerock.json.resource.http.HttpContext)7 SSOTokenContext (org.forgerock.openam.rest.resource.SSOTokenContext)7