diff --git a/src/main/java/com/microsoft/graph/http/BaseCollectionRequest.java b/src/main/java/com/microsoft/graph/http/BaseCollectionRequest.java index b53d156e1a9..b630a0aef7c 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 * diff --git a/src/main/java/com/microsoft/graph/http/BaseRequest.java b/src/main/java/com/microsoft/graph/http/BaseRequest.java index 078611d9ad5..5b1985205d2 100644 --- a/src/main/java/com/microsoft/graph/http/BaseRequest.java +++ b/src/main/java/com/microsoft/graph/http/BaseRequest.java @@ -68,7 +68,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 @@ -128,16 +128,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; @@ -191,8 +191,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("("); @@ -382,7 +401,7 @@ public Class getResponseType() { return responseClass; } - /** + /** * Sets the max redirects * * @param maxRedirects Max redirects that a request can take diff --git a/src/main/java/com/microsoft/graph/http/BaseStreamRequest.java b/src/main/java/com/microsoft/graph/http/BaseStreamRequest.java index c23a6717d6e..beb926948a4 100644 --- a/src/main/java/com/microsoft/graph/http/BaseStreamRequest.java +++ b/src/main/java/com/microsoft/graph/http/BaseStreamRequest.java @@ -119,6 +119,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 * diff --git a/src/main/java/com/microsoft/graph/http/IHttpRequest.java b/src/main/java/com/microsoft/graph/http/IHttpRequest.java index 9b8f8183d2b..14dff6b9288 100644 --- a/src/main/java/com/microsoft/graph/http/IHttpRequest.java +++ b/src/main/java/com/microsoft/graph/http/IHttpRequest.java @@ -35,6 +35,13 @@ */ public interface IHttpRequest { + /** + * Gets the base request URL + * + * @return the base request URL + */ + URL getBaseRequestUrl(); + /** * Gets the request URL * @@ -84,7 +91,7 @@ public interface IHttpRequest { * @return the value of useCaches */ boolean getUseCaches(); - + /** * Sets the max redirects * @@ -155,4 +162,3 @@ public interface IHttpRequest { */ long getDelay(); } - diff --git a/src/test/java/com/microsoft/graph/http/MockHttpRequest.java b/src/test/java/com/microsoft/graph/http/MockHttpRequest.java index e50cfc86a6a..87a7b22944e 100644 --- a/src/test/java/com/microsoft/graph/http/MockHttpRequest.java +++ b/src/test/java/com/microsoft/graph/http/MockHttpRequest.java @@ -32,6 +32,15 @@ public URL getRequestUrl() { } } + @Override + public URL getBaseRequestUrl() { + try { + return new URL("http://localhost"); + } catch (final MalformedURLException ex) { + throw new ClientException("Invalid URL", ex); + } + } + @Override public HttpMethod getHttpMethod() { return mHttpMethod; diff --git a/src/test/java/com/microsoft/graph/http/MockRequest.java b/src/test/java/com/microsoft/graph/http/MockRequest.java index af4cea087d2..1efae5e430d 100644 --- a/src/test/java/com/microsoft/graph/http/MockRequest.java +++ b/src/test/java/com/microsoft/graph/http/MockRequest.java @@ -48,6 +48,15 @@ public URL getRequestUrl() { return null; } + @Override + public URL getBaseRequestUrl() { + try { + return new URL("http://localhost"); + } catch (final MalformedURLException ignored) { + } + return null; + } + @Override public HttpMethod getHttpMethod() { return HttpMethod.GET;