diff --git a/here-naksha-lib-model/src/commonMain/kotlin/naksha/model/request/query/POr.kt b/here-naksha-lib-model/src/commonMain/kotlin/naksha/model/request/query/POr.kt index c4e7e6cb1..e9aca724c 100644 --- a/here-naksha-lib-model/src/commonMain/kotlin/naksha/model/request/query/POr.kt +++ b/here-naksha-lib-model/src/commonMain/kotlin/naksha/model/request/query/POr.kt @@ -22,6 +22,7 @@ class POr() : ListProxy(IPropertyQuery::class), IPropertyQuery { } override fun toString(): String { + //TODO will not work like expected key=val1,val2, rather currently it is key1=val1,key2=val2 return joinToString(",") } } \ No newline at end of file diff --git a/here-naksha-lib-model/src/commonMain/kotlin/naksha/model/request/query/PQuery.kt b/here-naksha-lib-model/src/commonMain/kotlin/naksha/model/request/query/PQuery.kt index a53adf9e3..01f2d1663 100644 --- a/here-naksha-lib-model/src/commonMain/kotlin/naksha/model/request/query/PQuery.kt +++ b/here-naksha-lib-model/src/commonMain/kotlin/naksha/model/request/query/PQuery.kt @@ -46,4 +46,8 @@ open class PQuery() : AnyObject(), IPropertyQuery { * The parameter value of the operation; if any. */ var value by ANY +// TODO +// override fun toString(): String { +// +// } } diff --git a/here-naksha-storage-http/src/main/java/com/here/naksha/storage/http/HttpStorage.java b/here-naksha-storage-http/src/main/java/com/here/naksha/storage/http/HttpStorage.java index 09243c7d8..04e3c3fd3 100644 --- a/here-naksha-storage-http/src/main/java/com/here/naksha/storage/http/HttpStorage.java +++ b/here-naksha-storage-http/src/main/java/com/here/naksha/storage/http/HttpStorage.java @@ -18,15 +18,15 @@ */ package com.here.naksha.storage.http; -import static com.here.naksha.storage.http.RequestSender.KeyProperties; - import com.here.naksha.lib.core.models.naksha.Storage; +import com.here.naksha.storage.http.RequestSender.KeyProperties; import com.here.naksha.storage.http.cache.RequestSenderCache; import java.util.Map; import naksha.base.Int64; import naksha.base.JvmProxyUtil; import naksha.model.*; import naksha.model.objects.NakshaFeature; +import org.apache.commons.lang3.NotImplementedException; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; @@ -40,6 +40,13 @@ public class HttpStorage implements IStorage { public HttpStorage(@NotNull Storage storage) { HttpStorageProperties properties = HttpStorage.getProperties(storage); + if (properties == null) { + if (!storage.getProperties().hasRaw(HttpStorageProperties.URL)) { + throw new IllegalArgumentException("A HTTP storage must have properties containing a 'url'"); + } + properties = new HttpStorageProperties( + storage.getProperties().get(HttpStorageProperties.URL).toString(), null, null, null); + } requestSender = RequestSenderCache.getInstance() .getSenderWith(new KeyProperties( storage.getId(), @@ -53,7 +60,7 @@ public HttpStorage(@NotNull Storage storage) { return new HttpStorageReadSession(context, useMaster, requestSender); } - private static @NotNull HttpStorageProperties getProperties(@NotNull Storage storage) { + private static @Nullable HttpStorageProperties getProperties(@NotNull Storage storage) { return JvmProxyUtil.box(storage.getProperties(), HttpStorageProperties.class); } @@ -63,7 +70,13 @@ public void close() {} @NotNull @Override public IReadSession newReadSession(@Nullable SessionOptions options) { - return null; + boolean useMaster = false; + if (options != null) { + requestSender.keyProps.connectionTimeoutSec = options.connectTimeout; + requestSender.keyProps.socketTimeoutSec = options.socketTimeout; + useMaster = options.useMaster; + } + return new HttpStorageReadSession(NakshaContext.currentContext(), useMaster, requestSender); } @NotNull @@ -132,7 +145,7 @@ public Tuple featureToTuple(@NotNull NakshaFeature feature) { @NotNull @Override public ILock enterLock(@NotNull String id, @NotNull Int64 waitMillis) { - throw new NakshaException(NakshaError.NOT_IMPLEMENTED, "enterLock", null, null); + throw new NotImplementedException("Enter lock not supported"); } @Override diff --git a/here-naksha-storage-http/src/main/java/com/here/naksha/storage/http/HttpStorageProperties.java b/here-naksha-storage-http/src/main/java/com/here/naksha/storage/http/HttpStorageProperties.java index ff0d9465d..8680811ed 100644 --- a/here-naksha-storage-http/src/main/java/com/here/naksha/storage/http/HttpStorageProperties.java +++ b/here-naksha-storage-http/src/main/java/com/here/naksha/storage/http/HttpStorageProperties.java @@ -39,7 +39,7 @@ public class HttpStorageProperties extends NakshaProperties { "Content-Type", "application/json", "Accept-Encoding", "gzip"); - private static final String URL = "url"; + static final String URL = "url"; private static final String CONNECTION_TIMEOUT = "connectTimeout"; private static final String SOCKET_TIMEOUT = "socketTimeout"; private static final String HEADERS = "headers"; diff --git a/here-naksha-storage-http/src/main/java/com/here/naksha/storage/http/PrepareResult.java b/here-naksha-storage-http/src/main/java/com/here/naksha/storage/http/PrepareResult.java index 727db015e..7a7cb9244 100644 --- a/here-naksha-storage-http/src/main/java/com/here/naksha/storage/http/PrepareResult.java +++ b/here-naksha-storage-http/src/main/java/com/here/naksha/storage/http/PrepareResult.java @@ -77,21 +77,6 @@ private static String gzipDecode(byte[] encoded) { } } - // static SuccessResponse createHttpResultFromFeatureList(final @NotNull List features) { - // final List tuples = new ArrayList<>(); - // for (final NakshaFeature feature : features) { - // tuples.add(new ResultTuple()); - // codec.setOp(EExecutedOp.READ); - // codec.setFeature(feature); - // codec.setId(feature.getId()); - // codecs.add(codec); - // } - // - // final HeapCacheCursor cursor = new HeapCacheCursor<>(codecFactory, codecs, - // null); - // return new SuccessResponse(cursor); - // } - /** * @return null if http status is success (200-299) */ diff --git a/here-naksha-storage-http/src/main/java/com/here/naksha/storage/http/RequestSender.java b/here-naksha-storage-http/src/main/java/com/here/naksha/storage/http/RequestSender.java index 9fe7e9e35..9258c20e1 100644 --- a/here-naksha-storage-http/src/main/java/com/here/naksha/storage/http/RequestSender.java +++ b/here-naksha-storage-http/src/main/java/com/here/naksha/storage/http/RequestSender.java @@ -42,7 +42,7 @@ public class RequestSender { private final HttpClient httpClient; @NotNull - private final RequestSender.KeyProperties keyProps; + final RequestSender.KeyProperties keyProps; public RequestSender(@NotNull RequestSender.KeyProperties keyProps) { this.keyProps = keyProps; @@ -114,12 +114,49 @@ public boolean hasKeyProps(KeyProperties thatKeyProps) { /** * Set of properties that are just enough to construct the sender * and distinguish unambiguously between objects - * in terms of their effective configuration + * in terms of their effective configuration. + * Objects of this class are compared based on their contents, not on object reference. */ - public record KeyProperties( - @NotNull String name, - @NotNull String hostUrl, - @NotNull Map defaultHeaders, - long connectionTimeoutSec, - long socketTimeoutSec) {} + public static class KeyProperties { + private final String name; + private final String hostUrl; + private final Map defaultHeaders; + long connectionTimeoutSec; + long socketTimeoutSec; + + public KeyProperties( + @NotNull String name, + @NotNull String hostUrl, + @NotNull Map defaultHeaders, + long connectionTimeoutSec, + long socketTimeoutSec) { + this.name = name; + this.hostUrl = hostUrl; + this.defaultHeaders = defaultHeaders; + this.connectionTimeoutSec = connectionTimeoutSec; + this.socketTimeoutSec = socketTimeoutSec; + } + + public String getName() { + return name; + } + + public String getHostUrl() { + return hostUrl; + } + + public Map getDefaultHeaders() { + return defaultHeaders; + } + + @Override + public boolean equals(Object o) { + if (!(o instanceof KeyProperties kepProps)) return false; + return (name.equals(kepProps.name) + && hostUrl.equals(kepProps.hostUrl) + && defaultHeaders.equals(kepProps.defaultHeaders) + && connectionTimeoutSec == kepProps.connectionTimeoutSec + && socketTimeoutSec == kepProps.socketTimeoutSec); + } + } } diff --git a/here-naksha-storage-http/src/main/java/com/here/naksha/storage/http/cache/RequestSenderCache.java b/here-naksha-storage-http/src/main/java/com/here/naksha/storage/http/cache/RequestSenderCache.java index b6083e522..ee80b8aa8 100644 --- a/here-naksha-storage-http/src/main/java/com/here/naksha/storage/http/cache/RequestSenderCache.java +++ b/here-naksha-storage-http/src/main/java/com/here/naksha/storage/http/cache/RequestSenderCache.java @@ -18,9 +18,8 @@ */ package com.here.naksha.storage.http.cache; -import static com.here.naksha.storage.http.RequestSender.KeyProperties; - import com.here.naksha.storage.http.RequestSender; +import com.here.naksha.storage.http.RequestSender.KeyProperties; import java.util.concurrent.*; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -48,7 +47,7 @@ public static RequestSenderCache getInstance() { @NotNull public RequestSender getSenderWith(KeyProperties keyProperties) { return requestSenders.compute( - keyProperties.name(), (__, cachedSender) -> getUpdated(cachedSender, keyProperties)); + keyProperties.getName(), (__, cachedSender) -> getUpdated(cachedSender, keyProperties)); } private @NotNull RequestSender getUpdated( diff --git a/here-naksha-storage-http/src/test/java/com/here/naksha/storage/http/cache/RequestSenderCacheTest.java b/here-naksha-storage-http/src/test/java/com/here/naksha/storage/http/cache/RequestSenderCacheTest.java index 4d912b07d..0eb103030 100644 --- a/here-naksha-storage-http/src/test/java/com/here/naksha/storage/http/cache/RequestSenderCacheTest.java +++ b/here-naksha-storage-http/src/test/java/com/here/naksha/storage/http/cache/RequestSenderCacheTest.java @@ -95,7 +95,6 @@ void testOneId() { TimeUnit.HOURS ); - assertEquals(PROP_ID_1, PROP_ID_1_COPY); assertNotSame(PROP_ID_1, PROP_ID_1_COPY); // Tests @@ -124,7 +123,6 @@ void testOneIdMapChange() { TimeUnit.HOURS ); - assertEquals(PROP_ID_1, PROP_ID_1_MAP_COPIED); assertNotSame(PROP_ID_1, PROP_ID_1_MAP_COPIED); // Tests