Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
Merge pull request #143 from wirecardBrasil/feature/WR-129
Browse files Browse the repository at this point in the history
Alteração para forçar o envio do Body vazio
  • Loading branch information
Fernando Petroni authored Oct 26, 2021
2 parents b47a0b1 + 410ae98 commit a5ef092
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apply plugin: 'signing'

group = 'br.com.moip'
archivesBaseName = "java-sdk"
version = '4.7.3'
version = '4.7.6'

description = "Moip v2 SDK"

Expand Down
11 changes: 9 additions & 2 deletions src/main/java/br/com/moip/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ private <T> T doRequest(final RequestProps requestProps) {
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("User-Agent", USER_AGENT);
conn.setRequestProperty("Content-type", requestProps.contentType.getMimeType());

if (requestProps.accept != null) conn.setRequestProperty("Accept", requestProps.accept);

conn.setRequestMethod(requestProps.method);
Expand All @@ -124,7 +125,7 @@ private <T> T doRequest(final RequestProps requestProps) {
LOGGER.debug("---> {} {}", requestProps.method, conn.getURL().toString());
logHeaders(conn.getRequestProperties().entrySet());

if (requestProps.object != null) {
if (requestProps.shouldSendBody()) {
conn.setDoOutput(true);
String body = getBody(requestProps.object, requestProps.contentType);

Expand All @@ -136,7 +137,7 @@ private <T> T doRequest(final RequestProps requestProps) {
writer.close();
wr.flush();
wr.close();
}
}

LOGGER.debug("---> END HTTP");

Expand Down Expand Up @@ -258,6 +259,12 @@ public RequestProps() {}
public ContentType getContentType() { return contentType; }

public String getAccept() { return accept; }

public boolean shouldSendBody(){
if(object != null)
return true;
return getMethod().equals("POST") || getMethod().equals("PUT") || getMethod().equals("PATCH");
}
}

private static class RequestPropsBuilder extends RequestProps {
Expand Down

0 comments on commit a5ef092

Please sign in to comment.