diff --git a/.build-rpm b/.build-rpm new file mode 100644 index 0000000..e69de29 diff --git a/pom.xml b/pom.xml old mode 100644 new mode 100755 index f0d60d4..d662d31 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ com.proofpoint.platform rest-server-base - 1.02 + 1.07 @@ -25,6 +25,7 @@ com.proofpoint.event.collector.Main + platform @@ -167,8 +168,8 @@ - com.sun.jersey - jersey-core + javax.ws.rs + javax.ws.rs-api diff --git a/src/main/java/com/proofpoint/event/collector/EventResource.java b/src/main/java/com/proofpoint/event/collector/EventResource.java index 82a71ba..8cca3d6 100644 --- a/src/main/java/com/proofpoint/event/collector/EventResource.java +++ b/src/main/java/com/proofpoint/event/collector/EventResource.java @@ -63,6 +63,15 @@ public Response write(List events) return processEvents(WRITER, events, WRITE); } + // Separate method to permit gathering of statistics + @POST + @Consumes("application/x-jackson-smile") + public Response writeSmile(List events) + throws IOException + { + return write(events); + } + @POST @Path("/distribute") @Consumes(MediaType.APPLICATION_JSON) @@ -72,6 +81,17 @@ public Response distribute(List events) return processEvents(DISTRIBUTOR, events, DISTRIBUTE); } + + // Separate method to permit gathering of statistics + @POST + @Path("/distribute") + @Consumes("application/x-jackson-smile") + public Response distributeSmile(List events) + throws IOException + { + return distribute(events); + } + private Response processEvents(EventProcessor processor, List events, ProcessType processType) throws IOException { diff --git a/src/main/java/com/proofpoint/event/collector/Main.java b/src/main/java/com/proofpoint/event/collector/Main.java index c33cb07..b4f28e6 100755 --- a/src/main/java/com/proofpoint/event/collector/Main.java +++ b/src/main/java/com/proofpoint/event/collector/Main.java @@ -21,7 +21,6 @@ import com.proofpoint.discovery.client.announce.Announcer; import com.proofpoint.event.client.JsonEventModule; import com.proofpoint.http.server.HttpServerModule; -import com.proofpoint.jaxrs.JaxrsModule; import com.proofpoint.jmx.JmxHttpModule; import com.proofpoint.jmx.JmxModule; import com.proofpoint.json.JsonModule; @@ -31,6 +30,8 @@ import com.proofpoint.reporting.ReportingModule; import org.weakref.jmx.guice.MBeanModule; +import static com.proofpoint.jaxrs.JaxrsModule.explicitJaxrsModule; + public class Main { private final static Logger log = Logger.get(Main.class); @@ -45,7 +46,7 @@ public static void main(String[] args) new DiscoveryModule(), new HttpServerModule(), new JsonModule(), - new JaxrsModule(), + explicitJaxrsModule(), new MBeanModule(), new JmxModule(), new JmxHttpModule(), diff --git a/src/main/java/com/proofpoint/event/collector/MainModule.java b/src/main/java/com/proofpoint/event/collector/MainModule.java index af07313..19e9212 100644 --- a/src/main/java/com/proofpoint/event/collector/MainModule.java +++ b/src/main/java/com/proofpoint/event/collector/MainModule.java @@ -47,6 +47,7 @@ import static com.proofpoint.configuration.ConfigurationModule.bindConfig; import static com.proofpoint.discovery.client.DiscoveryBinder.discoveryBinder; import static com.proofpoint.event.client.EventBinder.eventBinder; +import static com.proofpoint.jaxrs.JaxrsBinder.jaxrsBinder; import static com.proofpoint.reporting.ReportBinder.reportBinder; import static org.weakref.jmx.guice.ExportBinder.newExporter; import static java.util.concurrent.Executors.newScheduledThreadPool; @@ -71,7 +72,7 @@ public void configure(Binder binder) newExporter(binder).export(SpoolingEventWriter.class).withGeneratedName(); newSetBinder(binder, EventWriter.class).addBinding().to(Key.get(SpoolingEventWriter.class)).in(Scopes.SINGLETON); - binder.bind(EventResource.class).in(Scopes.SINGLETON); + jaxrsBinder(binder).bind(EventResource.class); binder.bind(StoredObjectCombiner.class).in(Scopes.SINGLETON); newExporter(binder).export(StoredObjectCombiner.class).withGeneratedName(); @@ -86,7 +87,7 @@ public void configure(Binder binder) eventBinder(binder).bindEventClient(CombineCompleted.class); - binder.bind(EventWriterStatsResource.class).in(Scopes.SINGLETON); + jaxrsBinder(binder).bind(EventWriterStatsResource.class); reportBinder(binder).bindReportCollection(EventCollectorStats.class).as(new ObjectNameBuilder(EventCollectorStats.class.getPackage().getName()).withProperty("type", "EventCollector").build()); diff --git a/src/test/java/com/proofpoint/event/collector/TestEventResource.java b/src/test/java/com/proofpoint/event/collector/TestEventResource.java index d4cdfe5..4079e6f 100644 --- a/src/test/java/com/proofpoint/event/collector/TestEventResource.java +++ b/src/test/java/com/proofpoint/event/collector/TestEventResource.java @@ -79,6 +79,24 @@ public void testWrite() verifyMetrics(WRITE, ImmutableList.of(new EventMetric("Test", VALID, 1))); } + @Test + public void testWriteSmile() + throws IOException + { + EventResource resource = new EventResource(ImmutableSet.of(writer), new ServerConfig().setAcceptedEventTypes("Test"), eventCollectorStats); + + Event event = new Event("Test", UUID.randomUUID().toString(), "test.local", new DateTime(), ARBITRARY_DATA); + + List events = ImmutableList.of(event); + Response response = resource.writeSmile(events); + + verifyAcceptedResponse(response); + + verifyWrittenAndDistributedEvents(events, ImmutableList.of()); + + verifyMetrics(WRITE, ImmutableList.of(new EventMetric("Test", VALID, 1))); + } + @Test public void testWriteUnsupportedType() throws IOException @@ -140,6 +158,24 @@ public void testDistribute() verifyMetrics(DISTRIBUTE, ImmutableList.of(new EventMetric("Test", VALID, 1))); } + @Test + public void testDistributeSmile() + throws IOException + { + EventResource resource = new EventResource(ImmutableSet.of(writer), new ServerConfig().setAcceptedEventTypes("Test"), eventCollectorStats); + + Event event = new Event("Test", UUID.randomUUID().toString(), "test.local", new DateTime(), ARBITRARY_DATA); + + List events = ImmutableList.of(event); + Response response = resource.distributeSmile(events); + + verifyAcceptedResponse(response); + + verifyWrittenAndDistributedEvents(ImmutableList.of(), events); + + verifyMetrics(DISTRIBUTE, ImmutableList.of(new EventMetric("Test", VALID, 1))); + } + @Test public void testDistributeUnsupportedType() throws IOException diff --git a/src/test/java/com/proofpoint/event/collector/TestServer.java b/src/test/java/com/proofpoint/event/collector/TestServer.java index 523d3dd..6be33f0 100755 --- a/src/test/java/com/proofpoint/event/collector/TestServer.java +++ b/src/test/java/com/proofpoint/event/collector/TestServer.java @@ -15,7 +15,11 @@ */ package com.proofpoint.event.collector; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.dataformat.smile.SmileFactory; import com.google.common.base.Charsets; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.io.Files; import com.google.common.io.Resources; @@ -30,7 +34,6 @@ import com.proofpoint.http.client.jetty.JettyHttpClient; import com.proofpoint.http.server.testing.TestingHttpServer; import com.proofpoint.http.server.testing.TestingHttpServerModule; -import com.proofpoint.jaxrs.JaxrsModule; import com.proofpoint.jmx.testing.TestingJmxModule; import com.proofpoint.json.JsonCodec; import com.proofpoint.json.JsonModule; @@ -47,12 +50,15 @@ import java.net.URI; import java.util.concurrent.ExecutionException; +import static com.proofpoint.http.client.JsonBodyGenerator.jsonBodyGenerator; import static com.proofpoint.http.client.Request.Builder.prepareDelete; import static com.proofpoint.http.client.Request.Builder.prepareGet; import static com.proofpoint.http.client.Request.Builder.preparePost; +import static com.proofpoint.http.client.SmileBodyGenerator.smileBodyGenerator; import static com.proofpoint.http.client.StaticBodyGenerator.createStaticBodyGenerator; import static com.proofpoint.http.client.StatusResponseHandler.createStatusResponseHandler; import static com.proofpoint.http.client.StringResponseHandler.createStringResponseHandler; +import static com.proofpoint.jaxrs.JaxrsModule.explicitJaxrsModule; import static javax.ws.rs.core.HttpHeaders.CONTENT_TYPE; import static javax.ws.rs.core.MediaType.APPLICATION_JSON; import static javax.ws.rs.core.Response.Status; @@ -60,7 +66,19 @@ public class TestServer { - private JsonCodec OBJECT_CODEC = JsonCodec.jsonCodec(Object.class); + private static final JsonCodec OBJECT_CODEC = JsonCodec.jsonCodec(Object.class); + private static final Object TESTING_SINGLE_EVENT_STRUCTURE = ImmutableList.of( + ImmutableMap.of( + "type", "Test", + "uuid", "DCD36293-3072-4AFD-B6E3-A9EB9CE1F219", + "host", "test.local", + "timestamp", "2011-03-30T16:10:16.000Z", + "data", ImmutableMap.of( + "foo", "bar", + "hello", "world" + ) + ) + ); private HttpClient client; private TestingHttpServer server; private File tempStageDir; @@ -91,7 +109,7 @@ public void setup() new TestingDiscoveryModule(), new TestingJmxModule(), new JsonModule(), - new JaxrsModule(), + explicitJaxrsModule(), new JsonEventModule(), new EventTapModule(), new ReportingModule(), @@ -134,17 +152,30 @@ public void teardown() public void testPostSingle() throws IOException, ExecutionException, InterruptedException { - String json = Resources.toString(Resources.getResource("single.json"), Charsets.UTF_8); StatusResponse response = client.execute(preparePost() .setUri(urlFor("/v2/event")) .setHeader("Content-Type", APPLICATION_JSON) - .setBodyGenerator(createStaticBodyGenerator(json, Charsets.UTF_8)) + .setBodyGenerator(jsonBodyGenerator(OBJECT_CODEC, TESTING_SINGLE_EVENT_STRUCTURE)) .build(), createStatusResponseHandler()); assertEquals(response.getStatusCode(), Status.ACCEPTED.getStatusCode()); } + @Test + public void testPostSmile() + throws IOException, ExecutionException, InterruptedException + { + StatusResponse response = client.execute(preparePost() + .setUri(urlFor("/v2/event")) + .setHeader("Content-Type", "application/x-jackson-smile") + .setBodyGenerator(smileBodyGenerator(OBJECT_CODEC, TESTING_SINGLE_EVENT_STRUCTURE)) + .build(), + createStatusResponseHandler()); + + assertEquals(response.getStatusCode(), Status.ACCEPTED.getStatusCode()); + } + @Test public void testPostMultiple() throws IOException, ExecutionException, InterruptedException @@ -190,17 +221,30 @@ public void testClearSpoolCounts() public void testDistributeSingle() throws IOException, ExecutionException, InterruptedException { - String json = Resources.toString(Resources.getResource("single.json"), Charsets.UTF_8); StatusResponse response = client.execute(preparePost() .setUri(urlFor("/v2/event/distribute")) .setHeader("Content-Type", APPLICATION_JSON) - .setBodyGenerator(createStaticBodyGenerator(json, Charsets.UTF_8)) + .setBodyGenerator(jsonBodyGenerator(OBJECT_CODEC, TESTING_SINGLE_EVENT_STRUCTURE)) .build(), createStatusResponseHandler()); assertEquals(response.getStatusCode(), Status.ACCEPTED.getStatusCode()); } + @Test + public void testDistributeSmile() + throws IOException, ExecutionException, InterruptedException + { + StatusResponse response = client.execute(preparePost() + .setUri(urlFor("/v2/event/distribute")) + .setHeader("Content-Type", "application/x-jackson-smile") + .setBodyGenerator(smileBodyGenerator(OBJECT_CODEC, TESTING_SINGLE_EVENT_STRUCTURE)) + .build(), + createStatusResponseHandler()); + + assertEquals(response.getStatusCode(), Status.ACCEPTED.getStatusCode()); + } + private URI urlFor(String path) { return server.getBaseUrl().resolve(path); diff --git a/src/test/resources/single.json b/src/test/resources/single.json deleted file mode 100644 index 648ec20..0000000 --- a/src/test/resources/single.json +++ /dev/null @@ -1,12 +0,0 @@ -[ - { - "type": "Test", - "uuid": "DCD36293-3072-4AFD-B6E3-A9EB9CE1F219", - "host": "test.local", - "timestamp": "2011-03-30T16:10:16.000Z", - "data": { - "foo": "bar", - "hello": "world" - } - } -]