-
Notifications
You must be signed in to change notification settings - Fork 16
Handle null response body and support Parameters #7
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,13 @@ | ||
target | ||
*.class | ||
|
||
# IDE files | ||
# Intellij | ||
.idea/ | ||
*.iml | ||
*.iws | ||
*~ | ||
|
||
# Mobile Tools for Java (J2ME) | ||
.mtj.tmp/ | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,20 +4,25 @@ | |
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class GenericApiGatewayRequest { | ||
|
||
private final HttpMethodName httpMethod; | ||
private final String resourcePath; | ||
private final InputStream body; | ||
private final Map<String, String> headers; | ||
private final Map<String, List<String>> parameters; | ||
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. Should this be called queryStringParameters? 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. parameters seemed to be in the same flavor of 'headers', 'body' etc. Also it is setParameters() in the DefaultRequest |
||
|
||
public GenericApiGatewayRequest(HttpMethodName httpMethod, String resourcePath, | ||
InputStream body, Map<String, String> headers) { | ||
InputStream body, Map<String, String> headers, | ||
Map<String, List<String>> parameters) { | ||
this.httpMethod = httpMethod; | ||
this.resourcePath = resourcePath; | ||
this.body = body; | ||
this.headers = headers; | ||
this.parameters = parameters; | ||
} | ||
|
||
public HttpMethodName getHttpMethod() { | ||
|
@@ -35,4 +40,8 @@ public InputStream getBody() { | |
public Map<String, String> getHeaders() { | ||
return headers; | ||
} | ||
|
||
public Map<String, List<String>> getParameters() { | ||
return parameters; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,13 +4,15 @@ | |
import ca.ryangreen.apigateway.util.Validate; | ||
|
||
import java.io.InputStream; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class GenericApiGatewayRequestBuilder { | ||
private HttpMethodName httpMethod; | ||
private String resourcePath; | ||
private InputStream body; | ||
private Map<String, String> headers; | ||
private Map<String, List<String>> parameters; | ||
|
||
public GenericApiGatewayRequestBuilder withHttpMethod(HttpMethodName name) { | ||
httpMethod = name; | ||
|
@@ -32,9 +34,14 @@ public GenericApiGatewayRequestBuilder withHeaders(Map<String, String> headers) | |
return this; | ||
} | ||
|
||
public GenericApiGatewayRequestBuilder withParameters(Map<String,List<String>> parameters) { | ||
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. Should this be withQueryStringParameters? 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. see above |
||
this.parameters = parameters; | ||
return this; | ||
} | ||
|
||
public GenericApiGatewayRequest build() { | ||
Validate.notNull(httpMethod, "HTTP method"); | ||
Validate.notEmpty(resourcePath, "Resource path"); | ||
return new GenericApiGatewayRequest(httpMethod, resourcePath, body, headers); | ||
return new GenericApiGatewayRequest(httpMethod, resourcePath, body, headers, parameters); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,11 @@ public class GenericApiGatewayResponse { | |
|
||
public GenericApiGatewayResponse(HttpResponse httpResponse) throws IOException { | ||
this.httpResponse = httpResponse; | ||
this.body = IOUtils.toString(httpResponse.getContent()); | ||
if (httpResponse.getContent()!= null) { | ||
this.body = IOUtils.toString(httpResponse.getContent()); | ||
} else { | ||
this.body = null; | ||
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. Is this else block required? Isn't body null by default? 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. because it is final, there are "Error:(17, 5) java: variable body might not have been initialized" without it |
||
} | ||
} | ||
|
||
public HttpResponse getHttpResponse() { | ||
|
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.
Is this null check necessary?
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.
Your unit tests fail without it.