Loading lib/src/main/java/com/nextcloud/android/sso/api/NextcloudAPI.java +1 −1 Original line number Diff line number Diff line Loading @@ -137,7 +137,7 @@ public class NextcloudAPI { return convertStreamToTargetEntity(response.getBody(), type); } private <T> T convertStreamToTargetEntity(InputStream inputStream, Type targetEntity) throws IOException { public <T> T convertStreamToTargetEntity(InputStream inputStream, Type targetEntity) throws IOException { final T result; try (InputStream os = inputStream; Reader targetReader = new InputStreamReader(os)) { Loading lib/src/main/java/com/nextcloud/android/sso/helper/Retrofit2Helper.java +8 −2 Original line number Diff line number Diff line Loading @@ -7,7 +7,9 @@ import com.nextcloud.android.sso.api.NextcloudAPI; import com.nextcloud.android.sso.exceptions.NextcloudHttpRequestFailedException; import java.lang.reflect.Type; import java.util.List; import okhttp3.Headers; import okhttp3.MediaType; import okhttp3.Protocol; import okhttp3.Request; Loading Loading @@ -53,8 +55,12 @@ public final class Retrofit2Helper { @Override public Response<T> execute() { try { T body = nextcloudAPI.performRequestV2(resType, nextcloudRequest); return Response.success(body); com.nextcloud.android.sso.api.Response response = nextcloudAPI.performNetworkRequestV2(nextcloudRequest); T body = nextcloudAPI.convertStreamToTargetEntity(response.getBody(), resType); return Response.success(body, Headers.of((String[]) response.getPlainHeaders().stream().map(h -> List.of(h.getName(), h.getValue())).toArray()) ); } catch (NextcloudHttpRequestFailedException e) { final Throwable cause = e.getCause(); return convertExceptionToResponse(e.getStatusCode(), cause == null ? e.getMessage() : cause.getMessage()); Loading lib/src/test/java/com/nextcloud/android/sso/api/TestRetrofitAPI.java +20 −10 Original line number Diff line number Diff line Loading @@ -113,7 +113,8 @@ public class TestRetrofitAPI { Type type = new TypeToken<List<String>>() {}.getType(); try { verify(nextcloudApiMock).performRequestV2(eq(type), eq(request)); verify(nextcloudApiMock).performNetworkRequestV2(eq(request)); verify(nextcloudApiMock).convertStreamToTargetEntity(any(), eq(type)); } catch (Exception e) { fail(e.getMessage()); } Loading Loading @@ -199,7 +200,8 @@ public class TestRetrofitAPI { Type type = new TypeToken<List<String>>() {}.getType(); try { verify(nextcloudApiMock).performRequestV2(eq(type), eq(request)); verify(nextcloudApiMock).performNetworkRequestV2(eq(request)); verify(nextcloudApiMock).convertStreamToTargetEntity(any(), eq(type)); } catch (Exception e) { fail(e.getMessage()); } Loading Loading @@ -260,7 +262,8 @@ public class TestRetrofitAPI { Type type = new TypeToken<Void>() {}.getType(); try { verify(nextcloudApiMock).performRequestV2(eq(type), eq(request)); verify(nextcloudApiMock).performNetworkRequestV2(eq(request)); verify(nextcloudApiMock).convertStreamToTargetEntity(any(), eq(type)); } catch (Exception e) { fail(e.getMessage()); } Loading Loading @@ -319,7 +322,8 @@ public class TestRetrofitAPI { Type type = new TypeToken<Void>() {}.getType(); try { verify(nextcloudApiMock).performRequestV2(eq(type), eq(request)); verify(nextcloudApiMock).performNetworkRequestV2(eq(request)); verify(nextcloudApiMock).convertStreamToTargetEntity(any(), eq(type)); } catch (Exception e) { fail(e.getMessage()); } Loading Loading @@ -350,7 +354,8 @@ public class TestRetrofitAPI { Type type = new TypeToken<Void>() {}.getType(); try { verify(nextcloudApiMock).performRequestV2(eq(type), eq(request)); verify(nextcloudApiMock).performNetworkRequestV2(eq(request)); verify(nextcloudApiMock).convertStreamToTargetEntity(any(), eq(type)); } catch (Exception e) { fail(e.getMessage()); } Loading @@ -377,7 +382,8 @@ public class TestRetrofitAPI { Type type = new TypeToken<Void>() {}.getType(); try { verify(nextcloudApiMock).performRequestV2(eq(type), eq(request)); verify(nextcloudApiMock).performNetworkRequestV2(eq(request)); verify(nextcloudApiMock).convertStreamToTargetEntity(any(), eq(type)); } catch (Exception e) { fail(e.getMessage()); } Loading @@ -401,7 +407,8 @@ public class TestRetrofitAPI { Type type = new TypeToken<ResponseBody>() {}.getType(); try { verify(nextcloudApiMock).performRequestV2(eq(type), eq(request)); verify(nextcloudApiMock).performNetworkRequestV2(eq(request)); verify(nextcloudApiMock).convertStreamToTargetEntity(any(), eq(type)); } catch (Exception e) { fail(e.getMessage()); } Loading @@ -426,7 +433,8 @@ public class TestRetrofitAPI { Type type = new TypeToken<ResponseBody>() {}.getType(); try { verify(nextcloudApiMock).performRequestV2(eq(type), eq(request)); verify(nextcloudApiMock).performNetworkRequestV2(eq(request)); verify(nextcloudApiMock).convertStreamToTargetEntity(any(), eq(type)); } catch (Exception e) { fail(e.getMessage()); } Loading Loading @@ -454,7 +462,8 @@ public class TestRetrofitAPI { Type type = new TypeToken<ResponseBody>() { }.getType(); try { verify(nextcloudApiMock).performRequestV2(eq(type), eq(request)); verify(nextcloudApiMock).performNetworkRequestV2(eq(request)); verify(nextcloudApiMock).convertStreamToTargetEntity(any(), eq(type)); } catch (Exception e) { fail(e.getMessage()); } Loading Loading @@ -482,7 +491,8 @@ public class TestRetrofitAPI { Type type = new TypeToken<ResponseBody>() { }.getType(); try { verify(nextcloudApiMock).performRequestV2(eq(type), eq(request)); verify(nextcloudApiMock).performNetworkRequestV2(eq(request)); verify(nextcloudApiMock).convertStreamToTargetEntity(any(), eq(type)); } catch (Exception e) { fail(e.getMessage()); } Loading Loading
lib/src/main/java/com/nextcloud/android/sso/api/NextcloudAPI.java +1 −1 Original line number Diff line number Diff line Loading @@ -137,7 +137,7 @@ public class NextcloudAPI { return convertStreamToTargetEntity(response.getBody(), type); } private <T> T convertStreamToTargetEntity(InputStream inputStream, Type targetEntity) throws IOException { public <T> T convertStreamToTargetEntity(InputStream inputStream, Type targetEntity) throws IOException { final T result; try (InputStream os = inputStream; Reader targetReader = new InputStreamReader(os)) { Loading
lib/src/main/java/com/nextcloud/android/sso/helper/Retrofit2Helper.java +8 −2 Original line number Diff line number Diff line Loading @@ -7,7 +7,9 @@ import com.nextcloud.android.sso.api.NextcloudAPI; import com.nextcloud.android.sso.exceptions.NextcloudHttpRequestFailedException; import java.lang.reflect.Type; import java.util.List; import okhttp3.Headers; import okhttp3.MediaType; import okhttp3.Protocol; import okhttp3.Request; Loading Loading @@ -53,8 +55,12 @@ public final class Retrofit2Helper { @Override public Response<T> execute() { try { T body = nextcloudAPI.performRequestV2(resType, nextcloudRequest); return Response.success(body); com.nextcloud.android.sso.api.Response response = nextcloudAPI.performNetworkRequestV2(nextcloudRequest); T body = nextcloudAPI.convertStreamToTargetEntity(response.getBody(), resType); return Response.success(body, Headers.of((String[]) response.getPlainHeaders().stream().map(h -> List.of(h.getName(), h.getValue())).toArray()) ); } catch (NextcloudHttpRequestFailedException e) { final Throwable cause = e.getCause(); return convertExceptionToResponse(e.getStatusCode(), cause == null ? e.getMessage() : cause.getMessage()); Loading
lib/src/test/java/com/nextcloud/android/sso/api/TestRetrofitAPI.java +20 −10 Original line number Diff line number Diff line Loading @@ -113,7 +113,8 @@ public class TestRetrofitAPI { Type type = new TypeToken<List<String>>() {}.getType(); try { verify(nextcloudApiMock).performRequestV2(eq(type), eq(request)); verify(nextcloudApiMock).performNetworkRequestV2(eq(request)); verify(nextcloudApiMock).convertStreamToTargetEntity(any(), eq(type)); } catch (Exception e) { fail(e.getMessage()); } Loading Loading @@ -199,7 +200,8 @@ public class TestRetrofitAPI { Type type = new TypeToken<List<String>>() {}.getType(); try { verify(nextcloudApiMock).performRequestV2(eq(type), eq(request)); verify(nextcloudApiMock).performNetworkRequestV2(eq(request)); verify(nextcloudApiMock).convertStreamToTargetEntity(any(), eq(type)); } catch (Exception e) { fail(e.getMessage()); } Loading Loading @@ -260,7 +262,8 @@ public class TestRetrofitAPI { Type type = new TypeToken<Void>() {}.getType(); try { verify(nextcloudApiMock).performRequestV2(eq(type), eq(request)); verify(nextcloudApiMock).performNetworkRequestV2(eq(request)); verify(nextcloudApiMock).convertStreamToTargetEntity(any(), eq(type)); } catch (Exception e) { fail(e.getMessage()); } Loading Loading @@ -319,7 +322,8 @@ public class TestRetrofitAPI { Type type = new TypeToken<Void>() {}.getType(); try { verify(nextcloudApiMock).performRequestV2(eq(type), eq(request)); verify(nextcloudApiMock).performNetworkRequestV2(eq(request)); verify(nextcloudApiMock).convertStreamToTargetEntity(any(), eq(type)); } catch (Exception e) { fail(e.getMessage()); } Loading Loading @@ -350,7 +354,8 @@ public class TestRetrofitAPI { Type type = new TypeToken<Void>() {}.getType(); try { verify(nextcloudApiMock).performRequestV2(eq(type), eq(request)); verify(nextcloudApiMock).performNetworkRequestV2(eq(request)); verify(nextcloudApiMock).convertStreamToTargetEntity(any(), eq(type)); } catch (Exception e) { fail(e.getMessage()); } Loading @@ -377,7 +382,8 @@ public class TestRetrofitAPI { Type type = new TypeToken<Void>() {}.getType(); try { verify(nextcloudApiMock).performRequestV2(eq(type), eq(request)); verify(nextcloudApiMock).performNetworkRequestV2(eq(request)); verify(nextcloudApiMock).convertStreamToTargetEntity(any(), eq(type)); } catch (Exception e) { fail(e.getMessage()); } Loading @@ -401,7 +407,8 @@ public class TestRetrofitAPI { Type type = new TypeToken<ResponseBody>() {}.getType(); try { verify(nextcloudApiMock).performRequestV2(eq(type), eq(request)); verify(nextcloudApiMock).performNetworkRequestV2(eq(request)); verify(nextcloudApiMock).convertStreamToTargetEntity(any(), eq(type)); } catch (Exception e) { fail(e.getMessage()); } Loading @@ -426,7 +433,8 @@ public class TestRetrofitAPI { Type type = new TypeToken<ResponseBody>() {}.getType(); try { verify(nextcloudApiMock).performRequestV2(eq(type), eq(request)); verify(nextcloudApiMock).performNetworkRequestV2(eq(request)); verify(nextcloudApiMock).convertStreamToTargetEntity(any(), eq(type)); } catch (Exception e) { fail(e.getMessage()); } Loading Loading @@ -454,7 +462,8 @@ public class TestRetrofitAPI { Type type = new TypeToken<ResponseBody>() { }.getType(); try { verify(nextcloudApiMock).performRequestV2(eq(type), eq(request)); verify(nextcloudApiMock).performNetworkRequestV2(eq(request)); verify(nextcloudApiMock).convertStreamToTargetEntity(any(), eq(type)); } catch (Exception e) { fail(e.getMessage()); } Loading Loading @@ -482,7 +491,8 @@ public class TestRetrofitAPI { Type type = new TypeToken<ResponseBody>() { }.getType(); try { verify(nextcloudApiMock).performRequestV2(eq(type), eq(request)); verify(nextcloudApiMock).performNetworkRequestV2(eq(request)); verify(nextcloudApiMock).convertStreamToTargetEntity(any(), eq(type)); } catch (Exception e) { fail(e.getMessage()); } Loading