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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

package org.eclipse.digitaltwin.basyx.aasrepository.client;

import org.eclipse.digitaltwin.basyx.aasrepository.client.internal.AssetAdministrationShellRepositoryApi;
import org.eclipse.digitaltwin.basyx.aasrepository.client.internal.AssetAdministrationShellRepositoryApiFactory;
import org.eclipse.digitaltwin.basyx.aasservice.client.ConnectedAasService;
import org.eclipse.digitaltwin.basyx.aasservice.client.AuthorizedConnectedAasService;
import org.eclipse.digitaltwin.basyx.client.internal.ApiException;
Expand All @@ -41,7 +41,7 @@ public class AuthorizedConnectedAasRepository extends ConnectedAasRepository {
private TokenManager tokenManager;

public AuthorizedConnectedAasRepository(String repoUrl, TokenManager tokenManager) {
super(repoUrl, new AssetAdministrationShellRepositoryApi(repoUrl, tokenManager));
super(repoUrl, AssetAdministrationShellRepositoryApiFactory.create(repoUrl, tokenManager));
this.tokenManager = tokenManager;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.eclipse.digitaltwin.aas4j.v3.model.SpecificAssetId;
import org.eclipse.digitaltwin.basyx.aasrepository.AasRepository;
import org.eclipse.digitaltwin.basyx.aasrepository.client.internal.AssetAdministrationShellRepositoryApi;
import org.eclipse.digitaltwin.basyx.aasrepository.client.internal.AssetAdministrationShellRepositoryApiFactory;
import org.eclipse.digitaltwin.basyx.aasservice.client.ConnectedAasService;
import org.eclipse.digitaltwin.basyx.client.internal.ApiException;
import org.eclipse.digitaltwin.basyx.core.exceptions.CollidingIdentifierException;
Expand Down Expand Up @@ -67,7 +68,7 @@ public class ConnectedAasRepository implements AasRepository {
*/
public ConnectedAasRepository(String repoUrl) {
this.aasRepoUrl = repoUrl;
this.repoApi = new AssetAdministrationShellRepositoryApi(repoUrl);
this.repoApi = AssetAdministrationShellRepositoryApiFactory.create(repoUrl);
}

public ConnectedAasRepository(String repoUrl, AssetAdministrationShellRepositoryApi assetAdministrationShellRepositoryApi) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.eclipse.digitaltwin.aas4j.v3.model.AssetInformation;
import org.eclipse.digitaltwin.aas4j.v3.model.Reference;
import org.eclipse.digitaltwin.basyx.client.internal.ApiClient;
import org.eclipse.digitaltwin.basyx.client.internal.ApiClientPool;
import org.eclipse.digitaltwin.basyx.client.internal.ApiException;
import org.eclipse.digitaltwin.basyx.client.internal.ApiResponse;
import org.eclipse.digitaltwin.basyx.client.internal.Pair;
Expand Down Expand Up @@ -100,6 +101,10 @@ public AssetAdministrationShellRepositoryApi(ApiClient apiClient) {
memberVarReadTimeout = apiClient.getReadTimeout();
}

public void setTokenManager(TokenManager tokenManager) {
this.tokenManager = tokenManager;
}

protected ApiException getApiException(String operationId, HttpResponse<String> response) throws IOException {
String message = formatExceptionMessage(operationId, response.statusCode(), response.body());
return new ApiException(response.statusCode(), message, response.headers(), response.body());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*******************************************************************************
* Copyright (C) 2026 the Eclipse BaSyx Authors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* SPDX-License-Identifier: MIT
******************************************************************************/


package org.eclipse.digitaltwin.basyx.aasrepository.client.internal;

import org.eclipse.digitaltwin.aas4j.v3.dataformat.json.JsonMapperFactory;
import org.eclipse.digitaltwin.aas4j.v3.dataformat.json.SimpleAbstractTypeResolverFactory;
import org.eclipse.digitaltwin.basyx.client.internal.authorization.TokenManager;
import org.eclipse.digitaltwin.basyx.client.internal.ApiClient;
import org.eclipse.digitaltwin.basyx.client.internal.ApiClientPool;

import com.fasterxml.jackson.databind.ObjectMapper;

/**
* Factory class for creating instances of {@link AssetAdministrationShellRepositoryApi} using an {@link ApiClientPool}.
*
* @author koort
*/
public class AssetAdministrationShellRepositoryApiFactory {

private AssetAdministrationShellRepositoryApiFactory() {
}

/**
* Creates a new instance of {@link AssetAdministrationShellRepositoryApi} with default configuration.
*
* @param repositoryBaseUri the base URI of the AAS repository
* @return a new AssetAdministrationShellRepositoryApi instance
*/
public static AssetAdministrationShellRepositoryApi create(String repositoryBaseUri) {
return create(repositoryBaseUri, null, null);
}

/**
* Creates a new instance of {@link AssetAdministrationShellRepositoryApi} with the specified ObjectMapper.
*
* @param repositoryBaseUri the base URI of the AAS repository
* @param objectMapper the ObjectMapper
* @return a new AssetAdministrationShellRepositoryApi instance
*/
public static AssetAdministrationShellRepositoryApi create(String repositoryBaseUri, ObjectMapper objectMapper) {
return create(repositoryBaseUri, objectMapper, null);
}

/**
* Creates a new instance of {@link AssetAdministrationShellRepositoryApi} with the specified TokenManager.
*
* @param repositoryBaseUri the base URI of the AAS repository
* @param tokenManager the TokenManager
* @return a new AssetAdministrationShellRepositoryApi instance
*/
public static AssetAdministrationShellRepositoryApi create(String repositoryBaseUri, TokenManager tokenManager) {
return create(repositoryBaseUri, null, tokenManager);
}

/**
* Creates a new instance of {@link AssetAdministrationShellRepositoryApi} with the specified ObjectMapper and TokenManager.
*
* @param repositoryBaseUri the base URI of the AAS repository
* @param objectMapper the ObjectMapper
* @param tokenManager the TokenManager
* @return a new AssetAdministrationShellRepositoryApi instance
*/
public static AssetAdministrationShellRepositoryApi create(String repositoryBaseUri, ObjectMapper objectMapper, TokenManager tokenManager) {
ObjectMapper mapper = objectMapper != null ? objectMapper : new JsonMapperFactory().create(new SimpleAbstractTypeResolverFactory().create());

ApiClient apiClient = ApiClientPool.getInstance().getOrCreateAasRepoApiClient(repositoryBaseUri, mapper);

AssetAdministrationShellRepositoryApi repoApi = new AssetAdministrationShellRepositoryApi(apiClient);

if (tokenManager != null) {
repoApi.setTokenManager(tokenManager);
}

return repoApi;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

package org.eclipse.digitaltwin.basyx.aasservice.client;

import org.eclipse.digitaltwin.basyx.aasservice.client.internal.AssetAdministrationShellServiceApi;
import org.eclipse.digitaltwin.basyx.aasservice.client.internal.AssetAdministrationShellServiceApiFactory;
import org.eclipse.digitaltwin.basyx.client.internal.authorization.TokenManager;

/**
Expand All @@ -43,7 +43,7 @@ public class AuthorizedConnectedAasService extends ConnectedAasService {
* @param tokenManager
*/
public AuthorizedConnectedAasService(String repoUrl, TokenManager tokenManager) {
super(new AssetAdministrationShellServiceApi(repoUrl, tokenManager));
super(AssetAdministrationShellServiceApiFactory.create(repoUrl, tokenManager));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.eclipse.digitaltwin.aas4j.v3.model.Reference;
import org.eclipse.digitaltwin.basyx.aasservice.AasService;
import org.eclipse.digitaltwin.basyx.aasservice.client.internal.AssetAdministrationShellServiceApi;
import org.eclipse.digitaltwin.basyx.aasservice.client.internal.AssetAdministrationShellServiceApiFactory;
import org.eclipse.digitaltwin.basyx.client.internal.ApiException;
import org.eclipse.digitaltwin.basyx.core.exceptions.CollidingSubmodelReferenceException;
import org.eclipse.digitaltwin.basyx.core.exceptions.ElementDoesNotExistException;
Expand All @@ -56,7 +57,7 @@ public class ConnectedAasService implements AasService {
private AssetAdministrationShellServiceApi serviceApi;

public ConnectedAasService(String aasServiceUrl) {
this.serviceApi = new AssetAdministrationShellServiceApi(aasServiceUrl);
this.serviceApi = AssetAdministrationShellServiceApiFactory.create(aasServiceUrl);
}

public ConnectedAasService(AssetAdministrationShellServiceApi assetAdministrationShellServiceApi) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ public AssetAdministrationShellServiceApi(ApiClient apiClient) {
memberVarReadTimeout = apiClient.getReadTimeout();
}

public void setTokenManager(TokenManager tokenManager) {
this.tokenManager = tokenManager;
}

protected ApiException getApiException(String operationId, HttpResponse<String> response) throws IOException {
String message = formatExceptionMessage(operationId, response.statusCode(), response.body());
return new ApiException(response.statusCode(), message, response.headers(), response.body());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*******************************************************************************
* Copyright (C) 2026 the Eclipse BaSyx Authors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* SPDX-License-Identifier: MIT
******************************************************************************/


package org.eclipse.digitaltwin.basyx.aasservice.client.internal;

import org.eclipse.digitaltwin.aas4j.v3.dataformat.json.JsonMapperFactory;
import org.eclipse.digitaltwin.aas4j.v3.dataformat.json.SimpleAbstractTypeResolverFactory;
import org.eclipse.digitaltwin.basyx.client.internal.ApiClient;
import org.eclipse.digitaltwin.basyx.client.internal.authorization.TokenManager;
import org.eclipse.digitaltwin.basyx.client.internal.ApiClientPool;

import com.fasterxml.jackson.databind.ObjectMapper;

/**
* Factory class for creating instances of {@link AssetAdministrationShellServiceApi} using an {@link ApiClientPool}.
*
* @author koort
*/
public class AssetAdministrationShellServiceApiFactory {

private AssetAdministrationShellServiceApiFactory() {
}

/**
* Creates a new instance of {@link AssetAdministrationShellServiceApi} with default configuration.
*
* @param aasServiceUrl the base URL of the AAS service
* @return a new AssetAdministrationShellServiceApi instance
*/
public static AssetAdministrationShellServiceApi create(String aasServiceUrl) {
return create(aasServiceUrl, null, null);
}

/**
* Creates a new instance of {@link AssetAdministrationShellServiceApi} with the specified TokenManager.
*
* @param aasServiceUrl the base URL of the AAS service
* @param tokenManager the TokenManager
* @return a new AssetAdministrationShellServiceApi instance
*/
public static AssetAdministrationShellServiceApi create(String aasServiceUrl, TokenManager tokenManager) {
return create(aasServiceUrl, null, tokenManager);
}

/**
* Creates a new instance of {@link AssetAdministrationShellServiceApi} with the specified ObjectMapper.
*
* @param aasServiceUrl the base URL of the AAS service
* @param objectMapper the ObjectMapper
* @return a new AssetAdministrationShellServiceApi instance
*/
public static AssetAdministrationShellServiceApi create(String aasServiceUrl, ObjectMapper objectMapper) {
return create(aasServiceUrl, objectMapper, null);
}

/**
* Creates a new instance of {@link AssetAdministrationShellServiceApi} with the specified ObjectMapper and TokenManager.
*
* @param aasServiceUrl the base URL of the AAS service
* @param objectMapper the ObjectMapper
* @param tokenManager the TokenManager
* @return a new AssetAdministrationShellServiceApi instance
*/
public static AssetAdministrationShellServiceApi create(String aasServiceUrl, ObjectMapper objectMapper, TokenManager tokenManager) {
ObjectMapper mapper = objectMapper != null ? objectMapper : new JsonMapperFactory().create(new SimpleAbstractTypeResolverFactory().create());

ApiClient apiClient = ApiClientPool.getInstance().getOrCreateAasServiceApiClient(aasServiceUrl, mapper);

AssetAdministrationShellServiceApi serviceApi = new AssetAdministrationShellServiceApi(apiClient);

if (tokenManager != null) {
serviceApi.setTokenManager(tokenManager);
}

return serviceApi;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public class ApiClient {
private Consumer<HttpResponse<String>> asyncResponseInterceptor;
private Duration readTimeout;
private Duration connectTimeout;
private HttpClient httpClient;

private static String valueToString(Object value) {
if (value == null) {
Expand Down Expand Up @@ -190,6 +191,7 @@ public ApiClient() {
connectTimeout = null;
responseInterceptor = null;
asyncResponseInterceptor = null;
this.httpClient = this.builder.build();
}

/**
Expand All @@ -208,6 +210,7 @@ public ApiClient(HttpClient.Builder builder, ObjectMapper mapper, String baseUri
connectTimeout = null;
responseInterceptor = null;
asyncResponseInterceptor = null;
this.httpClient = this.builder.build();
}

protected ObjectMapper createDefaultObjectMapper() {
Expand Down Expand Up @@ -249,6 +252,7 @@ public void updateBaseUri(String baseUri) {
*/
public ApiClient setHttpClientBuilder(HttpClient.Builder builder) {
this.builder = builder;
this.httpClient = null;
return this;
}

Expand All @@ -260,7 +264,10 @@ public ApiClient setHttpClientBuilder(HttpClient.Builder builder) {
* @return The HTTP client.
*/
public HttpClient getHttpClient() {
return builder.build();
if (httpClient == null) {
httpClient = builder.build();
}
return httpClient;
}

/**
Expand Down
Loading