Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
- `BaseDocument` and `BaseEdgeDocument` are now `final`
- `BaseDocument#getProperties()` and `BaseEdgeDocument#getProperties()` return now an unmodifiable map
- changed API method signatures removing throw declarations like: `throws ArangoDBException` (unchecked exception)
- removed passwords from debug level requests logs

### Removed

Expand Down
49 changes: 12 additions & 37 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,7 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>1.7.36</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
Expand All @@ -327,9 +324,14 @@
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-web-client</artifactId>
</dependency>
<dependency>
<groupId>com.arangodb</groupId>
<artifactId>jackson-dataformat-velocypack</artifactId>
<version>3.0.1</version>
<optional>true</optional>
</dependency>
<dependency>
Expand All @@ -346,6 +348,7 @@
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.11</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -399,39 +402,11 @@
<type>pom</type>
</dependency>
<dependency>
<groupId>com.arangodb</groupId>
<artifactId>jackson-dataformat-velocypack</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.13</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.15</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.15</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.36</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.11</version>
<groupId>io.vertx</groupId>
<artifactId>vertx-stack-depchain</artifactId>
<version>4.3.4</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.junit</groupId>
Expand Down
33 changes: 7 additions & 26 deletions src/main/java/com/arangodb/ArangoDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,8 @@
import com.arangodb.serde.JacksonSerde;
import com.arangodb.velocystream.Request;
import com.arangodb.velocystream.Response;
import org.apache.http.client.HttpRequestRetryHandler;

import javax.annotation.concurrent.ThreadSafe;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext;
import java.io.InputStream;
import java.util.Collection;
Expand Down Expand Up @@ -351,7 +349,7 @@ private static Protocol loadProtocol(final Properties properties, final Protocol
return Protocol.valueOf(
getProperty(properties, PROPERTY_KEY_PROTOCOL, currentValue,
ArangoDefaults.DEFAULT_NETWORK_PROTOCOL)
.toUpperCase(Locale.ENGLISH));
.toUpperCase(Locale.ROOT));
}

@Override
Expand Down Expand Up @@ -450,30 +448,13 @@ public Builder sslContext(final SSLContext sslContext) {
}

/**
* Sets the {@link javax.net.ssl.HostnameVerifier} to be used when using ssl with http protocol.
* Set whether hostname verification is enabled
*
* @param hostnameVerifier HostnameVerifier to be used
* @param verifyHost {@code true} if enabled
* @return {@link ArangoDB.Builder}
*/
public Builder hostnameVerifier(final HostnameVerifier hostnameVerifier) {
setHostnameVerifier(hostnameVerifier);
return this;
}

