2525package org .eclipse .digitaltwin .basyx .aasdiscoveryservice .client .internal ;
2626
2727import java .io .IOException ;
28- import java .io .InputStream ;
2928import java .net .URI ;
3029import java .net .http .HttpClient ;
3130import java .net .http .HttpRequest ;
@@ -63,8 +62,6 @@ public class AssetAdministrationShellDiscoveryApi {
6362 private final String baseUri ;
6463 private final Consumer <HttpRequest .Builder > requestInterceptor ;
6564 private final Duration readTimeout ;
66- private final Consumer <HttpResponse <InputStream >> responseInterceptor ;
67- private final Consumer <HttpResponse <String >> asyncResponseInterceptor ;
6865 private TokenManager tokenManager ;
6966
7067 public AssetAdministrationShellDiscoveryApi () {
@@ -82,8 +79,6 @@ public AssetAdministrationShellDiscoveryApi(ApiClient apiClient) {
8279 this .baseUri = apiClient .getBaseUri ();
8380 this .requestInterceptor = apiClient .getRequestInterceptor ();
8481 this .readTimeout = apiClient .getReadTimeout ();
85- this .responseInterceptor = apiClient .getResponseInterceptor ();
86- this .asyncResponseInterceptor = apiClient .getAsyncResponseInterceptor ();
8782 }
8883
8984 public AssetAdministrationShellDiscoveryApi (String baseUri ) {
@@ -103,9 +98,11 @@ public CursorResult<List<String>> getAllAssetAdministrationShellIdsByAssetLink(L
10398 public ApiResponse <Base64UrlEncodedCursorResult <List <String >>> getAllAssetAdministrationShellIdsByAssetLinkWithHttpInfo (List <AssetLink > assetIds , Integer limit , String cursor ) throws ApiException {
10499 HttpRequest .Builder requestBuilder = getAllShellIdsRequestBuilder (assetIds , limit , cursor );
105100 try {
106- HttpResponse <InputStream > response = httpClient .send (requestBuilder .build (), HttpResponse .BodyHandlers .ofInputStream ());
107- if (responseInterceptor != null ) responseInterceptor .accept (response );
108- if (response .statusCode () / 100 != 2 ) throw getApiException ("getAllAssetAdministrationShellIdsByAssetLink" , response );
101+ HttpResponse <String > response = httpClient .send (requestBuilder .build (),
102+ HttpResponse .BodyHandlers .ofString ());
103+ if (response .statusCode () / 100 != 2 ) {
104+ throw getApiException ("getAllAssetAdministrationShellIdsByAssetLink" , response );
105+ }
109106 return new ApiResponse <>(
110107 response .statusCode (),
111108 response .headers ().map (),
@@ -136,14 +133,20 @@ private HttpRequest.Builder getAllShellIdsRequestBuilder(List<AssetLink> assetId
136133 queryParams .addAll (ApiClient .parameterToPairs ("cursor" , cursor ));
137134
138135 StringJoiner query = new StringJoiner ("&" );
139- for (Pair p : queryParams ) query .add (p .getName () + "=" + p .getValue ());
136+ for (Pair p : queryParams ) {
137+ query .add (p .getName () + "=" + p .getValue ());
138+ }
140139
141140 builder .uri (URI .create (baseUri + path + (query .length () > 0 ? "?" + query : "" )));
142141 builder .header ("Accept" , "application/json" );
143142 addAuthorizationHeaderIfAuthIsEnabled (builder );
144143 builder .method ("GET" , HttpRequest .BodyPublishers .noBody ());
145- if (readTimeout != null ) builder .timeout (readTimeout );
146- if (requestInterceptor != null ) requestInterceptor .accept (builder );
144+ if (readTimeout != null ) {
145+ builder .timeout (readTimeout );
146+ }
147+ if (requestInterceptor != null ) {
148+ requestInterceptor .accept (builder );
149+ }
147150 return builder ;
148151 }
149152
@@ -153,14 +156,18 @@ public List<SpecificAssetId> getAllAssetLinksById(String aasIdentifier) throws A
153156 builder .header ("Accept" , "application/json" );
154157 addAuthorizationHeaderIfAuthIsEnabled (builder );
155158 builder .method ("GET" , HttpRequest .BodyPublishers .noBody ());
156- if (readTimeout != null ) builder .timeout (readTimeout );
157- if (requestInterceptor != null ) requestInterceptor .accept (builder );
159+ if (readTimeout != null ) {
160+ builder .timeout (readTimeout );
161+ }
162+ if (requestInterceptor != null ) {
163+ requestInterceptor .accept (builder );
164+ }
158165
159166 try {
160- HttpResponse <InputStream > response = httpClient .send (builder .build (), HttpResponse .BodyHandlers .ofInputStream ());
161- if (responseInterceptor != null ) responseInterceptor . accept ( response );
162- if ( response . statusCode () / 100 != 2 )
163- throw getApiException ( "getAllAssetLinksById" , response );
167+ HttpResponse <String > response = httpClient .send (builder .build (), HttpResponse .BodyHandlers .ofString ());
168+ if (response . statusCode () / 100 != 2 ) {
169+ throw getApiException ( "getAllAssetLinksById" , response );
170+ }
164171 return objectMapper .readValue (response .body (), new TypeReference <List <SpecificAssetId >>() {});
165172 } catch (IOException | InterruptedException e ) {
166173 Thread .currentThread ().interrupt ();
@@ -182,14 +189,18 @@ public List<SpecificAssetId> postAllAssetLinksById(String aasIdentifier, List<Sp
182189 throw new ApiException (e );
183190 }
184191
185- if (readTimeout != null ) builder .timeout (readTimeout );
186- if (requestInterceptor != null ) requestInterceptor .accept (builder );
192+ if (readTimeout != null ) {
193+ builder .timeout (readTimeout );
194+ }
195+ if (requestInterceptor != null ) {
196+ requestInterceptor .accept (builder );
197+ }
187198
188199 try {
189- HttpResponse <InputStream > response = httpClient .send (builder .build (), HttpResponse .BodyHandlers .ofInputStream ());
190- if (responseInterceptor != null ) responseInterceptor . accept ( response );
191- if ( response . statusCode () / 100 != 2 )
192- throw getApiException ( "postAllAssetLinksById" , response );
200+ HttpResponse <String > response = httpClient .send (builder .build (), HttpResponse .BodyHandlers .ofString ());
201+ if (response . statusCode () / 100 != 2 ) {
202+ throw getApiException ( "postAllAssetLinksById" , response );
203+ }
193204 return objectMapper .readValue (response .body (), new TypeReference <List <SpecificAssetId >>() {});
194205 } catch (IOException | InterruptedException e ) {
195206 Thread .currentThread ().interrupt ();
@@ -203,14 +214,18 @@ public void deleteAllAssetLinksById(String aasIdentifier) throws ApiException {
203214 builder .header ("Accept" , "application/json" );
204215 addAuthorizationHeaderIfAuthIsEnabled (builder );
205216 builder .method ("DELETE" , HttpRequest .BodyPublishers .noBody ());
206- if (readTimeout != null ) builder .timeout (readTimeout );
207- if (requestInterceptor != null ) requestInterceptor .accept (builder );
217+ if (readTimeout != null ) {
218+ builder .timeout (readTimeout );
219+ }
220+ if (requestInterceptor != null ) {
221+ requestInterceptor .accept (builder );
222+ }
208223
209224 try {
210- HttpResponse <InputStream > response = httpClient .send (builder .build (), HttpResponse .BodyHandlers .ofInputStream ());
211- if (responseInterceptor != null ) responseInterceptor . accept ( response );
212- if ( response . statusCode () / 100 != 2 )
213- throw getApiException ( "deleteAllAssetLinksById" , response );
225+ HttpResponse <String > response = httpClient .send (builder .build (), HttpResponse .BodyHandlers .ofString ());
226+ if (response . statusCode () / 100 != 2 ) {
227+ throw getApiException ( "deleteAllAssetLinksById" , response );
228+ }
214229 } catch (IOException | InterruptedException e ) {
215230 Thread .currentThread ().interrupt ();
216231 throw new ApiException (e );
@@ -223,24 +238,29 @@ public Object getDescription() throws ApiException {
223238 builder .header ("Accept" , "application/json" );
224239 addAuthorizationHeaderIfAuthIsEnabled (builder );
225240 builder .method ("GET" , HttpRequest .BodyPublishers .noBody ());
226- if (readTimeout != null ) builder .timeout (readTimeout );
227- if (requestInterceptor != null ) requestInterceptor .accept (builder );
241+ if (readTimeout != null ) {
242+ builder .timeout (readTimeout );
243+ }
244+ if (requestInterceptor != null ) {
245+ requestInterceptor .accept (builder );
246+ }
228247
229248 try {
230- HttpResponse <InputStream > response = httpClient .send (builder .build (), HttpResponse .BodyHandlers .ofInputStream ());
231- if (responseInterceptor != null ) responseInterceptor . accept ( response );
232- if ( response . statusCode () / 100 != 2 )
233- throw getApiException ( "getDescription" , response );
249+ HttpResponse <String > response = httpClient .send (builder .build (), HttpResponse .BodyHandlers .ofString ());
250+ if (response . statusCode () / 100 != 2 ) {
251+ throw getApiException ( "getDescription" , response );
252+ }
234253 return objectMapper .readValue (response .body (), Object .class );
235254 } catch (IOException | InterruptedException e ) {
236255 Thread .currentThread ().interrupt ();
237256 throw new ApiException (e );
238257 }
239258 }
240259
241- private ApiException getApiException (String operationId , HttpResponse <InputStream > response ) throws IOException {
242- String body = response .body () == null ? null : new String (response .body ().readAllBytes ());
243- return new ApiException (response .statusCode (), operationId + " call failed with: " + response .statusCode () + " - " + (body != null ? body : "[no body]" ), response .headers (), body );
260+ private ApiException getApiException (String operationId , HttpResponse <String > response ) throws IOException {
261+ return new ApiException (response .statusCode (),
262+ operationId + " call failed with: " + response .statusCode () + " - " + response .body (),
263+ response .headers (), response .body ());
244264 }
245265
246266 private void addAuthorizationHeaderIfAuthIsEnabled (HttpRequest .Builder builder ) {
0 commit comments