Skip to content

Commit 2cb5b11

Browse files
authored
fix: concatenation of url (#180)
1 parent e76f23f commit 2cb5b11

File tree

6 files changed

+106
-6
lines changed

6 files changed

+106
-6
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
### Bug Fixes
77
1. [#173](https://github.com/influxdata/influxdb-client-java/pull/173): Query error could be after _success_ table
88
1. [#176](https://github.com/influxdata/influxdb-client-java/pull/176): Blocking API batches Point by precision
9+
1. [#180](https://github.com/influxdata/influxdb-client-java/pull/180): Fixed concatenation of url
910

1011
## 1.13.0 [2020-10-30]
1112

client/src/main/java/com/influxdb/client/internal/AuthenticateInterceptor.java

+16-2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import okhttp3.Call;
3636
import okhttp3.Cookie;
3737
import okhttp3.Credentials;
38+
import okhttp3.HttpUrl;
3839
import okhttp3.Interceptor;
3940
import okhttp3.OkHttpClient;
4041
import okhttp3.Request;
@@ -117,7 +118,7 @@ void initToken(@Nonnull final OkHttpClient okHttpClient) {
117118
.basic(influxDBClientOptions.getUsername(), string(influxDBClientOptions.getPassword()));
118119

119120
Request authRequest = new Request.Builder()
120-
.url(influxDBClientOptions.getUrl() + "/api/v2/signin")
121+
.url(buildPath("api/v2/signin"))
121122
.addHeader("Authorization", credentials)
122123
.post(RequestBody.create(null, ""))
123124
.build();
@@ -155,14 +156,27 @@ void signout() throws IOException {
155156
this.sessionToken = null;
156157

157158
Request authRequest = new Request.Builder()
158-
.url(influxDBClientOptions.getUrl() + "/api/v2/signout")
159+
.url(buildPath("api/v2/signout"))
159160
.post(RequestBody.create(null, ""))
160161
.build();
161162

162163
Response response = this.okHttpClient.newCall(authRequest).execute();
163164
response.close();
164165
}
165166

167+
@Nonnull
168+
String buildPath(final String buildPath) {
169+
170+
Arguments.checkNotNull(buildPath, "buildPath");
171+
172+
return HttpUrl
173+
.parse(influxDBClientOptions.getUrl())
174+
.newBuilder()
175+
.addEncodedPathSegments(buildPath)
176+
.build()
177+
.toString();
178+
}
179+
166180
@Nonnull
167181
private String string(final char[] password) {
168182
return String.valueOf(password);

client/src/main/java/com/influxdb/client/write/Point.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public Point addField(@Nonnull final String field, @Nullable final Number value)
179179
}
180180

181181
/**
182-
* Add {@link Boolean} field.
182+
* Add {@link String} field.
183183
*
184184
* @param field the field name
185185
* @param value the field value

client/src/test/java/com/influxdb/client/ITTemplatesApi.java

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
* @author Jakub Bednar (bednar@github) (25/03/2019 09:52)
5252
*/
5353
@RunWith(JUnitPlatform.class)
54+
@Disabled("https://github.com/influxdata/influxdb/issues/20163")
5455
class ITTemplatesApi extends AbstractITClientTest {
5556

5657
private TemplatesApi templatesApi;

client/src/test/java/com/influxdb/client/QueryApiTest.java

-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
package com.influxdb.client;
2323

2424
import java.io.IOException;
25-
import java.util.concurrent.TimeUnit;
2625

2726
import com.influxdb.client.domain.Dialect;
2827
import com.influxdb.client.domain.Query;
@@ -405,7 +404,5 @@ void parametersFromOptions() throws InterruptedException, IOException {
405404
request = takeRequest();
406405

407406
Assertions.assertThat(request.getRequestUrl().queryParameter("org")).isEqualTo("123456");
408-
409-
410407
}
411408
}

client/src/test/java/com/influxdb/client/internal/AuthenticateInterceptorTest.java

+87
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,93 @@ void authorizationSession() throws IOException, InterruptedException {
120120
.isEqualTo("session=yCgXaEBF8mYSmJUweRcW0g_5jElMs7mv6_-G1bNcau4Z0ZLQYtj0BkHZYRnBVA6uXHtyuhflcOzyNDNRxnaC0A==");
121121
}
122122

123+
@Test
124+
public void buildPath() {
125+
126+
InfluxDBClientOptions options = InfluxDBClientOptions.builder()
127+
.url("http://localhost:8086")
128+
.authenticate("user", "secret".toCharArray())
129+
.build();
130+
131+
Assertions
132+
.assertThat("http://localhost:8086/api/v2/signin")
133+
.isEqualTo(new AuthenticateInterceptor(options).buildPath("api/v2/signin"));
134+
135+
options = InfluxDBClientOptions.builder()
136+
.url("http://localhost:8086/")
137+
.authenticate("user", "secret".toCharArray())
138+
.build();
139+
140+
Assertions
141+
.assertThat("http://localhost:8086/api/v2/signin")
142+
.isEqualTo(new AuthenticateInterceptor(options).buildPath("api/v2/signin"));
143+
144+
options = InfluxDBClientOptions.builder()
145+
.url("http://localhost:8086/proxy")
146+
.authenticate("user", "secret".toCharArray())
147+
.build();
148+
149+
Assertions
150+
.assertThat("http://localhost:8086/proxy/api/v2/signin")
151+
.isEqualTo(new AuthenticateInterceptor(options).buildPath("api/v2/signin"));
152+
153+
options = InfluxDBClientOptions.builder()
154+
.url("http://localhost:8086/proxy/")
155+
.authenticate("user", "secret".toCharArray())
156+
.build();
157+
158+
Assertions
159+
.assertThat("http://localhost:8086/proxy/api/v2/signin")
160+
.isEqualTo(new AuthenticateInterceptor(options).buildPath("api/v2/signin"));
161+
}
162+
163+
@Test
164+
void connectionStringSigInSignOutURL() {
165+
166+
InfluxDBClientOptions options = InfluxDBClientOptions.builder()
167+
.connectionString("http://localhost:8086?writeTimeout=1000&connectTimeout=1000&logLevel=BODY")
168+
.authenticate("user", "secret".toCharArray())
169+
.build();
170+
171+
AuthenticateInterceptor interceptor = new AuthenticateInterceptor(options);
172+
173+
Assertions
174+
.assertThat("http://localhost:8086/api/v2/signin")
175+
.isEqualTo(interceptor.buildPath("api/v2/signin"));
176+
177+
Assertions
178+
.assertThat("http://localhost:8086/api/v2/signout")
179+
.isEqualTo(interceptor.buildPath("api/v2/signout"));
180+
181+
Assertions
182+
.assertThat("http://localhost:8086/api/v2/setup")
183+
.isEqualTo(interceptor.buildPath("api/v2/setup"));
184+
}
185+
186+
187+
@Test
188+
void connectionStringSigInSignOutURLProxy() {
189+
190+
InfluxDBClientOptions options = InfluxDBClientOptions.builder()
191+
.connectionString("http://localhost:8086/proxy?writeTimeout=1000&connectTimeout=1000&logLevel=BODY")
192+
.authenticate("user", "secret".toCharArray())
193+
.build();
194+
195+
AuthenticateInterceptor interceptor = new AuthenticateInterceptor(options);
196+
197+
Assertions
198+
.assertThat("http://localhost:8086/proxy/api/v2/signin")
199+
.isEqualTo(interceptor.buildPath("api/v2/signin"));
200+
201+
Assertions
202+
.assertThat("http://localhost:8086/proxy/api/v2/signout")
203+
.isEqualTo(interceptor.buildPath("api/v2/signout"));
204+
205+
Assertions
206+
.assertThat("http://localhost:8086/proxy/api/v2/setup")
207+
.isEqualTo(interceptor.buildPath("api/v2/setup"));
208+
}
209+
123210
@Test
124211
void authorizationSessionWithoutCookie() throws IOException, InterruptedException {
125212

0 commit comments

Comments
 (0)