22 * dip-mds
33 * DIP-Massendatenschnittstelle
44 *
5- * The version of the OpenAPI document: DIP-MDS 1.3
5+ * The version of the OpenAPI document: DIP-MDS 2.1
66 *
77 *
88 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
5656import java .util .Date ;
5757import java .util .function .Supplier ;
5858import java .util .TimeZone ;
59+ import java .util .Locale ;
5960import java .util .regex .Matcher ;
6061import java .util .regex .Pattern ;
6162
7778import java .text .DateFormat ;
7879
7980import software .xdev .bzst .dip .client .generated .client .auth .Authentication ;
81+ import software .xdev .bzst .dip .client .generated .client .auth .HttpBearerAuth ;
8082
8183public class ApiClient extends JavaTimeFormatter {
82- private Map <String , String > defaultHeaderMap = new HashMap <String , String >();
83- private Map <String , String > defaultCookieMap = new HashMap <String , String >();
84- private String basePath = "http://localhost" ;
84+ protected Map <String , String > defaultHeaderMap = new HashMap <String , String >();
85+ protected Map <String , String > defaultCookieMap = new HashMap <String , String >();
86+ protected String basePath = "http://localhost" ;
8587 protected List <ServerConfiguration > servers = new ArrayList <ServerConfiguration >(Arrays .asList (
8688 new ServerConfiguration (
8789 "" ,
@@ -91,22 +93,22 @@ public class ApiClient extends JavaTimeFormatter {
9193 ));
9294 protected Integer serverIndex = 0 ;
9395 protected Map <String , String > serverVariables = null ;
94- private boolean debugging = false ;
95- private int connectionTimeout = 0 ;
96+ protected boolean debugging = false ;
97+ protected int connectionTimeout = 0 ;
9698
97- private CloseableHttpClient httpClient ;
98- private ObjectMapper objectMapper ;
99+ protected CloseableHttpClient httpClient ;
100+ protected ObjectMapper objectMapper ;
99101 protected String tempFolderPath = null ;
100102
101- private Map <String , Authentication > authentications ;
103+ protected Map <String , Authentication > authentications ;
102104
103- private int statusCode ;
104- private Map <String , List <String >> responseHeaders ;
105+ protected ThreadLocal < Integer > lastStatusCode = new ThreadLocal <>() ;
106+ protected ThreadLocal < Map <String , List <String >>> lastResponseHeaders = new ThreadLocal <>() ;
105107
106- private DateFormat dateFormat ;
108+ protected DateFormat dateFormat ;
107109
108110 // Methods that can have a request body
109- private static List <String > bodyMethods = Arrays .asList ("POST" , "PUT" , "DELETE" , "PATCH" );
111+ protected static List <String > bodyMethods = Arrays .asList ("POST" , "PUT" , "DELETE" , "PATCH" );
110112
111113 public ApiClient (CloseableHttpClient httpClient ) {
112114 objectMapper = new ObjectMapper ();
@@ -118,15 +120,17 @@ public ApiClient(CloseableHttpClient httpClient) {
118120 objectMapper .enable (DeserializationFeature .READ_ENUMS_USING_TO_STRING );
119121 objectMapper .registerModule (new JavaTimeModule ());
120122 objectMapper .registerModule (new JsonNullableModule ());
123+ objectMapper .registerModule (new RFC3339JavaTimeModule ());
121124 objectMapper .setDateFormat (ApiClient .buildDefaultDateFormat ());
122125
123126 dateFormat = ApiClient .buildDefaultDateFormat ();
124127
125128 // Set default User-Agent.
126- setUserAgent ("OpenAPI-Generator/DIP-MDS 1.3 /java" );
129+ setUserAgent ("OpenAPI-Generator/DIP-MDS 2.1 /java" );
127130
128131 // Setup authentications (key: authentication name, value: authentication).
129132 authentications = new HashMap <String , Authentication >();
133+ authentications .put ("BearerAuth" , new HttpBearerAuth ("bearer" ));
130134 // Prevent the authentications from being modified.
131135 authentications = Collections .unmodifiableMap (authentications );
132136
@@ -245,16 +249,18 @@ public ApiClient setServerVariables(Map<String, String> serverVariables) {
245249 *
246250 * @return Status code
247251 */
252+ @ Deprecated
248253 public int getStatusCode () {
249- return statusCode ;
254+ return lastStatusCode . get () ;
250255 }
251256
252257 /**
253258 * Gets the response headers of the previous request
254259 * @return Response headers
255260 */
261+ @ Deprecated
256262 public Map <String , List <String >> getResponseHeaders () {
257- return responseHeaders ;
263+ return lastResponseHeaders . get () ;
258264 }
259265
260266 /**
@@ -286,6 +292,35 @@ public String getTempFolderPath() {
286292 return tempFolderPath ;
287293 }
288294
295+ /**
296+ * Helper method to set access token for the first Bearer authentication.
297+ * @param bearerToken Bearer token
298+ * @return API client
299+ */
300+ public ApiClient setBearerToken (String bearerToken ) {
301+ for (Authentication auth : authentications .values ()) {
302+ if (auth instanceof HttpBearerAuth ) {
303+ ((HttpBearerAuth ) auth ).setBearerToken (bearerToken );
304+ return this ;
305+ }
306+ }
307+ throw new RuntimeException ("No Bearer authentication configured!" );
308+ }
309+
310+ /**
311+ * Helper method to set the supplier of access tokens for Bearer authentication.
312+ *
313+ * @param tokenSupplier the token supplier function
314+ */
315+ public void setBearerToken (Supplier <String > tokenSupplier ) {
316+ for (Authentication auth : authentications .values ()) {
317+ if (auth instanceof HttpBearerAuth ) {
318+ ((HttpBearerAuth ) auth ).setBearerToken (tokenSupplier );
319+ return ;
320+ }
321+ }
322+ throw new RuntimeException ("No Bearer authentication configured!" );
323+ }
289324
290325
291326
@@ -295,7 +330,7 @@ public String getTempFolderPath() {
295330 * @param userAgent User agent
296331 * @return API client
297332 */
298- public ApiClient setUserAgent (String userAgent ) {
333+ public final ApiClient setUserAgent (String userAgent ) {
299334 addDefaultHeader ("User-Agent" , userAgent );
300335 return this ;
301336 }
@@ -317,7 +352,7 @@ public ApiClient setTempFolderPath(String tempFolderPath) {
317352 * @param value The header's value
318353 * @return API client
319354 */
320- public ApiClient addDefaultHeader (String key , String value ) {
355+ public final ApiClient addDefaultHeader (String key , String value ) {
321356 defaultHeaderMap .put (key , value );
322357 return this ;
323358 }
@@ -473,7 +508,7 @@ public List<Pair> parameterToPair(String name, Object value) {
473508 * @param value The value of the parameter.
474509 * @return A list of {@code Pair} objects.
475510 */
476- public List <Pair > parameterToPairs (String collectionFormat , String name , Collection value ) {
511+ public List <Pair > parameterToPairs (String collectionFormat , String name , Collection <?> value ) {
477512 List <Pair > params = new ArrayList <Pair >();
478513
479514 // preconditions
@@ -607,7 +642,7 @@ protected Map<String, List<String>> transformResponseHeaders(Header[] headers) {
607642 /**
608643 * Parse content type object from header value
609644 */
610- private ContentType getContentType (String headerValue ) throws ApiException {
645+ protected ContentType getContentType (String headerValue ) throws ApiException {
611646 try {
612647 return ContentType .parse (headerValue );
613648 } catch (UnsupportedCharsetException e ) {
@@ -618,7 +653,7 @@ private ContentType getContentType(String headerValue) throws ApiException {
618653 /**
619654 * Get content type of a response or null if one was not provided
620655 */
621- private String getResponseMimeType (HttpResponse response ) throws ApiException {
656+ protected String getResponseMimeType (HttpResponse response ) throws ApiException {
622657 Header contentTypeHeader = response .getFirstHeader ("Content-Type" );
623658 if (contentTypeHeader != null ) {
624659 return getContentType (contentTypeHeader .getValue ()).getMimeType ();
@@ -713,10 +748,11 @@ public <T> T deserialize(CloseableHttpResponse response, TypeReference<T> valueT
713748 }
714749
715750 return objectMapper .readValue (content , valueType );
716- } else if ("text/plain" . equalsIgnoreCase ( mimeType )) {
751+ } else if (mimeType . toLowerCase (). startsWith ( "text/" )) {
717752 // convert input stream to string
718753 return (T ) EntityUtils .toString (entity );
719754 } else {
755+ Map <String , List <String >> responseHeaders = transformResponseHeaders (response .getHeaders ());
720756 throw new ApiException (
721757 "Deserialization for content type '" + mimeType + "' not supported for type '" + valueType + "'" ,
722758 response .getCode (),
@@ -726,7 +762,7 @@ public <T> T deserialize(CloseableHttpResponse response, TypeReference<T> valueT
726762 }
727763 }
728764
729- private File downloadFileFromResponse (CloseableHttpResponse response ) throws IOException {
765+ protected File downloadFileFromResponse (CloseableHttpResponse response ) throws IOException {
730766 Header contentDispositionHeader = response .getFirstHeader ("Content-Disposition" );
731767 String contentDisposition = contentDispositionHeader == null ? null : contentDispositionHeader .getValue ();
732768 File file = prepareDownloadFile (contentDisposition );
@@ -778,6 +814,7 @@ public String getBaseURL() {
778814 if (serverIndex != null ) {
779815 if (serverIndex < 0 || serverIndex >= servers .size ()) {
780816 throw new ArrayIndexOutOfBoundsException (String .format (
817+ Locale .ROOT ,
781818 "Invalid index %d when selecting the host settings. Must be less than %d" , serverIndex , servers .size ()
782819 ));
783820 }
@@ -797,7 +834,7 @@ public String getBaseURL() {
797834 * @param urlQueryDeepObject URL query string of the deep object parameters
798835 * @return The full URL
799836 */
800- private String buildUrl (String path , List <Pair > queryParams , List <Pair > collectionQueryParams , String urlQueryDeepObject ) {
837+ protected String buildUrl (String path , List <Pair > queryParams , List <Pair > collectionQueryParams , String urlQueryDeepObject ) {
801838 String baseURL = getBaseURL ();
802839
803840 final StringBuilder url = new StringBuilder ();
@@ -862,12 +899,15 @@ protected Cookie buildCookie(String key, String value, URI uri) {
862899 }
863900
864901 protected <T > T processResponse (CloseableHttpResponse response , TypeReference <T > returnType ) throws ApiException , IOException , ParseException {
865- statusCode = response .getCode ();
902+ int statusCode = response .getCode ();
903+ lastStatusCode .set (statusCode );
866904 if (statusCode == HttpStatus .SC_NO_CONTENT ) {
867905 return null ;
868906 }
869907
870- responseHeaders = transformResponseHeaders (response .getHeaders ());
908+ Map <String , List <String >> responseHeaders = transformResponseHeaders (response .getHeaders ());
909+ lastResponseHeaders .set (responseHeaders );
910+
871911 if (isSuccessfulStatus (statusCode )) {
872912 return this .deserialize (response , returnType );
873913 } else {
@@ -973,7 +1013,7 @@ public <T> T invokeAPI(
9731013 * @param headerParams Header parameters
9741014 * @param cookieParams Cookie parameters
9751015 */
976- private void updateParamsForAuth (String [] authNames , List <Pair > queryParams , Map <String , String > headerParams , Map <String , String > cookieParams ) {
1016+ protected void updateParamsForAuth (String [] authNames , List <Pair > queryParams , Map <String , String > headerParams , Map <String , String > cookieParams ) {
9771017 for (String authName : authNames ) {
9781018 Authentication auth = authentications .get (authName );
9791019 if (auth == null ) throw new RuntimeException ("Authentication undefined: " + authName );
0 commit comments