From 1729facac5079f249e67343a4963a191deff2516 Mon Sep 17 00:00:00 2001 From: Kris Oblucki Date: Fri, 28 Dec 2018 13:33:26 -0800 Subject: [PATCH] Core change to eliminate duplicate processing of the request url Further changes are required to the generated java files --- .../graph/http/BaseCollectionRequest.java | 12 +++++- .../com/microsoft/graph/http/BaseRequest.java | 37 ++++++++++++++----- .../graph/http/BaseStreamRequest.java | 12 +++++- .../microsoft/graph/http/IHttpRequest.java | 10 ++++- .../microsoft/graph/http/MockHttpRequest.java | 11 +++++- .../com/microsoft/graph/http/MockRequest.java | 11 +++++- 6 files changed, 78 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/microsoft/graph/http/BaseCollectionRequest.java b/src/main/java/com/microsoft/graph/http/BaseCollectionRequest.java index ac6cfdd4e6a..af5939e6a49 100644 --- a/src/main/java/com/microsoft/graph/http/BaseCollectionRequest.java +++ b/src/main/java/com/microsoft/graph/http/BaseCollectionRequest.java @@ -112,6 +112,16 @@ public URL getRequestUrl() { return baseRequest.getRequestUrl(); } + /** + * Gets the request URL + * + * @return the request URL + */ + @Override + public URL getBaseRequestUrl() { + return baseRequest.getBaseRequestUrl(); + } + /** * Gets the HTTP method * @@ -207,4 +217,4 @@ protected BaseRequest getBaseRequest() { public Class getCollectionPageClass() { return collectionPageClass; } -} +} \ No newline at end of file diff --git a/src/main/java/com/microsoft/graph/http/BaseRequest.java b/src/main/java/com/microsoft/graph/http/BaseRequest.java index d5cdd7fa577..92f37593c21 100644 --- a/src/main/java/com/microsoft/graph/http/BaseRequest.java +++ b/src/main/java/com/microsoft/graph/http/BaseRequest.java @@ -65,7 +65,7 @@ public abstract class BaseRequest implements IHttpRequest { /** * The URL for this request */ - private final String requestUrl; + private final String baseRequestUrl; /** * The backing client for this request @@ -100,16 +100,16 @@ public abstract class BaseRequest implements IHttpRequest { /** * Creates the request * - * @param requestUrl the URL to make the request against - * @param client the client which can issue the request - * @param options the options for this request - * @param responseClass the class for the response + * @param baseRequestUrl the URL to make the request against + * @param client the client which can issue the request + * @param options the options for this request + * @param responseClass the class for the response */ - public BaseRequest(final String requestUrl, + public BaseRequest(final String baseRequestUrl, final IBaseClient client, final List options, final Class responseClass) { - this.requestUrl = requestUrl; + this.baseRequestUrl = baseRequestUrl; this.client = client; this.responseClass = responseClass; @@ -163,8 +163,27 @@ public URL getRequestUrl() { return null; } + /** + * Gets the base request URL + * + * @return the base request URL + */ + @Override + public URL getBaseRequestUrl() { + try { + return new URL(this.baseRequestUrl); + } catch (final MalformedURLException e) { + if (this instanceof CustomRequest) { + this.getClient().getLogger().logError("Invalid custom URL: " + this.baseRequestUrl, e); + } else { + throw new ClientException("Invalid URL: " + this.baseRequestUrl, e); + } + } + return null; + } + private String addFunctionParameters() { - final StringBuilder requestUrl = new StringBuilder(this.requestUrl); + final StringBuilder requestUrl = new StringBuilder(this.baseRequestUrl); if (!getFunctionOptions().isEmpty()) { requestUrl.append("("); @@ -354,4 +373,4 @@ public IBaseClient getClient() { public Class getResponseType() { return responseClass; } -} +} \ No newline at end of file diff --git a/src/main/java/com/microsoft/graph/http/BaseStreamRequest.java b/src/main/java/com/microsoft/graph/http/BaseStreamRequest.java index f02586ee7d1..ea7219a6952 100644 --- a/src/main/java/com/microsoft/graph/http/BaseStreamRequest.java +++ b/src/main/java/com/microsoft/graph/http/BaseStreamRequest.java @@ -115,6 +115,16 @@ public URL getRequestUrl() { return baseRequest.getRequestUrl(); } + /** + * Gets the request URL + * + * @return the request URL + */ + @Override + public URL getBaseRequestUrl() { + return baseRequest.getBaseRequestUrl(); + } + /** * Gets the HTTP method * @@ -175,4 +185,4 @@ public List getHeaders() { public List