/**
* Sets the {@link HttpRequestRetryHandler} to be used when using http protocol.
*
* @param httpRequestRetryHandler HttpRequestRetryHandler to be used
* @return {@link ArangoDB.Builder}
* <p>
* <br /><br />
* NOTE:
* Some ArangoDB HTTP endpoints do not honor RFC-2616 HTTP 1.1 specification in respect to
* <a href="https://tools.ietf.org/html/rfc2616#section-9.1">9.1 Safe and Idempotent Methods</a>.
* Please refer to <a href="https://www.arangodb.com/docs/stable/http/">HTTP API Documentation</a> for details.
*/
public Builder httpRequestRetryHandler(final HttpRequestRetryHandler httpRequestRetryHandler) {
setHttpRequestRetryHandler(httpRequestRetryHandler);
public Builder verifyHost(final Boolean verifyHost) {
setVerifyHost(verifyHost);
return this;
}

Expand Down Expand Up @@ -621,8 +602,8 @@ public ArangoDB build() {

final ConnectionFactory connectionFactory = (protocol == null || Protocol.VST == protocol)
? new VstConnectionFactorySync(host, timeout, connectionTtl, keepAliveInterval, useSsl, sslContext)
: new HttpConnectionFactory(timeout, user, password, useSsl, sslContext, hostnameVerifier, serde,
protocol, connectionTtl, httpCookieSpec, httpRequestRetryHandler);
: new HttpConnectionFactory(timeout, user, password, useSsl, sslContext, verifyHost, serde,
protocol, connectionTtl);

final Collection<Host> hostList = createHostList(max, connectionFactory);
final HostResolver hostResolver = createHostResolver(hostList, max, connectionFactory);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/arangodb/internal/ArangoExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ protected <T> T createResult(final Type type, final Response response) {
}

protected final void interceptResponse(Response response) {
String queueTime = response.getMeta().get("X-Arango-Queue-Time-Seconds");
String queueTime = response.getMeta("X-Arango-Queue-Time-Seconds");
if (queueTime != null) {
qtMetrics.add(Double.parseDouble(queueTime));
}
}

protected final Request interceptRequest(Request request) {
request.putHeaderParam("X-Arango-Queue-Time-Seconds", timeoutS);
request.putHeaderParam("x-arango-queue-time-seconds", timeoutS);
return request;
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/arangodb/internal/ArangoRequestParam.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public final class ArangoRequestParam {
public static final String SYSTEM = "_system";
public static final String DATABASE = "database";
public static final String WAIT_FOR_SYNC = "waitForSync";
public static final String IF_NONE_MATCH = "If-None-Match";
public static final String IF_MATCH = "If-Match";
public static final String IF_NONE_MATCH = "if-none-match";
public static final String IF_MATCH = "if-match";
public static final String KEEP_NULL = "keepNull";

private ArangoRequestParam() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ protected <T> ResponseDeserializer<MultiDocumentEntity<T>> getDocumentsResponseD
final Class<T> type, final DocumentReadOptions options) {
return response -> {
final MultiDocumentEntity<T> multiDocument = new MultiDocumentEntity<>();
boolean potentialDirtyRead = Boolean.parseBoolean(response.getMeta().get("X-Arango-Potential-Dirty-Read"));
boolean potentialDirtyRead = Boolean.parseBoolean(response.getMeta("X-Arango-Potential-Dirty-Read"));
multiDocument.setPotentialDirtyRead(potentialDirtyRead);
final Collection<T> docs = new ArrayList<>();
final Collection<ErrorEntity> errors = new ArrayList<>();
Expand Down
22 changes: 4 additions & 18 deletions src/main/java/com/arangodb/internal/InternalArangoDBBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@
import com.arangodb.internal.net.*;
import com.arangodb.internal.util.HostUtils;
import com.arangodb.serde.ArangoSerde;
import org.apache.http.client.HttpRequestRetryHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext;
import java.io.IOException;
import java.io.InputStream;
Expand All @@ -52,7 +50,6 @@ public abstract class InternalArangoDBBuilder {
private static final String PROPERTY_KEY_PASSWORD = "arangodb.password";
private static final String PROPERTY_KEY_JWT = "arangodb.jwt";
private static final String PROPERTY_KEY_USE_SSL = "arangodb.usessl";
private static final String PROPERTY_KEY_COOKIE_SPEC = "arangodb.httpCookieSpec";
private static final String PROPERTY_KEY_V_STREAM_CHUNK_CONTENT_SIZE = "arangodb.chunksize";
private static final String PROPERTY_KEY_MAX_CONNECTIONS = "arangodb.connections.max";
private static final String PROPERTY_KEY_CONNECTION_TTL = "arangodb.connections.ttl";
Expand All @@ -70,10 +67,8 @@ public abstract class InternalArangoDBBuilder {
protected String password;
protected String jwt;
protected Boolean useSsl;
protected String httpCookieSpec;
protected HttpRequestRetryHandler httpRequestRetryHandler;
protected SSLContext sslContext;
protected HostnameVerifier hostnameVerifier;
protected Boolean verifyHost;
protected Integer chunksize;
protected Integer maxConnections;
protected Long connectionTtl;
Expand Down Expand Up @@ -151,10 +146,6 @@ private static Boolean loadUseSsl(final Properties properties, final Boolean cur
getProperty(properties, PROPERTY_KEY_USE_SSL, currentValue, ArangoDefaults.DEFAULT_USE_SSL));
}

private static String loadhttpCookieSpec(final Properties properties, final String currentValue) {
return getProperty(properties, PROPERTY_KEY_COOKIE_SPEC, currentValue, "");
}

private static Integer loadChunkSize(final Properties properties, final Integer currentValue) {
return Integer.parseInt(getProperty(properties, PROPERTY_KEY_V_STREAM_CHUNK_CONTENT_SIZE, currentValue,
ArangoDefaults.CHUNK_DEFAULT_CONTENT_SIZE));
Expand Down Expand Up @@ -196,7 +187,7 @@ private static LoadBalancingStrategy loadLoadBalancingStrategy(
final Properties properties,
final LoadBalancingStrategy currentValue) {
return LoadBalancingStrategy.valueOf(getProperty(properties, PROPERTY_KEY_LOAD_BALANCING_STRATEGY, currentValue,
ArangoDefaults.DEFAULT_LOAD_BALANCING_STRATEGY).toUpperCase(Locale.ENGLISH));
ArangoDefaults.DEFAULT_LOAD_BALANCING_STRATEGY).toUpperCase(Locale.ROOT));
}

protected static <T> String getProperty(
Expand Down Expand Up @@ -245,7 +236,6 @@ protected void loadProperties(final Properties properties) {
password = loadPassword(properties, password);
jwt = loadJwt(properties, jwt);
useSsl = loadUseSsl(properties, useSsl);
httpCookieSpec = loadhttpCookieSpec(properties, httpCookieSpec);
chunksize = loadChunkSize(properties, chunksize);
maxConnections = loadMaxConnections(properties, maxConnections);
connectionTtl = loadConnectionTtl(properties, connectionTtl);
Expand Down Expand Up @@ -284,12 +274,8 @@ protected void setSslContext(final SSLContext sslContext) {
this.sslContext = sslContext;
}

protected void setHostnameVerifier(final HostnameVerifier hostnameVerifier) {
this.hostnameVerifier = hostnameVerifier;
}

protected void setHttpRequestRetryHandler(final HttpRequestRetryHandler httpRequestRetryHandler) {
this.httpRequestRetryHandler = httpRequestRetryHandler;
protected void setVerifyHost(final Boolean verifyHost) {
this.verifyHost = verifyHost;
}

protected void setChunksize(final Integer chunksize) {
Expand Down
10 changes: 2 additions & 8 deletions src/main/java/com/arangodb/internal/InternalArangoDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,7 @@ protected Request queryRequest(final String query, final Map<String, Object> bin
protected Request queryNextRequest(final String id, final AqlQueryOptions options, Map<String, String> meta) {

final Request request = request(dbName, RequestType.POST, PATH_API_CURSOR, id);

if (meta != null) {
request.getHeaderParam().putAll(meta);
}
request.putHeaderParams(meta);

final AqlQueryOptions opt = options != null ? options : new AqlQueryOptions();

Expand All @@ -179,10 +176,7 @@ protected Request queryNextRequest(final String id, final AqlQueryOptions option
protected Request queryCloseRequest(final String id, final AqlQueryOptions options, Map<String, String> meta) {

final Request request = request(dbName, RequestType.DELETE, PATH_API_CURSOR, id);

if (meta != null) {
request.getHeaderParam().putAll(meta);
}
request.putHeaderParams(meta);

final AqlQueryOptions opt = options != null ? options : new AqlQueryOptions();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public ArangoCursorImpl(final InternalArangoDatabase<?, ?> db, final ArangoCurso
this.type = type;
iterator = createIterator(this, db, execute, result);
id = result.getId();
this.isPontentialDirtyRead = Boolean.parseBoolean(result.getMeta().get("X-Arango-Potential-Dirty-Read"));
this.isPontentialDirtyRead = Boolean.parseBoolean(result.getMeta().get("x-arango-potential-dirty-read"));
}

protected ArangoCursorIterator<T> createIterator(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
* @author Mark Vollmary
Expand Down Expand Up @@ -89,22 +92,24 @@ public JsonNode getResult() {
return result;
}

@Override
public Map<String, String> getMeta() {
if (meta == null) return Collections.emptyMap();
return meta;
return Collections.unmodifiableMap(meta);
}

@Override
public void setMeta(Map<String, String> meta) {
this.meta = cleanupMeta(meta);
this.meta = cleanupMeta(new HashMap<>(meta));
}

/**
* @return remove not allowed (valid storable) meta information
*/
public Map<String, String> cleanupMeta(Map<String, String> meta) {
meta.remove("Content-Length");
meta.remove("Transfer-Encoding");
meta.remove("X-Arango-Queue-Time-Seconds");
meta.remove("content-length");
meta.remove("transfer-encoding");
meta.remove("x-arango-queue-time-seconds");
return meta;
}

Expand Down
16 changes: 4 additions & 12 deletions src/main/java/com/arangodb/internal/http/CURLLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import com.arangodb.internal.serde.InternalSerde;
import com.arangodb.velocystream.Request;
import com.arangodb.velocystream.RequestType;
import org.apache.http.auth.Credentials;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -40,10 +39,9 @@ private CURLLogger() {
}

public static void log(
final String url,
final String baseUrl,
final String path,
final Request request,
final Credentials credentials,
final String jwt,
final InternalSerde util) {
final RequestType requestType = request.getRequestType();
final boolean includeBody = (requestType == RequestType.POST || requestType == RequestType.PUT
Expand All @@ -54,23 +52,17 @@ public static void log(
buffer.append("cat <<-___EOB___ | ");
}
buffer.append("curl -X ").append(requestType);
// FIXME: add --http2 in case protocol is HTTP/2
buffer.append(" --dump -");
if (request.getHeaderParam().size() > 0) {
for (final Entry<String, String> header : request.getHeaderParam().entrySet()) {
buffer.append(" -H '").append(header.getKey()).append(":").append(header.getValue()).append("'");
}
}
if (credentials != null) {
buffer.append(" -u ").append(credentials.getUserPrincipal().getName()).append(":")
.append(credentials.getPassword());
}
if (jwt != null) {
buffer.append(" -H ").append("'Authorization: Bearer ").append(jwt).append("'");
}
if (includeBody) {
buffer.append(" -d @-");
}
buffer.append(" '").append(url).append("'");
buffer.append(" '").append(baseUrl).append(path).append("'");
if (includeBody) {
buffer.append("\n");
buffer.append(util.toJsonString(request.getBody()));
Expand Down
Loading