Skip to content

Commit

Permalink
Merge pull request #58 from SparkPost/feature/httpclient_4_5_3_compat…
Browse files Browse the repository at this point in the history
…_issue57

Feature/httpclient 4 5 3 compat issue57
  • Loading branch information
yepher authored Mar 8, 2017
2 parents b7fcbf4 + a183530 commit 2828ad0
Show file tree
Hide file tree
Showing 56 changed files with 1,727 additions and 275 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ Use this library in Java applications to easily access the SparkPost Email API i

## Version Compatibility Note

### Version 0.6.2 -> 0.6.3

Due to [issue 57](https://github.com/SparkPost/java-sparkpost/issues/57) and to maintain compatibility with old and new version of Apache HTTP Client `SPARKPOST_BASE_URL` must not end with a `/` slash.

### Version 0.12 -> 0.13

Although we try to maintain library backward compatibility this migration may require some minor changes to your code. Substitution data was changed from `Map<String, String>` to `Map<String, Object>`. Most client code will just need to change their map to this new signature.
Expand All @@ -23,7 +27,7 @@ The SparkPost Java Library is available in this [Maven Repository](http://maven.
<dependency>
<groupId>com.sparkpost</groupId>
<artifactId>sparkpost-lib</artifactId>
<version>0.16.2</version>
<version>0.17</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion apps/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>com.sparkpost</groupId>
<artifactId>sparkpost</artifactId>
<version>0.16.2</version>
<version>0.17</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>apps</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion apps/sparkpost-documentor-app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.sparkpost</groupId>
<artifactId>apps</artifactId>
<version>0.16.2</version>
<version>0.17</version>
</parent>
<artifactId>sparkpost-documentor-app</artifactId>
<name>Generates Markdown of Protocol</name>
Expand Down
2 changes: 1 addition & 1 deletion apps/sparkpost-javamail-app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.sparkpost</groupId>
<artifactId>apps</artifactId>
<version>0.16.2</version>
<version>0.17</version>
</parent>
<groupId>com.sparkpost.sample</groupId>
<artifactId>sparkpost-javamail-app</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.sparkpost.model.responses.Response;
import com.sparkpost.resources.ResourceTransmissions;
import com.sparkpost.sample.helpers.SparkPostBaseApp;
import com.sparkpost.transport.IRestConnection;
import com.sparkpost.transport.RestConnection;

/**
Expand Down Expand Up @@ -96,7 +97,7 @@ private void sendEmail(String from, String[] recipients, String email) throws Sp
transmission.setContentAttributes(contentAttributes);

// Send the Email
RestConnection connection = new RestConnection(sparkpostClient, getEndPoint());
IRestConnection connection = new RestConnection(sparkpostClient, getEndPoint());

Response response = ResourceTransmissions.create(connection, 0, transmission);
if (response.getResponseCode() == 200) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import com.sparkpost.Client;
import com.sparkpost.exception.SparkPostException;
import com.sparkpost.transport.RestConnection;
import com.sparkpost.transport.IRestConnection;

/**
* A simple class to setup up the SparkPost client with the API KEY from a property file.
Expand Down Expand Up @@ -52,7 +52,7 @@ protected Client newConfiguredClient() throws SparkPostException, IOException {
}

public String getEndPoint() {
String endpoint = this.properties.getProperty("SPARKPOST_BASE_URL", RestConnection.defaultApiEndpoint);
String endpoint = this.properties.getProperty("SPARKPOST_BASE_URL", IRestConnection.defaultApiEndpoint);

return endpoint;
}
Expand Down
2 changes: 1 addition & 1 deletion apps/sparkpost-samples-app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.sparkpost</groupId>
<artifactId>apps</artifactId>
<version>0.16.2</version>
<version>0.17</version>
</parent>
<artifactId>sparkpost-samples-app</artifactId>
<name>Example use SparkPost library</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.sparkpost.exception.SparkPostException;
import com.sparkpost.resources.ResourceSendingDomains;
import com.sparkpost.sdk.samples.helpers.SparkPostBaseApp;
import com.sparkpost.transport.IRestConnection;
import com.sparkpost.transport.RestConnection;

/**
Expand All @@ -32,7 +33,7 @@ public static void main(String[] args) throws SparkPostException, IOException {
private void runApp() throws SparkPostException, IOException {
this.client = this.newConfiguredClient();
this.client.setAuthKey("This_is_a_bad_api_key");
RestConnection connection = new RestConnection(this.client, getEndPoint());
IRestConnection connection = new RestConnection(this.client, getEndPoint());
try {
ResourceSendingDomains.list(connection);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.sparkpost.model.Webhook;
import com.sparkpost.resources.ResourceWebhooks;
import com.sparkpost.sdk.samples.helpers.SparkPostBaseApp;
import com.sparkpost.transport.IRestConnection;
import com.sparkpost.transport.RestConnection;

public class ForceTransportError extends SparkPostBaseApp {
Expand Down Expand Up @@ -41,7 +42,7 @@ private void runApp() throws SparkPostException, IOException {
private void foceFourHundredError() throws SparkPostException, IOException {
this.client = this.newConfiguredClient();

RestConnection restConnection = new RestConnection(this.client);
IRestConnection restConnection = new RestConnection(this.client);
Webhook webhook = new Webhook();
webhook.setName("name with spaces");
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.sparkpost.model.responses.ServerErrorResponse;
import com.sparkpost.resources.ResourceTransmissions;
import com.sparkpost.sdk.samples.helpers.SparkPostBaseApp;
import com.sparkpost.transport.IRestConnection;
import com.sparkpost.transport.RestConnection;

public class SendEmailErrorSample extends SparkPostBaseApp {
Expand Down Expand Up @@ -78,7 +79,7 @@ private void sendEmail(String from, String[] recipients) throws SparkPostExcepti
transmission.setContentAttributes(contentAttributes);

// Send the Email
RestConnection connection = new RestConnection(this.client, getEndPoint());
IRestConnection connection = new RestConnection(this.client, getEndPoint());

try {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.sparkpost.model.responses.ServerErrorResponse;
import com.sparkpost.resources.ResourceTransmissions;
import com.sparkpost.sdk.samples.helpers.SparkPostBaseApp;
import com.sparkpost.transport.IRestConnection;
import com.sparkpost.transport.RestConnection;

public class SendInvalidFromAddress extends SparkPostBaseApp {
Expand Down Expand Up @@ -75,7 +76,7 @@ private void sendEmail(String from, String[] recipients) throws SparkPostExcepti

// Send the Email
try {
RestConnection connection = new RestConnection(this.client, getEndPoint());
IRestConnection connection = new RestConnection(this.client, getEndPoint());
ResourceTransmissions.create(connection, 0, transmission);

throw new IllegalStateException("Error: Expected Exception for invalid to address");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.sparkpost.model.responses.Response;
import com.sparkpost.resources.ResourceRecipientLists;
import com.sparkpost.sdk.samples.helpers.SparkPostBaseApp;
import com.sparkpost.transport.IRestConnection;
import com.sparkpost.transport.RestConnection;

/**
Expand Down Expand Up @@ -48,7 +49,7 @@ private void runApp() throws SparkPostException, IOException {
RecipientList recipientList = createRecipientList();

client = this.newConfiguredClient();
RestConnection connection = new RestConnection(client, getEndPoint());
IRestConnection connection = new RestConnection(client, getEndPoint());

Response response = ResourceRecipientLists.create(connection, 0, recipientList);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.sparkpost.model.responses.Response;
import com.sparkpost.resources.ResourceTemplates;
import com.sparkpost.sdk.samples.helpers.SparkPostBaseApp;
import com.sparkpost.transport.IRestConnection;
import com.sparkpost.transport.RestConnection;

/**
Expand Down Expand Up @@ -57,7 +58,7 @@ public void createTemplate(String rfc822Content, String name) throws SparkPostEx
content.setEmailRFC822(rfc822Content);
template.setContent(content);

RestConnection connection = new RestConnection(client, getEndPoint());
IRestConnection connection = new RestConnection(client, getEndPoint());
try {
Response response = ResourceTemplates.create(connection, template);
if (logger.isDebugEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.sparkpost.model.responses.Response;
import com.sparkpost.resources.ResourceTemplates;
import com.sparkpost.sdk.samples.helpers.SparkPostBaseApp;
import com.sparkpost.transport.IRestConnection;
import com.sparkpost.transport.RestConnection;

/**
Expand Down Expand Up @@ -58,7 +59,7 @@ public void createTemplate(String html, String name) throws SparkPostException {
content.setHtml(html);
template.setContent(content);

RestConnection connection = new RestConnection(client, getEndPoint());
IRestConnection connection = new RestConnection(client, getEndPoint());
try {
Response response = ResourceTemplates.create(connection, template);
if (logger.isDebugEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.sparkpost.model.responses.Response;
import com.sparkpost.resources.ResourceTemplates;
import com.sparkpost.sdk.samples.helpers.SparkPostBaseApp;
import com.sparkpost.transport.IRestConnection;
import com.sparkpost.transport.RestConnection;

public class CreateTemplateSimple extends SparkPostBaseApp {
Expand Down Expand Up @@ -51,7 +52,7 @@ public void createTemplate() throws SparkPostException {
tpl.getContent().setFrom(new AddressAttributes(client.getFromEmail(), "me", null));
tpl.getContent().setHtml("Hello!");
tpl.getContent().setSubject("Template Test");
RestConnection connection = new RestConnection(client, getEndPoint());
IRestConnection connection = new RestConnection(client, getEndPoint());
Response response = ResourceTemplates.create(connection, tpl);

if (logger.isDebugEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.sparkpost.model.responses.TemplateListResponse;
import com.sparkpost.resources.ResourceTemplates;
import com.sparkpost.sdk.samples.helpers.SparkPostBaseApp;
import com.sparkpost.transport.IRestConnection;
import com.sparkpost.transport.RestConnection;

/**
Expand All @@ -34,7 +35,7 @@ public static void main(String[] args) throws SparkPostException, IOException {

private void runApp() throws SparkPostException, IOException {
client = this.newConfiguredClient();
RestConnection connection = new RestConnection(client, getEndPoint());
IRestConnection connection = new RestConnection(client, getEndPoint());

// Get All Templates
TemplateListResponse listResponse = ResourceTemplates.listAll(connection);
Expand All @@ -49,7 +50,7 @@ private void runApp() throws SparkPostException, IOException {
}
}

private void deleteTemplate(RestConnection connection, String templateId) throws SparkPostException {
private void deleteTemplate(IRestConnection connection, String templateId) throws SparkPostException {
Response deleteResponse = ResourceTemplates.delete(connection, templateId);
if (deleteResponse.getResponseCode() == 200) {
System.out.println("\tdeleted: " + templateId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.sparkpost.model.responses.WebhookListAllResponse;
import com.sparkpost.resources.ResourceWebhooks;
import com.sparkpost.sdk.samples.helpers.SparkPostBaseApp;
import com.sparkpost.transport.IRestConnection;
import com.sparkpost.transport.RestConnection;

/**
Expand All @@ -32,7 +33,7 @@ public static void main(String[] args) throws SparkPostException, IOException {

private void runApp() throws SparkPostException, IOException {
this.client = this.newConfiguredClient();
RestConnection connection = new RestConnection(this.client, getEndPoint());
IRestConnection connection = new RestConnection(this.client, getEndPoint());
WebhookListAllResponse response = ResourceWebhooks.listAll(connection, "America/Chicago");

int deletedCount = 0;
Expand Down
Loading

0 comments on commit 2828ad0

Please sign in to comment.