Skip to content

Conversation

@baywet
Copy link
Member

@baywet baywet commented Sep 11, 2020

Fixes #301
Depends on core 1.0.3
Depends on microsoftgraph/msgraph-sdk-java-core#70
Depends on microsoftgraph/msgraph-sdk-java-core#71

Changes proposed in this pull request

Other links

TODO: once this PR gets merged, ping the graph explorer API repo to update the sample https://docs.microsoft.com/en-us/graph/sdks/batch-requests?context=graph%2Fapi%2F1.0&view=graph-rest-1.0&tabs=java

@zengin
Copy link
Contributor

zengin commented Sep 14, 2020

@baywet, can you please summarize which parts of the code are generated, which parts are hand-crafted?

@baywet
Copy link
Member Author

baywet commented Sep 14, 2020

@zengin this commit is the only code-gen in the PR aa0b2c3 the rest is handcrafted.

basically I'm adding 2 methods + 2 overloads for one method (withHttpMethod and getHttpRequest) in IHttpRequest and implementing that in the different BaseRequest classes.

Then I'm relying on IHttpRequest inheritance (the code-gen part) to expose the methods in the object model without having to cast.

Copy link
Contributor

@zengin zengin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@baywet baywet merged commit 6e7acc8 into dev Sep 14, 2020
@baywet baywet deleted the feature/get-request branch September 14, 2020 20:41
Copy link
Collaborator

@MIchaelMainer MIchaelMainer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You get my review post merge. No required actions

}

// Request level middleware options
RedirectOptions redirectOptions = new RedirectOptions(request.getMaxRedirects() > 0? request.getMaxRedirects() : this.connectionConfig.getMaxRedirects(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: separate the ? one space from the last condition character, I started to incorrectly read the ternary operator.

// Request level middleware options
RedirectOptions redirectOptions = new RedirectOptions(request.getMaxRedirects() > 0? request.getMaxRedirects() : this.connectionConfig.getMaxRedirects(),
request.getShouldRedirect() != null? request.getShouldRedirect() : this.connectionConfig.getShouldRedirect());
RetryOptions retryOptions = new RetryOptions(request.getShouldRetry() != null? request.getShouldRetry() : this.connectionConfig.getShouldRetry(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General, not actionable per this PR, comment: we need a generic way to check for and add middleware options instead of this hardcoded approach. Please resolve this comment.

// Send an empty body through with a POST request
// This ensures that the Content-Length header is properly set
if (request.getHttpMethod() == HttpMethod.POST) {
bytesToWrite = new byte[0];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be consistent, also so that the log shows that the POST was sent intentionally without a request body. logger.logDebug("Sending empty request body");

RequestBody requestBody = null;
// Handle cases where we've got a body to process.
if (bytesToWrite != null) {
final String mediaContentType = contenttype;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Lines 302 - 332 - these lines have a discrete concern around getting a request body if bytesToWrite is not null so we have the option to make this a testable unit. Something like: GetRequestBody(byte[] bytesToWrite).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree on the fact that sendRequestInternal was waaay too long to be testable. The fact that this change already breaks it into to pieces is a step in the right direction for better testability. And yes, moving this section to a dedicated method would be a good next step. Same thing for the part that deals with the response in sendRequestInternal

* @param <responseType> the type of the response object
* @return the Request object to be executed
*/
<requestBodyType, responseType> Request getHttpRequest(final requestBodyType serializedObject, final IProgressCallback<responseType> progress) throws ClientException;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IHttpProvider should not contain an implementation specific type and should be generic instead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add GetRequest method to BaseRequest

4 participants