Skip to content

Commit

Permalink
Create a Inbound Parse data parser sendgrid#144 (wip)
Browse files Browse the repository at this point in the history
  • Loading branch information
florian-f committed Oct 31, 2016
1 parent 8703eb6 commit e9d66ea
Show file tree
Hide file tree
Showing 9 changed files with 384 additions and 0 deletions.
13 changes: 13 additions & 0 deletions examples/helpers/inbound/dropwizard-parse-example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# ParseExample

How to start the ParseExample application
---

1. Run `mvn clean install` to build your application
1. Start application with `java -jar target/dropwizard-parse-example-1.0-SNAPSHOT.jar server config.yml`
1. To check that your application is running enter url `http://localhost:8080`

Health Check
---

To see your applications health enter url `http://localhost:8081/healthcheck`
4 changes: 4 additions & 0 deletions examples/helpers/inbound/dropwizard-parse-example/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
logging:
level: INFO
loggers:
com.sendgrid: DEBUG
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.sendgrid</groupId>
<artifactId>dropwizard-parse-example</artifactId>
<name>ParseExample</name>
<version>1.0-SNAPSHOT</version>
<prerequisites>
<maven>3.0.0</maven>
</prerequisites>
<build>
<plugins>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
<configuration>
<createDependencyReducedPom>true</createDependencyReducedPom>
<transformers>
<transformer />
<transformer>
<mainClass>${mainClass}</mainClass>
</transformer>
</transformers>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>${mainClass}</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.3</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>2.8.1</version>
<configuration>
<dependencyLocationsEnabled>false</dependencyLocationsEnabled>
<dependencyDetailsEnabled>false</dependencyDetailsEnabled>
</configuration>
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.3</version>
</plugin>
</plugins>
</reporting>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-bom</artifactId>
<version>${dropwizard.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<properties>
<dropwizard.version>1.0.3</dropwizard.version>
<mainClass>com.sendgrid.ParseExampleApplication</mainClass>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>

146 changes: 146 additions & 0 deletions examples/helpers/inbound/dropwizard-parse-example/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>
<prerequisites>
<maven>3.0.0</maven>
</prerequisites>

<groupId>com.sendgrid</groupId>
<artifactId>dropwizard-parse-example</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>ParseExample</name>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<dropwizard.version>1.0.3</dropwizard.version>
<mainClass>com.sendgrid.ParseExampleApplication</mainClass>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-bom</artifactId>
<version>${dropwizard.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-core</artifactId>
</dependency>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-forms</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<createDependencyReducedPom>true</createDependencyReducedPom>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>${mainClass}</mainClass>
</transformer>
</transformers>
<!-- exclude signed Manifests -->
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>${mainClass}</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.3</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

<reporting>
<plugins>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>2.8.1</version>
<configuration>
<dependencyLocationsEnabled>false</dependencyLocationsEnabled>
<dependencyDetailsEnabled>false</dependencyDetailsEnabled>
</configuration>
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.3</version>
</plugin>
</plugins>
</reporting>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.sendgrid;

import com.sendgrid.resources.ParseResource;
import io.dropwizard.Application;
import io.dropwizard.forms.MultiPartBundle;
import io.dropwizard.setup.Bootstrap;
import io.dropwizard.setup.Environment;

public class ParseExampleApplication extends Application<ParseExampleConfiguration> {

public static void main(final String[] args) throws Exception {
new ParseExampleApplication().run(args);
}

@Override
public String getName() {
return "ParseExample";
}

@Override
public void initialize(final Bootstrap<ParseExampleConfiguration> bootstrap) {
bootstrap.addBundle(new MultiPartBundle());
}

@Override
public void run(final ParseExampleConfiguration configuration,
final Environment environment) {
final ParseResource resource = new ParseResource();
environment.jersey().register(resource);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.sendgrid;

import io.dropwizard.Configuration;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.hibernate.validator.constraints.*;
import javax.validation.constraints.*;

public class ParseExampleConfiguration extends Configuration {
// TODO: implement service configuration
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.sendgrid.api;

import com.fasterxml.jackson.annotation.JsonProperty;

public class Parse {

@JsonProperty
private String envelope;

public String getEnvelope() {
return envelope;
}

public void setEnvelope(String envelope) {
this.envelope = envelope;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.sendgrid.resources;

import com.sendgrid.api.Parse;
import org.glassfish.jersey.media.multipart.FormDataParam;
import org.hibernate.validator.constraints.NotBlank;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.core.MediaType;

@Path("/")
public class ParseResource {

@GET
public String hello() {
return "hello";
}

@POST
@Path("/inbound")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public String inbound(@FormDataParam("data") Parse parse) {
System.out.println(parse.getEnvelope());
return "OK";
}
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
================================================================================

ParseExample

================================================================================

0 comments on commit e9d66ea

Please sign in to comment.