Skip to content

Commit

Permalink
Merge branch 'main' of github.com:ActiveCampaign/postmark-java
Browse files Browse the repository at this point in the history
  • Loading branch information
ibalosh committed Mar 6, 2023
2 parents face255 + 2bcea7b commit b71f8da
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/main/java/com/postmarkapp/postmark/client/HttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
import org.apache.hc.core5.http.ClassicHttpRequest;
import org.apache.hc.core5.http.ContentType;
import org.apache.hc.core5.http.io.entity.EntityUtils;
import org.apache.hc.core5.http.io.support.ClassicRequestBuilder;
import org.apache.hc.core5.util.Timeout;

import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Map;

/**
Expand Down Expand Up @@ -77,15 +80,15 @@ public ClientResponse execute(REQUEST_TYPES requestType, String url, String data

switch (requestType) {
case POST:
request = ClassicRequestBuilder.post(getHttpUrl(url)).setEntity(data).build();
request = ClassicRequestBuilder.post(getHttpUrl(url)).setEntity(data, ContentType.APPLICATION_JSON).build();
break;

case PUT:
request = ClassicRequestBuilder.put(getHttpUrl(url)).setEntity(data).build();
request = ClassicRequestBuilder.put(getHttpUrl(url)).setEntity(data, ContentType.APPLICATION_JSON).build();
break;

case PATCH:
request = ClassicRequestBuilder.patch(getHttpUrl(url)).setEntity(data).build();
request = ClassicRequestBuilder.patch(getHttpUrl(url)).setEntity(data, ContentType.APPLICATION_JSON).build();
break;

case DELETE:
Expand Down
23 changes: 23 additions & 0 deletions src/test/java/integration/TemplateTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,29 @@ void createTemplate() throws PostmarkException, IOException {

}

@Test
void createTemplate_should_work_with_utf_8() throws PostmarkException, IOException {

String utf8String = "test html with unicode symbols: € Ä Æ ©";
String templateName = "name";

TemplateContent templateContent = new TemplateContent();
templateContent.setHtmlBody(utf8String);
templateContent.setTextBody("test text");
templateContent.setName(templateName);
templateContent.setSubject("subject");

BaseTemplate response = client.createTemplate(templateContent);
assertEquals(response.getName(),templateName);

Template template = client.getTemplate(response.getTemplateId());
assertEquals(utf8String, template.getHtmlBody());

Integer id = response.getTemplateId();
client.deleteTemplate(id);

}

@Test
void deleteTemplate() throws PostmarkException, IOException {
String templateName = "deleteName";
Expand Down

0 comments on commit b71f8da

Please sign in to comment.