Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b5e5ccf

Browse files
authored
x-arango-driver header (#484)
1 parent bfc031f commit b5e5ccf

File tree

6 files changed

+125
-4
lines changed

6 files changed

+125
-4
lines changed

‎pom.xml‎

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>com.arangodb</groupId>
77
<artifactId>arangodb-java-driver</artifactId>
8-
<version>6.20.0</version>
8+
<version>6.21.0</version>
99
<inceptionYear>2016</inceptionYear>
1010
<packaging>jar</packaging>
1111

@@ -234,6 +234,48 @@
234234
</execution>
235235
</executions>
236236
</plugin>
237+
<plugin>
238+
<groupId>com.google.code.maven-replacer-plugin</groupId>
239+
<artifactId>replacer</artifactId>
240+
<version>1.5.3</version>
241+
<executions>
242+
<execution>
243+
<phase>generate-sources</phase>
244+
<goals>
245+
<goal>replace</goal>
246+
</goals>
247+
</execution>
248+
</executions>
249+
<configuration>
250+
<file>${project.basedir}/src/main/java/com/arangodb/PackageVersion.java.in</file>
251+
<outputFile>${project.build.directory}/generated-sources/replacer/com/arangodb/PackageVersion.java
252+
</outputFile>
253+
<replacements>
254+
<replacement>
255+
<token>@project.version@</token>
256+
<value>${project.version}</value>
257+
</replacement>
258+
</replacements>
259+
</configuration>
260+
</plugin>
261+
<plugin>
262+
<groupId>org.codehaus.mojo</groupId>
263+
<artifactId>build-helper-maven-plugin</artifactId>
264+
<version>3.3.0</version>
265+
<executions>
266+
<execution>
267+
<phase>generate-sources</phase>
268+
<goals>
269+
<goal>add-source</goal>
270+
</goals>
271+
<configuration>
272+
<sources>
273+
<source>${project.build.directory}/generated-sources/replacer</source>
274+
</sources>
275+
</configuration>
276+
</execution>
277+
</executions>
278+
</plugin>
237279
</plugins>
238280
</build>
239281

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.arangodb;
2+
3+
/**
4+
* Automatically generated from PackageVersion.java.in by replacer plugin.
5+
*/
6+
public final class PackageVersion {
7+
public final static String VERSION = "@project.version@";
8+
}

‎src/main/java/com/arangodb/internal/http/HttpConnection.java‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import com.arangodb.ArangoDBException;
2424
import com.arangodb.DbName;
25+
import com.arangodb.PackageVersion;
2526
import com.arangodb.Protocol;
2627
import com.arangodb.internal.net.Connection;
2728
import com.arangodb.internal.net.HostDescription;
@@ -85,6 +86,8 @@ public class HttpConnection implements Connection {
8586
// max safe UTF-8 json string length, so that it can be converted to byte array
8687
private static final int MAX_JSON_LENGTH = (Integer.MAX_VALUE - 8) / 4;
8788

89+
private static final String X_ARANGO_DRIVER = "JavaDriver/" + PackageVersion.VERSION + " (JVM/" + System.getProperty("java.specification.version") + ")";
90+
8891
public static class Builder {
8992
private String user;
9093
private String password;
@@ -323,6 +326,7 @@ public Response execute(final Request request) throws ArangoDBException, IOExcep
323326
final String url = buildUrl(buildBaseUrl(host), request);
324327
final HttpRequestBase httpRequest = buildHttpRequestBase(request, url);
325328
httpRequest.setHeader("User-Agent", "Mozilla/5.0 (compatible; ArangoDB-JavaDriver/1.1; +http://mt.orz.at/)");
329+
httpRequest.setHeader("x-arango-driver", X_ARANGO_DRIVER);
326330
if (contentType == Protocol.HTTP_VPACK) {
327331
httpRequest.setHeader("Accept", "application/x-velocypack");
328332
}

‎src/main/java/com/arangodb/internal/velocystream/VstCommunication.java‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
package com.arangodb.internal.velocystream;
2222

2323
import com.arangodb.ArangoDBException;
24+
import com.arangodb.PackageVersion;
2425
import com.arangodb.internal.ArangoDefaults;
2526
import com.arangodb.internal.net.AccessType;
2627
import com.arangodb.internal.net.Host;
@@ -54,14 +55,13 @@ public abstract class VstCommunication<R, C extends VstConnection> implements Cl
5455
protected static final String ENCRYPTION_PLAIN = "plain";
5556
protected static final String ENCRYPTION_JWT = "jwt";
5657
private static final Logger LOGGER = LoggerFactory.getLogger(VstCommunication.class);
57-
5858
protected static final AtomicLong mId = new AtomicLong(0L);
59-
protectedfinal ArangoSerializationutil;
59+
privatestaticfinal StringX_ARANGO_DRIVER = "JavaDriver/" + PackageVersion.VERSION + " (JVM/" + System.getProperty("java.specification.version") + ")";
6060

61+
protected final ArangoSerialization util;
6162
protected final String user;
6263
protected final String password;
6364
protected volatile String jwt;
64-
6565
protected final Integer chunksize;
6666
protected final HostHandler hostHandler;
6767

@@ -168,6 +168,7 @@ protected Response createResponse(final Message message) throws VPackParserExcep
168168
protected final Message createMessage(final Request request) throws VPackParserException {
169169
request.putHeaderParam("accept", "application/x-velocypack");
170170
request.putHeaderParam("content-type", "application/x-velocypack");
171+
request.putHeaderParam("x-arango-driver", X_ARANGO_DRIVER);
171172
final long id = mId.incrementAndGet();
172173
return new Message(id, util.serialize(request), request.getBody());
173174
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.arangodb;
2+
3+
import com.arangodb.velocystream.Request;
4+
import com.arangodb.velocystream.RequestType;
5+
import com.arangodb.velocystream.Response;
6+
import org.junit.jupiter.api.Test;
7+
import org.junit.jupiter.params.ParameterizedTest;
8+
import org.junit.jupiter.params.provider.EnumSource;
9+
10+
import static org.assertj.core.api.Assertions.assertThat;
11+
12+
class UserAgentTest extends BaseJunit5 {
13+
14+
private static final String EXPECTED_VERSION = "6.21.0";
15+
16+
@Test
17+
void packageVersion() {
18+
assertThat(PackageVersion.VERSION).isEqualTo(EXPECTED_VERSION);
19+
}
20+
21+
@ParameterizedTest
22+
@EnumSource(Protocol.class)
23+
void userAgentHeader(Protocol protocol) {
24+
ArangoDB adb = new ArangoDB.Builder()
25+
.useProtocol(protocol)
26+
.build();
27+
28+
Request request = new Request(DbName.SYSTEM, RequestType.GET, "/_admin/echo");
29+
Response resp = adb.execute(request);
30+
String headerValue = resp.getBody().get("headers").get("x-arango-driver").getAsString();
31+
32+
String jvmVersion = System.getProperty("java.specification.version");
33+
String expected = "JavaDriver/" + PackageVersion.VERSION + " (JVM/" + jvmVersion + ")";
34+
35+
assertThat(headerValue).isEqualTo(expected);
36+
adb.shutdown();
37+
}
38+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.arangodb.async;
2+
3+
import com.arangodb.DbName;
4+
import com.arangodb.PackageVersion;
5+
import com.arangodb.velocystream.Request;
6+
import com.arangodb.velocystream.RequestType;
7+
import com.arangodb.velocystream.Response;
8+
import org.junit.jupiter.api.Test;
9+
10+
import java.util.concurrent.ExecutionException;
11+
12+
import static org.assertj.core.api.Assertions.assertThat;
13+
14+
class UserAgentTest {
15+
@Test
16+
void userAgentHeader() throws ExecutionException, InterruptedException {
17+
ArangoDBAsync adb = new ArangoDBAsync.Builder().build();
18+
Request request = new Request(DbName.SYSTEM, RequestType.GET, "/_admin/echo");
19+
Response resp = adb.execute(request).get();
20+
String headerValue = resp.getBody().get("headers").get("x-arango-driver").getAsString();
21+
22+
String jvmVersion = System.getProperty("java.specification.version");
23+
String expected = "JavaDriver/" + PackageVersion.VERSION + " (JVM/" + jvmVersion + ")";
24+
25+
assertThat(headerValue).isEqualTo(expected);
26+
adb.shutdown();
27+
}
28+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /