Skip to content

Commit 01abf47

Browse files
Version Bump v2.3.0: Automatically add Content-Type: application/json when there is a request body
1 parent 838da76 commit 01abf47

File tree

8 files changed

+24
-11
lines changed

8 files changed

+24
-11
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file.
33

44
This project adheres to [Semantic Versioning](http://semver.org/).
55

6+
## [2.3.0] - 2016-06-10
7+
### Added
8+
- Automatically add Content-Type: application/json when there is a request body
9+
610
## [2.2.1] - 2016-06-08
711
### Fixed
812
- Set client properly when testing

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ source ./sendgrid.env
8989
```bash
9090
./gradlew build
9191
cd examples
92-
javac -classpath ./commons-logging-1.2.jar:./httpcore-4.4.4.jar:./httpclient-4.5.2.jar:./jackson-databind-2.7.3.jar:./jackson-annotations-2.7.0.jar:./jackson-core-2.7.3.jar:../repo/com/sendgrid/2.2.0/sendgrid-java-http-client-2.2.1-jar.jar:. Example.java && java -classpath ./commons-logging-1.2.jar:./httpcore-4.4.4.jar:./httpclient-4.5.2.jar:./jackson-databind-2.7.3.jar:./jackson-annotations-2.7.0.jar:./jackson-core-2.7.3.jar:../repo/com/sendgrid/2.2.0/sendgrid-java-http-client-2.2.1-jar.jar:. Example
92+
javac -classpath ./commons-logging-1.2.jar:./httpcore-4.4.4.jar:./httpclient-4.5.2.jar:./jackson-databind-2.7.3.jar:./jackson-annotations-2.7.0.jar:./jackson-core-2.7.3.jar:../repo/com/sendgrid/2.3.0/sendgrid-java-http-client-2.3.0-jar.jar:. Example.java && java -classpath ./commons-logging-1.2.jar:./httpcore-4.4.4.jar:./httpclient-4.5.2.jar:./jackson-databind-2.7.3.jar:./jackson-annotations-2.7.0.jar:./jackson-core-2.7.3.jar:../repo/com/sendgrid/2.3.0/sendgrid-java-http-client-2.3.0-jar.jar:. Example
9393
```
9494

9595
<a name="understanding_the_codebase"></a>

README.md

+5-6
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ All updates to this project is documented in our [CHANGELOG](https://github.com/
1616
...
1717
dependencies {
1818
...
19-
compile 'com.sendgrid:java-http-client:2.2.1'
19+
compile 'com.sendgrid:java-http-client:2.3.0'
2020
}
2121
2222
repositories {
@@ -31,15 +31,15 @@ repositories {
3131
<dependency>
3232
<groupId>com.sendgrid</groupId>
3333
<artifactId>java-http-client</artifactId>
34-
<version>2.2.1</version>
34+
<version>2.3.0</version>
3535
</dependency>
3636
```
3737

3838
`mvn install`
3939

4040
## Fat Jar
4141

42-
[Download](http://repo1.maven.org/maven2/com/sendgrid/java-http-client/2.2.1/java-http-client-2.2.1-jar.jar)
42+
[Download](http://repo1.maven.org/maven2/com/sendgrid/java-http-client/2.3.0/java-http-client-2.3.0-jar.jar)
4343

4444
## Dependencies
4545

@@ -74,8 +74,7 @@ try {
7474

7575
```java
7676
Map<String,String> requestHeaders = new HashMap<String, String>();
77-
requestHeaders.put("Authorization", "Bearer " + System.getenv("SENDGRID_API_KEY"));
78-
requestHeaders.put("Content-Type", "application/json");
77+
requestHeaders.put("Authorization", "Bearer YOUR_API_KEY");
7978
request.headers = requestHeaders;
8079
Map<String,String> queryParams = new HashMap<String, String>();
8180
queryParams.put("limit", "100");
@@ -113,7 +112,7 @@ source ./sendgrid.env
113112
```bash
114113
mvn package
115114
cd examples
116-
javac -classpath ./jackson-databind-2.7.3.jar:./jackson-annotations-2.7.0.jar:./jackson-core-2.7.3.jar:/{path_to}/java-http-client-2.2.1-jar.jar:. Example.java && java -classpath ./jackson-databind-2.7.3.jar:./jackson-annotations-2.7.0.jar:./jackson-core-2.7.3.jar:/{path_to}/java-http-client-2.2.1-jar.jar:. Example
115+
javac -classpath ./jackson-databind-2.7.3.jar:./jackson-annotations-2.7.0.jar:./jackson-core-2.7.3.jar:/{path_to}/java-http-client-2.3.0-jar.jar:. Example.java && java -classpath ./jackson-databind-2.7.3.jar:./jackson-annotations-2.7.0.jar:./jackson-core-2.7.3.jar:/{path_to}/java-http-client-2.3.0-jar.jar:. Example
117116
```
118117

119118
## Roadmap

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ apply plugin: 'maven'
1717
apply plugin: 'signing'
1818

1919
group = 'com.sendgrid'
20-
version = '2.2.1'
20+
version = '2.3.0'
2121
ext.packaging = 'jar'
2222

2323
allprojects {

examples/Example.java

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ public static void main(String[] args) throws IOException {
2020
request.baseUri = "api.sendgrid.com";
2121
Map<String,String> requestHeaders = new HashMap<String, String>();
2222
requestHeaders.put("Authorization", "Bearer " + System.getenv("SENDGRID_API_KEY"));
23-
requestHeaders.put("Content-Type", "application/json");
2423
request.headers = requestHeaders;
2524

2625
Response response = new Response();

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<packaging>jar</packaging>
1212
<name>A simple HTTP client</name>
1313
<description>HTTP REST client, simplified for Java</description>
14-
<version>2.1.0</version>
14+
<version>2.3.0</version>
1515
<url>https://github.com/sendgrid/java-http-client</url>
1616
<licenses>
1717
<license>

src/main/java/com/sendgrid/Client.java

+12
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,9 @@ public Response post(Request request) throws URISyntaxException, IOException {
208208

209209
try {
210210
httpPost.setEntity(new StringEntity(request.body));
211+
if (request.body != "") {
212+
httpPost.setHeader("Content-Type", "application/json");
213+
}
211214
} catch (IOException ex) {
212215
throw ex;
213216
}
@@ -251,6 +254,9 @@ public Response patch(Request request) throws URISyntaxException, IOException {
251254

252255
try {
253256
httpPatch.setEntity(new StringEntity(request.body));
257+
if (request.body != "") {
258+
httpPatch.setHeader("Content-Type", "application/json");
259+
}
254260
} catch (IOException ex) {
255261
throw ex;
256262
}
@@ -295,6 +301,9 @@ public Response put(Request request) throws URISyntaxException, IOException {
295301

296302
try {
297303
httpPut.setEntity(new StringEntity(request.body));
304+
if (request.body != "") {
305+
httpPut.setHeader("Content-Type", "application/json");
306+
}
298307
} catch (IOException ex) {
299308
throw ex;
300309
}
@@ -338,6 +347,9 @@ public Response delete(Request request) throws URISyntaxException, IOException {
338347

339348
try {
340349
httpDelete.setEntity(new StringEntity(request.body));
350+
if (request.body != "") {
351+
httpDelete.setHeader("Content-Type", "application/json");
352+
}
341353
} catch (IOException ex) {
342354
throw ex;
343355
}

src/test/java/com/sendgrid/ClientTest.java

-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ public void testMethod(Method method, int statusCode) {
131131
request.endpoint = "/test";
132132
Map<String,String> requestHeaders = new HashMap<String, String>();
133133
requestHeaders.put("Authorization", "Bearer XXXX");
134-
requestHeaders.put("Content-Type", "application/json");
135134
request.headers = requestHeaders;
136135
Client client = new Client(httpClient);
137136
testResponse = client.get(request);

0 commit comments

Comments
 (0)