-
Notifications
You must be signed in to change notification settings - Fork 441
feat: Enable json request body #749
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
42a5c25
[Librarian] Regenerated @ 0430a9c977225d55252b84f4d16e16ad2091cde1
twilio-dx 11a8368
Release 9.7.0
twilio-dx f836b57
added json body support
sbansla ecaad23
corrected test cases
sbansla 0653e4c
chore: added default content type for post request
sbansla eef9814
test: added test cases for json support
sbansla 3f19e90
Merge branch '10.0.0-rc' into enable-json-request-body
sbansla 6662c6f
resolved conflicts
sbansla f7fa050
corrected test cases
sbansla File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.twilio.constant; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
public class Enum { | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public enum ContentType { | ||
JSON("application/json"), | ||
FORM_URLENCODED("application/x-www-form-urlencoded"); | ||
|
||
private final String value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package com.twilio.http; | ||
|
||
import com.twilio.Twilio; | ||
import com.twilio.constant.Enum; | ||
import com.twilio.exception.ApiException; | ||
|
||
import java.io.IOException; | ||
|
@@ -19,6 +20,8 @@ | |
import org.apache.http.client.utils.HttpClientUtils; | ||
import org.apache.http.config.SocketConfig; | ||
import org.apache.http.entity.BufferedHttpEntity; | ||
import org.apache.http.entity.ContentType; | ||
import org.apache.http.entity.StringEntity; | ||
import org.apache.http.impl.client.HttpClientBuilder; | ||
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; | ||
import org.apache.http.message.BasicHeader; | ||
|
@@ -123,13 +126,23 @@ public Response makeRequest(final Request request) { | |
} | ||
|
||
if (method == HttpMethod.POST) { | ||
builder.addHeader(HttpHeaders.CONTENT_TYPE, "application/x-www-form-urlencoded"); | ||
|
||
for (Map.Entry<String, List<String>> entry : request.getPostParams().entrySet()) { | ||
for (String value : entry.getValue()) { | ||
builder.addParameter(entry.getKey(), value); | ||
// TODO: It will be removed after one RC Release. | ||
if (request.getContentType() == null) request.setContentType(Enum.ContentType.FORM_URLENCODED); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. java code does not have content type set. It will throw Null pointer exception on test. This line of code will be removed after one RC release. |
||
if (Enum.ContentType.JSON.getValue().equals(request.getContentType().getValue())) { | ||
HttpEntity entity = new StringEntity(request.getBody(), ContentType.APPLICATION_JSON); | ||
builder.setEntity(entity); | ||
builder.addHeader( | ||
HttpHeaders.CONTENT_TYPE, Enum.ContentType.JSON.getValue()); | ||
} else { | ||
builder.addHeader( | ||
HttpHeaders.CONTENT_TYPE, Enum.ContentType.FORM_URLENCODED.getValue()); | ||
for (Map.Entry<String, List<String>> entry : request.getPostParams().entrySet()) { | ||
for (String value : entry.getValue()) { | ||
builder.addParameter(entry.getKey(), value); | ||
} | ||
} | ||
} | ||
|
||
} | ||
builder.addHeader(HttpHeaders.USER_AGENT, HttpUtility.getUserAgentString(request.getUserAgentExtensions(), isCustomClient)); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line of code is added to support all object serialization which has a value of type Object or any object.