From 846aacd91526be53b6798815529d6d8a96c271bf Mon Sep 17 00:00:00 2001
From: Michael Jacoby
Date: Thu, 12 Dec 2024 16:10:00 +0100
Subject: [PATCH] Code Review before release (#3)
Code Review before release (#3)
---
.../client/exception/BadRequestException.java | 11 +-
.../client/exception/ClientException.java | 6 +-
.../client/exception/ConflictException.java | 11 +-
.../client/exception/ForbiddenException.java | 11 +-
.../InternalServerErrorException.java | 11 +-
.../exception/InvalidPayloadException.java | 16 +-
.../exception/MethodNotAllowedException.java | 11 +-
.../client/exception/NotFoundException.java | 11 +-
.../client/exception/StatusCodeException.java | 60 +-
.../exception/UnauthorizedException.java | 11 +-
.../UnsupportedStatusCodeException.java | 29 +-
.../client/{util => http}/HttpMethod.java | 2 +-
.../ilt/faaast/client/http/HttpStatus.java | 117 +++
.../client/interfaces/AASInterface.java | 112 ++-
.../interfaces/AASRegistryInterface.java | 73 +-
.../interfaces/AASRepositoryInterface.java | 129 ++-
.../client/interfaces/BaseInterface.java | 877 ++++++++++++++----
...ConceptDescriptionRepositoryInterface.java | 56 +-
.../interfaces/DescriptionInterface.java | 35 +-
.../client/interfaces/SubmodelInterface.java | 331 +++----
.../interfaces/SubmodelRegistryInterface.java | 65 +-
.../SubmodelRepositoryInterface.java | 200 ++--
.../query/AASDescriptorSearchCriteria.java | 48 +-
.../client/query/AASSearchCriteria.java | 34 +-
.../ConceptDescriptionSearchCriteria.java | 23 +-
.../client/query/DefaultSearchCriteria.java | 27 -
.../faaast/client/query/SearchCriteria.java | 2 +-
.../client/query/SubmodelSearchCriteria.java | 15 +-
.../faaast/client/util/ExceptionHandler.java | 68 --
...HttpClientUtility.java => HttpHelper.java} | 29 +-
.../{UriBuilder.java => QueryHelper.java} | 95 +-
.../client/interfaces/AASInterfaceTest.java | 67 +-
.../interfaces/AASRegistryInterfaceTest.java | 30 +-
.../AASRepositoryInterfaceTest.java | 41 +-
...eptDescriptionRepositoryInterfaceTest.java | 25 +-
.../interfaces/ExceptionHandlingTest.java | 1 -
.../interfaces/SubmodelInterfaceTest.java | 107 +--
.../SubmodelRegistryInterfaceTest.java | 27 +-
.../SubmodelRepositoryInterfaceTest.java | 41 +-
pom.xml | 43 +-
40 files changed, 1781 insertions(+), 1127 deletions(-)
rename core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/{util => http}/HttpMethod.java (94%)
create mode 100644 core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/http/HttpStatus.java
delete mode 100644 core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/query/DefaultSearchCriteria.java
delete mode 100644 core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/util/ExceptionHandler.java
rename core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/util/{HttpClientUtility.java => HttpHelper.java} (82%)
rename core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/util/{UriBuilder.java => QueryHelper.java} (51%)
diff --git a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/exception/BadRequestException.java b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/exception/BadRequestException.java
index b8cb8f9..ab547a3 100644
--- a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/exception/BadRequestException.java
+++ b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/exception/BadRequestException.java
@@ -14,7 +14,6 @@
*/
package de.fraunhofer.iosb.ilt.faaast.client.exception;
-import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
@@ -23,7 +22,13 @@
* (e.g., malformed request syntax, size too large, invalid request message framing, or deceptive request routing).
*/
public class BadRequestException extends StatusCodeException {
- public BadRequestException(HttpRequest request, HttpResponse response) {
- super(request, response);
+
+ /**
+ * Constructs a new exception.
+ *
+ * @param response the response representing the exception
+ */
+ public BadRequestException(HttpResponse response) {
+ super(response);
}
}
diff --git a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/exception/ClientException.java b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/exception/ClientException.java
index 5df6ef2..983fc3d 100644
--- a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/exception/ClientException.java
+++ b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/exception/ClientException.java
@@ -24,7 +24,7 @@ public abstract class ClientException extends Exception {
*
* @param message the detail message
*/
- public ClientException(String message) {
+ protected ClientException(String message) {
super(message);
}
@@ -35,7 +35,7 @@ public ClientException(String message) {
* @param message the detail message
* @param cause the cause
*/
- public ClientException(String message, Throwable cause) {
+ protected ClientException(String message, Throwable cause) {
super(message, cause);
}
@@ -45,7 +45,7 @@ public ClientException(String message, Throwable cause) {
*
* @param cause the cause
*/
- public ClientException(Throwable cause) {
+ protected ClientException(Throwable cause) {
super(cause);
}
}
diff --git a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/exception/ConflictException.java b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/exception/ConflictException.java
index 1af18b3..003f7e3 100644
--- a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/exception/ConflictException.java
+++ b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/exception/ConflictException.java
@@ -14,7 +14,6 @@
*/
package de.fraunhofer.iosb.ilt.faaast.client.exception;
-import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
@@ -23,7 +22,13 @@
* such as an edit conflict between multiple simultaneous updates.
*/
public class ConflictException extends StatusCodeException {
- public ConflictException(HttpRequest request, HttpResponse response) {
- super(request, response);
+
+ /**
+ * Constructs a new exception.
+ *
+ * @param response the response representing the exception
+ */
+ public ConflictException(HttpResponse response) {
+ super(response);
}
}
diff --git a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/exception/ForbiddenException.java b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/exception/ForbiddenException.java
index 49231e0..62f883e 100644
--- a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/exception/ForbiddenException.java
+++ b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/exception/ForbiddenException.java
@@ -14,7 +14,6 @@
*/
package de.fraunhofer.iosb.ilt.faaast.client.exception;
-import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
@@ -25,7 +24,13 @@
* The request should not be repeated.
*/
public class ForbiddenException extends StatusCodeException {
- public ForbiddenException(HttpRequest request, HttpResponse response) {
- super(request, response);
+
+ /**
+ * Constructs a new exception.
+ *
+ * @param response the response representing the exception
+ */
+ public ForbiddenException(HttpResponse response) {
+ super(response);
}
}
diff --git a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/exception/InternalServerErrorException.java b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/exception/InternalServerErrorException.java
index 7e34f40..7c1c18a 100644
--- a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/exception/InternalServerErrorException.java
+++ b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/exception/InternalServerErrorException.java
@@ -14,7 +14,6 @@
*/
package de.fraunhofer.iosb.ilt.faaast.client.exception;
-import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
@@ -22,7 +21,13 @@
* A generic error message, given when an unexpected condition was encountered and no more specific message is suitable.
*/
public class InternalServerErrorException extends StatusCodeException {
- public InternalServerErrorException(HttpRequest request, HttpResponse response) {
- super(request, response);
+
+ /**
+ * Constructs a new exception.
+ *
+ * @param response the response representing the exception
+ */
+ public InternalServerErrorException(HttpResponse response) {
+ super(response);
}
}
diff --git a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/exception/InvalidPayloadException.java b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/exception/InvalidPayloadException.java
index 0cd17d9..ffc822a 100644
--- a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/exception/InvalidPayloadException.java
+++ b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/exception/InvalidPayloadException.java
@@ -14,19 +14,27 @@
*/
package de.fraunhofer.iosb.ilt.faaast.client.exception;
-import de.fraunhofer.iosb.ilt.faaast.service.dataformat.DeserializationException;
-import org.json.JSONException;
-
-
/**
* This exception is thrown if the server responds with a body that cannot be deserialized.
*/
public class InvalidPayloadException extends RuntimeException {
+
+ /**
+ * Constructs a new exception.
+ *
+ * @param cause the cause of the exception
+ */
public InvalidPayloadException(Throwable cause) {
super(cause);
}
+ /**
+ * Constructs a new exception.
+ *
+ * @param message the message
+ * @param cause the cause of the exception
+ */
public InvalidPayloadException(String message, Throwable cause) {
super(message, cause);
}
diff --git a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/exception/MethodNotAllowedException.java b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/exception/MethodNotAllowedException.java
index 0bb1a19..51ff44d 100644
--- a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/exception/MethodNotAllowedException.java
+++ b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/exception/MethodNotAllowedException.java
@@ -14,7 +14,6 @@
*/
package de.fraunhofer.iosb.ilt.faaast.client.exception;
-import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
@@ -24,7 +23,13 @@
* resource.
*/
public class MethodNotAllowedException extends StatusCodeException {
- public MethodNotAllowedException(HttpRequest request, HttpResponse response) {
- super(request, response);
+
+ /**
+ * Constructs a new exception.
+ *
+ * @param response the response representing the exception
+ */
+ public MethodNotAllowedException(HttpResponse response) {
+ super(response);
}
}
diff --git a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/exception/NotFoundException.java b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/exception/NotFoundException.java
index 43e2225..beeefdd 100644
--- a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/exception/NotFoundException.java
+++ b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/exception/NotFoundException.java
@@ -14,7 +14,6 @@
*/
package de.fraunhofer.iosb.ilt.faaast.client.exception;
-import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
@@ -23,7 +22,13 @@
* permissible.
*/
public class NotFoundException extends StatusCodeException {
- public NotFoundException(HttpRequest request, HttpResponse response) {
- super(request, response);
+
+ /**
+ * Constructs a new exception.
+ *
+ * @param response the response representing the exception
+ */
+ public NotFoundException(HttpResponse response) {
+ super(response);
}
}
diff --git a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/exception/StatusCodeException.java b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/exception/StatusCodeException.java
index 92bb98e..0e3a559 100644
--- a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/exception/StatusCodeException.java
+++ b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/exception/StatusCodeException.java
@@ -15,7 +15,6 @@
package de.fraunhofer.iosb.ilt.faaast.client.exception;
import java.net.URI;
-import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
@@ -24,64 +23,61 @@
*/
public abstract class StatusCodeException extends ClientException {
- private final HttpResponse> response;
- private final HttpRequest request;
+ private final URI uri;
+ private final int statusCode;
+ private final String body;
/**
- * Constructor.
+ * Constructs a new exception.
*
- * @param request The http Request
- * @param response The http Response
+ * @param response the response representing the exception
*/
- public StatusCodeException(HttpRequest request, HttpResponse response) {
- super("httpMethod='" + request.method() + "',\n" +
- "requestUri='" + request.uri() + "',\n" +
- "ResponseUri='" + response.uri() + "',\n" +
- "statusCode='" + response.statusCode() + "',\n" +
- "requestBody=\n" + request.bodyPublisher().toString() + "',\n" +
- "responseBody=\n" + response.body());
-
- this.response = response;
- this.request = request;
+ protected StatusCodeException(HttpResponse response) {
+ this(response.uri(), response.statusCode(), response.body());
}
/**
- * The URI that generated the failure response.
+ * Constructs a new exception.
*
- * @return the URI that generated the failure response
+ * @param uri the uri called
+ * @param statusCode the status code received
+ * @param body the body of the response
*/
- public URI getServiceUri() {
- return response.uri();
+ protected StatusCodeException(URI uri, int statusCode, String body) {
+ super(String.format("Received HTTP status code %d (uri: %s uri, response body: %s)", statusCode, uri, body));
+ this.uri = uri;
+ this.statusCode = statusCode;
+ this.body = body;
}
/**
- * The status code returned by the server.
+ * The URI that generated the failure response.
*
- * @return the statusCode
+ * @return the URI that generated the failure response
*/
- public int getStatusCode() {
- return response.statusCode();
+ public URI getUri() {
+ return uri;
}
/**
- * The content returned by the server.
+ * The status code returned by the server.
*
- * @return the response body
+ * @return the statusCode
*/
- public HttpResponse> getResponse() {
- return response;
+ public int getStatusCode() {
+ return statusCode;
}
/**
- * The content sent to the server.
+ * The body of the response.
*
- * @return the response body
+ * @return the body of the response
*/
- public HttpRequest getRequest() {
- return request;
+ public String getBody() {
+ return body;
}
}
diff --git a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/exception/UnauthorizedException.java b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/exception/UnauthorizedException.java
index d29fb08..2c8eda2 100644
--- a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/exception/UnauthorizedException.java
+++ b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/exception/UnauthorizedException.java
@@ -14,7 +14,6 @@
*/
package de.fraunhofer.iosb.ilt.faaast.client.exception;
-import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
@@ -25,7 +24,13 @@
* resource.
*/
public class UnauthorizedException extends StatusCodeException {
- public UnauthorizedException(HttpRequest request, HttpResponse response) {
- super(request, response);
+
+ /**
+ * Constructs a new exception.
+ *
+ * @param response the response representing the exception
+ */
+ public UnauthorizedException(HttpResponse response) {
+ super(response);
}
}
diff --git a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/exception/UnsupportedStatusCodeException.java b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/exception/UnsupportedStatusCodeException.java
index 58b26c2..712967a 100644
--- a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/exception/UnsupportedStatusCodeException.java
+++ b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/exception/UnsupportedStatusCodeException.java
@@ -14,7 +14,7 @@
*/
package de.fraunhofer.iosb.ilt.faaast.client.exception;
-import java.net.http.HttpRequest;
+import java.net.URI;
import java.net.http.HttpResponse;
@@ -22,12 +22,25 @@
* This exception is thrown if the server responds with an error code that is not handled by the client.
*/
public class UnsupportedStatusCodeException extends RuntimeException {
- public UnsupportedStatusCodeException(HttpRequest request, HttpResponse response) {
- super("httpMethod='" + request.method() + "',\n" +
- "requestUri='" + request.uri() + "',\n" +
- "ResponseUri='" + response.uri() + "',\n" +
- "statusCode='" + response.statusCode() + "',\n" +
- "requestBody=\n" + request.bodyPublisher().toString() + "',\n" +
- "responseBody=\n" + response.body());
+
+ /**
+ * Constructs a new exception.
+ *
+ * @param response the response representing the exception
+ */
+ public UnsupportedStatusCodeException(HttpResponse response) {
+ this(response.uri(), response.statusCode(), response.body());
+ }
+
+
+ /**
+ * Constructs a new exception.
+ *
+ * @param uri the uri called
+ * @param statusCode the status code received
+ * @param body the body of the response
+ */
+ public UnsupportedStatusCodeException(URI uri, int statusCode, String body) {
+ super(String.format("Received HTTP status code %d (uri: %s uri, response body: %s)", statusCode, uri, body));
}
}
diff --git a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/util/HttpMethod.java b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/http/HttpMethod.java
similarity index 94%
rename from core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/util/HttpMethod.java
rename to core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/http/HttpMethod.java
index f97c86e..9c15024 100644
--- a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/util/HttpMethod.java
+++ b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/http/HttpMethod.java
@@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package de.fraunhofer.iosb.ilt.faaast.client.util;
+package de.fraunhofer.iosb.ilt.faaast.client.http;
/**
* Enum describing supported HTTP methods.
diff --git a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/http/HttpStatus.java b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/http/HttpStatus.java
new file mode 100644
index 0000000..d3fa1a6
--- /dev/null
+++ b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/http/HttpStatus.java
@@ -0,0 +1,117 @@
+/*
+ * Copyright (c) 2024 Fraunhofer IOSB, eine rechtlich nicht selbstaendige
+ * Einrichtung der Fraunhofer-Gesellschaft zur Foerderung der angewandten
+ * Forschung e.V.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package de.fraunhofer.iosb.ilt.faaast.client.http;
+
+import java.util.stream.Stream;
+
+
+/**
+ * Enum describing the relevant HTTP status codes.
+ */
+public enum HttpStatus {
+ OK(200),
+ CREATED(201),
+ ACCEPTED(202),
+ NO_CONTENT(204),
+ MOVED_PERMANENTLY(301),
+ FOUND(302),
+ SEE_OTHER(303),
+ BAD_REQUEST(400),
+ UNAUTHORIZED(401),
+ FORBIDDEN(403),
+ NOT_FOUND(404),
+ METHOD_NOT_ALLOWED(405),
+ REQUEST_TIMEOUT(408),
+ CONFLICT(409),
+ UNSUPPORTED_MEDIA_TYPE(415),
+ INTERNAL_SERVER_ERROR(500),
+ NOT_IMPLEMENTED(501),
+ BAD_GATEWAY(502),
+ SERVICE_UNAVAILABLE(503),
+ GATEWAY_TIMEOUT(504);
+
+ private final int code;
+
+ private HttpStatus(int code) {
+ this.code = code;
+ }
+
+
+ /**
+ * Gets the HTTP status code.
+ *
+ * @return the HTTP status code
+ */
+ public int getCode() {
+ return code;
+ }
+
+
+ /**
+ * Checks if this status represents success, i.e., is of form 2xx.
+ *
+ * @return true if status represents success, otherwise false
+ */
+ public boolean isSuccess() {
+ return 200 <= code && code <= 299;
+ }
+
+
+ /**
+ * Checks if this status represents a redirection, i.e., is of form 3xx.
+ *
+ * @return true if status represents a redirection, otherwise false
+ */
+ public boolean isRedirection() {
+ return 300 <= code && code <= 399;
+ }
+
+
+ /**
+ * Checks if this status represents a client error, i.e., is of form 4xx.
+ *
+ * @return true if status represents a client error, otherwise false
+ */
+ public boolean isClientError() {
+ return 400 <= code && code <= 499;
+ }
+
+
+ /**
+ * Checks if this status represents a server error, i.e., is of form 5xx.
+ *
+ * @return true if status represents a server error, otherwise false
+ */
+ public boolean isServerError() {
+ return 500 <= code && code <= 599;
+ }
+
+
+ /**
+ * Creates a {@link HttpStatus} based on the underlying HTTP status code.
+ *
+ * @param code the HTTP status code
+ * @return the corresponding HTTP status
+ * @throws IllegalArgumentException if the status code is unsupported
+ */
+ public static HttpStatus from(int code) {
+ return Stream.of(HttpStatus.values())
+ .filter(x -> x.code == code)
+ .findAny()
+ .orElseThrow(() -> new IllegalArgumentException(String.format(
+ "Unknown HTTP status (code: %s)",
+ code)));
+ }
+}
diff --git a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/interfaces/AASInterface.java b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/interfaces/AASInterface.java
index 3e8d162..f8746a2 100644
--- a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/interfaces/AASInterface.java
+++ b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/interfaces/AASInterface.java
@@ -16,6 +16,7 @@
import de.fraunhofer.iosb.ilt.faaast.client.exception.ConnectivityException;
import de.fraunhofer.iosb.ilt.faaast.client.exception.StatusCodeException;
+import de.fraunhofer.iosb.ilt.faaast.client.http.HttpStatus;
import de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.Content;
import de.fraunhofer.iosb.ilt.faaast.service.model.api.paging.Page;
import de.fraunhofer.iosb.ilt.faaast.service.model.api.paging.PagingInfo;
@@ -41,28 +42,40 @@ public class AASInterface extends BaseInterface {
/**
* Creates a new Asset Administration Shell Interface.
*
- * @param serviceUri Uri used to communicate with the FA³ST service.
+ * @param endpoint Uri used to communicate with the FA³ST service
*/
- public AASInterface(URI serviceUri) {
- super(serviceUri, "");
+ public AASInterface(URI endpoint) {
+ super(endpoint);
}
/**
* Creates a new Asset Administration Shell Interface.
*
- * @param httpClient Allows user to specify custom http-client.
- * @param serviceUri Uri used to communicate with the FA³ST service.
+ * @param endpoint Uri used to communicate with the FA³ST Service
+ * @param user String to allow for basic authentication
+ * @param password String to allow for basic authentication
*/
- public AASInterface(URI serviceUri, HttpClient httpClient) {
- super(serviceUri, "", httpClient);
+ public AASInterface(URI endpoint, String user, String password) {
+ super(endpoint, user, password);
+ }
+
+
+ /**
+ * Creates a new Asset Administration Shell Interface.
+ *
+ * @param endpoint Uri used to communicate with the FA³ST service
+ * @param httpClient Allows user to specify custom http-client
+ */
+ public AASInterface(URI endpoint, HttpClient httpClient) {
+ super(endpoint, httpClient);
}
/**
* Retrieves the Asset Administration Shell (AAS) from the server.
*
- * @return The requested Asset Administration Shell object.
+ * @return The requested Asset Administration Shell object
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -73,17 +86,17 @@ public AASInterface(URI serviceUri, HttpClient httpClient) {
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public AssetAdministrationShell get() throws StatusCodeException, ConnectivityException {
- return get(basePath(), AssetAdministrationShell.class);
+ return get(AssetAdministrationShell.class);
}
/**
* Replaces the current Asset Administration Shell with a new one.
*
- * @param aas The new Asset Administration Shell object to replace the current one.
+ * @param aas The new Asset Administration Shell object to replace the current one
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -94,17 +107,17 @@ public AssetAdministrationShell get() throws StatusCodeException, ConnectivityEx
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public void put(AssetAdministrationShell aas) throws StatusCodeException, ConnectivityException {
- put(basePath(), aas);
+ super.put(aas);
}
/**
* Retrieves the Asset Administration Shell (AAS) as a reference.
*
- * @return The requested Asset Administration Shell reference.
+ * @return The requested Asset Administration Shell reference
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -115,17 +128,17 @@ public void put(AssetAdministrationShell aas) throws StatusCodeException, Connec
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public Reference getAsReference() throws StatusCodeException, ConnectivityException {
- return get(basePath(), Content.REFERENCE, Reference.class);
+ return get(Content.REFERENCE, Reference.class);
}
/**
* Retrieves the asset information associated with the Asset Administration Shell.
*
- * @return The requested Asset Information object.
+ * @return The requested Asset Information object
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -136,7 +149,7 @@ public Reference getAsReference() throws StatusCodeException, ConnectivityExcept
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public AssetInformation getAssetInformation() throws StatusCodeException, ConnectivityException {
return get(assetInfoPath(), AssetInformation.class);
@@ -146,7 +159,7 @@ public AssetInformation getAssetInformation() throws StatusCodeException, Connec
/**
* Updates the asset information of the Asset Administration Shell.
*
- * @param assetInfo The new Asset Information object to replace the current one.
+ * @param assetInfo The new Asset Information object to replace the current one
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -157,7 +170,7 @@ public AssetInformation getAssetInformation() throws StatusCodeException, Connec
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public void putAssetInformation(AssetInformation assetInfo) throws StatusCodeException, ConnectivityException {
put(assetInfoPath(), assetInfo);
@@ -167,7 +180,7 @@ public void putAssetInformation(AssetInformation assetInfo) throws StatusCodeExc
/**
* Retrieves the thumbnail image associated with the Asset Administration Shell.
*
- * @return The requested thumbnail as a Resource object.
+ * @return The requested thumbnail as a Resource object
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -178,7 +191,7 @@ public void putAssetInformation(AssetInformation assetInfo) throws StatusCodeExc
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public Resource getThumbnail() throws StatusCodeException, ConnectivityException {
return get(thumbnailPath(), Resource.class);
@@ -188,7 +201,7 @@ public Resource getThumbnail() throws StatusCodeException, ConnectivityException
/**
* Replaces the current thumbnail image of the Asset Administration Shell.
*
- * @param file The new thumbnail file to replace the current one.
+ * @param file The new thumbnail file to replace the current one
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -199,7 +212,7 @@ public Resource getThumbnail() throws StatusCodeException, ConnectivityException
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public void putThumbnail(Resource file) throws StatusCodeException, ConnectivityException {
put(thumbnailPath(), file);
@@ -219,17 +232,17 @@ public void putThumbnail(Resource file) throws StatusCodeException, Connectivity
* 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public void deleteThumbnail() throws StatusCodeException, ConnectivityException {
- delete(thumbnailPath());
+ delete(thumbnailPath(), HttpStatus.OK);
}
/**
* Retrieves all references to submodels within the Asset Administration Shell.
*
- * @return A list of references to all submodels.
+ * @return A list of references to all submodels
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -240,7 +253,7 @@ public void deleteThumbnail() throws StatusCodeException, ConnectivityException
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public List getAllSubmodelReferences() throws StatusCodeException, ConnectivityException {
return getList(submodelRefPath(), Reference.class);
@@ -250,8 +263,8 @@ public List getAllSubmodelReferences() throws StatusCodeException, Co
/**
* Retrieves a page of references to submodels.
*
- * @param pagingInfo Metadata for controlling the pagination of results.
- * @return A page of references to submodels.
+ * @param pagingInfo Metadata for controlling the pagination of results
+ * @return A page of references to submodels
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -262,7 +275,7 @@ public List getAllSubmodelReferences() throws StatusCodeException, Co
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public Page getSubmodelReference(PagingInfo pagingInfo) throws StatusCodeException, ConnectivityException {
return getPage(submodelRefPath(), pagingInfo, Reference.class);
@@ -272,8 +285,8 @@ public Page getSubmodelReference(PagingInfo pagingInfo) throws Status
/**
* Creates a new reference to a submodel within the Asset Administration Shell.
*
- * @param reference The reference to the submodel to be added.
- * @return The created submodel reference.
+ * @param reference The reference to the submodel to be added
+ * @return The created submodel reference
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -285,7 +298,7 @@ public Page getSubmodelReference(PagingInfo pagingInfo) throws Status
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public Reference postSubmodelReference(Reference reference) throws StatusCodeException, ConnectivityException {
return post(submodelRefPath(), reference, Reference.class);
@@ -295,7 +308,7 @@ public Reference postSubmodelReference(Reference reference) throws StatusCodeExc
/**
* Deletes a specific submodel reference from the Asset Administration Shell.
*
- * @param submodelId The unique identifier of the submodel to delete.
+ * @param submodelId The unique identifier of the submodel to delete
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -306,7 +319,7 @@ public Reference postSubmodelReference(Reference reference) throws StatusCodeExc
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public void deleteSubmodelReference(String submodelId) throws StatusCodeException, ConnectivityException {
delete(submodelRefPath() + submodelId);
@@ -316,7 +329,7 @@ public void deleteSubmodelReference(String submodelId) throws StatusCodeExceptio
/**
* Deletes a specific submodel from the Asset Administration Shell.
*
- * @param submodelId The unique identifier of the submodel to delete.
+ * @param submodelId The unique identifier of the submodel to delete
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -327,7 +340,7 @@ public void deleteSubmodelReference(String submodelId) throws StatusCodeExceptio
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public void deleteSubmodel(String submodelId) throws StatusCodeException, ConnectivityException {
delete(submodelPath() + submodelId);
@@ -339,30 +352,31 @@ public void deleteSubmodel(String submodelId) throws StatusCodeException, Connec
* Although submodels can be managed directly through this interface,
* it is recommended to use the Submodel Repository Interface.
*
- * @param submodelId The unique identifier of the submodel to retrieve.
- * @return The SubmodelInterface object for interacting with the specified submodel.
+ * @param submodelId The unique identifier of the submodel to retrieve
+ * @return The SubmodelInterface object for interacting with the specified submodel
*/
public SubmodelInterface getSubmodelInterface(String submodelId) {
- return new SubmodelInterface(URI.create(idPath(submodelId)));
+ return new SubmodelInterface(resolve(idPath(submodelId)));
}
- private String assetInfoPath() {
- return basePath() + "asset-information/";
+ private static String assetInfoPath() {
+ return "/asset-information";
}
- private String submodelRefPath() {
- return basePath() + "submodel-refs/";
+ private static String submodelRefPath() {
+ return "/submodel-refs";
}
- private String submodelPath() {
- return basePath() + "submodels/";
+ private static String submodelPath() {
+ return "/submodels";
}
- private String thumbnailPath() {
- return assetInfoPath() + "thumbnail/";
+ private static String thumbnailPath() {
+ return assetInfoPath() + "/thumbnail";
}
+
}
diff --git a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/interfaces/AASRegistryInterface.java b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/interfaces/AASRegistryInterface.java
index fead27a..0f6ffe1 100644
--- a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/interfaces/AASRegistryInterface.java
+++ b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/interfaces/AASRegistryInterface.java
@@ -39,43 +39,45 @@
*/
public class AASRegistryInterface extends BaseInterface {
+ private static final String API_PATH = "/shell-descriptors";
+
/**
* Creates a new Asset Administration Shell Registry Interface.
*
- * @param serviceUri Uri used to communicate with the FA³ST Service.
+ * @param endpoint Uri used to communicate with the FA³ST Service
*/
- public AASRegistryInterface(URI serviceUri) {
- super(serviceUri, "/shell-descriptors/");
+ public AASRegistryInterface(URI endpoint) {
+ super(resolve(endpoint, API_PATH));
}
/**
* Creates a new Asset Administration Shell Registry Interface.
*
- * @param user String to allow for basic authentication.
- * @param password String to allow for basic authentication.
- * @param serviceUri Uri used to communicate with the FA³ST Service.
+ * @param endpoint Uri used to communicate with the FA³ST Service
+ * @param user String to allow for basic authentication
+ * @param password String to allow for basic authentication
*/
- public AASRegistryInterface(URI serviceUri, String user, String password) {
- super(serviceUri, "/shell-descriptors/", user, password);
+ public AASRegistryInterface(URI endpoint, String user, String password) {
+ super(resolve(endpoint, API_PATH), user, password);
}
/**
* Creates a new Asset Administration Shell Registry Interface.
*
- * @param httpClient Allows the user to specify a custom httpClient.
- * @param serviceUri Uri used to communicate with the FA³ST Service.
+ * @param endpoint Uri used to communicate with the FA³ST Service
+ * @param httpClient Allows the user to specify a custom httpClient
*/
- public AASRegistryInterface(URI serviceUri, HttpClient httpClient) {
- super(serviceUri, "/shell-descriptors/", httpClient);
+ public AASRegistryInterface(URI endpoint, HttpClient httpClient) {
+ super(resolve(endpoint, API_PATH), httpClient);
}
/**
* Returns all Asset Administration Shell Descriptors in a List.
*
- * @return List containing all Asset Administration Shell Descriptors.
+ * @return List containing all Asset Administration Shell Descriptors
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -86,18 +88,18 @@ public AASRegistryInterface(URI serviceUri, HttpClient httpClient) {
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public List getAll() throws StatusCodeException, ConnectivityException {
- return getList(basePath(), DefaultAssetAdministrationShellDescriptor.class);
+ return getList(DefaultAssetAdministrationShellDescriptor.class);
}
/**
* Returns a page of Asset Administration Shell Descriptors.
*
- * @param pagingInfo Metadata for controlling the pagination of results.
- * @return A page of Asset Administration Shell Descriptors.
+ * @param pagingInfo Metadata for controlling the pagination of results
+ * @return A page of Asset Administration Shell Descriptors
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -108,7 +110,7 @@ public List getAll() throws StatusCod
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public Page get(PagingInfo pagingInfo) throws StatusCodeException, ConnectivityException {
return get(pagingInfo, AASDescriptorSearchCriteria.DEFAULT);
@@ -118,9 +120,9 @@ public Page get(PagingInfo pagingInfo
/**
* Returns a Page of Asset Administration Shell Descriptors.
*
- * @param pagingInfo Metadata for controlling the pagination of results.
- * @param aasDescriptorSearchCriteria Allows to filter Descriptors based on AssetType and AssetKind.
- * @return A page of Asset Administration Shell Descriptors.
+ * @param pagingInfo Metadata for controlling the pagination of results
+ * @param aasDescriptorSearchCriteria Allows to filter Descriptors based on AssetType and AssetKind
+ * @return A page of Asset Administration Shell Descriptors
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -131,19 +133,19 @@ public Page get(PagingInfo pagingInfo
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public Page get(PagingInfo pagingInfo, AASDescriptorSearchCriteria aasDescriptorSearchCriteria)
throws StatusCodeException, ConnectivityException {
- return getPage(basePath(), Content.DEFAULT, QueryModifier.DEFAULT, pagingInfo, aasDescriptorSearchCriteria, DefaultAssetAdministrationShellDescriptor.class);
+ return getPage(Content.DEFAULT, QueryModifier.DEFAULT, pagingInfo, aasDescriptorSearchCriteria, DefaultAssetAdministrationShellDescriptor.class);
}
/**
* Creates a new Asset Administration Shell Descriptor, i.e. registers an AAS.
*
- * @param shellDescriptor Object containing the Asset Administration Shell’s identification and endpoint information.
- * @return Created Asset Administration Shell Descriptor.
+ * @param shellDescriptor Object containing the Asset Administration Shell’s identification and endpoint information
+ * @return Created Asset Administration Shell Descriptor
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -155,7 +157,7 @@ public Page get(PagingInfo pagingInfo
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public DefaultAssetAdministrationShellDescriptor post(DefaultAssetAdministrationShellDescriptor shellDescriptor) throws StatusCodeException, ConnectivityException {
return post(idPath(shellDescriptor.getId()), shellDescriptor, DefaultAssetAdministrationShellDescriptor.class);
@@ -165,8 +167,8 @@ public DefaultAssetAdministrationShellDescriptor post(DefaultAssetAdministration
/**
* Returns a specific Asset Administration Shell Descriptor.
*
- * @param aasIdentifier The Asset Administration Shell’s unique id.
- * @return Requested Asset Administration Shell Descriptor.
+ * @param aasIdentifier The Asset Administration Shell’s unique id
+ * @return Requested Asset Administration Shell Descriptor
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -177,7 +179,7 @@ public DefaultAssetAdministrationShellDescriptor post(DefaultAssetAdministration
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public DefaultAssetAdministrationShellDescriptor get(String aasIdentifier) throws StatusCodeException, ConnectivityException {
return get(idPath(aasIdentifier), DefaultAssetAdministrationShellDescriptor.class);
@@ -187,7 +189,8 @@ public DefaultAssetAdministrationShellDescriptor get(String aasIdentifier) throw
/**
* Replaces an existing Asset Administration Shell Descriptor, i.e. replaces registration information.
*
- * @param shellDescriptor Object containing the Asset Administration Shell’s identification and endpoint information.
+ * @param aasIdentifier The Asset Administration Shell’s unique id
+ * @param shellDescriptor Object containing the Asset Administration Shell’s identification and endpoint information
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -198,7 +201,7 @@ public DefaultAssetAdministrationShellDescriptor get(String aasIdentifier) throw
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public void put(String aasIdentifier, AssetAdministrationShellDescriptor shellDescriptor) throws StatusCodeException, ConnectivityException {
super.put(idPath(aasIdentifier), shellDescriptor);
@@ -208,7 +211,7 @@ public void put(String aasIdentifier, AssetAdministrationShellDescriptor shellDe
/**
* Deletes an Asset Administration Shell Descriptor, i.e. de-registers an AAS.
*
- * @param aasIdentifier The Asset Administration Shell’s unique id.
+ * @param aasIdentifier The Asset Administration Shell’s unique id
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -219,8 +222,9 @@ public void put(String aasIdentifier, AssetAdministrationShellDescriptor shellDe
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
+ @Override
public void delete(String aasIdentifier) throws StatusCodeException, ConnectivityException {
super.delete(idPath(aasIdentifier));
}
@@ -230,8 +234,9 @@ public void delete(String aasIdentifier) throws StatusCodeException, Connectivit
* Returns the Submodel Registry Interface.
*
* @param aasIdentifier The unique id of the Submodel for the reference to be deleted
+ * @return the {@link SubmodelRegistryInterface}
*/
public SubmodelRegistryInterface getSubmodelRegistryInterface(String aasIdentifier) {
- return new SubmodelRegistryInterface(URI.create(idPath(aasIdentifier)));
+ return new SubmodelRegistryInterface(resolve(idPath(aasIdentifier)));
}
}
diff --git a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/interfaces/AASRepositoryInterface.java b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/interfaces/AASRepositoryInterface.java
index 2c6d77b..c77f3e4 100644
--- a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/interfaces/AASRepositoryInterface.java
+++ b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/interfaces/AASRepositoryInterface.java
@@ -37,43 +37,45 @@
*/
public class AASRepositoryInterface extends BaseInterface {
+ private static final String API_PATH = "/shells";
+
/**
* Creates a new Asset Administration Shell Repository Interface.
*
- * @param serviceUri Uri used to communicate with the FA³ST service.
+ * @param endpoint Uri used to communicate with the FA³ST service
*/
- public AASRepositoryInterface(URI serviceUri) {
- super(serviceUri, "/shells/");
+ public AASRepositoryInterface(URI endpoint) {
+ super(resolve(endpoint, API_PATH));
}
/**
* Creates a new Asset Administration Shell Repository Interface with basic authentication.
*
- * @param user String for basic authentication.
- * @param password String for basic authentication.
- * @param serviceUri Uri used to communicate with the FA³ST service.
+ * @param endpoint Uri used to communicate with the FA³ST service
+ * @param user String for basic authentication
+ * @param password String for basic authentication
*/
- public AASRepositoryInterface(URI serviceUri, String user, String password) {
- super(serviceUri, "/shells/", user, password);
+ public AASRepositoryInterface(URI endpoint, String user, String password) {
+ super(resolve(endpoint, API_PATH), user, password);
}
/**
* Creates a new Asset Administration Shell Repository Interface using a custom HTTP client.
*
- * @param httpClient Allows user to specify custom http-client.
- * @param serviceUri Uri used to communicate with the FA³ST service.
+ * @param endpoint Uri used to communicate with the FA³ST service
+ * @param httpClient Allows user to specify custom http-client
*/
- public AASRepositoryInterface(URI serviceUri, HttpClient httpClient) {
- super(serviceUri, "/shells/", httpClient);
+ public AASRepositoryInterface(URI endpoint, HttpClient httpClient) {
+ super(resolve(endpoint, API_PATH), httpClient);
}
/**
* Retrieves all Asset Administration Shells.
*
- * @return A list of all Asset Administration Shells.
+ * @return A list of all Asset Administration Shells
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -84,10 +86,9 @@ public AASRepositoryInterface(URI serviceUri, HttpClient httpClient) {
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
- public List getAll()
- throws StatusCodeException, ConnectivityException {
+ public List getAll() throws StatusCodeException, ConnectivityException {
return getAll(AASSearchCriteria.DEFAULT);
}
@@ -95,8 +96,8 @@ public List getAll()
/**
* Retrieves all Asset Administration Shells based on specific search criteria.
*
- * @param aasSearchCriteria Search criteria to filter Asset Administration Shells based on AssetType and AssetKind.
- * @return A list of Asset Administration Shells that match the search criteria.
+ * @param aasSearchCriteria Search criteria to filter Asset Administration Shells based on AssetType and AssetKind
+ * @return A list of Asset Administration Shells that match the search criteria
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -107,19 +108,18 @@ public List getAll()
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
- public List getAll(AASSearchCriteria aasSearchCriteria)
- throws StatusCodeException, ConnectivityException {
- return getList(basePath(), aasSearchCriteria, Content.DEFAULT, QueryModifier.DEFAULT, AssetAdministrationShell.class);
+ public List getAll(AASSearchCriteria aasSearchCriteria) throws StatusCodeException, ConnectivityException {
+ return getList(null, aasSearchCriteria, Content.DEFAULT, QueryModifier.DEFAULT, AssetAdministrationShell.class);
}
/**
* Retrieves a page of Asset Administration Shells.
*
- * @param pagingInfo Metadata for controlling the pagination of results.
- * @return A page of Asset Administration Shells.
+ * @param pagingInfo Metadata for controlling the pagination of results
+ * @return A page of Asset Administration Shells
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -130,10 +130,9 @@ public List getAll(AASSearchCriteria aasSearchCriteria
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
- public Page get(PagingInfo pagingInfo)
- throws StatusCodeException, ConnectivityException {
+ public Page get(PagingInfo pagingInfo) throws StatusCodeException, ConnectivityException {
return get(pagingInfo, AASSearchCriteria.DEFAULT);
}
@@ -141,9 +140,9 @@ public Page get(PagingInfo pagingInfo)
/**
* Retrieves a page of Asset Administration Shells based on specific search criteria.
*
- * @param pagingInfo Metadata for controlling the pagination of results.
- * @param aasSearchCriteria Search criteria to filter Asset Administration Shells based on AssetType and AssetKind.
- * @return A page of Asset Administration Shells.
+ * @param pagingInfo Metadata for controlling the pagination of results
+ * @param aasSearchCriteria Search criteria to filter Asset Administration Shells based on AssetType and AssetKind
+ * @return A page of Asset Administration Shells
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -154,11 +153,10 @@ public Page get(PagingInfo pagingInfo)
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
- public Page get(PagingInfo pagingInfo, AASSearchCriteria aasSearchCriteria)
- throws StatusCodeException, ConnectivityException {
- return getPage(basePath(), Content.DEFAULT, QueryModifier.DEFAULT, pagingInfo, aasSearchCriteria, AssetAdministrationShell.class);
+ public Page get(PagingInfo pagingInfo, AASSearchCriteria aasSearchCriteria) throws StatusCodeException, ConnectivityException {
+ return getPage(Content.DEFAULT, QueryModifier.DEFAULT, pagingInfo, aasSearchCriteria, AssetAdministrationShell.class);
}
@@ -166,8 +164,8 @@ public Page get(PagingInfo pagingInfo, AASSearchCriter
* Creates a new Asset Administration Shell.
* The unique identifier of the Asset Administration Shell must be provided in the payload.
*
- * @param aas Asset Administration Shell object to be created.
- * @return The created Asset Administration Shell.
+ * @param aas Asset Administration Shell object to be created
+ * @return The created Asset Administration Shell
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -179,18 +177,17 @@ public Page get(PagingInfo pagingInfo, AASSearchCriter
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
- public AssetAdministrationShell post(AssetAdministrationShell aas)
- throws StatusCodeException, ConnectivityException {
- return post(basePath(), aas, AssetAdministrationShell.class);
+ public AssetAdministrationShell post(AssetAdministrationShell aas) throws StatusCodeException, ConnectivityException {
+ return post(aas, AssetAdministrationShell.class);
}
/**
* Retrieves references to all Asset Administration Shells.
*
- * @return A list of references to all Asset Administration Shells.
+ * @return A list of references to all Asset Administration Shells
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -201,10 +198,9 @@ public AssetAdministrationShell post(AssetAdministrationShell aas)
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
- public List getAllAsReference()
- throws StatusCodeException, ConnectivityException {
+ public List getAllAsReference() throws StatusCodeException, ConnectivityException {
return getAllAsReference(AASSearchCriteria.DEFAULT);
}
@@ -213,8 +209,8 @@ public List getAllAsReference()
* Retrieves references to all Asset Administration Shells based on specific search criteria.
*
* @param aasSearchCriteria Search criteria to filter Asset Administration Shell references based on AssetType and
- * AssetKind.
- * @return A list of references to Asset Administration Shells.
+ * AssetKind
+ * @return A list of references to Asset Administration Shells
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -225,19 +221,18 @@ public List getAllAsReference()
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
- public List getAllAsReference(AASSearchCriteria aasSearchCriteria)
- throws StatusCodeException, ConnectivityException {
- return getList(basePath(), aasSearchCriteria, Content.REFERENCE, QueryModifier.DEFAULT, Reference.class);
+ public List getAllAsReference(AASSearchCriteria aasSearchCriteria) throws StatusCodeException, ConnectivityException {
+ return getList(null, aasSearchCriteria, Content.REFERENCE, QueryModifier.DEFAULT, Reference.class);
}
/**
* Retrieves a page of references to Asset Administration Shells.
*
- * @param pagingInfo Metadata for controlling the pagination of results.
- * @return A page of references to Asset Administration Shells.
+ * @param pagingInfo Metadata for controlling the pagination of results
+ * @return A page of references to Asset Administration Shells
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -248,10 +243,9 @@ public List getAllAsReference(AASSearchCriteria aasSearchCriteria)
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
- public Page getReference(PagingInfo pagingInfo)
- throws StatusCodeException, ConnectivityException {
+ public Page getReference(PagingInfo pagingInfo) throws StatusCodeException, ConnectivityException {
return getReference(pagingInfo, AASSearchCriteria.DEFAULT);
}
@@ -259,10 +253,10 @@ public Page getReference(PagingInfo pagingInfo)
/**
* Retrieves a page of references to Asset Administration Shells based on specific search criteria.
*
- * @param pagingInfo Metadata for controlling the pagination of results.
+ * @param pagingInfo Metadata for controlling the pagination of results
* @param aasSearchCriteria Search criteria to filter Asset Administration Shell references based on AssetType and
- * AssetKind.
- * @return A page of references to Asset Administration Shells.
+ * AssetKind
+ * @return A page of references to Asset Administration Shells
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -273,18 +267,17 @@ public Page getReference(PagingInfo pagingInfo)
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
- public Page getReference(PagingInfo pagingInfo, AASSearchCriteria aasSearchCriteria)
- throws StatusCodeException, ConnectivityException {
- return getPage(basePath(), Content.REFERENCE, QueryModifier.DEFAULT, pagingInfo, aasSearchCriteria, Reference.class);
+ public Page getReference(PagingInfo pagingInfo, AASSearchCriteria aasSearchCriteria) throws StatusCodeException, ConnectivityException {
+ return getPage(null, Content.REFERENCE, QueryModifier.DEFAULT, pagingInfo, aasSearchCriteria, Reference.class);
}
/**
* Deletes an Asset Administration Shell.
*
- * @param aasIdentifier The unique identifier of the Asset Administration Shell to be deleted.
+ * @param aasIdentifier The unique identifier of the Asset Administration Shell to be deleted
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -295,7 +288,7 @@ public Page getReference(PagingInfo pagingInfo, AASSearchCriteria aas
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
@Override
public void delete(String aasIdentifier) throws StatusCodeException, ConnectivityException {
@@ -304,12 +297,12 @@ public void delete(String aasIdentifier) throws StatusCodeException, Connectivit
/**
- * Returns an AAS Interface for accessing the data of AAS elements.
+ * Returns an AAS Interface for accessing the data of AAS elements
*
- * @param aasIdentifier The Asset Administration Shell’s unique id.
- * @return Requested Asset Administration Shell Interface.
+ * @param aasIdentifier The Asset Administration Shell’s unique id
+ * @return Requested Asset Administration Shell Interface
*/
public AASInterface getAASInterface(String aasIdentifier) {
- return new AASInterface(URI.create(idPath(aasIdentifier)), httpClient());
+ return new AASInterface(resolve(idPath(aasIdentifier)), httpClient);
}
}
diff --git a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/interfaces/BaseInterface.java b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/interfaces/BaseInterface.java
index 9e1dd5c..a70b11c 100644
--- a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/interfaces/BaseInterface.java
+++ b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/interfaces/BaseInterface.java
@@ -14,14 +14,22 @@
*/
package de.fraunhofer.iosb.ilt.faaast.client.interfaces;
+import de.fraunhofer.iosb.ilt.faaast.client.exception.BadRequestException;
+import de.fraunhofer.iosb.ilt.faaast.client.exception.ConflictException;
import de.fraunhofer.iosb.ilt.faaast.client.exception.ConnectivityException;
+import de.fraunhofer.iosb.ilt.faaast.client.exception.ForbiddenException;
+import de.fraunhofer.iosb.ilt.faaast.client.exception.InternalServerErrorException;
import de.fraunhofer.iosb.ilt.faaast.client.exception.InvalidPayloadException;
+import de.fraunhofer.iosb.ilt.faaast.client.exception.MethodNotAllowedException;
+import de.fraunhofer.iosb.ilt.faaast.client.exception.NotFoundException;
import de.fraunhofer.iosb.ilt.faaast.client.exception.StatusCodeException;
+import de.fraunhofer.iosb.ilt.faaast.client.exception.UnauthorizedException;
+import de.fraunhofer.iosb.ilt.faaast.client.exception.UnsupportedStatusCodeException;
import de.fraunhofer.iosb.ilt.faaast.client.query.SearchCriteria;
-import de.fraunhofer.iosb.ilt.faaast.client.util.ExceptionHandler;
-import de.fraunhofer.iosb.ilt.faaast.client.util.HttpClientUtility;
-import de.fraunhofer.iosb.ilt.faaast.client.util.HttpMethod;
-import de.fraunhofer.iosb.ilt.faaast.client.util.UriBuilder;
+import de.fraunhofer.iosb.ilt.faaast.client.util.HttpHelper;
+import de.fraunhofer.iosb.ilt.faaast.client.http.HttpMethod;
+import de.fraunhofer.iosb.ilt.faaast.client.http.HttpStatus;
+import de.fraunhofer.iosb.ilt.faaast.client.util.QueryHelper;
import de.fraunhofer.iosb.ilt.faaast.service.dataformat.DeserializationException;
import de.fraunhofer.iosb.ilt.faaast.service.dataformat.SerializationException;
import de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.JsonApiDeserializer;
@@ -39,10 +47,13 @@
import java.net.Authenticator;
import java.net.PasswordAuthentication;
import java.net.URI;
+import java.net.URISyntaxException;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
+import java.util.ArrayList;
import java.util.List;
+import java.util.Objects;
import org.json.JSONArray;
import org.json.JSONException;
@@ -56,91 +67,210 @@
* Subclasses extend these methods to interact with specific APIs.
*/
public abstract class BaseInterface {
- protected String basePath;
- protected URI serviceUri;
- protected UriBuilder uriBuilder;
- private final HttpClientUtility httpClientUtility;
- private final HttpClient httpClient;
-
- protected BaseInterface(URI serviceUri, String basePath) {
- this.basePath = serviceUri + basePath;
- this.serviceUri = serviceUri;
- this.uriBuilder = new UriBuilder(serviceUri);
- this.httpClient = HttpClient.newHttpClient();
- this.httpClientUtility = new HttpClientUtility(httpClient);
- }
-
-
- protected BaseInterface(URI serviceUri, String basePath, String username, String password) {
- this.basePath = serviceUri + basePath;
- this.serviceUri = serviceUri;
- this.uriBuilder = new UriBuilder(serviceUri);
- this.httpClient = HttpClient.newBuilder()
+ private static final String URI_PATH_SEPERATOR = "/";
+ private static final List SUPPORTED_DEFAULT_HTTP_STATUS = List.of(
+ HttpStatus.BAD_REQUEST,
+ HttpStatus.UNAUTHORIZED,
+ HttpStatus.FORBIDDEN,
+ HttpStatus.NOT_FOUND,
+ HttpStatus.INTERNAL_SERVER_ERROR);
+
+ protected final HttpClient httpClient;
+ private final URI endpoint;
+
+ /**
+ * Creates a new instance.
+ *
+ * @param endpoint Uri used to communicate with the FA³ST service
+ */
+ protected BaseInterface(URI endpoint) {
+ this(endpoint, HttpClient.newHttpClient());
+ }
+
+
+ /**
+ * Creates a new instance.
+ *
+ * @param endpoint Uri used to communicate with the FA³ST Service
+ * @param user String to allow for basic authentication
+ * @param password String to allow for basic authentication
+ */
+ protected BaseInterface(URI endpoint, String user, String password) {
+ this(endpoint, HttpClient.newBuilder()
.authenticator(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
- return new PasswordAuthentication(username, password.toCharArray());
+ return new PasswordAuthentication(user, password.toCharArray());
}
- }).build();
- this.httpClientUtility = new HttpClientUtility(httpClient);
+ }).build());
}
- protected BaseInterface(URI serviceUri, String basePath, HttpClient httpClient) {
- this.basePath = serviceUri + basePath;
- this.serviceUri = serviceUri;
- this.uriBuilder = new UriBuilder(serviceUri);
+ /**
+ * Creates a new instance.
+ *
+ * @param endpoint Uri used to communicate with the FA³ST service
+ * @param httpClient Allows user to specify custom http-client
+ */
+ protected BaseInterface(URI endpoint, HttpClient httpClient) {
+ this.endpoint = sanitizeEndpoint(endpoint);
this.httpClient = httpClient;
- this.httpClientUtility = new HttpClientUtility(httpClient);
}
+ /**
+ * Executes a HTTP GET and parses the response body as {@code responseType}.
+ *
+ * @param the result type
+ * @param responseType the result type
+ * @return the parsed HTTP response
+ * @throws ConnectivityException if connection to the server fails
+ * @throws StatusCodeException if HTTP request returns invalid statsu code
+ * @throws InvalidPayloadException if deserializing the payload fails
+ */
+ protected T get(Class responseType) throws ConnectivityException, StatusCodeException {
+ return get((String) null, Content.DEFAULT, responseType);
+ }
+
+
+ /**
+ * Executes a HTTP GET and parses the response body as {@code responseType}.
+ *
+ * @param the result type
+ * @param path the URL path relative to the current endpoint
+ * @param responseType the result type
+ * @return the parsed HTTP response
+ * @throws ConnectivityException if connection to the server fails
+ * @throws StatusCodeException if HTTP request returns invalid statsu code
+ * @throws InvalidPayloadException if deserializing the payload fails
+ */
protected T get(String path, Class responseType) throws ConnectivityException, StatusCodeException {
return get(path, Content.DEFAULT, responseType);
}
+ /**
+ * Executes a HTTP GET and parses the response body as {@code responseType}.
+ *
+ * @param the result type
+ * @param content the content modifier
+ * @param responseType the result type
+ * @return the parsed HTTP response
+ * @throws ConnectivityException if connection to the server fails
+ * @throws StatusCodeException if HTTP request returns invalid statsu code
+ * @throws InvalidPayloadException if deserializing the payload fails
+ */
+ protected T get(Content content, Class responseType) throws ConnectivityException, StatusCodeException {
+ return get(null, QueryModifier.DEFAULT, content, responseType);
+ }
+
+
+ /**
+ * Executes a HTTP GET and parses the response body as {@code responseType}.
+ *
+ * @param the result type
+ * @param path the URL path relative to the current endpoint
+ * @param content the content modifier
+ * @param responseType the result type
+ * @return the parsed HTTP response
+ * @throws ConnectivityException if connection to the server fails
+ * @throws StatusCodeException if HTTP request returns invalid statsu code
+ * @throws InvalidPayloadException if deserializing the payload fails
+ */
protected T get(String path, Content content, Class responseType) throws ConnectivityException, StatusCodeException {
return get(path, QueryModifier.DEFAULT, content, responseType);
}
- protected T get(String path, QueryModifier queryModifier, Class responseType) throws ConnectivityException, StatusCodeException {
- return get(path, queryModifier, Content.DEFAULT, responseType);
- }
-
-
+ /**
+ * Executes a HTTP GET and parses the response body as {@code responseType}.
+ *
+ * @param the result type
+ * @param modifier the query modifier
+ * @param responseType the result type
+ * @return the parsed HTTP response
+ * @throws ConnectivityException if connection to the server fails
+ * @throws StatusCodeException if HTTP request returns invalid statsu code
+ * @throws InvalidPayloadException if deserializing the payload fails
+ */
+ protected T get(QueryModifier modifier, Class responseType) throws ConnectivityException, StatusCodeException {
+ return get(null, modifier, Content.DEFAULT, responseType);
+ }
+
+
+ /**
+ * Executes a HTTP GET and parses the response body as {@code responseType}.
+ *
+ * @param the result type
+ * @param path the URL path relative to the current endpoint
+ * @param modifier the query modifier
+ * @param responseType the result type
+ * @return the parsed HTTP response
+ * @throws ConnectivityException if connection to the server fails
+ * @throws StatusCodeException if HTTP request returns invalid statsu code
+ * @throws InvalidPayloadException if deserializing the payload fails
+ */
+ protected T get(String path, QueryModifier modifier, Class responseType) throws ConnectivityException, StatusCodeException {
+ return get(path, modifier, Content.DEFAULT, responseType);
+ }
+
+
+ /**
+ * Executes a HTTP GET and parses the response body as {@code responseType}.
+ *
+ * @param the result type
+ * @param modifier the query modifier
+ * @param content the content modifier
+ * @param responseType the result type
+ * @return the parsed HTTP response
+ * @throws ConnectivityException if connection to the server fails
+ * @throws StatusCodeException if HTTP request returns invalid statsu code
+ * @throws InvalidPayloadException if deserializing the payload fails
+ */
+ protected T get(QueryModifier modifier, Content content, Class responseType) throws ConnectivityException, StatusCodeException {
+ return get(null, modifier, content, responseType);
+ }
+
+
+ /**
+ * Executes a HTTP GET and parses the response body as {@code responseType}.
+ *
+ * @param the result type
+ * @param path the URL path relative to the current endpoint
+ * @param modifier the query modifier
+ * @param content the content modifier
+ * @param responseType the result type
+ * @return the parsed HTTP response
+ * @throws ConnectivityException if connection to the server fails
+ * @throws StatusCodeException if HTTP request returns invalid statsu code
+ * @throws InvalidPayloadException if deserializing the payload fails
+ */
protected T get(String path, QueryModifier modifier, Content content, Class responseType) throws ConnectivityException, StatusCodeException {
-
- HttpRequest request = httpClientUtility.createGetRequest(uriBuilder.getUri(path, content, modifier));
- HttpResponse response = httpClientUtility.send(request);
-
- try {
- if (response.statusCode() == 200) {
- return new JsonApiDeserializer().read(response.body(), responseType);
- }
- else {
- throw ExceptionHandler.handleException(HttpMethod.GET, request, response);
- }
- }
- catch (DeserializationException e) {
- throw new InvalidPayloadException(e);
- }
- }
-
-
+ HttpRequest request = HttpHelper.createGetRequest(resolve(QueryHelper.apply(path, content, modifier)));
+ HttpResponse response = HttpHelper.send(httpClient, request);
+ validateStatusCode(HttpMethod.GET, response, HttpStatus.OK);
+ return parseBody(response, responseType);
+ }
+
+
+ /**
+ * Executes a HTTP GET and parses the response body as {@code responseType} using valueOnly serialization.
+ *
+ * @param the result type
+ * @param path the URL path relative to the current endpoint
+ * @param modifier the query modifier
+ * @param typeInfo the type information about the AAS element to be returned
+ * @return the parsed HTTP response
+ * @throws ConnectivityException if connection to the server fails
+ * @throws StatusCodeException if HTTP request returns invalid statsu code
+ * @throws InvalidPayloadException if deserializing the payload fails
+ */
protected T getValue(String path, QueryModifier modifier, TypeInfo> typeInfo) throws ConnectivityException, StatusCodeException {
-
- HttpRequest request = httpClientUtility.createGetRequest(uriBuilder.getUri(path, Content.VALUE, modifier));
- HttpResponse response = httpClientUtility.send(request);
-
+ HttpRequest request = HttpHelper.createGetRequest(resolve(QueryHelper.apply(path, Content.VALUE, modifier)));
+ HttpResponse response = HttpHelper.send(httpClient, request);
+ validateStatusCode(HttpMethod.GET, response, HttpStatus.OK);
try {
- if (response.statusCode() == 200) {
- return new JsonApiDeserializer().readValue(response.body(), typeInfo);
- }
- else {
- throw ExceptionHandler.handleException(HttpMethod.GET, request, response);
- }
+ return new JsonApiDeserializer().readValue(response.body(), typeInfo);
}
catch (DeserializationException e) {
throw new InvalidPayloadException(e);
@@ -148,33 +278,93 @@ protected T getValue(String path, QueryModifier modifie
}
- protected List getList(String path, Class responseType)
- throws ConnectivityException, StatusCodeException {
+ /**
+ * Executes a HTTP GET and parses the response body as a list of {@code responseType}.
+ *
+ * @param the result type
+ * @param responseType the result type
+ * @return the parsed HTTP response
+ * @throws ConnectivityException if connection to the server fails
+ * @throws StatusCodeException if HTTP request returns invalid statsu code
+ * @throws InvalidPayloadException if deserializing the payload fails
+ */
+ protected List getList(Class responseType) throws ConnectivityException, StatusCodeException {
+ return getList(null, QueryModifier.DEFAULT, responseType);
+ }
+
+
+ /**
+ * Executes a HTTP GET and parses the response body as a list of {@code responseType}.
+ *
+ * @param the result type
+ * @param path the URL path relative to the current endpoint
+ * @param responseType the result type
+ * @return the parsed HTTP response
+ * @throws ConnectivityException if connection to the server fails
+ * @throws StatusCodeException if HTTP request returns invalid statsu code
+ * @throws InvalidPayloadException if deserializing the payload fails
+ */
+ protected List getList(String path, Class responseType) throws ConnectivityException, StatusCodeException {
return getList(path, QueryModifier.DEFAULT, responseType);
}
- protected List getList(String path, QueryModifier modifier, Class responseType)
- throws ConnectivityException, StatusCodeException {
+ /**
+ * Executes a HTTP GET and parses the response body as a list of {@code responseType}.
+ *
+ * @param the result type
+ * @param path the URL path relative to the current endpoint
+ * @param modifier the query modifier
+ * @param responseType the result type
+ * @return the parsed HTTP response
+ * @throws ConnectivityException if connection to the server fails
+ * @throws StatusCodeException if HTTP request returns invalid statsu code
+ * @throws InvalidPayloadException if deserializing the payload fails
+ */
+ protected List getList(String path, QueryModifier modifier, Class responseType) throws ConnectivityException, StatusCodeException {
return getList(path, SearchCriteria.DEFAULT, Content.DEFAULT, modifier, responseType);
}
+ /**
+ * Executes a HTTP GET and parses the response body as a list of {@code responseType}.
+ *
+ * @param the result type
+ * @param searchCriteria the search criteria
+ * @param content the content modifier
+ * @param modifier the query modifier
+ * @param responseType the result type
+ * @return the parsed HTTP response
+ * @throws ConnectivityException if connection to the server fails
+ * @throws StatusCodeException if HTTP request returns invalid statsu code
+ * @throws InvalidPayloadException if deserializing the payload fails
+ */
+ protected List getList(SearchCriteria searchCriteria, Content content, QueryModifier modifier, Class responseType) throws ConnectivityException, StatusCodeException {
+ return getList(null, searchCriteria, content, modifier, responseType);
+ }
+
+
+ /**
+ * Executes a HTTP GET and parses the response body as a list of {@code responseType}.
+ *
+ * @param the result type
+ * @param path the URL path relative to the current endpoint
+ * @param searchCriteria the search criteria
+ * @param content the content modifier
+ * @param modifier the query modifier
+ * @param responseType the result type
+ * @return the parsed HTTP response
+ * @throws ConnectivityException if connection to the server fails
+ * @throws StatusCodeException if HTTP request returns invalid statsu code
+ * @throws InvalidPayloadException if deserializing the payload fails
+ */
protected List getList(String path, SearchCriteria searchCriteria, Content content, QueryModifier modifier, Class responseType)
throws ConnectivityException, StatusCodeException {
-
- HttpRequest request = httpClientUtility.createGetRequest(uriBuilder.getUri(
- path, content, modifier, new PagingInfo.Builder().build(), searchCriteria));
- HttpResponse response = httpClientUtility.send(request);
-
- uriBuilder.getUri(path, content, modifier, new PagingInfo.Builder().build(), searchCriteria);
+ HttpRequest request = HttpHelper.createGetRequest(resolve(QueryHelper.apply(path, content, modifier, PagingInfo.ALL, searchCriteria)));
+ HttpResponse response = HttpHelper.send(httpClient, request);
+ validateStatusCode(HttpMethod.GET, response, HttpStatus.OK);
try {
- if (response.statusCode() == 200) {
- return new JsonApiDeserializer().readList(response.body(), responseType);
- }
- else {
- throw ExceptionHandler.handleException(HttpMethod.GET, request, response);
- }
+ return new JsonApiDeserializer().readList(response.body(), responseType);
}
catch (DeserializationException e) {
throw new InvalidPayloadException(e);
@@ -182,38 +372,119 @@ protected List getList(String path, SearchCriteria searchCriteria, Conten
}
- protected Page getPage(String path, PagingInfo pagingInfo, Class responseType)
- throws ConnectivityException, StatusCodeException {
+ /**
+ * Executes a HTTP GET and parses the response body as a page of {@code responseType}.
+ *
+ * @param the result type
+ * @param pagingInfo the paging information
+ * @param responseType the result type
+ * @return the parsed HTTP response
+ * @throws ConnectivityException if connection to the server fails
+ * @throws StatusCodeException if HTTP request returns invalid statsu code
+ * @throws InvalidPayloadException if deserializing the payload fails
+ */
+ protected Page getPage(PagingInfo pagingInfo, Class responseType) throws ConnectivityException, StatusCodeException {
+ return getPage((String) null, pagingInfo, responseType);
+ }
+
+
+ /**
+ * Executes a HTTP GET and parses the response body as a page of {@code responseType}.
+ *
+ * @param the result type
+ * @param path the URL path relative to the current endpoint
+ * @param pagingInfo the paging information
+ * @param responseType the result type
+ * @return the parsed HTTP response
+ * @throws ConnectivityException if connection to the server fails
+ * @throws StatusCodeException if HTTP request returns invalid statsu code
+ * @throws InvalidPayloadException if deserializing the payload fails
+ */
+ protected Page getPage(String path, PagingInfo pagingInfo, Class responseType) throws ConnectivityException, StatusCodeException {
return getPage(path, QueryModifier.DEFAULT, pagingInfo, responseType);
}
- protected Page getPage(String path, QueryModifier modifier, PagingInfo pagingInfo, Class responseType)
- throws ConnectivityException, StatusCodeException {
+ /**
+ * Executes a HTTP GET and parses the response body as a page of {@code responseType}.
+ *
+ * @param the result type
+ * @param path the URL path relative to the current endpoint
+ * @param modifier the query modifier
+ * @param pagingInfo the paging information
+ * @param responseType the result type
+ * @return the parsed HTTP response
+ * @throws ConnectivityException if connection to the server fails
+ * @throws StatusCodeException if HTTP request returns invalid statsu code
+ * @throws InvalidPayloadException if deserializing the payload fails
+ */
+ protected Page getPage(String path, QueryModifier modifier, PagingInfo pagingInfo, Class responseType) throws ConnectivityException, StatusCodeException {
return getPage(path, Content.DEFAULT, modifier, pagingInfo, responseType);
}
+ /**
+ * Executes a HTTP GET and parses the response body as a page of {@code responseType}.
+ *
+ * @param the result type
+ * @param path the URL path relative to the current endpoint
+ * @param content the content modifier
+ * @param modifier the query modifier
+ * @param pagingInfo the paging information
+ * @param responseType the result type
+ * @return the parsed HTTP response
+ * @throws ConnectivityException if connection to the server fails
+ * @throws StatusCodeException if HTTP request returns invalid statsu code
+ * @throws InvalidPayloadException if deserializing the payload fails
+ */
protected Page getPage(String path, Content content, QueryModifier modifier, PagingInfo pagingInfo, Class responseType)
throws ConnectivityException, StatusCodeException {
return getPage(path, content, modifier, pagingInfo, SearchCriteria.DEFAULT, responseType);
}
+ /**
+ * Executes a HTTP GET and parses the response body as a page of {@code responseType}.
+ *
+ * @param the result type
+ * @param content the content modifier
+ * @param modifier the query modifier
+ * @param pagingInfo the paging information
+ * @param searchCriteria the search criteria
+ * @param responseType the result type
+ * @return the parsed HTTP response
+ * @throws ConnectivityException if connection to the server fails
+ * @throws StatusCodeException if HTTP request returns invalid statsu code
+ * @throws InvalidPayloadException if deserializing the payload fails
+ */
+ protected Page getPage(Content content, QueryModifier modifier, PagingInfo pagingInfo, SearchCriteria searchCriteria, Class responseType)
+ throws ConnectivityException, StatusCodeException {
+ return getPage(null, content, modifier, pagingInfo, searchCriteria, responseType);
+ }
+
+
+ /**
+ * Executes a HTTP GET and parses the response body as a page of {@code responseType}.
+ *
+ * @param the result type
+ * @param path the URL path relative to the current endpoint
+ * @param content the content modifier
+ * @param modifier the query modifier
+ * @param pagingInfo the paging information
+ * @param searchCriteria the search criteria
+ * @param responseType the result type
+ * @return the parsed HTTP response
+ * @throws ConnectivityException if connection to the server fails
+ * @throws StatusCodeException if HTTP request returns invalid statsu code
+ * @throws InvalidPayloadException if deserializing the payload fails
+ */
protected Page getPage(String path, Content content, QueryModifier modifier, PagingInfo pagingInfo, SearchCriteria searchCriteria, Class responseType)
throws ConnectivityException, StatusCodeException {
-
- HttpRequest request = httpClientUtility.createGetRequest(uriBuilder.getUri(
- path, content, modifier, pagingInfo, searchCriteria));
- HttpResponse response = httpClientUtility.send(request);
-
+ HttpRequest request = HttpHelper.createGetRequest(resolve(QueryHelper.apply(path, content, modifier, pagingInfo, searchCriteria)));
+ HttpResponse response = HttpHelper.send(httpClient, request);
+ validateStatusCode(HttpMethod.GET, response, HttpStatus.OK);
try {
- if (response.statusCode() == 200) {
- return deserializePage(response.body(), responseType);
- }
- else {
- throw ExceptionHandler.handleException(HttpMethod.GET, request, response);
- }
+ return deserializePage(response.body(), responseType);
}
catch (DeserializationException | JSONException e) {
throw new InvalidPayloadException(e);
@@ -221,138 +492,362 @@ protected Page getPage(String path, Content content, QueryModifier modifi
}
- protected T postValue(String path, Object entity, TypeInfo> typeInfo, QueryModifier modifier)
- throws ConnectivityException, StatusCodeException {
-
- HttpRequest request = httpClientUtility.createPostRequest(uriBuilder.getUri(
- path, Content.VALUE, QueryModifier.DEFAULT),
- serialize(entity, Content.VALUE, modifier));
- HttpResponse response = httpClientUtility.send(request);
-
- try {
- if (response.statusCode() == 200 || response.statusCode() == 201) {
- return new JsonApiDeserializer().readValue(response.body(), typeInfo);
- }
- else {
- throw ExceptionHandler.handleException(HttpMethod.POST, request, response);
- }
- }
- catch (DeserializationException e) {
- throw new InvalidPayloadException(e);
- }
- }
-
-
+ /**
+ * Executes a HTTP POST and parses the response body as {@code responseType}.
+ *
+ * @param the result type
+ * @param entity the payload to send in the POST body
+ * @param responseType the result type
+ * @return the parsed HTTP response
+ * @throws ConnectivityException if connection to the server fails
+ * @throws StatusCodeException if HTTP request returns invalid statsu code
+ * @throws InvalidPayloadException if deserializing the payload fails
+ */
+ protected T post(Object entity, Class responseType) throws ConnectivityException, StatusCodeException {
+ return post(null, entity, QueryModifier.DEFAULT, Content.DEFAULT, responseType);
+ }
+
+
+ /**
+ * Executes a HTTP POST and parses the response body as {@code responseType}.
+ *
+ * @param the result type
+ * @param path the URL path relative to the current endpoint
+ * @param entity the payload to send in the POST body
+ * @param responseType the result type
+ * @return the parsed HTTP response
+ * @throws ConnectivityException if connection to the server fails
+ * @throws StatusCodeException if HTTP request returns invalid statsu code
+ * @throws InvalidPayloadException if deserializing the payload fails
+ */
protected T post(String path, Object entity, Class responseType) throws ConnectivityException, StatusCodeException {
return post(path, entity, QueryModifier.DEFAULT, Content.DEFAULT, responseType);
}
+ /**
+ * Executes a HTTP POST and parses the response body as {@code responseType}.
+ *
+ * @param the result type
+ * @param path the URL path relative to the current endpoint
+ * @param entity the payload to send in the POST body
+ * @param expectedStatusCode the expected HTTP status code
+ * @param responseType the result type
+ * @return the parsed HTTP response
+ * @throws ConnectivityException if connection to the server fails
+ * @throws StatusCodeException if HTTP request returns invalid statsu code
+ * @throws InvalidPayloadException if deserializing the payload fails
+ */
+ protected T post(String path, Object entity, HttpStatus expectedStatusCode, Class responseType) throws ConnectivityException, StatusCodeException {
+ return post(path, entity, QueryModifier.DEFAULT, Content.DEFAULT, expectedStatusCode, responseType);
+ }
+
+
+ /**
+ * Executes a HTTP POST and parses the response body as {@code responseType}.
+ *
+ * @param the result type
+ * @param path the URL path relative to the current endpoint
+ * @param entity the payload to send in the POST body
+ * @param modifier the query modifier
+ * @param content the content modifier
+ * @param responseType the result type
+ * @return the parsed HTTP response
+ * @throws ConnectivityException if connection to the server fails
+ * @throws StatusCodeException if HTTP request returns invalid statsu code
+ * @throws InvalidPayloadException if deserializing the payload fails
+ */
protected T post(String path, Object entity, QueryModifier modifier, Content content, Class responseType) throws ConnectivityException, StatusCodeException {
-
- HttpRequest request = httpClientUtility.createPostRequest(uriBuilder.getUri(path, content, QueryModifier.DEFAULT),
+ return post(path, entity, modifier, content, HttpStatus.CREATED, responseType);
+ }
+
+
+ /**
+ * Executes a HTTP POST and parses the response body as {@code responseType}.
+ *
+ * @param the result type
+ * @param path the URL path relative to the current endpoint
+ * @param entity the payload to send in the POST body
+ * @param modifier the query modifier
+ * @param content the content modifier
+ * @param expectedStatusCode the expected HTTP status code
+ * @param responseType the result type
+ * @return the parsed HTTP response
+ * @throws ConnectivityException if connection to the server fails
+ * @throws StatusCodeException if HTTP request returns invalid statsu code
+ * @throws InvalidPayloadException if deserializing the payload fails
+ */
+ protected T post(String path, Object entity, QueryModifier modifier, Content content, HttpStatus expectedStatusCode, Class responseType)
+ throws ConnectivityException, StatusCodeException {
+ HttpRequest request = HttpHelper.createPostRequest(
+ resolve(QueryHelper.apply(path, content, QueryModifier.DEFAULT)),
serialize(entity, content, modifier));
- HttpResponse response = httpClientUtility.send(request);
+ HttpResponse response = HttpHelper.send(httpClient, request);
+ validateStatusCode(HttpMethod.POST, response, expectedStatusCode);
+ return parseBody(response, responseType);
+ }
- try {
- if (response.statusCode() == 200 || response.statusCode() == 201) {
- return new JsonApiDeserializer().read(response.body(), responseType);
- }
- else {
- throw ExceptionHandler.handleException(HttpMethod.POST, request, response);
- }
- }
- catch (DeserializationException e) {
- throw new InvalidPayloadException(e);
- }
+
+ /**
+ * Executes a HTTP PUT.
+ *
+ * @param entity the payload to send in the body
+ * @throws ConnectivityException if connection to the server fails
+ * @throws StatusCodeException if HTTP request returns invalid statsu code
+ */
+ protected void put(Object entity) throws ConnectivityException, StatusCodeException {
+ put(null, entity, QueryModifier.DEFAULT);
}
+ /**
+ * Executes a HTTP PUT.
+ *
+ * @param path the URL path relative to the current endpoint
+ * @param entity the payload to send in the body
+ * @throws ConnectivityException if connection to the server fails
+ * @throws StatusCodeException if HTTP request returns invalid statsu code
+ */
protected void put(String path, Object entity) throws ConnectivityException, StatusCodeException {
put(path, entity, QueryModifier.DEFAULT);
}
+ /**
+ * Executes a HTTP PUT.
+ *
+ * @param entity the payload to send in the body
+ * @param modifier the query modifier
+ * @throws ConnectivityException if connection to the server fails
+ * @throws StatusCodeException if HTTP request returns invalid statsu code
+ */
+ protected void put(Object entity, QueryModifier modifier) throws ConnectivityException, StatusCodeException {
+ put(null, entity, Content.DEFAULT, modifier);
+ }
+
+
+ /**
+ * Executes a HTTP PUT.
+ *
+ * @param path the URL path relative to the current endpoint
+ * @param entity the payload to send in the body
+ * @param modifier the query modifier
+ * @throws ConnectivityException if connection to the server fails
+ * @throws StatusCodeException if HTTP request returns invalid statsu code
+ */
protected void put(String path, Object entity, QueryModifier modifier) throws ConnectivityException, StatusCodeException {
put(path, entity, Content.DEFAULT, modifier);
}
- protected void put(String path, Object entity, Content content, QueryModifier modifier)
- throws ConnectivityException, StatusCodeException {
-
- HttpRequest request = httpClientUtility.createPutRequest(
- uriBuilder.getUri(path, content, modifier),
+ /**
+ * Executes a HTTP PUT.
+ *
+ * @param path the URL path relative to the current endpoint
+ * @param entity the payload to send in the body
+ * @param content the content modifier
+ * @param modifier the query modifier
+ * @throws ConnectivityException if connection to the server fails
+ * @throws StatusCodeException if HTTP request returns invalid statsu code
+ */
+ protected void put(String path, Object entity, Content content, QueryModifier modifier) throws ConnectivityException, StatusCodeException {
+ HttpRequest request = HttpHelper.createPutRequest(
+ resolve(QueryHelper.apply(path, content, modifier)),
serialize(entity, content, modifier));
- HttpResponse response = httpClientUtility.send(request);
-
- if (response.statusCode() != 200 && response.statusCode() != 204) {
- throw ExceptionHandler.handleException(HttpMethod.PUT, request, response);
- }
+ HttpResponse response = HttpHelper.send(httpClient, request);
+ validateStatusCode(HttpMethod.PUT, response, HttpStatus.NO_CONTENT);
}
+ /**
+ * Executes a HTTP PATCH.
+ *
+ * @param path the URL path relative to the current endpoint
+ * @param entity the payload to send in the body
+ * @throws ConnectivityException if connection to the server fails
+ * @throws StatusCodeException if HTTP request returns invalid statsu code
+ */
protected void patch(String path, Object entity) throws ConnectivityException, StatusCodeException {
patch(path, entity, QueryModifier.DEFAULT);
}
+ /**
+ * Executes a HTTP PATCH.
+ *
+ * @param entity the payload to send in the body
+ * @param modifier the query modifier
+ * @throws ConnectivityException if connection to the server fails
+ * @throws StatusCodeException if HTTP request returns invalid statsu code
+ */
+ protected void patch(Object entity, QueryModifier modifier) throws ConnectivityException, StatusCodeException {
+ patch(null, entity, Content.DEFAULT, modifier);
+ }
+
+
+ /**
+ * Executes a HTTP PATCH.
+ *
+ * @param path the URL path relative to the current endpoint
+ * @param entity the payload to send in the body
+ * @param modifier the query modifier
+ * @throws ConnectivityException if connection to the server fails
+ * @throws StatusCodeException if HTTP request returns invalid statsu code
+ */
protected void patch(String path, Object entity, QueryModifier modifier) throws ConnectivityException, StatusCodeException {
patch(path, entity, Content.DEFAULT, modifier);
}
- protected void patch(String path, Object entity, Content content, QueryModifier modifier)
- throws ConnectivityException, StatusCodeException {
-
- HttpRequest request = httpClientUtility.createPatchRequest(
- uriBuilder.getUri(path, content, modifier),
+ /**
+ * Executes a HTTP PATCH.
+ *
+ * @param entity the payload to send in the body
+ * @param content the content modifier
+ * @param modifier the query modifier
+ * @throws ConnectivityException if connection to the server fails
+ * @throws StatusCodeException if HTTP request returns invalid statsu code
+ */
+ protected void patch(Object entity, Content content, QueryModifier modifier) throws ConnectivityException, StatusCodeException {
+ patch(null, entity, content, modifier);
+ }
+
+
+ /**
+ * Executes a HTTP PATCH.
+ *
+ * @param path the URL path relative to the current endpoint
+ * @param entity the payload to send in the body
+ * @param content the content modifier
+ * @param modifier the query modifier
+ * @throws ConnectivityException if connection to the server fails
+ * @throws StatusCodeException if HTTP request returns invalid statsu code
+ */
+ protected void patch(String path, Object entity, Content content, QueryModifier modifier) throws ConnectivityException, StatusCodeException {
+ HttpRequest request = HttpHelper.createPatchRequest(
+ resolve(QueryHelper.apply(path, content, modifier)),
serialize(entity, content, modifier));
- HttpResponse response = httpClientUtility.send(request);
-
- if (response.statusCode() != 200 && response.statusCode() != 204) {
- throw ExceptionHandler.handleException(HttpMethod.PATCH, request, response);
- }
+ HttpResponse response = HttpHelper.send(httpClient, request);
+ validateStatusCode(HttpMethod.PATCH, response, HttpStatus.NO_CONTENT);
+ }
+
+
+ /**
+ * Executes a HTTP PATCH with valueOnly serialization.
+ *
+ * @param path the URL path relative to the current endpoint
+ * @param entity the payload to send in the body
+ * @param modifier the query modifier
+ * @throws ConnectivityException if connection to the server fails
+ * @throws StatusCodeException if HTTP request returns invalid statsu code
+ */
+ protected void patchValue(String path, Object entity, QueryModifier modifier) throws ConnectivityException, StatusCodeException {
+ HttpRequest request = HttpHelper.createPatchRequest(
+ resolve(QueryHelper.apply(path, Content.VALUE, modifier)),
+ serializeEntity(entity));
+ HttpResponse response = HttpHelper.send(httpClient, request);
+ validateStatusCode(HttpMethod.PATCH, response, HttpStatus.NO_CONTENT);
}
- protected void patchValue(String path, Object entity, QueryModifier modifier)
- throws ConnectivityException, StatusCodeException {
+ protected void delete(String path) throws ConnectivityException, StatusCodeException {
+ delete(path, HttpStatus.NO_CONTENT);
+ }
- HttpRequest request = httpClientUtility.createPatchRequest(
- uriBuilder.getUri(path, Content.VALUE, modifier),
- serializeEntity(entity));
- HttpResponse response = httpClientUtility.send(request);
- if (response.statusCode() != 200 && response.statusCode() != 204) {
- throw ExceptionHandler.handleException(HttpMethod.PATCH, request, response);
- }
+ /**
+ * Executes a HTTP DELETE.
+ *
+ * @param path the URL path relative to the current endpoint
+ * @param expectedStatus the expected HTTP status code
+ * @throws ConnectivityException if connection to the server fails
+ * @throws StatusCodeException if HTTP request returns invalid statsu code
+ */
+ protected void delete(String path, HttpStatus expectedStatus) throws ConnectivityException, StatusCodeException {
+ HttpRequest request = HttpHelper.createDeleteRequest(resolve(path));
+ HttpResponse response = HttpHelper.send(httpClient, request);
+ validateStatusCode(HttpMethod.DELETE, response, expectedStatus);
}
- protected void delete(String path) throws ConnectivityException, StatusCodeException {
+ /**
+ * Creates a URL path for an id in the form of "/{base64URL-encoded id}".
+ *
+ * @param id the id
+ * @return the URL path with the encoded id
+ */
+ protected String idPath(String id) {
+ return "/" + EncodingHelper.base64UrlEncode(id);
+ }
- HttpRequest request = httpClientUtility.createDeleteRequest(uriBuilder.getUri(path));
- HttpResponse response = httpClientUtility.send(request);
- if (response.statusCode() != 200 && response.statusCode() != 204) {
- throw ExceptionHandler.handleException(HttpMethod.DELETE, request, response);
- }
+ /**
+ * Resolves a path to the current {@code endpoint}.
+ *
+ * @param path the path to resolve
+ * @return the resolved path relative to the current {@code endpoint}
+ */
+ protected URI resolve(String path) {
+ return resolve(endpoint, path);
}
- protected String basePath() {
- return basePath;
+ /**
+ * Resolves a path to a given {@code baseUri}.
+ *
+ * @param baseUri the URI to resolve the path to
+ * @param path the path to resolve
+ * @return the resolved path relative to the current {@code baseUri}
+ */
+ protected static URI resolve(URI baseUri, String path) {
+ if (Objects.isNull(path) || path.isBlank()) {
+ return baseUri;
+ }
+ String actualPath = path;
+ if (actualPath.startsWith(URI_PATH_SEPERATOR)) {
+ actualPath = "." + actualPath;
+ }
+ else if (!actualPath.startsWith("./")) {
+ actualPath = "./" + actualPath;
+ }
+ if (actualPath.endsWith(URI_PATH_SEPERATOR)) {
+ actualPath = actualPath.substring(0, actualPath.length() - 1);
+ }
+ try {
+ return new URI(baseUri + URI_PATH_SEPERATOR).resolve(actualPath);
+ }
+ catch (URISyntaxException e) {
+ throw new IllegalArgumentException(
+ String.format(
+ "error resolving path (endpoint: %s, path: %s)",
+ baseUri,
+ actualPath),
+ e);
+ }
}
- protected String idPath(String id) {
- return basePath() + EncodingHelper.base64UrlEncode(id) + "/";
+ private static URI sanitizeEndpoint(URI endpoint) {
+ URI result = endpoint;
+ if (endpoint.getPath().endsWith(URI_PATH_SEPERATOR)) {
+ try {
+ result = new URI(endpoint.toString().substring(0, endpoint.toString().length() - 1));
+ }
+ catch (URISyntaxException e) {
+ throw new IllegalArgumentException(String.format("error sanitizing endpoint URI (endpoint: %s", endpoint), e);
+ }
+ }
+ return result;
}
- protected HttpClient httpClient() {
- return this.httpClient;
+ private static T parseBody(HttpResponse response, Class responseType) {
+ try {
+ return new JsonApiDeserializer().read(response.body(), responseType);
+ }
+ catch (DeserializationException e) {
+ throw new InvalidPayloadException(e);
+ }
}
@@ -388,4 +883,40 @@ private static Page deserializePage(String responseBody, Class respons
.metadata(new JsonApiDeserializer().read(metadata.toString(), PagingMetadata.class))
.build();
}
+
+
+ private static void validateStatusCode(HttpMethod method, HttpResponse response, HttpStatus expected) throws StatusCodeException {
+ if (Objects.isNull(response)) {
+ throw new IllegalArgumentException("response must be non-null");
+ }
+ if (Objects.equals(expected.getCode(), response.statusCode())) {
+ return;
+ }
+ List supported = new ArrayList<>(SUPPORTED_DEFAULT_HTTP_STATUS);
+ if (Objects.equals(method, HttpMethod.POST)) {
+ supported.add(HttpStatus.METHOD_NOT_ALLOWED);
+ supported.add(HttpStatus.CONFLICT);
+ }
+
+ try {
+ HttpStatus status = HttpStatus.from(response.statusCode());
+ if (!supported.contains(status)) {
+ throw new UnsupportedStatusCodeException(response);
+ }
+ throw switch (status) {
+ case BAD_REQUEST -> new BadRequestException(response);
+ case UNAUTHORIZED -> new UnauthorizedException(response);
+ case FORBIDDEN -> new ForbiddenException(response);
+ case NOT_FOUND -> new NotFoundException(response);
+ case METHOD_NOT_ALLOWED -> new MethodNotAllowedException(response);
+ case CONFLICT -> new ConflictException(response);
+ case INTERNAL_SERVER_ERROR -> new InternalServerErrorException(response);
+ default -> throw new UnsupportedStatusCodeException(response);
+ };
+ }
+ catch (IllegalArgumentException e) {
+ throw new UnsupportedStatusCodeException(response);
+ }
+ }
+
}
diff --git a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/interfaces/ConceptDescriptionRepositoryInterface.java b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/interfaces/ConceptDescriptionRepositoryInterface.java
index ac43776..e8d0e4f 100644
--- a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/interfaces/ConceptDescriptionRepositoryInterface.java
+++ b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/interfaces/ConceptDescriptionRepositoryInterface.java
@@ -36,43 +36,45 @@
*/
public class ConceptDescriptionRepositoryInterface extends BaseInterface {
+ private static final String API_PATH = "/concept-descriptions";
+
/**
* Creates a new Concept Description Interface.
*
- * @param serviceUri Uri used to communicate with the FA³ST service.
+ * @param endpoint Uri used to communicate with the FA³ST service
*/
- public ConceptDescriptionRepositoryInterface(URI serviceUri) {
- super(serviceUri, "/concept-descriptions/");
+ protected ConceptDescriptionRepositoryInterface(URI endpoint) {
+ super(resolve(endpoint, API_PATH));
}
/**
* Creates a new Concept Description Interface
*
+ * @param endpoint Uri used to communicate with the FA³ST service
* @param user String to enable basic authentication
* @param password String to enable basic authentication
- * @param serviceUri Uri used to communicate with the FA³ST service.
*/
- public ConceptDescriptionRepositoryInterface(URI serviceUri, String user, String password) {
- super(serviceUri, "/concept-descriptions/", user, password);
+ protected ConceptDescriptionRepositoryInterface(URI endpoint, String user, String password) {
+ super(resolve(endpoint, API_PATH), user, password);
}
/**
* Creates a new Concept Description Interface.
*
- * @param httpClient allows user to specify custom http-client.
- * @param serviceUri the serviceUri
+ * @param endpoint the endpoint
+ * @param httpClient allows user to specify custom http-client
*/
- public ConceptDescriptionRepositoryInterface(URI serviceUri, HttpClient httpClient) {
- super(serviceUri, "/concept-descriptions/", httpClient);
+ protected ConceptDescriptionRepositoryInterface(URI endpoint, HttpClient httpClient) {
+ super(resolve(endpoint, API_PATH), httpClient);
}
/**
* Retrieves all Concept Descriptions from the server.
*
- * @return List of all Concept Descriptions.
+ * @return List of all Concept Descriptions
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -83,7 +85,7 @@ public ConceptDescriptionRepositoryInterface(URI serviceUri, HttpClient httpClie
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public List getAll() throws StatusCodeException, ConnectivityException {
return getAll(ConceptDescriptionSearchCriteria.DEFAULT);
@@ -93,8 +95,8 @@ public List getAll() throws StatusCodeException, Connectivit
/**
* Retrieves Concept Descriptions according to specific search criteria.
*
- * @param conceptDescriptionSearchCriteria specific search criteria: idShort, isCaseOf or dataSpecificationRef.
- * @return List of Concept Descriptions matching search criteria.
+ * @param conceptDescriptionSearchCriteria specific search criteria: idShort, isCaseOf or dataSpecificationRef
+ * @return List of Concept Descriptions matching search criteria
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -105,18 +107,18 @@ public List getAll() throws StatusCodeException, Connectivit
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public List getAll(ConceptDescriptionSearchCriteria conceptDescriptionSearchCriteria) throws StatusCodeException, ConnectivityException {
- return getList(basePath(), conceptDescriptionSearchCriteria, Content.DEFAULT, QueryModifier.DEFAULT, ConceptDescription.class);
+ return getList(conceptDescriptionSearchCriteria, Content.DEFAULT, QueryModifier.DEFAULT, ConceptDescription.class);
}
/**
* Retrieves a page of Concept Descriptions.
*
- * @param pagingInfo Metadata for controlling the pagination of results.
- * @return A page of Concept Descriptions.
+ * @param pagingInfo Metadata for controlling the pagination of results
+ * @return A page of Concept Descriptions
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -127,7 +129,7 @@ public List getAll(ConceptDescriptionSearchCriteria conceptD
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public Page get(PagingInfo pagingInfo) throws StatusCodeException, ConnectivityException {
return get(pagingInfo, ConceptDescriptionSearchCriteria.DEFAULT);
@@ -150,11 +152,11 @@ public Page get(PagingInfo pagingInfo) throws StatusCodeExce
* 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public Page get(PagingInfo pagingInfo, ConceptDescriptionSearchCriteria conceptDescriptionSearchCriteria)
throws StatusCodeException, ConnectivityException {
- return getPage(basePath(), Content.DEFAULT, QueryModifier.DEFAULT, pagingInfo, conceptDescriptionSearchCriteria, ConceptDescription.class);
+ return getPage(Content.DEFAULT, QueryModifier.DEFAULT, pagingInfo, conceptDescriptionSearchCriteria, ConceptDescription.class);
}
@@ -174,10 +176,10 @@ public Page get(PagingInfo pagingInfo, ConceptDescriptionSea
* 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public ConceptDescription post(ConceptDescription conceptDescription) throws StatusCodeException, ConnectivityException {
- return post(basePath(), conceptDescription, ConceptDescription.class);
+ return post(conceptDescription, ConceptDescription.class);
}
@@ -196,7 +198,7 @@ public ConceptDescription post(ConceptDescription conceptDescription) throws Sta
* 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public ConceptDescription get(String cdIdentifier) throws StatusCodeException, ConnectivityException {
return get(idPath(cdIdentifier), ConceptDescription.class);
@@ -207,6 +209,7 @@ public ConceptDescription get(String cdIdentifier) throws StatusCodeException, C
* Replaces an existing Concept Description
*
* @param conceptDescription Concept Description object
+ * @param cdIdentifier The Concept Description’s unique id
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -217,7 +220,7 @@ public ConceptDescription get(String cdIdentifier) throws StatusCodeException, C
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public void put(ConceptDescription conceptDescription, String cdIdentifier) throws StatusCodeException, ConnectivityException {
put(idPath(cdIdentifier), conceptDescription);
@@ -238,8 +241,9 @@ public void put(ConceptDescription conceptDescription, String cdIdentifier) thro
* 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
+ @Override
public void delete(String cdIdentifier) throws StatusCodeException, ConnectivityException {
super.delete(idPath(cdIdentifier));
}
diff --git a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/interfaces/DescriptionInterface.java b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/interfaces/DescriptionInterface.java
index 1d24a16..d77c32d 100644
--- a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/interfaces/DescriptionInterface.java
+++ b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/interfaces/DescriptionInterface.java
@@ -30,31 +30,46 @@
*
*/
public class DescriptionInterface extends BaseInterface {
+
+ private static final String API_PATH = "/description";
+
+ /**
+ * Creates a new Description Interface.
+ *
+ * @param endpoint Uri used to communicate with the FA³ST service
+ */
+ public DescriptionInterface(URI endpoint) {
+ super(resolve(endpoint, API_PATH));
+ }
+
+
/**
* Creates a new Description Interface.
*
- * @param serviceUri Uri used to communicate with the FA³ST service.
+ * @param endpoint Uri used to communicate with the FA³ST Service
+ * @param user String to allow for basic authentication
+ * @param password String to allow for basic authentication
*/
- public DescriptionInterface(URI serviceUri) {
- super(serviceUri, "/description");
+ public DescriptionInterface(URI endpoint, String user, String password) {
+ super(resolve(endpoint, API_PATH), user, password);
}
/**
* Creates a new Description Interface.
*
- * @param serviceUri Uri used to communicate with the FA³ST service.
- * @param httpClient custom http-client in case the user wants to set specific attributes.
+ * @param endpoint Uri used to communicate with the FA³ST service
+ * @param httpClient custom http-client in case the user wants to set specific attributes
*/
- public DescriptionInterface(URI serviceUri, HttpClient httpClient) {
- super(serviceUri, "", httpClient);
+ public DescriptionInterface(URI endpoint, HttpClient httpClient) {
+ super(endpoint, httpClient);
}
/**
* Retrieves the self-describing information of a network resource (ServiceDescription) as a List of Strings.
*
- * @return Requested self-describing information.
+ * @return Requested self-describing information
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -65,10 +80,10 @@ public DescriptionInterface(URI serviceUri, HttpClient httpClient) {
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public List get() throws StatusCodeException, ConnectivityException {
- return getList(basePath(), String.class);
+ return getList(String.class);
}
}
diff --git a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/interfaces/SubmodelInterface.java b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/interfaces/SubmodelInterface.java
index f5a87c6..a621d7f 100644
--- a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/interfaces/SubmodelInterface.java
+++ b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/interfaces/SubmodelInterface.java
@@ -17,6 +17,7 @@
import com.fasterxml.jackson.databind.JsonNode;
import de.fraunhofer.iosb.ilt.faaast.client.exception.ConnectivityException;
import de.fraunhofer.iosb.ilt.faaast.client.exception.StatusCodeException;
+import de.fraunhofer.iosb.ilt.faaast.client.http.HttpStatus;
import de.fraunhofer.iosb.ilt.faaast.service.model.IdShortPath;
import de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.Content;
import de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.Level;
@@ -28,7 +29,6 @@
import java.net.URI;
import java.net.http.HttpClient;
-import java.util.ArrayList;
import java.util.List;
import org.eclipse.digitaltwin.aas4j.v3.model.*;
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultOperationRequest;
@@ -49,27 +49,40 @@ public class SubmodelInterface extends BaseInterface {
/**
* Creates a new Submodel API.
*
- * @param serviceUri Uri used to communicate with the FA³ST service.
+ * @param endpoint Uri used to communicate with the FA³ST service
*/
- public SubmodelInterface(URI serviceUri) {
- super(serviceUri, "");
+ public SubmodelInterface(URI endpoint) {
+ super(endpoint);
}
/**
* Creates a new Submodel API.
*
- * @param serviceUri Uri used to communicate with the FA³ST service.
+ * @param endpoint Uri used to communicate with the FA³ST Service
+ * @param user String to allow for basic authentication
+ * @param password String to allow for basic authentication
*/
- public SubmodelInterface(URI serviceUri, HttpClient httpClient) {
- super(serviceUri, "", httpClient);
+ public SubmodelInterface(URI endpoint, String user, String password) {
+ super(endpoint, user, password);
+ }
+
+
+ /**
+ * Creates a new Submodel API.
+ *
+ * @param endpoint Uri used to communicate with the FA³ST service
+ * @param httpClient the httpClient to use
+ */
+ public SubmodelInterface(URI endpoint, HttpClient httpClient) {
+ super(endpoint, httpClient);
}
/**
* Retrieves the Submodel from the server.
*
- * @return The requested Submodel object in standard format: deep structural depth and without blob value.
+ * @return The requested Submodel object in standard format: deep structural depth and without blob value
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -80,7 +93,7 @@ public SubmodelInterface(URI serviceUri, HttpClient httpClient) {
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public Submodel get() throws StatusCodeException, ConnectivityException {
return get(QueryModifier.DEFAULT);
@@ -90,8 +103,8 @@ public Submodel get() throws StatusCodeException, ConnectivityException {
/**
* Retrieves the Submodel formatted according to query modifier.
*
- * @param modifier The query modifier specifies the structural depth and resource serialization of the submodel.
- * @return Requested Submodel object formatted according to query modifier.
+ * @param modifier The query modifier specifies the structural depth and resource serialization of the submodel
+ * @return Requested Submodel object formatted according to query modifier
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -102,17 +115,17 @@ public Submodel get() throws StatusCodeException, ConnectivityException {
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public Submodel get(QueryModifier modifier) throws StatusCodeException, ConnectivityException {
- return get(basePath(), modifier, Submodel.class);
+ return get(modifier, Submodel.class);
}
/**
* Replaces the current Submodel with a new one.
*
- * @param submodel The new Submodel object to replace the current one.
+ * @param submodel The new Submodel object to replace the current one
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -123,17 +136,17 @@ public Submodel get(QueryModifier modifier) throws StatusCodeException, Connecti
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public void put(Submodel submodel) throws StatusCodeException, ConnectivityException {
- put(basePath(), submodel, new QueryModifier.Builder().level(Level.DEEP).build());
+ put(submodel, new QueryModifier.Builder().level(Level.DEEP).build());
}
/**
* Updates the Submodel.
*
- * @param submodel The new Submodel object to patch the current one.
+ * @param submodel The new Submodel object to patch the current one
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -144,19 +157,19 @@ public void put(Submodel submodel) throws StatusCodeException, ConnectivityExcep
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public void patch(Submodel submodel)
throws StatusCodeException, ConnectivityException {
- patch(basePath(), submodel, new QueryModifier.Builder().level(Level.CORE).build());
+ patch(submodel, new QueryModifier.Builder().level(Level.CORE).build());
}
/**
* Retrieves the metadata attributes of a specific Submodel.
*
- * @param modifier The query modifier specifies the structural depth and resource serialization of the submodel.
- * @return Requested Submodel object containing only metadata.
+ * @param modifier The query modifier specifies the structural depth and resource serialization of the submodel
+ * @return Requested Submodel object containing only metadata
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -167,17 +180,18 @@ public void patch(Submodel submodel)
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public Submodel getMetadata(QueryModifier modifier) throws StatusCodeException, ConnectivityException {
- return get(basePath(), modifier, Content.METADATA, Submodel.class);
+ return get(modifier, Content.METADATA, Submodel.class);
}
/**
* Updates the metadata attributes of a specific Submodel.
*
- * @param modifier The query modifier specifies the structural depth and resource serialization of the submodel.
+ * @param modifier The query modifier specifies the structural depth and resource serialization of the submodel
+ * @param submodel The new Submodel object to patch the current one
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -188,18 +202,18 @@ public Submodel getMetadata(QueryModifier modifier) throws StatusCodeException,
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public void patchMetadata(QueryModifier modifier, Submodel submodel) throws StatusCodeException, ConnectivityException {
- patch(basePath(), submodel, Content.METADATA, modifier);
+ patch(submodel, Content.METADATA, modifier);
}
/**
* Retrieves a specific Submodel in the value-only serialization.
*
- * @param modifier The query modifier specifies the structural depth and resource serialization of the submodel.
- * @return JsonNode containing only the values of a Submodel object.
+ * @param modifier The query modifier specifies the structural depth and resource serialization of the submodel
+ * @return JsonNode containing only the values of a Submodel object
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -210,18 +224,18 @@ public void patchMetadata(QueryModifier modifier, Submodel submodel) throws Stat
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public JsonNode getValue(QueryModifier modifier) throws StatusCodeException, ConnectivityException {
- return get(basePath(), modifier, Content.VALUE, JsonNode.class);
+ return get(modifier, Content.VALUE, JsonNode.class);
}
/**
* Updates the values of a specific Submodel.
*
- * @param modifier The query modifier specifies the structural depth and resource serialization of the submodel.
- * @param jsonNode JsonNode containing the new values of the Submodel to update the current ones.
+ * @param modifier The query modifier specifies the structural depth and resource serialization of the submodel
+ * @param jsonNode JsonNode containing the new values of the Submodel to update the current ones
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -232,17 +246,17 @@ public JsonNode getValue(QueryModifier modifier) throws StatusCodeException, Con
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public void patchValue(QueryModifier modifier, JsonNode jsonNode) throws StatusCodeException, ConnectivityException {
- patch(basePath(), jsonNode, Content.VALUE, modifier);
+ patch(jsonNode, Content.VALUE, modifier);
}
/**
* Retrieves the reference of a specific Submodel.
*
- * @return The reference of the requested Submodel object.
+ * @return The reference of the requested Submodel object
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -253,18 +267,18 @@ public void patchValue(QueryModifier modifier, JsonNode jsonNode) throws StatusC
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public Reference getReference() throws StatusCodeException, ConnectivityException {
- return get(basePath(), new QueryModifier.Builder().level(Level.CORE).build(), Content.REFERENCE, Reference.class);
+ return get(QueryModifier.MINIMAL, Content.REFERENCE, Reference.class);
}
/**
* Retrieves the path of a specific Submodel.
*
- * @param modifier The query modifier specifies the structural depth and resource serialization of the submodel.
- * @return The path of the requested Submodel object.
+ * @param modifier The query modifier specifies the structural depth and resource serialization of the submodel
+ * @return The path of the requested Submodel object
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -275,17 +289,17 @@ public Reference getReference() throws StatusCodeException, ConnectivityExceptio
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public String getPath(QueryModifier modifier) throws StatusCodeException, ConnectivityException {
- return get(basePath(), modifier, Content.PATH, String.class);
+ return get(modifier, Content.PATH, String.class);
}
/**
* Retrieves a list of all Submodel Elements including their hierarchy.
*
- * @return A List of all submodel elements.
+ * @return A List of all submodel elements
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -296,10 +310,9 @@ public String getPath(QueryModifier modifier) throws StatusCodeException, Connec
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
- public List getAllElements()
- throws StatusCodeException, ConnectivityException {
+ public List getAllElements() throws StatusCodeException, ConnectivityException {
return getList(submodelElementsPath(), SubmodelElement.class);
}
@@ -307,8 +320,8 @@ public List getAllElements()
/**
* Retrieves a list of all Submodel Elements including their hierarchy formatted according to query modifier.
*
- * @param modifier The query modifier specifies the structural depth and resource serialization of the submodel.
- * @return A List of all submodel elements.
+ * @param modifier The query modifier specifies the structural depth and resource serialization of the submodel
+ * @return A List of all submodel elements
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -319,10 +332,9 @@ public List getAllElements()
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
- public List getAllElements(QueryModifier modifier)
- throws StatusCodeException, ConnectivityException {
+ public List getAllElements(QueryModifier modifier) throws StatusCodeException, ConnectivityException {
return getList(submodelElementsPath(), modifier, SubmodelElement.class);
}
@@ -330,8 +342,8 @@ public List getAllElements(QueryModifier modifier)
/**
* Retrieves a Page of Submodel Elements including their hierarchy.
*
- * @param pagingInfo Metadata for controlling the pagination of results.
- * @return A page of Submodel Elements.
+ * @param pagingInfo Metadata for controlling the pagination of results
+ * @return A page of Submodel Elements
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -342,10 +354,9 @@ public List getAllElements(QueryModifier modifier)
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
- public Page getElements(PagingInfo pagingInfo)
- throws StatusCodeException, ConnectivityException {
+ public Page getElements(PagingInfo pagingInfo) throws StatusCodeException, ConnectivityException {
return getElements(pagingInfo, QueryModifier.DEFAULT);
}
@@ -353,9 +364,9 @@ public Page getElements(PagingInfo pagingInfo)
/**
* Retrieves a Page of Submodel Elements including their hierarchy.
*
- * @param pagingInfo Metadata for controlling the pagination of results.
- * @param modifier The query modifier specifies the structural depth and resource serialization of the submodel.
- * @return A page of Submodel elements.
+ * @param pagingInfo Metadata for controlling the pagination of results
+ * @param modifier The query modifier specifies the structural depth and resource serialization of the submodel
+ * @return A page of Submodel elements
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -366,10 +377,9 @@ public Page getElements(PagingInfo pagingInfo)
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
- public Page getElements(PagingInfo pagingInfo, QueryModifier modifier)
- throws StatusCodeException, ConnectivityException {
+ public Page getElements(PagingInfo pagingInfo, QueryModifier modifier) throws StatusCodeException, ConnectivityException {
return getPage(submodelElementsPath(), modifier, pagingInfo, SubmodelElement.class);
}
@@ -378,8 +388,8 @@ public Page getElements(PagingInfo pagingInfo, QueryModifier mo
* Creates a new Submodel Element as a child of the submodel. The idShort of the new Submodel Element must be set in the
* payload.
*
- * @param submodelElement The new Submodel Element object.
- * @return Created Submodel Element object.
+ * @param submodelElement The new Submodel Element object
+ * @return Created Submodel Element object
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -391,7 +401,7 @@ public Page getElements(PagingInfo pagingInfo, QueryModifier mo
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public SubmodelElement postElement(SubmodelElement submodelElement) throws StatusCodeException, ConnectivityException {
return post(submodelElementsPath(), submodelElement, SubmodelElement.class);
@@ -401,9 +411,9 @@ public SubmodelElement postElement(SubmodelElement submodelElement) throws Statu
/**
* Retrieves the metadata attributes of multiple Submodel Elements.
*
- * @param pagingInfo Metadata for controlling the pagination of results.
- * @param modifier The query modifier specifies the structural depth and resource serialization of the submodel.
- * @return A page of Submodel Element Metadata.
+ * @param pagingInfo Metadata for controlling the pagination of results
+ * @param modifier The query modifier specifies the structural depth and resource serialization of the submodel
+ * @return A page of Submodel Element Metadata
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -414,7 +424,7 @@ public SubmodelElement postElement(SubmodelElement submodelElement) throws Statu
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public Page getElementMetadata(PagingInfo pagingInfo, QueryModifier modifier) throws StatusCodeException, ConnectivityException {
return getPage(submodelElementsPath(), Content.METADATA, modifier, pagingInfo, SubmodelElement.class);
@@ -424,9 +434,9 @@ public Page getElementMetadata(PagingInfo pagingInfo, QueryModi
/**
* Retrieves the references of multiple Submodel Elements.
*
- * @param pagingInfo Metadata for controlling the pagination of results.
- * @param modifier The query modifier specifies the structural depth and resource serialization of the submodel.
- * @return A page of Submodel Element references.
+ * @param pagingInfo Metadata for controlling the pagination of results
+ * @param modifier The query modifier specifies the structural depth and resource serialization of the submodel
+ * @return A page of Submodel Element references
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -437,7 +447,7 @@ public Page getElementMetadata(PagingInfo pagingInfo, QueryModi
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public Page getElementReference(PagingInfo pagingInfo, QueryModifier modifier) throws StatusCodeException, ConnectivityException {
return getPage(submodelElementsPath(), Content.REFERENCE, modifier, pagingInfo, Reference.class);
@@ -447,9 +457,9 @@ public Page getElementReference(PagingInfo pagingInfo, QueryModifier
/**
* Retrieves the path of multiple Submodel Elements.
*
- * @param pagingInfo Metadata for controlling the pagination of results.
- * @param modifier The query modifier specifies the structural depth and resource serialization of the submodel.
- * @return A page of Submodel Element paths.
+ * @param pagingInfo Metadata for controlling the pagination of results
+ * @param modifier The query modifier specifies the structural depth and resource serialization of the submodel
+ * @return A page of Submodel Element paths
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -460,7 +470,7 @@ public Page getElementReference(PagingInfo pagingInfo, QueryModifier
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public Page getElementPath(PagingInfo pagingInfo, QueryModifier modifier) throws StatusCodeException, ConnectivityException {
return getPage(submodelElementsPath(), Content.PATH, modifier, pagingInfo, String.class);
@@ -470,8 +480,8 @@ public Page getElementPath(PagingInfo pagingInfo, QueryModifier modifier
/**
* Retrieves a specific submodel element from the Submodel at a specified path.
*
- * @param idShortPath The path of the Submodel Element.
- * @return The requested Submodel Element object.
+ * @param idShortPath The path of the Submodel Element
+ * @return The requested Submodel Element object
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -482,10 +492,9 @@ public Page getElementPath(PagingInfo pagingInfo, QueryModifier modifier
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
- public SubmodelElement getElement(IdShortPath idShortPath)
- throws StatusCodeException, ConnectivityException {
+ public SubmodelElement getElement(IdShortPath idShortPath) throws StatusCodeException, ConnectivityException {
return getElement(idShortPath, QueryModifier.DEFAULT);
}
@@ -493,9 +502,9 @@ public SubmodelElement getElement(IdShortPath idShortPath)
/**
* Retrieves a specific Submodel Element from the Submodel at a specified path.
*
- * @param idShortPath The path of the Submodel Element.
- * @param modifier The query modifier specifies the structural depth and resource serialization of the submodel.
- * @return The requested submodel element object.
+ * @param idShortPath The path of the Submodel Element
+ * @param modifier The query modifier specifies the structural depth and resource serialization of the submodel
+ * @return The requested submodel element object
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -506,10 +515,9 @@ public SubmodelElement getElement(IdShortPath idShortPath)
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
- public SubmodelElement getElement(IdShortPath idShortPath, QueryModifier modifier)
- throws StatusCodeException, ConnectivityException {
+ public SubmodelElement getElement(IdShortPath idShortPath, QueryModifier modifier) throws StatusCodeException, ConnectivityException {
return get(submodelElementIdPath(idShortPath), modifier, SubmodelElement.class);
}
@@ -519,9 +527,9 @@ public SubmodelElement getElement(IdShortPath idShortPath, QueryModifier modifie
* If the PostSubmodelElementByPath is executed towards a SubmodelElementList, the new SubmodelElement is added to the
* end of the list.
*
- * @param idShortPath The path under which the new SubmodelElement shall be added.
- * @param submodelElement The new Submodel Element object.
- * @return The new Submodel Element object as hosted on the server.
+ * @param idShortPath The path under which the new SubmodelElement shall be added
+ * @param submodelElement The new Submodel Element object
+ * @return The new Submodel Element object as hosted on the server
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -533,7 +541,7 @@ public SubmodelElement getElement(IdShortPath idShortPath, QueryModifier modifie
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public SubmodelElement postElement(IdShortPath idShortPath, SubmodelElement submodelElement) throws StatusCodeException, ConnectivityException {
return post(submodelElementIdPath(idShortPath), submodelElement, SubmodelElement.class);
@@ -543,8 +551,8 @@ public SubmodelElement postElement(IdShortPath idShortPath, SubmodelElement subm
/**
* Replaces an existing Submodel Element at a specified path within the submodel element hierarchy.
*
- * @param idShortPath The path to the Submodel Element which shall be replaced.
- * @param submodelElement The new Submodel Element object to replace the current one.
+ * @param idShortPath The path to the Submodel Element which shall be replaced
+ * @param submodelElement The new Submodel Element object to replace the current one
*
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
@@ -556,7 +564,7 @@ public SubmodelElement postElement(IdShortPath idShortPath, SubmodelElement subm
*
500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public void putElement(IdShortPath idShortPath, SubmodelElement submodelElement) throws StatusCodeException, ConnectivityException {
put(submodelElementIdPath(idShortPath), submodelElement);
@@ -566,8 +574,8 @@ public void putElement(IdShortPath idShortPath, SubmodelElement submodelElement)
/**
* Updates an existing Submodel Element at a specified path within the submodel element hierarchy.
*
- * @param idShortPath The path to the Submodel Element which shall be replaced.
- * @param submodelElement The new Submodel Element object to update the current one.
+ * @param idShortPath The path to the Submodel Element which shall be replaced
+ * @param submodelElement The new Submodel Element object to update the current one
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -578,7 +586,7 @@ public void putElement(IdShortPath idShortPath, SubmodelElement submodelElement)
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public void patchElement(IdShortPath idShortPath, SubmodelElement submodelElement) throws StatusCodeException, ConnectivityException {
patch(submodelElementIdPath(idShortPath), submodelElement);
@@ -588,7 +596,7 @@ public void patchElement(IdShortPath idShortPath, SubmodelElement submodelElemen
/**
* Deletes a Submodel Element at a specified path within the submodel elements hierarchy.
*
- * @param idShortPath The path to the Submodel Element which shall be replaced.
+ * @param idShortPath The path to the Submodel Element which shall be replaced
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -599,7 +607,7 @@ public void patchElement(IdShortPath idShortPath, SubmodelElement submodelElemen
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public void deleteElement(IdShortPath idShortPath) throws StatusCodeException, ConnectivityException {
delete(submodelElementIdPath(idShortPath));
@@ -609,8 +617,8 @@ public void deleteElement(IdShortPath idShortPath) throws StatusCodeException, C
/**
* Retrieves the metadata attributes of a specific Submodel Element.
*
- * @param idShortPath The path to the Submodel Element.
- * @return The Submodel Element metadata.
+ * @param idShortPath The path to the Submodel Element
+ * @return The Submodel Element metadata
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -621,7 +629,7 @@ public void deleteElement(IdShortPath idShortPath) throws StatusCodeException, C
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public SubmodelElement getElementMetadata(IdShortPath idShortPath) throws StatusCodeException, ConnectivityException {
return get(submodelElementIdPath(idShortPath), Content.METADATA, SubmodelElement.class);
@@ -631,8 +639,8 @@ public SubmodelElement getElementMetadata(IdShortPath idShortPath) throws Status
/**
* Updates the metadata attributes of a specific Submodel Element.
*
- * @param idShortPath The path to the Submodel Element.
- * @param submodelElement The new Submodel Element metadata to patch the current one.
+ * @param idShortPath The path to the Submodel Element
+ * @param submodelElement The new Submodel Element metadata to patch the current one
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -643,7 +651,7 @@ public SubmodelElement getElementMetadata(IdShortPath idShortPath) throws Status
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public void patchElementMetadata(IdShortPath idShortPath, SubmodelElement submodelElement) throws StatusCodeException, ConnectivityException {
patch(submodelElementIdPath(idShortPath), submodelElement, new QueryModifier.Builder().level(Level.CORE).build());
@@ -653,9 +661,10 @@ public void patchElementMetadata(IdShortPath idShortPath, SubmodelElement submod
/**
* Returns a specific Submodel Element value from the Submodel at a specified path.
*
- * @param idShortPath The path to the Submodel Element.
- * @param typeInfo Information specifying how the value should be deserialized. Requires type and datatype to be set.
- * @return The requested submodel element value.
+ * @param the return type
+ * @param idShortPath The path to the Submodel Element
+ * @param typeInfo Information specifying how the value should be deserialized. Requires type and datatype to be set
+ * @return The requested submodel element value
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -666,7 +675,7 @@ public void patchElementMetadata(IdShortPath idShortPath, SubmodelElement submod
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public T getElementValue(IdShortPath idShortPath, ElementValueTypeInfo typeInfo)
throws StatusCodeException, ConnectivityException {
@@ -677,10 +686,11 @@ public T getElementValue(IdShortPath idShortPath, Eleme
/**
* Returns a specific Submodel Element value from the Submodel at a specified path according to query modifier.
*
- * @param idShortPath The path to the Submodel Element.
- * @param typeInfo Information specifying how the value should be deserialized. Requires type and datatype to be set.
- * @param modifier The query modifier specifies the structural depth and resource serialization of the submodel.
- * @return The requested submodel element value according to query parameter.
+ * @param the return type
+ * @param idShortPath The path to the Submodel Element
+ * @param typeInfo Information specifying how the value should be deserialized. Requires type and datatype to be set
+ * @param modifier The query modifier specifies the structural depth and resource serialization of the submodel
+ * @return The requested submodel element value according to query parameter
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -691,7 +701,7 @@ public T getElementValue(IdShortPath idShortPath, Eleme
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public T getElementValue(IdShortPath idShortPath, ElementValueTypeInfo typeInfo, QueryModifier modifier)
throws StatusCodeException, ConnectivityException {
@@ -702,8 +712,8 @@ public T getElementValue(IdShortPath idShortPath, Eleme
/**
* Updates an existing Submodel Element value at a specified path within the submodel element hierarchy.
*
- * @param idShortPath The path to the Submodel Element which shall be updated.
- * @param value The new Submodel Element value object to replace the current one.
+ * @param idShortPath The path to the Submodel Element which shall be updated
+ * @param value The new Submodel Element value object to replace the current one
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -714,7 +724,7 @@ public T getElementValue(IdShortPath idShortPath, Eleme
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public void patchElementValue(IdShortPath idShortPath, Object value) throws StatusCodeException, ConnectivityException {
patchValue(submodelElementIdPath(idShortPath), value, new QueryModifier.Builder().level(Level.DEFAULT).build());
@@ -724,8 +734,8 @@ public void patchElementValue(IdShortPath idShortPath, Object value) throws Stat
/**
* Retrieves a specific Submodel Element reference from the server.
*
- * @param idShortPath The path to the Submodel Element.
- * @return The reference of the requested Submodel Element.
+ * @param idShortPath The path to the Submodel Element
+ * @return The reference of the requested Submodel Element
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -736,7 +746,7 @@ public void patchElementValue(IdShortPath idShortPath, Object value) throws Stat
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public Reference getElementReference(IdShortPath idShortPath) throws StatusCodeException, ConnectivityException {
return get(submodelElementIdPath(idShortPath), new QueryModifier.Builder().level(Level.CORE).build(), Content.REFERENCE, Reference.class);
@@ -746,8 +756,8 @@ public Reference getElementReference(IdShortPath idShortPath) throws StatusCodeE
/**
* Retrieves a specific Submodel Element path from the server.
*
- * @param idShortPath The path to the Submodel Element.
- * @return The path of the requested Submodel Element.
+ * @param idShortPath The path to the Submodel Element
+ * @return The path of the requested Submodel Element
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -758,7 +768,7 @@ public Reference getElementReference(IdShortPath idShortPath) throws StatusCodeE
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public String getElementPath(IdShortPath idShortPath) throws StatusCodeException, ConnectivityException {
return get(submodelElementIdPath(idShortPath), new QueryModifier.Builder().level(Level.DEEP).build(), Content.PATH, String.class);
@@ -768,8 +778,8 @@ public String getElementPath(IdShortPath idShortPath) throws StatusCodeException
/**
* Returns a specific file from the Submodel at a specified path.
*
- * @param idShortPath The path to the Submodel Element.
- * @return The requested file.
+ * @param idShortPath The path to the Submodel Element
+ * @return The requested file
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -780,7 +790,7 @@ public String getElementPath(IdShortPath idShortPath) throws StatusCodeException
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public File getAttachment(IdShortPath idShortPath) throws StatusCodeException, ConnectivityException {
return get(attachmentPath(idShortPath), File.class);
@@ -790,8 +800,8 @@ public File getAttachment(IdShortPath idShortPath) throws StatusCodeException, C
/**
* Replaces the file at a specified path within the submodel element hierarchy.
*
- * @param idShortPath The path to the Submodel Element.
- * @param attachment The new file to replace the current one.
+ * @param idShortPath The path to the Submodel Element
+ * @param attachment The new file to replace the current one
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -802,7 +812,7 @@ public File getAttachment(IdShortPath idShortPath) throws StatusCodeException, C
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public void putAttachment(IdShortPath idShortPath, File attachment) throws StatusCodeException, ConnectivityException {
put(attachmentPath(idShortPath), attachment);
@@ -812,21 +822,22 @@ public void putAttachment(IdShortPath idShortPath, File attachment) throws Statu
/**
* Deletes the file of an existing submodel element at a specified path within the submodel element hierarchy
*
- * @param idShortPath The path to the Submodel Element.
- * @throws StatusCodeException, ConnectivityException if the request fails
+ * @param idShortPath The path to the Submodel Element
+ * @throws StatusCodeException if the request fails
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public void deleteAttachment(IdShortPath idShortPath) throws StatusCodeException, ConnectivityException {
- delete(attachmentPath(idShortPath));
+ delete(attachmentPath(idShortPath), HttpStatus.OK);
}
/**
* Invokes a synchronous Operation at a specified path.
*
- * @param idShortPath The path to the Submodel Element.
- * @param input List of input variables.
- * @param timeout Timeout for client in java xml duration format.
- * @return The returned result of an operation’s invocation.
+ * @param idShortPath The path to the Submodel Element
+ * @param input List of input variables
+ * @param timeout Timeout for client in java xml duration format
+ * @return The returned result of an operation’s invocation
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -839,22 +850,21 @@ public void deleteAttachment(IdShortPath idShortPath) throws StatusCodeException
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public OperationResult invokeOperationSync(IdShortPath idShortPath, List input, Duration timeout) throws StatusCodeException, ConnectivityException {
- List inoutput = new ArrayList<>();
- return invokeOperationSync(idShortPath, input, inoutput, timeout);
+ return invokeOperationSync(idShortPath, input, List.of(), timeout);
}
/**
* Invokes a synchronous Operation at a specified path.
*
- * @param idShortPath The path to the Submodel Element.
- * @param input List of input variables.
- * @param inoutput List of inoutput variables.
- * @param timeout Timeout for client in java xml duration format.
- * @return The returned result of an operation’s invocation.
+ * @param idShortPath The path to the Submodel Element
+ * @param input List of input variables
+ * @param inoutput List of inoutput variables
+ * @param timeout Timeout for client in java xml duration format
+ * @return The returned result of an operation’s invocation
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -867,35 +877,38 @@ public OperationResult invokeOperationSync(IdShortPath idShortPath, List500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public OperationResult invokeOperationSync(IdShortPath idShortPath, List input, List inoutput, Duration timeout)
throws StatusCodeException, ConnectivityException {
- OperationRequest operationRequest = new DefaultOperationRequest.Builder()
- .inputArguments(input)
- .inoutputArguments(inoutput)
- .clientTimeoutDuration(timeout)
- .build();
- return post(invokePath(idShortPath), operationRequest, OperationResult.class);
+ return post(
+ invokePath(idShortPath),
+ new DefaultOperationRequest.Builder()
+ .inputArguments(input)
+ .inoutputArguments(inoutput)
+ .clientTimeoutDuration(timeout)
+ .build(),
+ HttpStatus.OK,
+ OperationResult.class);
}
- private String submodelElementsPath() {
- return basePath() + "submodel-elements/";
+ private static String submodelElementsPath() {
+ return "/submodel-elements";
}
- private String submodelElementIdPath(IdShortPath idShortPath) {
- return submodelElementsPath() + idShortPath.toString() + "/";
+ private static String submodelElementIdPath(IdShortPath idShortPath) {
+ return String.format("%s/%s", submodelElementsPath(), idShortPath.toString());
}
- private String attachmentPath(IdShortPath idShortPath) {
- return submodelElementIdPath(idShortPath) + "attachment/";
+ private static String attachmentPath(IdShortPath idShortPath) {
+ return submodelElementIdPath(idShortPath) + "/attachment";
}
- private String invokePath(IdShortPath idShortPath) {
- return submodelElementIdPath(idShortPath) + "invoke/";
+ private static String invokePath(IdShortPath idShortPath) {
+ return submodelElementIdPath(idShortPath) + "/invoke";
}
}
diff --git a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/interfaces/SubmodelRegistryInterface.java b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/interfaces/SubmodelRegistryInterface.java
index ad9ce3c..53bcf08 100644
--- a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/interfaces/SubmodelRegistryInterface.java
+++ b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/interfaces/SubmodelRegistryInterface.java
@@ -36,43 +36,45 @@
*/
public class SubmodelRegistryInterface extends BaseInterface {
+ private static final String API_PATH = "/submodel-descriptors";
+
/**
* Creates a new Submodel Registry Interface.
*
- * @param serviceURI Uri used to communicate with the FA³ST Service.
+ * @param endpoint Uri used to communicate with the FA³ST Service
*/
- public SubmodelRegistryInterface(URI serviceURI) {
- super(serviceURI, "/submodel-descriptors/");
+ public SubmodelRegistryInterface(URI endpoint) {
+ super(resolve(endpoint, API_PATH));
}
/**
* Creates a new Submodel Registry Interface.
*
- * @param user String to allow for basic authentication.
- * @param password String to allow for basic authentication.
- * @param serviceURI Uri used to communicate with the FA³ST Service.
+ * @param endpoint Uri used to communicate with the FA³ST Service
+ * @param user String to allow for basic authentication
+ * @param password String to allow for basic authentication
*/
- public SubmodelRegistryInterface(URI serviceURI, String user, String password) {
- super(serviceURI, "/submodel-descriptors/", user, password);
+ public SubmodelRegistryInterface(URI endpoint, String user, String password) {
+ super(resolve(endpoint, API_PATH), user, password);
}
/**
* Creates a new Submodel Registry Interface.
*
- * @param httpClient Allows the user to specify a custom httpClient.
- * @param serviceURI Uri used to communicate with the FA³ST Service.
+ * @param endpoint Uri used to communicate with the FA³ST Service
+ * @param httpClient Allows the user to specify a custom httpClient
*/
- public SubmodelRegistryInterface(URI serviceURI, HttpClient httpClient) {
- super(serviceURI, "/submodel-descriptors/", httpClient);
+ public SubmodelRegistryInterface(URI endpoint, HttpClient httpClient) {
+ super(resolve(endpoint, API_PATH), httpClient);
}
/**
* Retrieves a list of all Submodel Descriptors.
*
- * @return A list containing all Submodel Descriptors.
+ * @return A list containing all Submodel Descriptors
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -83,18 +85,18 @@ public SubmodelRegistryInterface(URI serviceURI, HttpClient httpClient) {
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public List getAll() throws StatusCodeException, ConnectivityException {
- return getList(basePath(), DefaultSubmodelDescriptor.class);
+ return getList(DefaultSubmodelDescriptor.class);
}
/**
* Returns a page of Submodel Descriptors.
*
- * @param pagingInfo Metadata for controlling the pagination of results.
- * @return A page of Submodel Descriptors.
+ * @param pagingInfo Metadata for controlling the pagination of results
+ * @return A page of Submodel Descriptors
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -105,18 +107,18 @@ public List getAll() throws StatusCodeException, Conn
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public Page get(PagingInfo pagingInfo) throws StatusCodeException, ConnectivityException {
- return getPage(basePath(), pagingInfo, DefaultSubmodelDescriptor.class);
+ return getPage(pagingInfo, DefaultSubmodelDescriptor.class);
}
/**
* Creates a new Submodel Descriptor, i.e. registers a Submodel.
*
- * @param submodelDescriptor Object containing the Submodel’s identification and endpoint information.
- * @return Created Submodel Descriptor.
+ * @param submodelDescriptor Object containing the Submodel’s identification and endpoint information
+ * @return Created Submodel Descriptor
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -128,18 +130,18 @@ public Page get(PagingInfo pagingInfo) throws StatusC
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public DefaultSubmodelDescriptor post(SubmodelDescriptor submodelDescriptor) throws StatusCodeException, ConnectivityException {
- return post(basePath(), submodelDescriptor, DefaultSubmodelDescriptor.class);
+ return post(submodelDescriptor, DefaultSubmodelDescriptor.class);
}
/**
* Returns a specific Submodel Descriptor.
*
- * @param submodelIdentifier The Submodel’s unique id.
- * @return Requested Submodel Descriptor.
+ * @param submodelIdentifier The Submodel’s unique id
+ * @return Requested Submodel Descriptor
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -150,7 +152,7 @@ public DefaultSubmodelDescriptor post(SubmodelDescriptor submodelDescriptor) thr
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public DefaultSubmodelDescriptor get(String submodelIdentifier) throws StatusCodeException, ConnectivityException {
return get(idPath(submodelIdentifier), DefaultSubmodelDescriptor.class);
@@ -160,8 +162,8 @@ public DefaultSubmodelDescriptor get(String submodelIdentifier) throws StatusCod
/**
* Replaces an existing Submodel Descriptor, i.e. replaces registration information.
*
- * @param submodelIdentifier The Submodel’s unique id.
- * @param submodelDescriptor Object containing the Submodel’s identification and endpoint information.
+ * @param submodelIdentifier The Submodel’s unique id
+ * @param submodelDescriptor Object containing the Submodel’s identification and endpoint information
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -172,7 +174,7 @@ public DefaultSubmodelDescriptor get(String submodelIdentifier) throws StatusCod
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public void put(String submodelIdentifier, DefaultSubmodelDescriptor submodelDescriptor) throws StatusCodeException, ConnectivityException {
super.put(idPath(submodelIdentifier), submodelDescriptor);
@@ -182,7 +184,7 @@ public void put(String submodelIdentifier, DefaultSubmodelDescriptor submodelDes
/**
* Deletes a Submodel Descriptor, i.e. de-registers a Submodel.
*
- * @param submodelIdentifier The Submodel’s unique id.
+ * @param submodelIdentifier The Submodel’s unique id
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -193,8 +195,9 @@ public void put(String submodelIdentifier, DefaultSubmodelDescriptor submodelDes
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
+ @Override
public void delete(String submodelIdentifier) throws StatusCodeException, ConnectivityException {
super.delete(idPath(submodelIdentifier));
}
diff --git a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/interfaces/SubmodelRepositoryInterface.java b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/interfaces/SubmodelRepositoryInterface.java
index 58af6b8..9e50ffa 100644
--- a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/interfaces/SubmodelRepositoryInterface.java
+++ b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/interfaces/SubmodelRepositoryInterface.java
@@ -37,43 +37,45 @@
*/
public class SubmodelRepositoryInterface extends BaseInterface {
+ private static final String API_PATH = "/submodels";
+
/**
* Creates a new Submodel Repository Interface.
*
- * @param serviceUri Uri used to communicate with the FA³ST service.
+ * @param endpoint Uri used to communicate with the FA³ST service
*/
- public SubmodelRepositoryInterface(URI serviceUri) {
- super(serviceUri, "/submodels/");
+ public SubmodelRepositoryInterface(URI endpoint) {
+ super(resolve(endpoint, API_PATH));
}
/**
* Creates a new Submodel Repository Interface with basic authentication.
*
- * @param user String for basic authentication.
- * @param password String for basic authentication.
- * @param serviceUri uri used to communicate with the FA³ST service
+ * @param endpoint uri used to communicate with the FA³ST service
+ * @param user String for basic authentication
+ * @param password String for basic authentication
*/
- public SubmodelRepositoryInterface(URI serviceUri, String user, String password) {
- super(serviceUri, "/submodels/", user, password);
+ public SubmodelRepositoryInterface(URI endpoint, String user, String password) {
+ super(resolve(endpoint, API_PATH), user, password);
}
/**
* Creates a new Submodel Repository API.
*
- * @param httpClient Allows user to specify custom http-client.
- * @param serviceUri uri used to communicate with the FA³ST service
+ * @param endpoint uri used to communicate with the FA³ST service
+ * @param httpClient Allows user to specify custom http-client
*/
- public SubmodelRepositoryInterface(URI serviceUri, HttpClient httpClient) {
- super(serviceUri, "/submodels/", httpClient);
+ public SubmodelRepositoryInterface(URI endpoint, HttpClient httpClient) {
+ super(resolve(endpoint, API_PATH), httpClient);
}
/**
* Retrieves all Submodels
*
- * @return A List of all Submodels.
+ * @return A List of all Submodels
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -84,7 +86,7 @@ public SubmodelRepositoryInterface(URI serviceUri, HttpClient httpClient) {
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public List getAll() throws StatusCodeException, ConnectivityException {
return getAll(QueryModifier.DEFAULT, SubmodelSearchCriteria.DEFAULT);
@@ -94,8 +96,8 @@ public List getAll() throws StatusCodeException, ConnectivityException
/**
* Retrieves all Submodels according to output modifier.
*
- * @param modifier The query modifier specifies the structural depth and resource serialization of the submodel.
- * @return List of all Submodels.
+ * @param modifier The query modifier specifies the structural depth and resource serialization of the submodel
+ * @return List of all Submodels
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -106,7 +108,7 @@ public List getAll() throws StatusCodeException, ConnectivityException
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public List getAll(QueryModifier modifier) throws StatusCodeException, ConnectivityException {
return getAll(modifier, SubmodelSearchCriteria.DEFAULT);
@@ -116,8 +118,8 @@ public List getAll(QueryModifier modifier) throws StatusCodeException,
/**
* Retrieves all Submodels that match specific search criteria.
*
- * @param submodelSearchCriteria Search criteria to filter Submodels based on IdShort and semanticId.
- * @return List of all submodels matching the search criteria.
+ * @param submodelSearchCriteria Search criteria to filter Submodels based on IdShort and semanticId
+ * @return List of all submodels matching the search criteria
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -128,7 +130,7 @@ public List getAll(QueryModifier modifier) throws StatusCodeException,
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public List getAll(SubmodelSearchCriteria submodelSearchCriteria) throws StatusCodeException, ConnectivityException {
return getAll(QueryModifier.DEFAULT, submodelSearchCriteria);
@@ -138,8 +140,8 @@ public List getAll(SubmodelSearchCriteria submodelSearchCriteria) thro
/**
* Retrieves all Submodels that match specific search criteria according to query modifiers.
*
- * @param modifier The query modifier specifies the structural depth and resource serialization of the submodel.
- * @param submodelSearchCriteria Search criteria to filter Submodels based on IdShort and semanticId.
+ * @param modifier The query modifier specifies the structural depth and resource serialization of the submodel
+ * @param submodelSearchCriteria Search criteria to filter Submodels based on IdShort and semanticId
* @return List of Submodels
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
@@ -151,18 +153,18 @@ public List getAll(SubmodelSearchCriteria submodelSearchCriteria) thro
* 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public List getAll(QueryModifier modifier, SubmodelSearchCriteria submodelSearchCriteria) throws StatusCodeException, ConnectivityException {
- return getList(basePath(), submodelSearchCriteria, Content.DEFAULT, modifier, Submodel.class);
+ return getList(submodelSearchCriteria, Content.DEFAULT, modifier, Submodel.class);
}
/**
* Retrieves a page of Submodels.
*
- * @param pagingInfo Metadata for controlling the pagination of results.
- * @return A page of submodels.
+ * @param pagingInfo Metadata for controlling the pagination of results
+ * @return A page of submodels
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -173,7 +175,7 @@ public List getAll(QueryModifier modifier, SubmodelSearchCriteria subm
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public Page get(PagingInfo pagingInfo) throws StatusCodeException, ConnectivityException {
return get(pagingInfo, QueryModifier.DEFAULT, SubmodelSearchCriteria.DEFAULT);
@@ -183,9 +185,9 @@ public Page get(PagingInfo pagingInfo) throws StatusCodeException, Con
/**
* Retrieves a page of Submodels that match specific search criteria.
*
- * @param pagingInfo Metadata for controlling the pagination of results.
- * @param submodelSearchCriteria Search criteria to filter Submodels based on IdShort and semanticId.
- * @return A page of Submodels.
+ * @param pagingInfo Metadata for controlling the pagination of results
+ * @param submodelSearchCriteria Search criteria to filter Submodels based on IdShort and semanticId
+ * @return A page of Submodels
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -196,10 +198,9 @@ public Page get(PagingInfo pagingInfo) throws StatusCodeException, Con
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
- public Page get(PagingInfo pagingInfo, SubmodelSearchCriteria submodelSearchCriteria)
- throws StatusCodeException, ConnectivityException {
+ public Page get(PagingInfo pagingInfo, SubmodelSearchCriteria submodelSearchCriteria) throws StatusCodeException, ConnectivityException {
return get(pagingInfo, QueryModifier.DEFAULT, submodelSearchCriteria);
}
@@ -207,9 +208,9 @@ public Page get(PagingInfo pagingInfo, SubmodelSearchCriteria submodel
/**
* Retrieves a page of Submodels according to query modifier.
*
- * @param pagingInfo Metadata for controlling the pagination of results.
- * @param modifier The query modifier specifies the structural depth and resource serialization of the submodel.
- * @return A page of Submodels.
+ * @param pagingInfo Metadata for controlling the pagination of results
+ * @param modifier The query modifier specifies the structural depth and resource serialization of the submodel
+ * @return A page of Submodels
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -220,10 +221,9 @@ public Page get(PagingInfo pagingInfo, SubmodelSearchCriteria submodel
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
- public Page get(PagingInfo pagingInfo, QueryModifier modifier)
- throws StatusCodeException, ConnectivityException {
+ public Page get(PagingInfo pagingInfo, QueryModifier modifier) throws StatusCodeException, ConnectivityException {
return get(pagingInfo, modifier, SubmodelSearchCriteria.DEFAULT);
}
@@ -231,10 +231,10 @@ public Page get(PagingInfo pagingInfo, QueryModifier modifier)
/**
* Retrieves a page of Submodels matching specific search criteria according to query modifier.
*
- * @param pagingInfo Metadata for controlling the pagination of results.
- * @param modifier The query modifier specifies the structural depth and resource serialization of the submodel.
- * @param submodelSearchCriteria Search criteria to filter Submodels based on IdShort and semanticId.
- * @return A page of Submodels.
+ * @param pagingInfo Metadata for controlling the pagination of results
+ * @param modifier The query modifier specifies the structural depth and resource serialization of the submodel
+ * @param submodelSearchCriteria Search criteria to filter Submodels based on IdShort and semanticId
+ * @return A page of Submodels
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -245,20 +245,19 @@ public Page get(PagingInfo pagingInfo, QueryModifier modifier)
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
- public Page get(PagingInfo pagingInfo, QueryModifier modifier, SubmodelSearchCriteria submodelSearchCriteria)
- throws StatusCodeException, ConnectivityException {
- return getPage(basePath(), Content.DEFAULT, modifier, pagingInfo, submodelSearchCriteria, Submodel.class);
+ public Page get(PagingInfo pagingInfo, QueryModifier modifier, SubmodelSearchCriteria submodelSearchCriteria) throws StatusCodeException, ConnectivityException {
+ return getPage(Content.DEFAULT, modifier, pagingInfo, submodelSearchCriteria, Submodel.class);
}
/**
* Retrieves all Submodel metadata matching specific search criteria.
*
- * @param modifier The query modifier specifies the structural depth and resource serialization of the submodel.
- * @param submodelSearchCriteria Search criteria to filter Submodels based on IdShort and semanticId.
- * @return A List containing all submodels serialised as metadata.
+ * @param modifier The query modifier specifies the structural depth and resource serialization of the submodel
+ * @param submodelSearchCriteria Search criteria to filter Submodels based on IdShort and semanticId
+ * @return A List containing all submodels serialised as metadata
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -269,20 +268,20 @@ public Page get(PagingInfo pagingInfo, QueryModifier modifier, Submode
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public List getAllMetadata(QueryModifier modifier, SubmodelSearchCriteria submodelSearchCriteria) throws StatusCodeException, ConnectivityException {
- return getList(basePath(), submodelSearchCriteria, Content.METADATA, modifier, Submodel.class);
+ return getList(submodelSearchCriteria, Content.METADATA, modifier, Submodel.class);
}
/**
* Retrieves a page of Submodel metadata matching specific search criteria.
*
- * @param pagingInfo Metadata for controlling the pagination of results.
- * @param modifier The query modifier specifies the structural depth and resource serialization of the submodel.
- * @param submodelSearchCriteria Search criteria to filter Submodels based on IdShort and semanticId.
- * @return A page of Submodel metadata.
+ * @param pagingInfo Metadata for controlling the pagination of results
+ * @param modifier The query modifier specifies the structural depth and resource serialization of the submodel
+ * @param submodelSearchCriteria Search criteria to filter Submodels based on IdShort and semanticId
+ * @return A page of Submodel metadata
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -293,20 +292,20 @@ public List getAllMetadata(QueryModifier modifier, SubmodelSearchCrite
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public Page getMetadata(PagingInfo pagingInfo, QueryModifier modifier, SubmodelSearchCriteria submodelSearchCriteria)
throws StatusCodeException, ConnectivityException {
- return getPage(basePath(), Content.METADATA, modifier, pagingInfo, submodelSearchCriteria, Submodel.class);
+ return getPage(Content.METADATA, modifier, pagingInfo, submodelSearchCriteria, Submodel.class);
}
/**
* Retrieves a List containing all Submodels matching specific search criteria in value only serialisation.
*
- * @param modifier The query modifier specifies the structural depth and resource serialization of the submodel.
- * @param submodelSearchCriteria Search criteria to filter Submodels based on IdShort and semanticId.
- * @return A list of Submodels.
+ * @param modifier The query modifier specifies the structural depth and resource serialization of the submodel
+ * @param submodelSearchCriteria Search criteria to filter Submodels based on IdShort and semanticId
+ * @return A list of Submodels
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -317,20 +316,20 @@ public Page getMetadata(PagingInfo pagingInfo, QueryModifier modifier,
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public List getAllValues(QueryModifier modifier, SubmodelSearchCriteria submodelSearchCriteria) throws StatusCodeException, ConnectivityException {
- return getList(basePath(), submodelSearchCriteria, Content.VALUE, modifier, Submodel.class);
+ return getList(submodelSearchCriteria, Content.VALUE, modifier, Submodel.class);
}
/**
* Retrieves a page containing Submodels matching specific search criteria in value only serialisation.
*
- * @param pagingInfo Metadata for controlling the pagination of results.
- * @param modifier The query modifier specifies the structural depth and resource serialization of the submodel.
- * @param submodelSearchCriteria Search criteria to filter Submodels based on IdShort and semanticId.
- * @return A page of Submodels in value only serialisation.
+ * @param pagingInfo Metadata for controlling the pagination of results
+ * @param modifier The query modifier specifies the structural depth and resource serialization of the submodel
+ * @param submodelSearchCriteria Search criteria to filter Submodels based on IdShort and semanticId
+ * @return A page of Submodels in value only serialisation
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -341,19 +340,18 @@ public List getAllValues(QueryModifier modifier, SubmodelSearchCriteri
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
- public Page getValue(PagingInfo pagingInfo, QueryModifier modifier, SubmodelSearchCriteria submodelSearchCriteria)
- throws StatusCodeException, ConnectivityException {
- return getPage(basePath(), Content.VALUE, modifier, pagingInfo, submodelSearchCriteria, Submodel.class);
+ public Page getValue(PagingInfo pagingInfo, QueryModifier modifier, SubmodelSearchCriteria submodelSearchCriteria) throws StatusCodeException, ConnectivityException {
+ return getPage(Content.VALUE, modifier, pagingInfo, submodelSearchCriteria, Submodel.class);
}
/**
* Retrieves a list of references to Submodels matching specific search criteria.
*
- * @param submodelSearchCriteria Search criteria to filter Submodels based on IdShort and semanticId.
- * @return A List of References.
+ * @param submodelSearchCriteria Search criteria to filter Submodels based on IdShort and semanticId
+ * @return A List of References
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -364,19 +362,19 @@ public Page getValue(PagingInfo pagingInfo, QueryModifier modifier, Su
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public List getAllReferences(SubmodelSearchCriteria submodelSearchCriteria) throws StatusCodeException, ConnectivityException {
- return getList(basePath(), submodelSearchCriteria, Content.REFERENCE, QueryModifier.MINIMAL, Reference.class);
+ return getList(submodelSearchCriteria, Content.REFERENCE, QueryModifier.MINIMAL, Reference.class);
}
/**
* Retrieves a page of references to Submodels matching specific search criteria.
*
- * @param pagingInfo Metadata for controlling the pagination of results.
- * @param submodelSearchCriteria Search criteria to filter Submodels based on IdShort and semanticId.
- * @return A page of References.
+ * @param pagingInfo Metadata for controlling the pagination of results
+ * @param submodelSearchCriteria Search criteria to filter Submodels based on IdShort and semanticId
+ * @return A page of References
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -387,20 +385,19 @@ public List getAllReferences(SubmodelSearchCriteria submodelSearchCri
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
- public Page getReference(PagingInfo pagingInfo, SubmodelSearchCriteria submodelSearchCriteria)
- throws StatusCodeException, ConnectivityException {
- return getPage(basePath(), Content.REFERENCE, QueryModifier.MINIMAL, pagingInfo, submodelSearchCriteria, Reference.class);
+ public Page getReference(PagingInfo pagingInfo, SubmodelSearchCriteria submodelSearchCriteria) throws StatusCodeException, ConnectivityException {
+ return getPage(Content.REFERENCE, QueryModifier.MINIMAL, pagingInfo, submodelSearchCriteria, Reference.class);
}
/**
* Retrieves a list of paths to Submodels matching specific search criteria.
*
- * @param modifier The query modifier specifies the structural depth and resource serialization of the submodel.
- * @param submodelSearchCriteria Search criteria to filter Submodels based on IdShort and semanticId.
- * @return A list of paths.
+ * @param modifier The query modifier specifies the structural depth and resource serialization of the submodel
+ * @param submodelSearchCriteria Search criteria to filter Submodels based on IdShort and semanticId
+ * @return A list of paths
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -411,20 +408,20 @@ public Page getReference(PagingInfo pagingInfo, SubmodelSearchCriteri
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public List getAllPaths(QueryModifier modifier, SubmodelSearchCriteria submodelSearchCriteria) throws StatusCodeException, ConnectivityException {
- return getList(basePath(), submodelSearchCriteria, Content.PATH, modifier, Reference.class);
+ return getList(submodelSearchCriteria, Content.PATH, modifier, Reference.class);
}
/**
* Retrieves a page of paths to Submodels matching specific search criteria.
*
- * @param pagingInfo Metadata for controlling the pagination of results.
- * @param modifier The query modifier specifies the structural depth and resource serialization of the submodel.
- * @param submodelSearchCriteria Search criteria to filter Submodels based on IdShort and semanticId.
- * @return A page of paths.
+ * @param pagingInfo Metadata for controlling the pagination of results
+ * @param modifier The query modifier specifies the structural depth and resource serialization of the submodel
+ * @param submodelSearchCriteria Search criteria to filter Submodels based on IdShort and semanticId
+ * @return A page of paths
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -435,11 +432,11 @@ public List getAllPaths(QueryModifier modifier, SubmodelSearchCriteri
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public Page getSubmodelsPath(PagingInfo pagingInfo, QueryModifier modifier, SubmodelSearchCriteria submodelSearchCriteria)
throws StatusCodeException, ConnectivityException {
- return getPage(basePath(), Content.PATH, modifier, pagingInfo, submodelSearchCriteria, Reference.class);
+ return getPage(Content.PATH, modifier, pagingInfo, submodelSearchCriteria, Reference.class);
}
@@ -447,7 +444,7 @@ public Page getSubmodelsPath(PagingInfo pagingInfo, QueryModifier mod
* Creates a new Submodel. The unique if of the new submodel must be set in the payload.
*
* @param submodel Submodel object
- * @return The created Submodel.
+ * @return The created Submodel
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -458,17 +455,17 @@ public Page getSubmodelsPath(PagingInfo pagingInfo, QueryModifier mod
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
public Submodel post(Submodel submodel) throws StatusCodeException, ConnectivityException {
- return post(basePath(), submodel, Submodel.class);
+ return post(submodel, Submodel.class);
}
/**
* Deletes a Submodel.
*
- * @param submodelIdentifier The unique identifier of the Submodel to be deleted.
+ * @param submodelIdentifier The unique identifier of the Submodel to be deleted
* @throws StatusCodeException if the server responds with an error. Possible Exceptions:
*
*
@@ -479,8 +476,9 @@ public Submodel post(Submodel submodel) throws StatusCodeException, Connectivity
* - 500: InternalServerErrorException
*
*
- * @throws ConnectivityException if the connection to the server cannot be established.
+ * @throws ConnectivityException if the connection to the server cannot be established
*/
+ @Override
public void delete(String submodelIdentifier) throws StatusCodeException, ConnectivityException {
super.delete(idPath(submodelIdentifier));
}
@@ -489,10 +487,10 @@ public void delete(String submodelIdentifier) throws StatusCodeException, Connec
/**
* Returns a Submodel Interface for use of Interface Methods.
*
- * @param submodelId The Submodels’ unique id.
- * @return The requested Submodel Interface.
+ * @param submodelId The Submodels’ unique id
+ * @return The requested Submodel Interface
*/
public SubmodelInterface getSubmodelInterface(String submodelId) {
- return new SubmodelInterface(URI.create(idPath(submodelId)), httpClient());
+ return new SubmodelInterface(resolve(idPath(submodelId)), httpClient);
}
}
diff --git a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/query/AASDescriptorSearchCriteria.java b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/query/AASDescriptorSearchCriteria.java
index 199955b..8f592f2 100644
--- a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/query/AASDescriptorSearchCriteria.java
+++ b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/query/AASDescriptorSearchCriteria.java
@@ -26,7 +26,8 @@
* asset kind and asset type.
*/
public class AASDescriptorSearchCriteria implements SearchCriteria {
- public static AASDescriptorSearchCriteria DEFAULT = new AASDescriptorSearchCriteria.Builder().build();
+
+ public static final AASDescriptorSearchCriteria DEFAULT = new AASDescriptorSearchCriteria.Builder().build();
private final AssetKind assetKind;
private final String assetType;
@@ -38,8 +39,8 @@ private AASDescriptorSearchCriteria(Builder builder) {
/**
* Getter method for retrieving the asset kind used to filter Asset Administration Shell descriptors.
- *
- * @return The asset kind object.
+ *
+ * @return The asset kind object
*/
public AssetKind getAssetKind() {
return assetKind;
@@ -48,13 +49,32 @@ public AssetKind getAssetKind() {
/**
* Getter method for retrieving the asset type used to filter Asset Administration Shell descriptors.
- *
- * @return The asset type object.
+ *
+ * @return The asset type object
*/
public String getAssetType() {
return assetType;
}
+
+ /**
+ * Serializes the asset kind and asset type as filters in a query string for the use in a http request.
+ *
+ * @return The query string
+ */
+ @Override
+ public String toQueryString() {
+ String assetKindString = assetKind == null ? ""
+ : "assetKind=" + EnumSerializer.serializeEnumName(assetKind.name());
+
+ String assetTypeString = assetType == null ? ""
+ : "assetType=" + EncodingHelper.base64Encode(assetType);
+
+ return Stream.of(assetKindString, assetTypeString)
+ .filter(s -> !s.isEmpty())
+ .collect(Collectors.joining("&"));
+ }
+
public static class Builder {
private AssetKind assetKind;
private String assetType;
@@ -75,22 +95,4 @@ public AASDescriptorSearchCriteria build() {
return new AASDescriptorSearchCriteria(this);
}
}
-
- /**
- * Serializes the asset kind and asset type as filters in a query string for the use in a http request.
- *
- * @return The query string.
- */
- @Override
- public String toQueryString() {
- String assetKindString = assetKind == null ? ""
- : "assetKind=" + EnumSerializer.serializeEnumName(assetKind.name());
-
- String assetTypeString = assetType == null ? ""
- : "assetType=" + EncodingHelper.base64Encode(assetType);
-
- return Stream.of(assetKindString, assetTypeString)
- .filter(s -> !s.isEmpty())
- .collect(Collectors.joining("&"));
- }
}
diff --git a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/query/AASSearchCriteria.java b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/query/AASSearchCriteria.java
index f88f77b..a883574 100644
--- a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/query/AASSearchCriteria.java
+++ b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/query/AASSearchCriteria.java
@@ -32,25 +32,13 @@
* idShort and a List of AssetIdentification objects.
*/
public class AASSearchCriteria extends AssetAdministrationShellSearchCriteria implements SearchCriteria {
- public static AASSearchCriteria DEFAULT = new AASSearchCriteria();
-
- public static class Builder extends AssetAdministrationShellSearchCriteria.AbstractBuilder {
- @Override
- protected Builder getSelf() {
- return this;
- }
-
- @Override
- protected AASSearchCriteria newBuildingInstance() {
- return new AASSearchCriteria();
- }
- }
+ public static final AASSearchCriteria DEFAULT = new AASSearchCriteria();
/**
* Serializes the asset kind and asset type as filters in a query string for the use in a http request.
*
- * @return The query string.
+ * @return The query string
*/
@Override
public String toQueryString() {
@@ -71,12 +59,11 @@ public String toQueryString() {
private String serializeAssetIdentification(AssetIdentification assetId) {
try {
- if (assetId instanceof SpecificAssetIdentification) {
-
+ if (assetId instanceof SpecificAssetIdentification specificAssetIdentification) {
return EncodingHelper.base64Encode(new JsonSerializer().write(
new DefaultSpecificAssetId.Builder()
.value(assetId.getValue())
- .name(((SpecificAssetIdentification) assetId).getKey())
+ .name(specificAssetIdentification.getKey())
.build()));
}
else if (assetId instanceof GlobalAssetIdentification) {
@@ -92,4 +79,17 @@ else if (assetId instanceof GlobalAssetIdentification) {
}
return "";
}
+
+ public static class Builder extends AssetAdministrationShellSearchCriteria.AbstractBuilder {
+ @Override
+ protected Builder getSelf() {
+ return this;
+ }
+
+
+ @Override
+ protected AASSearchCriteria newBuildingInstance() {
+ return new AASSearchCriteria();
+ }
+ }
}
diff --git a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/query/ConceptDescriptionSearchCriteria.java b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/query/ConceptDescriptionSearchCriteria.java
index d556409..7e960f3 100644
--- a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/query/ConceptDescriptionSearchCriteria.java
+++ b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/query/ConceptDescriptionSearchCriteria.java
@@ -21,16 +21,17 @@
/**
- * Allows to filter Concept Descriptions in a Concept Description Repository based on
- * idShort, isCaseOf and dataSpecification.
+ * Allows to filter Concept Descriptions in a Concept Description Repository based on idShort, isCaseOf and
+ * dataSpecification.
*/
public class ConceptDescriptionSearchCriteria extends de.fraunhofer.iosb.ilt.faaast.service.persistence.ConceptDescriptionSearchCriteria implements SearchCriteria {
- public static ConceptDescriptionSearchCriteria DEFAULT = new ConceptDescriptionSearchCriteria();
+
+ public static final ConceptDescriptionSearchCriteria DEFAULT = new ConceptDescriptionSearchCriteria();
/**
* Serializes isCaseOf, idShort and dataSpecification as filters in a query string for the use in a http request.
*
- * @return The query string.
+ * @return The query string
*/
@Override
public String toQueryString() {
@@ -44,4 +45,18 @@ public String toQueryString() {
.filter(s -> !s.isEmpty())
.collect(Collectors.joining("&"));
}
+
+ public static class Builder
+ extends de.fraunhofer.iosb.ilt.faaast.service.persistence.ConceptDescriptionSearchCriteria.AbstractBuilder {
+ @Override
+ protected Builder getSelf() {
+ return this;
+ }
+
+
+ @Override
+ protected ConceptDescriptionSearchCriteria newBuildingInstance() {
+ return new ConceptDescriptionSearchCriteria();
+ }
+ }
}
diff --git a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/query/DefaultSearchCriteria.java b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/query/DefaultSearchCriteria.java
deleted file mode 100644
index c273211..0000000
--- a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/query/DefaultSearchCriteria.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright (c) 2024 Fraunhofer IOSB, eine rechtlich nicht selbstaendige
- * Einrichtung der Fraunhofer-Gesellschaft zur Foerderung der angewandten
- * Forschung e.V.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package de.fraunhofer.iosb.ilt.faaast.client.query;
-
-/**
- * Default implementation of search criteria.
- * This class is used in methods that require a search criteria input parameter when no filters should be applied.
- */
-public class DefaultSearchCriteria implements SearchCriteria {
-
- @Override
- public String toQueryString() {
- return "";
- }
-}
diff --git a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/query/SearchCriteria.java b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/query/SearchCriteria.java
index 5b08e15..cbdd975 100644
--- a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/query/SearchCriteria.java
+++ b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/query/SearchCriteria.java
@@ -19,7 +19,7 @@
* These are used to filter the response of an AAS server based on specific criteria.
*/
public interface SearchCriteria {
- SearchCriteria DEFAULT = new DefaultSearchCriteria();
+ public static final SearchCriteria DEFAULT = () -> "";
String toQueryString();
}
diff --git a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/query/SubmodelSearchCriteria.java b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/query/SubmodelSearchCriteria.java
index 014e4ae..4700fed 100644
--- a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/query/SubmodelSearchCriteria.java
+++ b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/query/SubmodelSearchCriteria.java
@@ -28,7 +28,7 @@ public class SubmodelSearchCriteria extends de.fraunhofer.iosb.ilt.faaast.servic
/**
* Serializes the semanticId and idShort as filters in a query string for the use in a http request.
*
- * @return The query string.
+ * @return The query string
*/
@Override
public String toQueryString() {
@@ -41,4 +41,17 @@ public String toQueryString() {
.filter(s -> !s.isEmpty())
.collect(Collectors.joining("&"));
}
+
+ public static class Builder extends de.fraunhofer.iosb.ilt.faaast.service.persistence.SubmodelSearchCriteria.AbstractBuilder {
+ @Override
+ protected Builder getSelf() {
+ return this;
+ }
+
+
+ @Override
+ protected SubmodelSearchCriteria newBuildingInstance() {
+ return new SubmodelSearchCriteria();
+ }
+ }
}
diff --git a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/util/ExceptionHandler.java b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/util/ExceptionHandler.java
deleted file mode 100644
index d92d104..0000000
--- a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/util/ExceptionHandler.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Copyright (c) 2024 Fraunhofer IOSB, eine rechtlich nicht selbstaendige
- * Einrichtung der Fraunhofer-Gesellschaft zur Foerderung der angewandten
- * Forschung e.V.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package de.fraunhofer.iosb.ilt.faaast.client.util;
-
-import de.fraunhofer.iosb.ilt.faaast.client.exception.BadRequestException;
-import de.fraunhofer.iosb.ilt.faaast.client.exception.ForbiddenException;
-import de.fraunhofer.iosb.ilt.faaast.client.exception.NotFoundException;
-import de.fraunhofer.iosb.ilt.faaast.client.exception.UnauthorizedException;
-import de.fraunhofer.iosb.ilt.faaast.client.exception.InternalServerErrorException;
-import de.fraunhofer.iosb.ilt.faaast.client.exception.UnsupportedStatusCodeException;
-import de.fraunhofer.iosb.ilt.faaast.client.exception.MethodNotAllowedException;
-import de.fraunhofer.iosb.ilt.faaast.client.exception.ConflictException;
-import de.fraunhofer.iosb.ilt.faaast.client.exception.StatusCodeException;
-
-import java.net.http.HttpRequest;
-import java.net.http.HttpResponse;
-
-
-public final class ExceptionHandler {
-
- private ExceptionHandler() {}
-
-
- public static StatusCodeException handleException(HttpMethod httpMethod, HttpRequest request, HttpResponse response) {
- return switch (httpMethod) {
- case GET, PUT, PATCH, DELETE -> handleCommonException(request, response);
- case POST -> handlePostException(request, response);
- };
- }
-
-
- private static StatusCodeException handleCommonException(HttpRequest request, HttpResponse response) {
- return switch (response.statusCode()) {
- case 400 -> new BadRequestException(request, response);
- case 401 -> new UnauthorizedException(request, response);
- case 403 -> new ForbiddenException(request, response);
- case 404 -> new NotFoundException(request, response);
- case 500 -> new InternalServerErrorException(request, response);
- default -> throw new UnsupportedStatusCodeException(request, response);
- };
- }
-
-
- private static StatusCodeException handlePostException(HttpRequest request, HttpResponse response) {
- return switch (response.statusCode()) {
- case 400 -> new BadRequestException(request, response);
- case 401 -> new UnauthorizedException(request, response);
- case 403 -> new ForbiddenException(request, response);
- case 404 -> new NotFoundException(request, response);
- case 405 -> new MethodNotAllowedException(request, response);
- case 409 -> new ConflictException(request, response);
- case 500 -> new InternalServerErrorException(request, response);
- default -> throw new UnsupportedStatusCodeException(request, response);
- };
- }
-}
diff --git a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/util/HttpClientUtility.java b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/util/HttpHelper.java
similarity index 82%
rename from core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/util/HttpClientUtility.java
rename to core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/util/HttpHelper.java
index 512d660..7036d1a 100644
--- a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/util/HttpClientUtility.java
+++ b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/util/HttpHelper.java
@@ -14,6 +14,7 @@
*/
package de.fraunhofer.iosb.ilt.faaast.client.util;
+import de.fraunhofer.iosb.ilt.faaast.client.http.HttpMethod;
import de.fraunhofer.iosb.ilt.faaast.client.exception.ConnectivityException;
import java.io.IOException;
@@ -30,18 +31,9 @@
* This class wraps HttpClient and manages request building and sending,
* throwing a ConnectivityException in case of failures during the request.
*/
-public final class HttpClientUtility {
+public final class HttpHelper {
- private final HttpClient httpClient;
-
- /**
- * Constructs a new HttpClientUtility with the given HttpClient.
- *
- * @param httpClient the HttpClient instance to be used for sending requests
- */
- public HttpClientUtility(HttpClient httpClient) {
- this.httpClient = httpClient;
- }
+ private HttpHelper() {}
/**
@@ -50,7 +42,7 @@ public HttpClientUtility(HttpClient httpClient) {
* @param uri the target URI to send the GET request to
* @return the HttpResponse containing the response body as a string
*/
- public HttpRequest createGetRequest(URI uri) {
+ public static HttpRequest createGetRequest(URI uri) {
return HttpRequest.newBuilder().uri(uri).GET().build();
}
@@ -62,7 +54,7 @@ public HttpRequest createGetRequest(URI uri) {
* @param body the request body as a string
* @return the HttpResponse containing the response body as a string
*/
- public HttpRequest createPostRequest(URI uri, String body) {
+ public static HttpRequest createPostRequest(URI uri, String body) {
return HttpRequest.newBuilder()
.uri(uri)
.POST(HttpRequest.BodyPublishers.ofString(body))
@@ -77,7 +69,7 @@ public HttpRequest createPostRequest(URI uri, String body) {
* @param body the request body as a string
* @return the HttpResponse containing the response body as a string
*/
- public HttpRequest createPutRequest(URI uri, String body) {
+ public static HttpRequest createPutRequest(URI uri, String body) {
return HttpRequest.newBuilder()
.uri(uri)
.PUT(HttpRequest.BodyPublishers.ofString(body))
@@ -92,10 +84,10 @@ public HttpRequest createPutRequest(URI uri, String body) {
* @param body the request body as a string
* @return the HttpResponse containing the response body as a string
*/
- public HttpRequest createPatchRequest(URI uri, String body) {
+ public static HttpRequest createPatchRequest(URI uri, String body) {
return HttpRequest.newBuilder()
.uri(uri)
- .method("PATCH", HttpRequest.BodyPublishers.ofString(body))
+ .method(HttpMethod.PATCH.name(), HttpRequest.BodyPublishers.ofString(body))
.build();
}
@@ -106,7 +98,7 @@ public HttpRequest createPatchRequest(URI uri, String body) {
* @param uri the target URI to send the DELETE request to
* @return the HttpResponse containing the response body as a string
*/
- public HttpRequest createDeleteRequest(URI uri) {
+ public static HttpRequest createDeleteRequest(URI uri) {
return HttpRequest.newBuilder().uri(uri).DELETE().build();
}
@@ -116,11 +108,12 @@ public HttpRequest createDeleteRequest(URI uri) {
* Handles any IOException or InterruptedException by throwing
* a ConnectivityException.
*
+ * @param httpClient the client to use
* @param request the HttpRequest to be sent
* @return the HttpResponse containing the response body as a string
* @throws ConnectivityException if a connectivity error occurs during the request
*/
- public HttpResponse send(HttpRequest request) throws ConnectivityException {
+ public static HttpResponse send(HttpClient httpClient, HttpRequest request) throws ConnectivityException {
try {
return httpClient.send(request, HttpResponse.BodyHandlers.ofString());
}
diff --git a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/util/UriBuilder.java b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/util/QueryHelper.java
similarity index 51%
rename from core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/util/UriBuilder.java
rename to core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/util/QueryHelper.java
index 6ac7add..bc7b5a9 100644
--- a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/util/UriBuilder.java
+++ b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/client/util/QueryHelper.java
@@ -21,68 +21,44 @@
import de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.QueryModifier;
import de.fraunhofer.iosb.ilt.faaast.service.model.api.paging.PagingInfo;
import de.fraunhofer.iosb.ilt.faaast.service.util.EncodingHelper;
-import java.net.URI;
+import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;
-/**
- * Utility class for building the URIs used in HTTP requests.
- * Provides methods build uris from various combinations of input parameters.
- */
-public final class UriBuilder {
- URI serviceUri;
+public class QueryHelper {
+ private QueryHelper() {
- /**
- * Constructs a new UriBuilder with the given uri.
- *
- * @param uri the base uri of the AAS Server.
- */
- public UriBuilder(URI uri) {
- this.serviceUri = uri;
- }
-
-
- /**
- * Creates an uri using the base path of the request.
- *
- * @param path the base path.
- * @return the uri to use in an http request.
- */
- public URI getUri(String path) {
- return serviceUri.resolve(path);
}
/**
* Creates a uri using the query various query modifiers.
*
- * @param path the base path.
- * @param content the content modifier specifies the server responds: normal, metadata, path, reference or value only.
- * @param modifier The query modifier specifies the structural depth and resource serialization of the submodel.
- * @return the uri to use in an http request.
+ * @param path the base path
+ * @param content the content modifier specifies the server responds: normal, metadata, path, reference or value only
+ * @param modifier The query modifier specifies the structural depth and resource serialization of the submodel
+ * @return the uri to use in an http request
*/
- public URI getUri(String path, Content content, QueryModifier modifier) {
- String sb = path + serializeContentModifier(content) +
- serializeParameters(modifier);
- return serviceUri.resolve(sb);
+ public static String apply(String path, Content content, QueryModifier modifier) {
+ return apply(path, content, modifier, PagingInfo.ALL, SearchCriteria.DEFAULT);
}
/**
* Creates a uri using various query modifiers, paging and search criteria.
*
- * @param path The base path.
- * @param content The content modifier specifies the server responds: normal, metadata, path, reference or value only.
- * @param modifier The query modifier specifies the structural depth and resource serialization of the submodel.
- * @param pagingInfo Metadata for controlling the pagination of results.
- * @param searchCriteria Search criteria to filter identifiables based on specific criteria.
- * @return the uri to use in an http request.
+ * @param path The base path
+ * @param content The content modifier specifies the server responds: normal, metadata, path, reference or value only
+ * @param modifier The query modifier specifies the structural depth and resource serialization of the submodel
+ * @param pagingInfo Metadata for controlling the pagination of results
+ * @param searchCriteria Search criteria to filter identifiables based on specific criteria
+ * @return the uri to use in an http request
*/
- public URI getUri(String path, Content content, QueryModifier modifier, PagingInfo pagingInfo, SearchCriteria searchCriteria) {
- String sb = path + serializeContentModifier(content) +
- serializeParameters(modifier, pagingInfo, searchCriteria);
- return serviceUri.resolve(sb);
+ public static String apply(String path, Content content, QueryModifier modifier, PagingInfo pagingInfo, SearchCriteria searchCriteria) {
+ String result = Objects.nonNull(path) ? path : "";
+ result += serializeContentModifier(content) + serializeParameters(modifier, pagingInfo, searchCriteria);
+ return result;
}
@@ -90,31 +66,26 @@ private static String serializeContentModifier(Content contentModifier) {
if (contentModifier.equals(Content.DEFAULT)) {
return "";
}
- return String.format("$%s", contentModifier.name().toLowerCase());
- }
-
-
- private static String serializeParameters(QueryModifier queryModifier) {
- return serializeParameters(queryModifier, PagingInfo.ALL, SearchCriteria.DEFAULT);
+ return String.format("/$%s", contentModifier.name().toLowerCase());
}
private static String serializeParameters(QueryModifier queryModifier, PagingInfo pagingInfo, SearchCriteria searchCriteria) {
- String levelString = queryModifier.getLevel() == Level.DEFAULT ? ""
- : "level=" + queryModifier.getLevel().name().toLowerCase();
- String extentString = queryModifier.getExtent() == Extent.DEFAULT ? ""
- : "extent=" + queryModifier.getExtent().name().toLowerCase();
- String limitString = pagingInfo.getLimit() == PagingInfo.DEFAULT_LIMIT ? ""
- : String.format("%s=%d", "limit", pagingInfo.getLimit());
- String cursorString = pagingInfo.getCursor() == null ? ""
- : "cursor=" + EncodingHelper.base64UrlEncode(pagingInfo.getCursor());
- String searchCriteriaString = searchCriteria == SearchCriteria.DEFAULT ? ""
- : searchCriteria.toQueryString();
-
- String serializedParameters = Stream.of(levelString, extentString, limitString, cursorString, searchCriteriaString)
+ String levelString = queryModifier.getLevel() == Level.DEFAULT
+ ? ""
+ : String.format("level=%s", queryModifier.getLevel().name().toLowerCase());
+ String extentString = queryModifier.getExtent() == Extent.DEFAULT
+ ? ""
+ : String.format("extent=%s", queryModifier.getExtent().name().toLowerCase());
+ String limitString = pagingInfo.getLimit() == PagingInfo.DEFAULT_LIMIT
+ ? ""
+ : String.format("limit=%d", pagingInfo.getLimit());
+ String cursorString = pagingInfo.getCursor() == null
+ ? ""
+ : String.format("cursor=%s", EncodingHelper.base64UrlEncode(pagingInfo.getCursor()));
+ String serializedParameters = Stream.of(levelString, extentString, limitString, cursorString, searchCriteria.toQueryString())
.filter(s -> !s.isEmpty())
.collect(Collectors.joining("&"));
-
return serializedParameters.isEmpty() ? "" : "?" + serializedParameters;
}
}
diff --git a/core/src/test/java/de/fraunhofer/iosb/ilt/faaast/client/interfaces/AASInterfaceTest.java b/core/src/test/java/de/fraunhofer/iosb/ilt/faaast/client/interfaces/AASInterfaceTest.java
index 9b1ce12..8957325 100644
--- a/core/src/test/java/de/fraunhofer/iosb/ilt/faaast/client/interfaces/AASInterfaceTest.java
+++ b/core/src/test/java/de/fraunhofer/iosb/ilt/faaast/client/interfaces/AASInterfaceTest.java
@@ -37,7 +37,7 @@
public class AASInterfaceTest {
- private AASInterface AASInterface;
+ private AASInterface aasInterface;
private ApiSerializer serializer;
private MockWebServer server;
@@ -45,11 +45,11 @@ public class AASInterfaceTest {
public void setup() throws IOException {
server = new MockWebServer();
server.start();
- URI serviceUri = server.url("api/v3.0/aas/").uri();
+ URI serviceUri = server.url("api/v3.0/aas").uri();
serializer = new JsonApiSerializer();
- AASInterface = new AASInterface(serviceUri);
+ aasInterface = new AASInterface(serviceUri);
}
@@ -60,12 +60,12 @@ public void testGetAssetAdministrationShell() throws SerializationException, Int
String serializedAas = serializer.write(requestAas);
server.enqueue(new MockResponse().setBody(serializedAas));
- AssetAdministrationShell responseAas = AASInterface.get();
+ AssetAdministrationShell responseAas = aasInterface.get();
RecordedRequest request = server.takeRequest();
assertEquals("GET", request.getMethod());
assertEquals(0, request.getBodySize());
- assertEquals("/api/v3.0/aas/", request.getPath());
+ assertEquals("/api/v3.0/aas", request.getPath());
assertEquals(requestAas, responseAas);
}
@@ -75,14 +75,14 @@ public void testPutAssetAdministrationShell() throws SerializationException, Int
AssetAdministrationShell requestAas = new DefaultAssetAdministrationShell();
String serializedAas = serializer.write(requestAas);
- server.enqueue(new MockResponse().setBody(serializedAas));
- AASInterface.put(requestAas);
+ server.enqueue(new MockResponse().setResponseCode(204));
+ aasInterface.put(requestAas);
RecordedRequest request = server.takeRequest();
assertEquals("PUT", request.getMethod());
assertEquals(serializedAas, request.getBody().readUtf8());
- assertEquals("/api/v3.0/aas/", request.getPath());
+ assertEquals("/api/v3.0/aas", request.getPath());
}
@@ -96,7 +96,7 @@ public void testGetAssetAdministrationShellAsReference() throws SerializationExc
String serializedAasReference = serializer.write(requestAasReference);
server.enqueue(new MockResponse().setBody(serializedAasReference));
- Reference responseAasReference = AASInterface.getAsReference();
+ Reference responseAasReference = aasInterface.getAsReference();
RecordedRequest request = server.takeRequest();
assertEquals("GET", request.getMethod());
@@ -111,12 +111,12 @@ public void testGetAssetInformation() throws SerializationException, Interrupted
AssetInformation requestAssetInformation = new DefaultAssetInformation();
server.enqueue(new MockResponse().setBody(serializer.write(requestAssetInformation)));
- AssetInformation responseAssetInformation = AASInterface.getAssetInformation();
+ AssetInformation responseAssetInformation = aasInterface.getAssetInformation();
RecordedRequest request = server.takeRequest();
assertEquals("GET", request.getMethod());
assertEquals(0, request.getBodySize());
- assertEquals("/api/v3.0/aas/asset-information/", request.getPath());
+ assertEquals("/api/v3.0/aas/asset-information", request.getPath());
assertEquals(requestAssetInformation, responseAssetInformation);
}
@@ -125,14 +125,14 @@ public void testGetAssetInformation() throws SerializationException, Interrupted
public void testPutAssetInformation() throws SerializationException, InterruptedException, ClientException, UnsupportedModifierException {
AssetInformation requestAssetInformation = new DefaultAssetInformation();
String serializedAssetInfo = serializer.write(requestAssetInformation);
- server.enqueue(new MockResponse().setBody(serializedAssetInfo));
+ server.enqueue(new MockResponse().setResponseCode(204));
- AASInterface.putAssetInformation(requestAssetInformation);
+ aasInterface.putAssetInformation(requestAssetInformation);
RecordedRequest request = server.takeRequest();
assertEquals("PUT", request.getMethod());
assertEquals(serializedAssetInfo, request.getBody().readUtf8());
- assertEquals("/api/v3.0/aas/asset-information/", request.getPath());
+ assertEquals("/api/v3.0/aas/asset-information", request.getPath());
}
@@ -146,13 +146,13 @@ public void testGetThumbnail() throws InterruptedException, SerializationExcepti
server.enqueue(new MockResponse().setBody(serializer.write(requestThumbnail)));
- Resource responseThumbnail = AASInterface.getThumbnail();
+ Resource responseThumbnail = aasInterface.getThumbnail();
RecordedRequest request = server.takeRequest();
assertEquals("GET", request.getMethod());
assertEquals(0, request.getBodySize());
- assertEquals("/api/v3.0/aas/asset-information/thumbnail/", request.getPath());
+ assertEquals("/api/v3.0/aas/asset-information/thumbnail", request.getPath());
assertEquals(requestThumbnail, responseThumbnail);
}
@@ -165,9 +165,9 @@ public void testPutThumbnail() throws InterruptedException, SerializationExcepti
assetInformation.setDefaultThumbnail(requestThumbnail);
requestAas.setAssetInformation(assetInformation);
- server.enqueue(new MockResponse().setBody(serializer.write(requestThumbnail)));
+ server.enqueue(new MockResponse().setResponseCode(204));
- AASInterface.putThumbnail(requestThumbnail);
+ aasInterface.putThumbnail(requestThumbnail);
RecordedRequest request = server.takeRequest();
@@ -175,27 +175,27 @@ public void testPutThumbnail() throws InterruptedException, SerializationExcepti
assertEquals("PUT", request.getMethod());
assertEquals(serializedThumbnail, request.getBody().readUtf8());
- assertEquals("/api/v3.0/aas/asset-information/thumbnail/", request.getPath());
+ assertEquals("/api/v3.0/aas/asset-information/thumbnail", request.getPath());
}
@Test
- public void testDeleteThumbnail() throws InterruptedException, SerializationException, ClientException, UnsupportedModifierException {
+ public void testDeleteThumbnail() throws InterruptedException, ClientException {
AssetAdministrationShell requestAas = new DefaultAssetAdministrationShell();
Resource requestThumbnail = new DefaultResource();
AssetInformation assetInformation = new DefaultAssetInformation();
assetInformation.setDefaultThumbnail(requestThumbnail);
requestAas.setAssetInformation(assetInformation);
- server.enqueue(new MockResponse().setBody(serializer.write(requestThumbnail)));
+ server.enqueue(new MockResponse().setResponseCode(200));
- AASInterface.deleteThumbnail();
+ aasInterface.deleteThumbnail();
RecordedRequest request = server.takeRequest();
assertEquals("DELETE", request.getMethod());
assertEquals(0, request.getBodySize());
- assertEquals("/api/v3.0/aas/asset-information/thumbnail/", request.getPath());
+ assertEquals("/api/v3.0/aas/asset-information/thumbnail", request.getPath());
}
@@ -205,12 +205,12 @@ public void testGetAllSubmodelReferences() throws SerializationException, Interr
requestSubmodelReferenceList.add(new DefaultReference());
server.enqueue(new MockResponse().setBody(serializer.write(requestSubmodelReferenceList)));
- List responseList = AASInterface.getAllSubmodelReferences();
+ List responseList = aasInterface.getAllSubmodelReferences();
RecordedRequest request = server.takeRequest();
assertEquals("GET", request.getMethod());
assertEquals(0, request.getBodySize());
- assertEquals("/api/v3.0/aas/submodel-refs/", request.getPath());
+ assertEquals("/api/v3.0/aas/submodel-refs", request.getPath());
assertEquals(requestSubmodelReferenceList, responseList);
}
@@ -219,28 +219,29 @@ public void testGetAllSubmodelReferences() throws SerializationException, Interr
@Test
public void testPostSubmodelReference() throws SerializationException, InterruptedException, ClientException, UnsupportedModifierException {
Reference requestSubmodelReference = new DefaultReference();
- server.enqueue(new MockResponse().setBody(serializer.write(requestSubmodelReference)));
+ server.enqueue(new MockResponse()
+ .setResponseCode(201)
+ .setBody(serializer.write(requestSubmodelReference)));
- Reference responseSubmodelReference = AASInterface.postSubmodelReference(requestSubmodelReference);
+ Reference responseSubmodelReference = aasInterface.postSubmodelReference(requestSubmodelReference);
RecordedRequest request = server.takeRequest();
assertEquals("POST", request.getMethod());
- assertEquals("/api/v3.0/aas/submodel-refs/", request.getPath());
+ assertEquals("/api/v3.0/aas/submodel-refs", request.getPath());
assertEquals(requestSubmodelReference, responseSubmodelReference);
}
@Test
- public void testDeleteSubmodelReference() throws SerializationException, InterruptedException, ClientException, UnsupportedModifierException {
- Reference requestSubmodelReference = new DefaultReference();
- server.enqueue(new MockResponse().setBody(serializer.write(requestSubmodelReference)));
+ public void testDeleteSubmodelReference() throws InterruptedException, ClientException {
+ server.enqueue(new MockResponse().setResponseCode(204));
String requestSubmodelId = Base64.getUrlEncoder().encodeToString("submodelId".getBytes());
- AASInterface.deleteSubmodelReference(requestSubmodelId);
+ aasInterface.deleteSubmodelReference(requestSubmodelId);
RecordedRequest request = server.takeRequest();
assertEquals("DELETE", request.getMethod());
assertEquals(0, request.getBodySize());
- assertEquals("/api/v3.0/aas/submodel-refs/" + requestSubmodelId, request.getPath());
+ assertEquals("/api/v3.0/aas/submodel-refs" + requestSubmodelId, request.getPath());
}
}
diff --git a/core/src/test/java/de/fraunhofer/iosb/ilt/faaast/client/interfaces/AASRegistryInterfaceTest.java b/core/src/test/java/de/fraunhofer/iosb/ilt/faaast/client/interfaces/AASRegistryInterfaceTest.java
index bec281a..4832d27 100644
--- a/core/src/test/java/de/fraunhofer/iosb/ilt/faaast/client/interfaces/AASRegistryInterfaceTest.java
+++ b/core/src/test/java/de/fraunhofer/iosb/ilt/faaast/client/interfaces/AASRegistryInterfaceTest.java
@@ -19,12 +19,12 @@
import de.fraunhofer.iosb.ilt.faaast.service.dataformat.SerializationException;
import de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.JsonApiSerializer;
import de.fraunhofer.iosb.ilt.faaast.service.model.exception.UnsupportedModifierException;
+import de.fraunhofer.iosb.ilt.faaast.service.util.EncodingHelper;
import org.eclipse.digitaltwin.aas4j.v3.model.AssetAdministrationShellDescriptor;
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultAssetAdministrationShellDescriptor;
import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
-import java.util.Base64;
import java.util.List;
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
@@ -47,7 +47,7 @@ public class AASRegistryInterfaceTest {
public void setup() throws IOException {
server = new MockWebServer();
server.start();
- URI serviceUri = server.url("/example.com/api/v3.0").uri();
+ URI serviceUri = server.url("/example/api/v3.0").uri();
assetAdministrationShellRegistryInterface = new AASRegistryInterface(serviceUri);
serializer = new JsonApiSerializer();
@@ -78,7 +78,7 @@ public void testGetAllAssetAdministrationShellDescriptors() throws ClientExcepti
assertEquals("GET", request.getMethod());
assertEquals(0, request.getBodySize());
- assertEquals("/example.com/api/v3.0/shell-descriptors/", request.getPath());
+ assertEquals("/example/api/v3.0/shell-descriptors", request.getPath());
assertEquals(requestShellDescriptors, responseShellDescriptors);
}
@@ -90,7 +90,9 @@ public void testPost() throws SerializationException, ClientException, Interrupt
requestShellDescriptor.setId(requestAasIdentifier);
String serializedShellDescriptors = serializer.write(requestShellDescriptor);
- server.enqueue(new MockResponse().setBody(serializedShellDescriptors));
+ server.enqueue(new MockResponse()
+ .setResponseCode(201)
+ .setBody(serializedShellDescriptors));
AssetAdministrationShellDescriptor returnShellDescriptor = assetAdministrationShellRegistryInterface.post(requestShellDescriptor);
@@ -98,8 +100,7 @@ public void testPost() throws SerializationException, ClientException, Interrupt
assertEquals("POST", request.getMethod());
assertEquals(requestShellDescriptor, returnShellDescriptor);
- assertEquals("/example.com/api/v3.0/shell-descriptors/" +
- Base64.getUrlEncoder().encodeToString(requestAasIdentifier.getBytes()) + "/", request.getPath());
+ assertEquals("/example/api/v3.0/shell-descriptors/" + EncodingHelper.base64UrlEncode(requestAasIdentifier), request.getPath());
}
@@ -118,8 +119,7 @@ public void testGet() throws SerializationException, ClientException, Interrupte
assertEquals("GET", request.getMethod());
assertEquals(0, request.getBodySize());
- assertEquals("/example.com/api/v3.0/shell-descriptors/" +
- Base64.getUrlEncoder().encodeToString(requestAasIdentifier.getBytes()) + "/", request.getPath());
+ assertEquals("/example/api/v3.0/shell-descriptors/" + EncodingHelper.base64UrlEncode(requestAasIdentifier), request.getPath());
assertEquals(requestShellDescriptor, responseShellDescriptor);
}
@@ -131,7 +131,7 @@ public void testPut() throws ClientException, SerializationException, Interrupte
requestShellDescriptor.setId(requestAasId);
String serializedShellDescriptors = serializer.write(requestShellDescriptor);
- server.enqueue(new MockResponse().setBody(serializedShellDescriptors));
+ server.enqueue(new MockResponse().setResponseCode(204));
assetAdministrationShellRegistryInterface.put(requestAasId, requestShellDescriptor);
@@ -139,27 +139,23 @@ public void testPut() throws ClientException, SerializationException, Interrupte
assertEquals("PUT", request.getMethod());
assertEquals(serializedShellDescriptors, request.getBody().readUtf8());
- assertEquals("/example.com/api/v3.0/shell-descriptors/" +
- Base64.getUrlEncoder().encodeToString(requestAasId.getBytes()) + "/", request.getPath());
+ assertEquals("/example/api/v3.0/shell-descriptors/" + EncodingHelper.base64UrlEncode(requestAasId), request.getPath());
}
@Test
- public void testDelete() throws SerializationException, ClientException, InterruptedException, UnsupportedModifierException {
+ public void testDelete() throws ClientException, InterruptedException {
AssetAdministrationShellDescriptor requestShellDescriptor = new DefaultAssetAdministrationShellDescriptor();
String requestAasIdentifier = "DefaultId";
requestShellDescriptor.setId(requestAasIdentifier);
- String serializedShellDescriptors = serializer.write(requestShellDescriptor);
- server.enqueue(new MockResponse().setBody(serializedShellDescriptors));
+ server.enqueue(new MockResponse().setResponseCode(204));
assetAdministrationShellRegistryInterface.delete(requestAasIdentifier);
-
RecordedRequest request = server.takeRequest();
assertEquals("DELETE", request.getMethod());
assertEquals(0, request.getBody().size());
- assertEquals("/example.com/api/v3.0/shell-descriptors/" +
- Base64.getUrlEncoder().encodeToString(requestAasIdentifier.getBytes()) + "/", request.getPath());
+ assertEquals("/example/api/v3.0/shell-descriptors/" + EncodingHelper.base64UrlEncode(requestAasIdentifier), request.getPath());
}
}
diff --git a/core/src/test/java/de/fraunhofer/iosb/ilt/faaast/client/interfaces/AASRepositoryInterfaceTest.java b/core/src/test/java/de/fraunhofer/iosb/ilt/faaast/client/interfaces/AASRepositoryInterfaceTest.java
index e616734..0f07cf8 100644
--- a/core/src/test/java/de/fraunhofer/iosb/ilt/faaast/client/interfaces/AASRepositoryInterfaceTest.java
+++ b/core/src/test/java/de/fraunhofer/iosb/ilt/faaast/client/interfaces/AASRepositoryInterfaceTest.java
@@ -26,7 +26,6 @@
import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
-import java.util.Base64;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -59,7 +58,7 @@
public class AASRepositoryInterfaceTest {
- private static AASRepositoryInterface AASRepositoryInterface;
+ private static AASRepositoryInterface aasRepositoryInterface;
private static ApiSerializer serializer;
private static MockWebServer server;
private static List requestAssetAdministrationShellList;
@@ -69,8 +68,8 @@ public void setup() throws IOException {
server = new MockWebServer();
server.requireClientAuth();
server.start();
- URI serviceUri = server.url("/example.com/api/v3.0").uri();
- AASRepositoryInterface = new AASRepositoryInterface(serviceUri);
+ URI serviceUri = server.url("/example/api/v3.0").uri();
+ aasRepositoryInterface = new AASRepositoryInterface(serviceUri);
serializer = new JsonApiSerializer();
requestAssetAdministrationShellList = new ArrayList<>();
@@ -85,7 +84,7 @@ private static AssetAdministrationShell getRequestAssetAdministrationShell(Strin
AssetAdministrationShell requestAssetAdministrationShell = new DefaultAssetAdministrationShell.Builder().build();
requestAssetAdministrationShell.setIdShort(idShort);
requestAssetAdministrationShell.setId(idShort);
- String requestGlobalAssetId = Base64.getUrlEncoder().encodeToString(globalAssetId.getBytes()) + "/";
+ String requestGlobalAssetId = EncodingHelper.base64UrlEncode(globalAssetId);
AssetInformation requestAssetInformation = new DefaultAssetInformation.Builder()
.globalAssetId(requestGlobalAssetId).build();
requestAssetAdministrationShell.setAssetInformation(requestAssetInformation);
@@ -103,7 +102,7 @@ public void testGetAASPage() throws SerializationException, InterruptedException
String serializedAasPage = serializer.write(aasPage);
server.enqueue(new MockResponse().setBody(serializedAasPage));
- Page responseAssetAdministrationShellPage = AASRepositoryInterface.get(
+ Page responseAssetAdministrationShellPage = aasRepositoryInterface.get(
new PagingInfo.Builder()
.limit(1)
.build());
@@ -111,7 +110,7 @@ public void testGetAASPage() throws SerializationException, InterruptedException
assertEquals("GET", request.getMethod());
assertEquals(0, request.getBodySize());
- assertEquals("/example.com/api/v3.0/shells/?limit=1", request.getPath());
+ assertEquals("/example/api/v3.0/shells/?limit=1", request.getPath());
assertEquals("1", responseAssetAdministrationShellPage.getMetadata().getCursor());
}
@@ -127,7 +126,7 @@ public void testGetAllAssetAdministrationShellsWithPagingWithSearchCriteria()
List assetIdentificationList = createAssetIdentificationList();
List serializedAssetIdentificationList = serializeAssetIdentificationList(assetIdentificationList);
- Page responseAssetAdministrationShellPage = AASRepositoryInterface.get(
+ Page responseAssetAdministrationShellPage = aasRepositoryInterface.get(
new PagingInfo.Builder()
.cursor("1")
.limit(1)
@@ -196,15 +195,17 @@ private List extractAssetIdsfromUrl(RecordedRequest request) {
public void postAssetAdministrationShell() throws SerializationException, InterruptedException, ClientException, UnsupportedModifierException {
AssetAdministrationShell requestAssetAdministrationShell = requestAssetAdministrationShellList.get(0);
String serializedAas = serializer.write(requestAssetAdministrationShell);
- server.enqueue(new MockResponse().setBody(serializedAas));
+ server.enqueue(new MockResponse()
+ .setResponseCode(201)
+ .setBody(serializedAas));
- AssetAdministrationShell responseAssetAdministrationShell = AASRepositoryInterface.post(
+ AssetAdministrationShell responseAssetAdministrationShell = aasRepositoryInterface.post(
requestAssetAdministrationShell);
RecordedRequest request = server.takeRequest();
assertEquals("POST", request.getMethod());
assertEquals(requestAssetAdministrationShell, responseAssetAdministrationShell);
- assertEquals("/example.com/api/v3.0/shells/", request.getPath());
+ assertEquals("/example/api/v3.0/shells", request.getPath());
}
@@ -216,30 +217,28 @@ public void testGetAllAssetAdministrationShellsAsReference() throws Serializatio
String serializedAasReferenceList = serializer.write(requestAasReferenceList);
server.enqueue(new MockResponse().setBody(serializedAasReferenceList));
- List responseAasReferenceList = AASRepositoryInterface.getAllAsReference();
+ List responseAasReferenceList = aasRepositoryInterface.getAllAsReference();
RecordedRequest request = server.takeRequest();
assertEquals("GET", request.getMethod());
assertEquals(0, request.getBodySize());
- assertEquals("/example.com/api/v3.0/shells/$reference", request.getPath());
+ assertEquals("/example/api/v3.0/shells/$reference", request.getPath());
assertEquals(responseAasReferenceList, requestAasReferenceList);
}
@Test
- public void delete() throws SerializationException, InterruptedException, ClientException, UnsupportedModifierException {
+ public void delete() throws InterruptedException, ClientException {
AssetAdministrationShell requestAssetAdministrationShell = requestAssetAdministrationShellList.get(0);
- String serializedAas = serializer.write(requestAssetAdministrationShell);
String requestAasIdentifier = requestAssetAdministrationShell.getId();
- server.enqueue(new MockResponse().setBody(serializedAas));
+ server.enqueue(new MockResponse().setResponseCode(204));
- AASRepositoryInterface.delete(requestAasIdentifier);
+ aasRepositoryInterface.delete(requestAasIdentifier);
RecordedRequest request = server.takeRequest();
assertEquals("DELETE", request.getMethod());
assertEquals(0, request.getBodySize());
- assertEquals("/example.com/api/v3.0/shells/" +
- Base64.getUrlEncoder().encodeToString(requestAasIdentifier.getBytes()) + "/", request.getPath());
+ assertEquals("/example/api/v3.0/shells/" + EncodingHelper.base64UrlEncode(requestAasIdentifier), request.getPath());
}
@@ -250,12 +249,12 @@ public void testGetAssetAdministrationShell() throws SerializationException, Int
String serializedAas = serializer.write(requestAas);
server.enqueue(new MockResponse().setBody(serializedAas));
- AssetAdministrationShell responseAas = AASRepositoryInterface.getAASInterface(requestAas.getId()).get();
+ AssetAdministrationShell responseAas = aasRepositoryInterface.getAASInterface(requestAas.getId()).get();
RecordedRequest request = server.takeRequest();
assertEquals("GET", request.getMethod());
assertEquals(0, request.getBodySize());
- assertEquals("/example.com/api/v3.0/shells/" + Base64.getUrlEncoder().encodeToString(requestAas.getId().getBytes()) + "/", request.getPath());
+ assertEquals("/example/api/v3.0/shells/" + EncodingHelper.base64UrlEncode(requestAas.getId()), request.getPath());
assertEquals(requestAas, responseAas);
}
}
diff --git a/core/src/test/java/de/fraunhofer/iosb/ilt/faaast/client/interfaces/ConceptDescriptionRepositoryInterfaceTest.java b/core/src/test/java/de/fraunhofer/iosb/ilt/faaast/client/interfaces/ConceptDescriptionRepositoryInterfaceTest.java
index 723279a..a120c1c 100644
--- a/core/src/test/java/de/fraunhofer/iosb/ilt/faaast/client/interfaces/ConceptDescriptionRepositoryInterfaceTest.java
+++ b/core/src/test/java/de/fraunhofer/iosb/ilt/faaast/client/interfaces/ConceptDescriptionRepositoryInterfaceTest.java
@@ -22,7 +22,6 @@
import de.fraunhofer.iosb.ilt.faaast.service.util.EncodingHelper;
import java.io.IOException;
import java.util.ArrayList;
-import java.util.Base64;
import java.util.List;
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
@@ -63,7 +62,7 @@ public void testGetAll() throws SerializationException, InterruptedException, Cl
assertEquals("GET", request.getMethod());
assertEquals(0, request.getBodySize());
- assertEquals("/api/v3.0/concept-descriptions/", request.getPath());
+ assertEquals("/api/v3.0/concept-descriptions", request.getPath());
assertEquals(requestConceptDescriptions, responseServiceDescription);
}
@@ -75,14 +74,16 @@ public void testPost() throws SerializationException, InterruptedException, Clie
requestConceptDescription.setId(cdIdentifier);
String serializedConceptDescription = serializer.write(requestConceptDescription);
- server.enqueue(new MockResponse().setBody(serializedConceptDescription));
+ server.enqueue(new MockResponse()
+ .setResponseCode(201)
+ .setBody(serializedConceptDescription));
ConceptDescription returnConceptDescription = conceptDescriptionRepositoryInterface.post(requestConceptDescription);
RecordedRequest request = server.takeRequest();
assertEquals("POST", request.getMethod());
assertEquals(requestConceptDescription, returnConceptDescription);
- assertEquals("/api/v3.0/concept-descriptions/", request.getPath());
+ assertEquals("/api/v3.0/concept-descriptions", request.getPath());
}
@@ -100,8 +101,7 @@ public void testGetById() throws SerializationException, InterruptedException, C
assertEquals("GET", request.getMethod());
assertEquals(0, request.getBodySize());
- assertEquals("/api/v3.0/concept-descriptions/" +
- Base64.getUrlEncoder().encodeToString(cdIdentifier.getBytes()) + "/", request.getPath());
+ assertEquals("/api/v3.0/concept-descriptions/" + EncodingHelper.base64UrlEncode(cdIdentifier), request.getPath());
assertEquals(requestConceptDescription, responseServiceDescription);
}
@@ -113,33 +113,30 @@ public void testPut() throws SerializationException, InterruptedException, Clien
requestConceptDescription.setId(cdIdentifier);
String serializedConceptDescription = serializer.write(requestConceptDescription);
- server.enqueue(new MockResponse().setBody(serializedConceptDescription));
+ server.enqueue(new MockResponse().setResponseCode(204));
conceptDescriptionRepositoryInterface.put(requestConceptDescription, cdIdentifier);
RecordedRequest request = server.takeRequest();
assertEquals("PUT", request.getMethod());
assertEquals(serializedConceptDescription, request.getBody().readUtf8());
- assertEquals("/api/v3.0/concept-descriptions/" +
- Base64.getUrlEncoder().encodeToString(cdIdentifier.getBytes()) + "/", request.getPath());
+ assertEquals("/api/v3.0/concept-descriptions/" + EncodingHelper.base64UrlEncode(cdIdentifier), request.getPath());
}
@Test
- public void testDelete() throws SerializationException, InterruptedException, ClientException, UnsupportedModifierException {
+ public void testDelete() throws InterruptedException, ClientException {
ConceptDescription requestConceptDescription = new DefaultConceptDescription();
String cdIdentifier = "cdIdentifier";
requestConceptDescription.setId(cdIdentifier);
- String serializedConceptDescription = serializer.write(requestConceptDescription);
- server.enqueue(new MockResponse().setBody(serializedConceptDescription));
+ server.enqueue(new MockResponse().setResponseCode(204));
conceptDescriptionRepositoryInterface.delete(requestConceptDescription.getId());
RecordedRequest request = server.takeRequest();
assertEquals("DELETE", request.getMethod());
assertEquals(0, request.getBodySize());
- assertEquals("/api/v3.0/concept-descriptions/" +
- Base64.getUrlEncoder().encodeToString(cdIdentifier.getBytes()) + "/", request.getPath());
+ assertEquals("/api/v3.0/concept-descriptions/" + EncodingHelper.base64UrlEncode(cdIdentifier), request.getPath());
}
}
diff --git a/core/src/test/java/de/fraunhofer/iosb/ilt/faaast/client/interfaces/ExceptionHandlingTest.java b/core/src/test/java/de/fraunhofer/iosb/ilt/faaast/client/interfaces/ExceptionHandlingTest.java
index 73f530a..577233a 100644
--- a/core/src/test/java/de/fraunhofer/iosb/ilt/faaast/client/interfaces/ExceptionHandlingTest.java
+++ b/core/src/test/java/de/fraunhofer/iosb/ilt/faaast/client/interfaces/ExceptionHandlingTest.java
@@ -67,7 +67,6 @@ public void testPostConflictException() {
assertThrows(ConflictException.class, () -> {
submodelRepositoryInterface.post(new DefaultSubmodel.Builder().id("id").build());
});
- // Nullpointer Exception if id is not set
}
diff --git a/core/src/test/java/de/fraunhofer/iosb/ilt/faaast/client/interfaces/SubmodelInterfaceTest.java b/core/src/test/java/de/fraunhofer/iosb/ilt/faaast/client/interfaces/SubmodelInterfaceTest.java
index 4bd2c98..60fdc6f 100644
--- a/core/src/test/java/de/fraunhofer/iosb/ilt/faaast/client/interfaces/SubmodelInterfaceTest.java
+++ b/core/src/test/java/de/fraunhofer/iosb/ilt/faaast/client/interfaces/SubmodelInterfaceTest.java
@@ -23,11 +23,11 @@
import de.fraunhofer.iosb.ilt.faaast.service.model.value.Datatype;
import de.fraunhofer.iosb.ilt.faaast.service.model.value.PropertyValue;
import de.fraunhofer.iosb.ilt.faaast.service.typing.ElementValueTypeInfo;
+import de.fraunhofer.iosb.ilt.faaast.service.util.EncodingHelper;
import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
-import java.util.Base64;
import java.util.List;
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
@@ -55,7 +55,7 @@ public class SubmodelInterfaceTest {
public void setup() throws IOException {
server = new MockWebServer();
server.start();
- URI serviceUri = server.url("api/v3.0/submodel/").uri();
+ URI serviceUri = server.url("api/v3.0/submodel").uri();
submodelInterface = new SubmodelInterface(serviceUri);
serializer = new JsonApiSerializer();
@@ -84,40 +84,12 @@ private static List getElements() {
private static void instantiateSubmodel() {
requestSubmodel = new DefaultSubmodel();
String requestSubmodelIdShort = "idShort";
- String requestSubmodelId = Base64.getUrlEncoder().encodeToString(requestSubmodelIdShort.getBytes());
+ String requestSubmodelId = EncodingHelper.base64UrlEncode(requestSubmodelIdShort);
requestSubmodel.setId(requestSubmodelId);
requestSubmodel.setSubmodelElements(getElements());
}
- @NotNull
- private static OperationResult getOperationResult() {
- OperationResult requestOperationResult = new DefaultOperationResult();
-
- OperationVariable requestOutputArgument = new DefaultOperationVariable();
- List requestOutputArgumentList = new ArrayList<>();
- requestOutputArgumentList.add(requestOutputArgument);
- requestOperationResult.setOutputArguments(requestOutputArgumentList);
-
- OperationVariable requestInoutputArgument = new DefaultOperationVariable();
- List requestInoutputArgumentList = new ArrayList<>();
- requestOutputArgumentList.add(requestInoutputArgument);
- requestOperationResult.setInoutputArguments(requestInoutputArgumentList);
-
- requestOperationResult.setExecutionState(ExecutionState.INITIATED);
-
- return requestOperationResult;
- }
-
-
- @NotNull
- private static OperationHandle getOperationHandle() {
- OperationHandle requestOperationHandle = new DefaultOperationHandle();
- requestOperationHandle.setHandleId("handleId");
- return requestOperationHandle;
- }
-
-
@Test
public void testGetDefault() throws SerializationException, InterruptedException, ClientException, UnsupportedModifierException {
String serializedSubmodel = serializer.write(requestSubmodel);
@@ -128,7 +100,7 @@ public void testGetDefault() throws SerializationException, InterruptedException
assertEquals("GET", request.getMethod());
assertEquals(0, request.getBodySize());
- assertEquals("/api/v3.0/submodel/", request.getPath());
+ assertEquals("/api/v3.0/submodel", request.getPath());
assertEquals(requestSubmodel, responseSubmodel);
}
@@ -136,20 +108,20 @@ public void testGetDefault() throws SerializationException, InterruptedException
@Test
public void testPut() throws SerializationException, InterruptedException, ClientException, UnsupportedModifierException {
String serializedSubmodel = serializer.write(requestSubmodel);
- server.enqueue(new MockResponse().setBody(serializedSubmodel));
+ server.enqueue(new MockResponse().setResponseCode(204));
submodelInterface.put(requestSubmodel);
RecordedRequest request = server.takeRequest();
assertEquals("PUT", request.getMethod());
assertEquals(serializedSubmodel, request.getBody().readUtf8());
- assertEquals("/api/v3.0/submodel/", request.getPath());
+ assertEquals("/api/v3.0/submodel", request.getPath());
}
@Test
public void testPatchDefault() throws SerializationException, InterruptedException, ClientException, UnsupportedModifierException {
String serializedSubmodel = serializer.write(requestSubmodel);
- server.enqueue(new MockResponse().setBody(serializedSubmodel));
+ server.enqueue(new MockResponse().setResponseCode(204));
submodelInterface.patch(requestSubmodel);
RecordedRequest request = server.takeRequest();
@@ -169,7 +141,7 @@ public void testGetAllElements() throws SerializationException, InterruptedExcep
assertEquals("GET", request.getMethod());
assertEquals(requestSubmodelElements, responseSubmodelElements);
- assertEquals("/api/v3.0/submodel/submodel-elements/", request.getPath());
+ assertEquals("/api/v3.0/submodel/submodel-elements", request.getPath());
}
@@ -177,14 +149,15 @@ public void testGetAllElements() throws SerializationException, InterruptedExcep
public void testPostElement() throws SerializationException, InterruptedException, ClientException, UnsupportedModifierException {
SubmodelElement requestSubmodelElement = requestSubmodel.getSubmodelElements().get(0);
String serializedSubmodelElement = serializer.write(requestSubmodelElement);
- server.enqueue(new MockResponse().setBody(serializedSubmodelElement));
-
+ server.enqueue(new MockResponse()
+ .setResponseCode(201)
+ .setBody(serializedSubmodelElement));
SubmodelElement responseSubmodelElement = submodelInterface.postElement(requestSubmodelElement);
RecordedRequest request = server.takeRequest();
assertEquals("POST", request.getMethod());
assertEquals(requestSubmodelElement, responseSubmodelElement);
- assertEquals("/api/v3.0/submodel/submodel-elements/", request.getPath());
+ assertEquals("/api/v3.0/submodel/submodel-elements", request.getPath());
}
@@ -200,7 +173,7 @@ public void testGetElementDefault() throws SerializationException, InterruptedEx
assertEquals("GET", request.getMethod());
assertEquals(requestSubmodelElement, responseSubmodelElement);
- assertEquals("/api/v3.0/submodel/submodel-elements/" + requestSubmodelElement.getIdShort() + "/", request.getPath());
+ assertEquals("/api/v3.0/submodel/submodel-elements/" + requestSubmodelElement.getIdShort(), request.getPath());
}
@@ -209,16 +182,19 @@ public void testGetElementValue() throws SerializationException, InterruptedExce
Double value = 2.0;
String serializedPropertyValue = serializer.write(value);
server.enqueue(new MockResponse().setBody(serializedPropertyValue));
- ElementValueTypeInfo propertyTypeInfo = ElementValueTypeInfo.builder().datatype(Datatype.DOUBLE).type(PropertyValue.class).build();
- IdShortPath idShort = new IdShortPath.Builder().idShort(
- requestSubmodel.getSubmodelElements().get(0).getIdShort()).build();
+ ElementValueTypeInfo propertyTypeInfo = ElementValueTypeInfo.builder()
+ .datatype(Datatype.DOUBLE)
+ .type(PropertyValue.class)
+ .build();
+ IdShortPath idShort = new IdShortPath.Builder()
+ .idShort(requestSubmodel.getSubmodelElements().get(0).getIdShort())
+ .build();
PropertyValue responseSubmodelElementValue = submodelInterface.getElementValue(idShort, propertyTypeInfo);
RecordedRequest request = server.takeRequest();
assertEquals("GET", request.getMethod());
- assertEquals("/api/v3.0/submodel/submodel-elements/" +
- idShort.toString() + "/$value", request.getPath());
+ assertEquals(String.format("/api/v3.0/submodel/submodel-elements/%s/$value", idShort), request.getPath());
assertEquals(value, Double.valueOf(responseSubmodelElementValue.getValue().asString()));
}
@@ -227,16 +203,16 @@ public void testGetElementValue() throws SerializationException, InterruptedExce
public void testPatchElementValue() throws SerializationException, InterruptedException, ClientException, UnsupportedModifierException {
DefaultProperty property = new DefaultProperty.Builder().value("2.0").valueType(DataTypeDefXsd.FLOAT).idShort("value").build();
String serializedPropertyValue = serializer.write(property, OutputModifier.DEFAULT);
- server.enqueue(new MockResponse().setBody(serializedPropertyValue));
- IdShortPath idShort = new IdShortPath.Builder().idShort(
- requestSubmodel.getSubmodelElements().get(0).getIdShort()).build();
+ server.enqueue(new MockResponse().setResponseCode(204));
+ IdShortPath idShort = new IdShortPath.Builder()
+ .idShort(requestSubmodel.getSubmodelElements().get(0).getIdShort())
+ .build();
submodelInterface.patchElementValue(idShort, property);
RecordedRequest request = server.takeRequest();
assertEquals("PATCH", request.getMethod());
assertEquals(serializedPropertyValue, request.getBody().readUtf8());
- assertEquals("/api/v3.0/submodel/submodel-elements/" +
- idShort.toString() + "/$value", request.getPath());
+ assertEquals(String.format("/api/v3.0/submodel/submodel-elements/%s/$value", idShort), request.getPath());
}
@@ -244,7 +220,9 @@ public void testPatchElementValue() throws SerializationException, InterruptedEx
public void testPostElementByPath() throws SerializationException, InterruptedException, ClientException, UnsupportedModifierException {
SubmodelElement requestSubmodelElement = requestSubmodel.getSubmodelElements().get(0);
String serializedSubmodelElement = serializer.write(requestSubmodelElement);
- server.enqueue(new MockResponse().setBody(serializedSubmodelElement));
+ server.enqueue(new MockResponse()
+ .setResponseCode(201)
+ .setBody(serializedSubmodelElement));
IdShortPath idShort = new IdShortPath.Builder().idShort(
requestSubmodelElement.getIdShort()).build();
SubmodelElement responseSubmodelElement = submodelInterface.postElement(
@@ -253,7 +231,7 @@ public void testPostElementByPath() throws SerializationException, InterruptedEx
assertEquals("POST", request.getMethod());
assertEquals(requestSubmodelElement, responseSubmodelElement);
- assertEquals("/api/v3.0/submodel/submodel-elements/" + requestSubmodelElement.getIdShort() + "/", request.getPath());
+ assertEquals("/api/v3.0/submodel/submodel-elements/" + requestSubmodelElement.getIdShort(), request.getPath());
}
@@ -261,7 +239,7 @@ public void testPostElementByPath() throws SerializationException, InterruptedEx
public void testPutElementByPath() throws SerializationException, InterruptedException, ClientException, UnsupportedModifierException {
SubmodelElement requestSubmodelElement = requestSubmodel.getSubmodelElements().get(0);
String serializedSubmodelElement = serializer.write(requestSubmodelElement);
- server.enqueue(new MockResponse().setBody(serializedSubmodelElement));
+ server.enqueue(new MockResponse().setResponseCode(204));
IdShortPath idShort = new IdShortPath.Builder().idShort(
requestSubmodelElement.getIdShort()).build();
submodelInterface.putElement(idShort, requestSubmodelElement);
@@ -269,7 +247,7 @@ public void testPutElementByPath() throws SerializationException, InterruptedExc
assertEquals("PUT", request.getMethod());
assertEquals(serializedSubmodelElement, request.getBody().readUtf8());
- assertEquals("/api/v3.0/submodel/submodel-elements/" + requestSubmodelElement.getIdShort() + "/", request.getPath());
+ assertEquals("/api/v3.0/submodel/submodel-elements/" + requestSubmodelElement.getIdShort(), request.getPath());
}
@@ -277,7 +255,7 @@ public void testPutElementByPath() throws SerializationException, InterruptedExc
public void testPatchElementByPath() throws SerializationException, InterruptedException, ClientException, UnsupportedModifierException {
SubmodelElement requestSubmodelElement = requestSubmodel.getSubmodelElements().get(0);
String serializedSubmodelElement = serializer.write(requestSubmodelElement);
- server.enqueue(new MockResponse().setBody(serializedSubmodelElement));
+ server.enqueue(new MockResponse().setResponseCode(204));
IdShortPath idShort = new IdShortPath.Builder().idShort(
requestSubmodelElement.getIdShort()).build();
submodelInterface.patchElement(idShort, requestSubmodelElement);
@@ -285,15 +263,14 @@ public void testPatchElementByPath() throws SerializationException, InterruptedE
assertEquals("PATCH", request.getMethod());
assertEquals(serializedSubmodelElement, request.getBody().readUtf8());
- assertEquals("/api/v3.0/submodel/submodel-elements/" + requestSubmodelElement.getIdShort() + "/", request.getPath());
+ assertEquals("/api/v3.0/submodel/submodel-elements/" + requestSubmodelElement.getIdShort(), request.getPath());
}
@Test
- public void testDeleteElement() throws SerializationException, InterruptedException, ClientException, UnsupportedModifierException {
+ public void testDeleteElement() throws InterruptedException, ClientException {
SubmodelElement requestSubmodelElement = requestSubmodel.getSubmodelElements().get(0);
- String serializedSubmodelElement = serializer.write(requestSubmodelElement);
- server.enqueue(new MockResponse().setBody(serializedSubmodelElement));
+ server.enqueue(new MockResponse().setResponseCode(204));
IdShortPath idShort = new IdShortPath.Builder().idShort(
requestSubmodelElement.getIdShort()).build();
submodelInterface.deleteElement(idShort);
@@ -301,7 +278,7 @@ public void testDeleteElement() throws SerializationException, InterruptedExcept
assertEquals("DELETE", request.getMethod());
assertEquals(0, request.getBodySize());
- assertEquals("/api/v3.0/submodel/submodel-elements/" + requestSubmodelElement.getIdShort() + "/", request.getPath());
+ assertEquals("/api/v3.0/submodel/submodel-elements/" + requestSubmodelElement.getIdShort(), request.getPath());
}
@@ -316,14 +293,14 @@ public void testGetFileByPath() throws SerializationException, InterruptedExcept
assertEquals("GET", request.getMethod());
assertEquals(requestFile, responseFile);
- assertEquals("/api/v3.0/submodel/submodel-elements/" + requestFile.getIdShort() + "/attachment/", request.getPath());
+ assertEquals(String.format("/api/v3.0/submodel/submodel-elements/%s/attachment", requestFile.getIdShort()), request.getPath());
}
@Test
public void testPutFileByPath() throws SerializationException, InterruptedException, ClientException, UnsupportedModifierException {
String serializedFile = serializer.write(requestFile);
- server.enqueue(new MockResponse().setBody(serializedFile));
+ server.enqueue(new MockResponse().setResponseCode(204));
IdShortPath idShort = new IdShortPath.Builder().idShort(
requestFile.getIdShort()).build();
submodelInterface.putAttachment(idShort, requestFile);
@@ -331,7 +308,7 @@ public void testPutFileByPath() throws SerializationException, InterruptedExcept
assertEquals("PUT", request.getMethod());
assertEquals(serializedFile, request.getBody().readUtf8());
- assertEquals("/api/v3.0/submodel/submodel-elements/" + requestFile.getIdShort() + "/attachment/", request.getPath());
+ assertEquals(String.format("/api/v3.0/submodel/submodel-elements/%s/attachment", requestFile.getIdShort()), request.getPath());
}
@@ -346,7 +323,7 @@ public void testDeleteFileByPath() throws SerializationException, InterruptedExc
assertEquals("DELETE", request.getMethod());
assertEquals(0, request.getBodySize());
- assertEquals("/api/v3.0/submodel/submodel-elements/" + requestFile.getIdShort() + "/attachment/", request.getPath());
+ assertEquals(String.format("/api/v3.0/submodel/submodel-elements/%s/attachment", requestFile.getIdShort()), request.getPath());
}
@@ -371,6 +348,6 @@ public void testInvokeOperationSync() throws SerializationException, Interrupted
assertEquals("POST", request.getMethod());
assertEquals(requestOperationResult, responseOperationResult);
- assertEquals("/api/v3.0/submodel/submodel-elements/" + idShort + "/invoke/", request.getPath());
+ assertEquals(String.format("/api/v3.0/submodel/submodel-elements/%s/invoke", idShort), request.getPath());
}
}
diff --git a/core/src/test/java/de/fraunhofer/iosb/ilt/faaast/client/interfaces/SubmodelRegistryInterfaceTest.java b/core/src/test/java/de/fraunhofer/iosb/ilt/faaast/client/interfaces/SubmodelRegistryInterfaceTest.java
index a665f90..28c97b8 100644
--- a/core/src/test/java/de/fraunhofer/iosb/ilt/faaast/client/interfaces/SubmodelRegistryInterfaceTest.java
+++ b/core/src/test/java/de/fraunhofer/iosb/ilt/faaast/client/interfaces/SubmodelRegistryInterfaceTest.java
@@ -19,12 +19,12 @@
import de.fraunhofer.iosb.ilt.faaast.service.dataformat.SerializationException;
import de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.JsonApiSerializer;
import de.fraunhofer.iosb.ilt.faaast.service.model.exception.UnsupportedModifierException;
+import de.fraunhofer.iosb.ilt.faaast.service.util.EncodingHelper;
import org.eclipse.digitaltwin.aas4j.v3.model.SubmodelDescriptor;
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultSubmodelDescriptor;
import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
-import java.util.Base64;
import java.util.List;
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
@@ -79,7 +79,7 @@ public void testGetAll() throws ClientException, SerializationException, Interru
assertEquals("GET", request.getMethod());
assertEquals(0, request.getBodySize());
- assertEquals("/api/v3.0/submodel-descriptors/", request.getPath());
+ assertEquals("/api/v3.0/submodel-descriptors", request.getPath());
assertEquals(requestSubmodelDescriptors, responseSubmodelDescriptors);
}
@@ -87,9 +87,10 @@ public void testGetAll() throws ClientException, SerializationException, Interru
@Test
public void testPost() throws SerializationException, ClientException, InterruptedException, UnsupportedModifierException {
DefaultSubmodelDescriptor requestSubmodelDescriptor = requestSubmodelDescriptors.get(0);
- String requestSubmodelIdentifier = requestSubmodelDescriptor.getId();
String serializedSubmodelDescriptors = serializer.write(requestSubmodelDescriptor);
- server.enqueue(new MockResponse().setBody(serializedSubmodelDescriptors));
+ server.enqueue(new MockResponse()
+ .setResponseCode(201)
+ .setBody(serializedSubmodelDescriptors));
DefaultSubmodelDescriptor responseSubmodelDescriptor = submodelRegistryInterface.post(requestSubmodelDescriptor);
@@ -97,7 +98,7 @@ public void testPost() throws SerializationException, ClientException, Interrupt
assertEquals("POST", request.getMethod());
assertEquals(requestSubmodelDescriptor, responseSubmodelDescriptor);
- assertEquals("/api/v3.0/submodel-descriptors/", request.getPath());
+ assertEquals("/api/v3.0/submodel-descriptors", request.getPath());
}
@@ -114,8 +115,7 @@ public void testGetById() throws SerializationException, ClientException, Interr
assertEquals("GET", request.getMethod());
assertEquals(0, request.getBodySize());
- assertEquals("/api/v3.0/submodel-descriptors/" +
- Base64.getUrlEncoder().encodeToString(requestSubmodelIdentifier.getBytes()) + "/", request.getPath());
+ assertEquals("/api/v3.0/submodel-descriptors/" + EncodingHelper.base64UrlEncode(requestSubmodelIdentifier), request.getPath());
assertEquals(requestSubmodelDescriptor, responseSubmodelDescriptor);
}
@@ -125,31 +125,28 @@ public void testPutById() throws ClientException, SerializationException, Interr
DefaultSubmodelDescriptor requestSubmodelDescriptor = requestSubmodelDescriptors.get(0);
String requestSubmodelIdentifier = requestSubmodelDescriptor.getId();
String serializedSubmodelDescriptors = serializer.write(requestSubmodelDescriptor);
- server.enqueue(new MockResponse().setBody(serializedSubmodelDescriptors));
+ server.enqueue(new MockResponse().setResponseCode(204));
submodelRegistryInterface.put(requestSubmodelIdentifier, requestSubmodelDescriptor);
RecordedRequest request = server.takeRequest();
assertEquals("PUT", request.getMethod());
assertEquals(serializedSubmodelDescriptors, request.getBody().readUtf8());
- assertEquals("/api/v3.0/submodel-descriptors/" +
- Base64.getUrlEncoder().encodeToString(requestSubmodelIdentifier.getBytes()) + "/", request.getPath());
+ assertEquals("/api/v3.0/submodel-descriptors/" + EncodingHelper.base64UrlEncode(requestSubmodelIdentifier), request.getPath());
}
@Test
- public void testDeleteById() throws SerializationException, ClientException, InterruptedException, UnsupportedModifierException {
+ public void testDeleteById() throws ClientException, InterruptedException {
SubmodelDescriptor requestSubmodelDescriptor = requestSubmodelDescriptors.get(0);
String requestSubmodelIdentifier = requestSubmodelDescriptor.getId();
- String serializedSubmodelDescriptors = serializer.write(requestSubmodelDescriptor);
- server.enqueue(new MockResponse().setBody(serializedSubmodelDescriptors));
+ server.enqueue(new MockResponse().setResponseCode(204));
submodelRegistryInterface.delete(requestSubmodelIdentifier);
RecordedRequest request = server.takeRequest();
assertEquals("DELETE", request.getMethod());
assertEquals(0, request.getBody().size());
- assertEquals("/api/v3.0/submodel-descriptors/" +
- Base64.getUrlEncoder().encodeToString(requestSubmodelIdentifier.getBytes()) + "/", request.getPath());
+ assertEquals("/api/v3.0/submodel-descriptors/" + EncodingHelper.base64UrlEncode(requestSubmodelIdentifier), request.getPath());
}
}
diff --git a/core/src/test/java/de/fraunhofer/iosb/ilt/faaast/client/interfaces/SubmodelRepositoryInterfaceTest.java b/core/src/test/java/de/fraunhofer/iosb/ilt/faaast/client/interfaces/SubmodelRepositoryInterfaceTest.java
index 0b5bb48..855d9c2 100644
--- a/core/src/test/java/de/fraunhofer/iosb/ilt/faaast/client/interfaces/SubmodelRepositoryInterfaceTest.java
+++ b/core/src/test/java/de/fraunhofer/iosb/ilt/faaast/client/interfaces/SubmodelRepositoryInterfaceTest.java
@@ -25,11 +25,11 @@
import de.fraunhofer.iosb.ilt.faaast.service.model.value.PropertyValue;
import de.fraunhofer.iosb.ilt.faaast.service.model.value.primitive.StringValue;
import de.fraunhofer.iosb.ilt.faaast.service.typing.ElementValueTypeInfo;
+import de.fraunhofer.iosb.ilt.faaast.service.util.EncodingHelper;
import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
-import java.util.Base64;
import java.util.List;
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
@@ -112,7 +112,7 @@ public void testGetAll() throws SerializationException, InterruptedException, Cl
assertEquals("GET", request.getMethod());
assertEquals(0, request.getBodySize());
- assertEquals("/api/v3.0/submodels/", request.getPath());
+ assertEquals("/api/v3.0/submodels", request.getPath());
assertEquals(requestSubmodelList, responseSubmodelList);
}
@@ -137,34 +137,34 @@ public void testGetAllReference() throws SerializationException, InterruptedExce
@Test
- public void post() throws SerializationException, InterruptedException, ClientException, UnsupportedModifierException {
+ public void testPost() throws SerializationException, InterruptedException, ClientException, UnsupportedModifierException {
Submodel requestSubmodel = requestSubmodelList.get(0);
String serializedSubmodel = serializer.write(requestSubmodel);
- server.enqueue(new MockResponse().setBody(serializedSubmodel));
+ server.enqueue(new MockResponse()
+ .setResponseCode(201)
+ .setBody(serializedSubmodel));
Submodel responseSubmodel = submodelRepositoryInterface.post(requestSubmodel);
RecordedRequest request = server.takeRequest();
assertEquals("POST", request.getMethod());
assertEquals(requestSubmodel, responseSubmodel);
- assertEquals("/api/v3.0/submodels/", request.getPath());
+ assertEquals("/api/v3.0/submodels", request.getPath());
}
@Test
- public void delete() throws SerializationException, InterruptedException, ClientException, UnsupportedModifierException {
+ public void testDelete() throws InterruptedException, ClientException {
Submodel requestSubmodel = requestSubmodelList.get(0);
- String serializedSubmodel = serializer.write(requestSubmodel);
String requestSubmodelIdentifier = requestSubmodel.getId();
- server.enqueue(new MockResponse().setBody(serializedSubmodel));
+ server.enqueue(new MockResponse().setResponseCode(204));
submodelRepositoryInterface.delete(requestSubmodelIdentifier);
RecordedRequest request = server.takeRequest();
assertEquals("DELETE", request.getMethod());
assertEquals(0, request.getBodySize());
- assertEquals("/api/v3.0/submodels/" +
- Base64.getUrlEncoder().encodeToString(requestSubmodelIdentifier.getBytes()) + "/", request.getPath());
+ assertEquals("/api/v3.0/submodels/" + EncodingHelper.base64UrlEncode(requestSubmodelIdentifier), request.getPath());
}
@@ -180,7 +180,7 @@ public void testGetSubmodel() throws SerializationException, InterruptedExceptio
RecordedRequest request = server.takeRequest();
assertEquals("GET", request.getMethod());
assertEquals(0, request.getBodySize());
- assertEquals("/api/v3.0/submodels/" + Base64.getUrlEncoder().encodeToString(requestSubmodel.getId().getBytes()) + "/", request.getPath());
+ assertEquals("/api/v3.0/submodels/" + EncodingHelper.base64UrlEncode(requestSubmodel.getId()), request.getPath());
assertEquals(requestSubmodel, responseSubmodel);
}
@@ -216,9 +216,12 @@ public void testGetSubmodelElementValue() throws SerializationException, Interru
RecordedRequest request = server.takeRequest();
assertEquals("GET", request.getMethod());
- assertEquals("/api/v3.0/submodels/"
- + Base64.getUrlEncoder().encodeToString(requestSubmodelId.getBytes())
- + "/submodel-elements/" + idShort.toString() + "/$value", request.getPath());
+
+ assertEquals(
+ String.format("/api/v3.0/submodels/%s/submodel-elements/%s/$value",
+ EncodingHelper.base64UrlEncode(requestSubmodelId),
+ idShort),
+ request.getPath());
assertEquals(value, Double.valueOf(responseSubmodelElementValue.getValue().asString()));
}
@@ -228,7 +231,7 @@ public void testPatchSubmodelElementValue() throws SerializationException, Inter
DefaultProperty property = new DefaultProperty.Builder().value("2.0").valueType(DataTypeDefXsd.FLOAT).idShort("value").build();
String serializedPropertyValue = serializer.write(property, OutputModifier.DEFAULT);
String requestSubmodelId = requestSubmodelList.get(0).getId();
- server.enqueue(new MockResponse().setBody(serializedPropertyValue));
+ server.enqueue(new MockResponse().setResponseCode(204));
IdShortPath idShort = new IdShortPath.Builder().idShort(
requestSubmodelList.get(0).getId()).build();
@@ -237,8 +240,10 @@ public void testPatchSubmodelElementValue() throws SerializationException, Inter
assertEquals("PATCH", request.getMethod());
assertEquals(serializedPropertyValue, request.getBody().readUtf8());
- assertEquals("/api/v3.0/submodels/"
- + Base64.getUrlEncoder().encodeToString(requestSubmodelId.getBytes())
- + "/submodel-elements/" + idShort.toString() + "/$value", request.getPath());
+ assertEquals(
+ String.format("/api/v3.0/submodels/%s/submodel-elements/%s/$value",
+ EncodingHelper.base64UrlEncode(requestSubmodelId),
+ idShort),
+ request.getPath());
}
}
diff --git a/pom.xml b/pom.xml
index 06c5b3f..f732ff9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -55,7 +55,7 @@
1.0.3
10.20.2
- 1.2.0-SNAPSHOT
+ 1.2.0
4.13.2
1.5.8
17
@@ -64,10 +64,12 @@
3.6.0
3.13.0
3.8.1
+ 3.5.2
3.2.7
0.8.12
3.4.2
3.11.2
+ 2.5.0
1.7.0
11.1.1
3.3.1
@@ -191,6 +193,31 @@
+
+ org.apache.maven.plugins
+ maven-failsafe-plugin
+ ${maven.plugin.failsafe.version}
+
+
+ **/*IT
+
+
+
+
+ org.apache.maven.surefire
+ surefire-junit4
+ ${maven.plugin.surefire.version}
+
+
+
+
+
+ integration-test
+ verify
+
+
+
+
com.diffplug.spotless
spotless-maven-plugin
@@ -256,7 +283,7 @@
org.codehaus.mojo
license-maven-plugin
- 2.5.0
+ ${maven.plugin.license}
${root.basedir}/docs/third_party_licenses_report
@@ -336,6 +363,18 @@
com.diffplug.spotless
spotless-maven-plugin
+
+ org.apache.maven.plugins
+ maven-release-plugin
+
+
+ org.codehaus.mojo
+ license-maven-plugin
+
+
+ org.apache.maven.plugins
+ maven-failsafe-plugin
+