001/* 002 * The contents of this file are subject to the terms of the Common Development and 003 * Distribution License (the License). You may not use this file except in compliance with the 004 * License. 005 * 006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the 007 * specific language governing permission and limitations under the License. 008 * 009 * When distributing Covered Software, include this CDDL Header Notice in each file and include 010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL 011 * Header, with the fields enclosed by brackets [] replaced by your own identifying 012 * information: "Portions copyright [year] [name of copyright owner]". 013 * 014 * Copyright 2015 ForgeRock AS. 015 */ 016 017package org.forgerock.audit.events.handlers; 018 019import static org.forgerock.json.JsonValue.json; 020import static org.forgerock.json.JsonValue.object; 021import static org.forgerock.json.resource.Responses.newQueryResponse; 022import static org.forgerock.json.resource.Responses.newResourceResponse; 023 024import java.util.Collections; 025 026import org.forgerock.audit.events.EventTopicsMetaData; 027import org.forgerock.json.JsonValue; 028import org.forgerock.json.resource.BadRequestException; 029import org.forgerock.json.resource.QueryRequest; 030import org.forgerock.json.resource.QueryResourceHandler; 031import org.forgerock.json.resource.QueryResponse; 032import org.forgerock.json.resource.ResourceException; 033import org.forgerock.json.resource.ResourceResponse; 034import org.forgerock.services.context.Context; 035import org.forgerock.util.promise.Promise; 036 037/** 038 * An event handler that does nothing. 039 * <p> 040 * The purpose of this handler is mainly to be able to assess performance of the Audit Service alone, without 041 * the cost implied by the actual handlers. 042 */ 043public class NoOpAuditEventHandler extends AuditEventHandlerBase { 044 045 public NoOpAuditEventHandler() { 046 super("NullAuditEventHandler", 047 new EventTopicsMetaData(Collections.<String, JsonValue>emptyMap()), Collections.<String>emptySet(), true); 048 } 049 050 @Override 051 public void startup() throws ResourceException { 052 // nothing to do 053 } 054 055 @Override 056 public void shutdown() throws ResourceException { 057 // nothing to do 058 } 059 060 @Override 061 public Promise<ResourceResponse, ResourceException> publishEvent(Context context, String topic, JsonValue event) { 062 return newResourceResponse(event.get(ResourceResponse.FIELD_CONTENT_ID).asString(), null, event).asPromise(); 063 } 064 065 @Override 066 public Promise<QueryResponse, ResourceException> queryEvents(Context context, String topic, QueryRequest query, 067 QueryResourceHandler handler) { 068 try { 069 return newQueryResponse().asPromise(); 070 } catch (Exception e) { 071 return new BadRequestException(e).asPromise(); 072 } 073 } 074 075 @Override 076 public Promise<ResourceResponse, ResourceException> readEvent(Context context, String topic, String resourceId) { 077 return newResourceResponse(resourceId, null, json(object())).asPromise(); 078 } 079 080}