From 8703eb6b484dd729fd67e914ed70b77ab4f88889 Mon Sep 17 00:00:00 2001 From: Florian Friemel Date: Mon, 31 Oct 2016 08:47:45 +0100 Subject: [PATCH 1/2] Create a test Inbound Parse data sender #145 --- .../inbound/java-send/default_data.txt | 58 +++++++++++++++++++ .../java-send/src/com/example/Main.java | 29 ++++++++++ 2 files changed, 87 insertions(+) create mode 100644 examples/helpers/inbound/java-send/default_data.txt create mode 100644 examples/helpers/inbound/java-send/src/com/example/Main.java diff --git a/examples/helpers/inbound/java-send/default_data.txt b/examples/helpers/inbound/java-send/default_data.txt new file mode 100644 index 00000000..cdf52d68 --- /dev/null +++ b/examples/helpers/inbound/java-send/default_data.txt @@ -0,0 +1,58 @@ +--xYzZY +Content-Disposition: form-data; name="headers" + +MIME-Version: 1.0 +Received: by 0.0.0.0 with HTTP; Wed, 10 Aug 2016 18:10:13 -0700 (PDT) +From: Example User +Date: Wed, 10 Aug 2016 18:10:13 -0700 +Subject: Inbound Parse Test Data +To: inbound@inbound.example.com +Content-Type: multipart/alternative; boundary=001a113df448cad2d00539c16e89 + +--xYzZY +Content-Disposition: form-data; name="dkim" + +{@sendgrid.com : pass} +--xYzZY +Content-Disposition: form-data; name="to" + +inbound@inbound.example.com +--xYzZY +Content-Disposition: form-data; name="html" + +Hello SendGrid! + +--xYzZY +Content-Disposition: form-data; name="from" + +Example User +--xYzZY +Content-Disposition: form-data; name="text" + +Hello SendGrid! + +--xYzZY +Content-Disposition: form-data; name="sender_ip" + +0.0.0.0 +--xYzZY +Content-Disposition: form-data; name="envelope" + +{"to":["inbound@inbound.example.com"],"from":"test@example.com"} +--xYzZY +Content-Disposition: form-data; name="attachments" + +0 +--xYzZY +Content-Disposition: form-data; name="subject" + +Testing non-raw +--xYzZY +Content-Disposition: form-data; name="charsets" + +{"to":"UTF-8","html":"UTF-8","subject":"UTF-8","from":"UTF-8","text":"UTF-8"} +--xYzZY +Content-Disposition: form-data; name="SPF" + +pass +--xYzZY-- \ No newline at end of file diff --git a/examples/helpers/inbound/java-send/src/com/example/Main.java b/examples/helpers/inbound/java-send/src/com/example/Main.java new file mode 100644 index 00000000..5b211f7f --- /dev/null +++ b/examples/helpers/inbound/java-send/src/com/example/Main.java @@ -0,0 +1,29 @@ +package com.example; + +import java.io.IOException; +import java.io.OutputStream; +import java.net.*; +import java.nio.file.Files; +import java.nio.file.Paths; + +public class Main { + + public static void main(String[] args) throws IOException { + + URL url = new URL(args[1]); + URLConnection con = url.openConnection(); + HttpURLConnection http = (HttpURLConnection) con; + http.setRequestMethod("POST"); + http.setDoOutput(true); + + byte[] out = Files.readAllBytes(Paths.get(args[0])); + int length = out.length; + + http.setFixedLengthStreamingMode(length); + http.setRequestProperty("Content-Type", "multipart/form-data; boundary=xYzZY"); + http.connect(); + try (OutputStream os = http.getOutputStream()) { + os.write(out); + } + } +} From e9d66ea067f3e60d277bde30b854ae66c10bd4ca Mon Sep 17 00:00:00 2001 From: Florian Friemel Date: Mon, 31 Oct 2016 09:11:51 +0100 Subject: [PATCH 2/2] Create a Inbound Parse data parser #144 (wip) --- .../dropwizard-parse-example/README.md | 13 ++ .../dropwizard-parse-example/config.yml | 4 + .../dependency-reduced-pom.xml | 124 +++++++++++++++ .../inbound/dropwizard-parse-example/pom.xml | 146 ++++++++++++++++++ .../com/sendgrid/ParseExampleApplication.java | 32 ++++ .../sendgrid/ParseExampleConfiguration.java | 10 ++ .../src/main/java/com/sendgrid/api/Parse.java | 17 ++ .../com/sendgrid/resources/ParseResource.java | 32 ++++ .../src/main/resources/banner.txt | 6 + 9 files changed, 384 insertions(+) create mode 100644 examples/helpers/inbound/dropwizard-parse-example/README.md create mode 100644 examples/helpers/inbound/dropwizard-parse-example/config.yml create mode 100644 examples/helpers/inbound/dropwizard-parse-example/dependency-reduced-pom.xml create mode 100644 examples/helpers/inbound/dropwizard-parse-example/pom.xml create mode 100644 examples/helpers/inbound/dropwizard-parse-example/src/main/java/com/sendgrid/ParseExampleApplication.java create mode 100644 examples/helpers/inbound/dropwizard-parse-example/src/main/java/com/sendgrid/ParseExampleConfiguration.java create mode 100644 examples/helpers/inbound/dropwizard-parse-example/src/main/java/com/sendgrid/api/Parse.java create mode 100644 examples/helpers/inbound/dropwizard-parse-example/src/main/java/com/sendgrid/resources/ParseResource.java create mode 100644 examples/helpers/inbound/dropwizard-parse-example/src/main/resources/banner.txt diff --git a/examples/helpers/inbound/dropwizard-parse-example/README.md b/examples/helpers/inbound/dropwizard-parse-example/README.md new file mode 100644 index 00000000..dea9a801 --- /dev/null +++ b/examples/helpers/inbound/dropwizard-parse-example/README.md @@ -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` diff --git a/examples/helpers/inbound/dropwizard-parse-example/config.yml b/examples/helpers/inbound/dropwizard-parse-example/config.yml new file mode 100644 index 00000000..4285a87e --- /dev/null +++ b/examples/helpers/inbound/dropwizard-parse-example/config.yml @@ -0,0 +1,4 @@ +logging: + level: INFO + loggers: + com.sendgrid: DEBUG diff --git a/examples/helpers/inbound/dropwizard-parse-example/dependency-reduced-pom.xml b/examples/helpers/inbound/dropwizard-parse-example/dependency-reduced-pom.xml new file mode 100644 index 00000000..08435570 --- /dev/null +++ b/examples/helpers/inbound/dropwizard-parse-example/dependency-reduced-pom.xml @@ -0,0 +1,124 @@ + + + 4.0.0 + com.sendgrid + dropwizard-parse-example + ParseExample + 1.0-SNAPSHOT + + 3.0.0 + + + + + maven-shade-plugin + 2.4.1 + + + package + + shade + + + + + true + + + + ${mainClass} + + + + + *:* + + META-INF/*.SF + META-INF/*.DSA + META-INF/*.RSA + + + + + + + maven-jar-plugin + 2.6 + + + + true + ${mainClass} + + + + + + maven-compiler-plugin + 3.3 + + 1.8 + 1.8 + + + + maven-source-plugin + 2.4 + + + attach-sources + + jar + + + + + + maven-javadoc-plugin + 2.10.3 + + + attach-javadocs + + jar + + + + + + + + + + maven-project-info-reports-plugin + 2.8.1 + + false + false + + + + maven-javadoc-plugin + 2.10.3 + + + + + + + io.dropwizard + dropwizard-bom + ${dropwizard.version} + pom + import + + + + + 1.0.3 + com.sendgrid.ParseExampleApplication + UTF-8 + UTF-8 + + + diff --git a/examples/helpers/inbound/dropwizard-parse-example/pom.xml b/examples/helpers/inbound/dropwizard-parse-example/pom.xml new file mode 100644 index 00000000..d28cba71 --- /dev/null +++ b/examples/helpers/inbound/dropwizard-parse-example/pom.xml @@ -0,0 +1,146 @@ + + + + 4.0.0 + + 3.0.0 + + + com.sendgrid + dropwizard-parse-example + 1.0-SNAPSHOT + jar + + ParseExample + + + UTF-8 + UTF-8 + 1.0.3 + com.sendgrid.ParseExampleApplication + + + + + + io.dropwizard + dropwizard-bom + ${dropwizard.version} + pom + import + + + + + + + io.dropwizard + dropwizard-core + + + io.dropwizard + dropwizard-forms + + + + + + + maven-shade-plugin + 2.4.1 + + true + + + + ${mainClass} + + + + + + *:* + + META-INF/*.SF + META-INF/*.DSA + META-INF/*.RSA + + + + + + + package + + shade + + + + + + maven-jar-plugin + 2.6 + + + + true + ${mainClass} + + + + + + maven-compiler-plugin + 3.3 + + 1.8 + 1.8 + + + + maven-source-plugin + 2.4 + + + attach-sources + + jar + + + + + + maven-javadoc-plugin + 2.10.3 + + + attach-javadocs + + jar + + + + + + + + + + + maven-project-info-reports-plugin + 2.8.1 + + false + false + + + + maven-javadoc-plugin + 2.10.3 + + + + diff --git a/examples/helpers/inbound/dropwizard-parse-example/src/main/java/com/sendgrid/ParseExampleApplication.java b/examples/helpers/inbound/dropwizard-parse-example/src/main/java/com/sendgrid/ParseExampleApplication.java new file mode 100644 index 00000000..802ffaef --- /dev/null +++ b/examples/helpers/inbound/dropwizard-parse-example/src/main/java/com/sendgrid/ParseExampleApplication.java @@ -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 { + + 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 bootstrap) { + bootstrap.addBundle(new MultiPartBundle()); + } + + @Override + public void run(final ParseExampleConfiguration configuration, + final Environment environment) { + final ParseResource resource = new ParseResource(); + environment.jersey().register(resource); + } + +} diff --git a/examples/helpers/inbound/dropwizard-parse-example/src/main/java/com/sendgrid/ParseExampleConfiguration.java b/examples/helpers/inbound/dropwizard-parse-example/src/main/java/com/sendgrid/ParseExampleConfiguration.java new file mode 100644 index 00000000..4088c0c2 --- /dev/null +++ b/examples/helpers/inbound/dropwizard-parse-example/src/main/java/com/sendgrid/ParseExampleConfiguration.java @@ -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 +} diff --git a/examples/helpers/inbound/dropwizard-parse-example/src/main/java/com/sendgrid/api/Parse.java b/examples/helpers/inbound/dropwizard-parse-example/src/main/java/com/sendgrid/api/Parse.java new file mode 100644 index 00000000..e70c60aa --- /dev/null +++ b/examples/helpers/inbound/dropwizard-parse-example/src/main/java/com/sendgrid/api/Parse.java @@ -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; + } +} diff --git a/examples/helpers/inbound/dropwizard-parse-example/src/main/java/com/sendgrid/resources/ParseResource.java b/examples/helpers/inbound/dropwizard-parse-example/src/main/java/com/sendgrid/resources/ParseResource.java new file mode 100644 index 00000000..69d81b08 --- /dev/null +++ b/examples/helpers/inbound/dropwizard-parse-example/src/main/java/com/sendgrid/resources/ParseResource.java @@ -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"; + } +} + + diff --git a/examples/helpers/inbound/dropwizard-parse-example/src/main/resources/banner.txt b/examples/helpers/inbound/dropwizard-parse-example/src/main/resources/banner.txt new file mode 100644 index 00000000..e783f16d --- /dev/null +++ b/examples/helpers/inbound/dropwizard-parse-example/src/main/resources/banner.txt @@ -0,0 +1,6 @@ +================================================================================ + + ParseExample + +================================================================================ +