6161 */
6262public class ApiClient {
6363
64- private String basePath = "https://api.dofusdu.de" ;
64+ protected String basePath = "https://api.dofusdu.de" ;
6565 protected List <ServerConfiguration > servers = new ArrayList <ServerConfiguration >(Arrays .asList (
6666 new ServerConfiguration (
6767 "https://api.dofusdu.de" ,
@@ -71,26 +71,26 @@ public class ApiClient {
7171 ));
7272 protected Integer serverIndex = 0 ;
7373 protected Map <String , String > serverVariables = null ;
74- private boolean debugging = false ;
75- private Map <String , String > defaultHeaderMap = new HashMap <String , String >();
76- private Map <String , String > defaultCookieMap = new HashMap <String , String >();
77- private String tempFolderPath = null ;
74+ protected boolean debugging = false ;
75+ protected Map <String , String > defaultHeaderMap = new HashMap <String , String >();
76+ protected Map <String , String > defaultCookieMap = new HashMap <String , String >();
77+ protected String tempFolderPath = null ;
7878
79- private Map <String , Authentication > authentications ;
79+ protected Map <String , Authentication > authentications ;
8080
81- private DateFormat dateFormat ;
82- private DateFormat datetimeFormat ;
83- private boolean lenientDatetimeFormat ;
84- private int dateLength ;
81+ protected DateFormat dateFormat ;
82+ protected DateFormat datetimeFormat ;
83+ protected boolean lenientDatetimeFormat ;
84+ protected int dateLength ;
8585
86- private InputStream sslCaCert ;
87- private boolean verifyingSsl ;
88- private KeyManager [] keyManagers ;
86+ protected InputStream sslCaCert ;
87+ protected boolean verifyingSsl ;
88+ protected KeyManager [] keyManagers ;
8989
90- private OkHttpClient httpClient ;
91- private JSON json ;
90+ protected OkHttpClient httpClient ;
91+ protected JSON json ;
9292
93- private HttpLoggingInterceptor loggingInterceptor ;
93+ protected HttpLoggingInterceptor loggingInterceptor ;
9494
9595 /**
9696 * Basic constructor for ApiClient
@@ -119,11 +119,11 @@ public ApiClient(OkHttpClient client) {
119119 authentications = Collections .unmodifiableMap (authentications );
120120 }
121121
122- private void initHttpClient () {
122+ protected void initHttpClient () {
123123 initHttpClient (Collections .<Interceptor >emptyList ());
124124 }
125125
126- private void initHttpClient (List <Interceptor > interceptors ) {
126+ protected void initHttpClient (List <Interceptor > interceptors ) {
127127 OkHttpClient .Builder builder = new OkHttpClient .Builder ();
128128 builder .addNetworkInterceptor (getProgressInterceptor ());
129129 for (Interceptor interceptor : interceptors ) {
@@ -133,7 +133,7 @@ private void initHttpClient(List<Interceptor> interceptors) {
133133 httpClient = builder .build ();
134134 }
135135
136- private void init () {
136+ protected void init () {
137137 verifyingSsl = true ;
138138
139139 json = new JSON ();
@@ -800,7 +800,7 @@ public String collectionPathParameterToString(String collectionFormat, Collectio
800800 * @return The sanitized filename
801801 */
802802 public String sanitizeFilename (String filename ) {
803- return filename .replaceAll ( " .*[/\\ \\ ]" , "" );
803+ return filename .replaceFirst ( "^ .*[/\\ \\ ]" , "" );
804804 }
805805
806806 /**
@@ -910,17 +910,8 @@ public <T> T deserialize(Response response, Type returnType) throws ApiException
910910 return (T ) downloadFileFromResponse (response );
911911 }
912912
913- String respBody ;
914- try {
915- if (response .body () != null )
916- respBody = response .body ().string ();
917- else
918- respBody = null ;
919- } catch (IOException e ) {
920- throw new ApiException (e );
921- }
922-
923- if (respBody == null || "" .equals (respBody )) {
913+ ResponseBody respBody = response .body ();
914+ if (respBody == null ) {
924915 return null ;
925916 }
926917
@@ -929,17 +920,25 @@ public <T> T deserialize(Response response, Type returnType) throws ApiException
929920 // ensuring a default content type
930921 contentType = "application/json" ;
931922 }
932- if (isJsonMime (contentType )) {
933- return JSON .deserialize (respBody , returnType );
934- } else if (returnType .equals (String .class )) {
935- // Expecting string, return the raw response body.
936- return (T ) respBody ;
937- } else {
938- throw new ApiException (
923+ try {
924+ if (isJsonMime (contentType )) {
925+ return JSON .deserialize (respBody .byteStream (), returnType );
926+ } else if (returnType .equals (String .class )) {
927+ String respBodyString = respBody .string ();
928+ if (respBodyString .isEmpty ()) {
929+ return null ;
930+ }
931+ // Expecting string, return the raw response body.
932+ return (T ) respBodyString ;
933+ } else {
934+ throw new ApiException (
939935 "Content type \" " + contentType + "\" is not supported for type: " + returnType ,
940936 response .code (),
941937 response .headers ().toMultimap (),
942- respBody );
938+ response .body ().string ());
939+ }
940+ } catch (IOException e ) {
941+ throw new ApiException (e );
943942 }
944943 }
945944
@@ -1435,7 +1434,7 @@ public String guessContentTypeFromFile(File file) {
14351434 * @param key The key of the Header element
14361435 * @param file The file to add to the Header
14371436 */
1438- private void addPartToMultiPartBuilder (MultipartBody .Builder mpBuilder , String key , File file ) {
1437+ protected void addPartToMultiPartBuilder (MultipartBody .Builder mpBuilder , String key , File file ) {
14391438 Headers partHeaders = Headers .of ("Content-Disposition" , "form-data; name=\" " + key + "\" ; filename=\" " + file .getName () + "\" " );
14401439 MediaType mediaType = MediaType .parse (guessContentTypeFromFile (file ));
14411440 mpBuilder .addPart (partHeaders , RequestBody .create (file , mediaType ));
@@ -1448,7 +1447,7 @@ private void addPartToMultiPartBuilder(MultipartBody.Builder mpBuilder, String k
14481447 * @param key The key of the Header element
14491448 * @param obj The complex object to add to the Header
14501449 */
1451- private void addPartToMultiPartBuilder (MultipartBody .Builder mpBuilder , String key , Object obj ) {
1450+ protected void addPartToMultiPartBuilder (MultipartBody .Builder mpBuilder , String key , Object obj ) {
14521451 RequestBody requestBody ;
14531452 if (obj instanceof String ) {
14541453 requestBody = RequestBody .create ((String ) obj , MediaType .parse ("text/plain" ));
@@ -1470,7 +1469,7 @@ private void addPartToMultiPartBuilder(MultipartBody.Builder mpBuilder, String k
14701469 * Get network interceptor to add it to the httpClient to track download progress for
14711470 * async requests.
14721471 */
1473- private Interceptor getProgressInterceptor () {
1472+ protected Interceptor getProgressInterceptor () {
14741473 return new Interceptor () {
14751474 @ Override
14761475 public Response intercept (Interceptor .Chain chain ) throws IOException {
@@ -1491,7 +1490,7 @@ public Response intercept(Interceptor.Chain chain) throws IOException {
14911490 * Apply SSL related settings to httpClient according to the current values of
14921491 * verifyingSsl and sslCaCert.
14931492 */
1494- private void applySslSettings () {
1493+ protected void applySslSettings () {
14951494 try {
14961495 TrustManager [] trustManagers ;
14971496 HostnameVerifier hostnameVerifier ;
@@ -1553,7 +1552,7 @@ public boolean verify(String hostname, SSLSession session) {
15531552 }
15541553 }
15551554
1556- private KeyStore newEmptyKeyStore (char [] password ) throws GeneralSecurityException {
1555+ protected KeyStore newEmptyKeyStore (char [] password ) throws GeneralSecurityException {
15571556 try {
15581557 KeyStore keyStore = KeyStore .getInstance (KeyStore .getDefaultType ());
15591558 keyStore .load (null , password );
@@ -1570,7 +1569,7 @@ private KeyStore newEmptyKeyStore(char[] password) throws GeneralSecurityExcepti
15701569 * @return The string representation of the HTTP request body
15711570 * @throws com.dofusdude.client.ApiException If fail to serialize the request body object into a string
15721571 */
1573- private String requestBodyToString (RequestBody requestBody ) throws ApiException {
1572+ protected String requestBodyToString (RequestBody requestBody ) throws ApiException {
15741573 if (requestBody != null ) {
15751574 try {
15761575 final Buffer buffer = new Buffer ();
0 commit comments