Skip to content

Commit 62b9b48

Browse files
committed
Adding setBaseUrl to JsonHttpClient
1 parent 059de13 commit 62b9b48

File tree

2 files changed

+5
-55
lines changed

2 files changed

+5
-55
lines changed

google-http-client/src/main/java/com/google/api/client/http/json/JsonHttpClient.java

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ public static class Builder {
287287
* be URL-encoded and must end with a "/". This is determined when the library is generated and
288288
* normally should not be changed.
289289
*/
290-
private final GenericUrl baseUrl;
290+
private GenericUrl baseUrl;
291291

292292
/**
293293
* The application name to be sent in the User-Agent header of each request or {@code null} for
@@ -334,35 +334,12 @@ public final GenericUrl getBaseUrl() {
334334
}
335335

336336
/**
337-
* Convenience method for setting base host on the base URL, for example
338-
* {@code "www.googleapis.com"}.
339-
*
340-
* <p>
341-
* This method is equivalent to calling {@code getBaseUrl().setHost()}.
342-
* </p>
343-
*
344-
* @since 1.7
345-
*/
346-
public Builder setBaseHost(String baseHost) {
347-
baseUrl.setHost(baseHost);
348-
return this;
349-
}
350-
351-
/**
352-
* Convenience method for setting base path on the base URL, for example {@code "/plus/v1/"}.
353-
*
354-
* <p>
355-
* This method is equivalent to calling {@code getBaseUrl().setRawPath()}. Must be URL-encoded
356-
* and must start and end with a "/".
357-
* </p>
337+
* Sets the base URL of the service. Subclasses should override by calling super.
358338
*
359339
* @since 1.7
360340
*/
361-
public Builder setBasePath(String basePath) {
362-
Preconditions.checkArgument(
363-
basePath.startsWith("/") && basePath.endsWith("/"),
364-
"base path must start and end with a '/'");
365-
baseUrl.setRawPath(basePath);
341+
public Builder setBaseUrl(GenericUrl baseUrl) {
342+
this.baseUrl = baseUrl;
366343
return this;
367344
}
368345

google-http-client/src/test/java/com/google/api/client/http/json/JsonHttpClientTest.java

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -79,39 +79,12 @@ public void testBaseServerAndBasePathBuilder() {
7979
JsonHttpClient
8080
.builder(new NetHttpTransport(), new JacksonFactory(),
8181
new GenericUrl("http://www.testgoogleapis.com/test/path/v1/"))
82-
.setBaseHost("www.googleapis.com")
83-
.setBasePath("/test/path/v2/")
82+
.setBaseUrl(new GenericUrl("http://www.googleapis.com/test/path/v2/"))
8483
.build();
8584

8685
assertEquals("http://www.googleapis.com/test/path/v2/", client.getBaseUrl());
8786
}
8887

89-
public void testInvalidBasePath() {
90-
JsonHttpClient.Builder builder =
91-
JsonHttpClient.builder(new NetHttpTransport(), new JacksonFactory(), new GenericUrl(
92-
"http://www.testgoogleapis.com/test/path/v1/"));
93-
try {
94-
builder.setBasePath(null);
95-
fail("Expected exception not thrown!");
96-
} catch (NullPointerException e) {
97-
// Expected because base path cannot be null.
98-
}
99-
100-
try {
101-
builder.setBasePath("test/path/v2/");
102-
fail("Expected exception not thrown!");
103-
} catch (IllegalArgumentException e) {
104-
// Expected because base path did not start with "/".
105-
}
106-
107-
try {
108-
builder.setBasePath("/test/path/v2");
109-
fail("Expected exception not thrown!");
110-
} catch (IllegalArgumentException e) {
111-
// Expected because base path did not end with "/".
112-
}
113-
}
114-
11588
public void testInitialize() throws IOException {
11689
TestRemoteRequestInitializer remoteRequestInitializer = new TestRemoteRequestInitializer();
11790
JsonHttpClient client =

0 commit comments

Comments
 (0)