I would create a common
executeRequest
method:private HttpResponse executeRequest(final HttpUriRequest request, final String authHeader, final boolean authHeader) { if (authHeader){ request.addHeader(authHeader); } return httpClient.execute(request); }
then remove the code duplication from the case
branches.
switch (httpVerb) {
case HTTP_POST:
return executeRequest(httpPost, authHeader, header);
case HTTP_PUT:
return executeRequest(httpPut, authHeader, header);
case HTTP_GET:
return executeRequest(httpGet, authHeader, header);
default:
return null;
}
Anyway, it doesn't seem too good that you have httpPost
, httpGet
and httpPut
at the same time.
Wouldn't it worth to check the result of
isInternetConnected()
at the beginning of the method? I'm not too familiar with Android development, maybe it's the best to put into thecatch
block. Anyway, if it is not a slow/costly service I would call at the beginning of the method too.Calling
String.valueOf(numberOfTries)
seem unnecessary. I could be simplyLog.i(TAG, "executing for the " + numberOfTries + " time");
I'd use a loop instead of recursion. Two links on the topic:
I would create a common
executeRequest
method:private HttpResponse executeRequest(final HttpUriRequest request, final String authHeader, final boolean authHeader) { if (authHeader){ request.addHeader(authHeader); } return httpClient.execute(request); }
then remove the code duplication from the case
branches.
switch (httpVerb) {
case HTTP_POST:
return executeRequest(httpPost, authHeader, header);
case HTTP_PUT:
return executeRequest(httpPut, authHeader, header);
case HTTP_GET:
return executeRequest(httpGet, authHeader, header);
default:
return null;
}
Anyway, it doesn't seem too good that you have httpPost
, httpGet
and httpPut
at the same time.
Wouldn't it worth to check the result of
isInternetConnected()
at the beginning of the method? I'm not too familiar with Android development, maybe it's the best to put into thecatch
block. Anyway, if it is not a slow/costly service I would call at the beginning of the method too.Calling
String.valueOf(numberOfTries)
seem unnecessary. I could be simplyLog.i(TAG, "executing for the " + numberOfTries + " time");
I'd use a loop instead of recursion. Two links on the topic:
I would create a common
executeRequest
method:private HttpResponse executeRequest(final HttpUriRequest request, final String authHeader, final boolean authHeader) { if (authHeader){ request.addHeader(authHeader); } return httpClient.execute(request); }
then remove the code duplication from the case
branches.
switch (httpVerb) {
case HTTP_POST:
return executeRequest(httpPost, authHeader, header);
case HTTP_PUT:
return executeRequest(httpPut, authHeader, header);
case HTTP_GET:
return executeRequest(httpGet, authHeader, header);
default:
return null;
}
Anyway, it doesn't seem too good that you have httpPost
, httpGet
and httpPut
at the same time.
Wouldn't it worth to check the result of
isInternetConnected()
at the beginning of the method? I'm not too familiar with Android development, maybe it's the best to put into thecatch
block. Anyway, if it is not a slow/costly service I would call at the beginning of the method too.Calling
String.valueOf(numberOfTries)
seem unnecessary. I could be simplyLog.i(TAG, "executing for the " + numberOfTries + " time");
I'd use a loop instead of recursion. Two links on the topic:
I would create a common
executeRequest
method:private HttpResponse executeRequest(final HttpUriRequest request, final String authHeader, final boolean authHeader) { if (authHeader){ request.addHeader(authHeader); } return httpClient.execute(request); }
then remove the code duplication from the case
branches.
switch (httpVerb) {
case HTTP_POST:
return executeRequest(httpPost, authHeader, header);
case HTTP_PUT:
return executeRequest(httpPut, authHeader, header);
case HTTP_GET:
return executeRequest(httpGet, authHeader, header);
default:
return null;
}
Anyway, it doesn't seem too good that you have httpPost
, httpGet
and httpPut
at the same time.
Wouldn't it worth to check the result of
isInternetConnected()
at the beginning of the method? I'm not too familiar with Android development, maybe it's the best to put into thecatch
block. Anyway, if it is not a slow/costly service I would call at the beginning of the method too.Calling
String.valueOf(numberOfTries)
seem unnecessary. I could be simplyLog.i(TAG, "executing for the " + numberOfTries + " time");
I'd use a loop instead of recursion. Two links on the topic:
I would create a common
executeRequest
method:private HttpResponse executeRequest(final HttpUriRequest request, final String authHeader, final boolean authHeader) { if (authHeader){ request.addHeader(authHeader); } return httpClient.execute(request); }
then remove the code duplication from the case
branches.
switch (httpVerb) {
case HTTP_POST:
return executeRequest(httpPost, authHeader, header);
case HTTP_PUT:
return executeRequest(httpPut, authHeader, header);
case HTTP_GET:
return executeRequest(httpGet, authHeader, header);
default:
return null;
}
Anyway, it doesn't seem too good that you have httpPost
, httpGet
and httpPut
at the same time.
Wouldn't it worth to check the result of
isInternetConnected()
at the beginning of the method? I'm not too familiar with Android development, maybe it's the best to put into thecatch
block.Calling
String.valueOf(numberOfTries)
seem unnecessary. I could be simplyLog.i(TAG, "executing for the " + numberOfTries + " time");
I'd use a loop instead of recursion. Two links on the topic:
I would create a common
executeRequest
method:private HttpResponse executeRequest(final HttpUriRequest request, final String authHeader, final boolean authHeader) { if (authHeader){ request.addHeader(authHeader); } return httpClient.execute(request); }
then remove the code duplication from the case
branches.
switch (httpVerb) {
case HTTP_POST:
return executeRequest(httpPost, authHeader, header);
case HTTP_PUT:
return executeRequest(httpPut, authHeader, header);
case HTTP_GET:
return executeRequest(httpGet, authHeader, header);
default:
return null;
}
Anyway, it doesn't seem too good that you have httpPost
, httpGet
and httpPut
at the same time.
Wouldn't it worth to check the result of
isInternetConnected()
at the beginning of the method? I'm not too familiar with Android development, maybe it's the best to put into thecatch
block. Anyway, if it is not a slow/costly service I would call at the beginning of the method too.Calling
String.valueOf(numberOfTries)
seem unnecessary. I could be simplyLog.i(TAG, "executing for the " + numberOfTries + " time");
I'd use a loop instead of recursion. Two links on the topic:
I would create a common
executeRequest
method:private HttpResponse executeRequest(final HttpUriRequest request, final String authHeader, final boolean authHeader) { if (authHeader){ request.addHeader(authHeader); } return httpClient.execute(request); }
then remove the code duplication from the case
branches.
switch (httpVerb) {
case HTTP_POST:
return executeRequest(httpPost, authHeader, header);
case HTTP_PUT:
return executeRequest(httpPut, authHeader, header);
case HTTP_GET:
return executeRequest(httpGet, authHeader, header);
default:
return null;
}
Anyway, it doesn't seem too good that you have httpPost
, httpGet
and httpPut
at the same time.
Wouldn't it worth to check the result of
isInternetConnected()
at the beginning of the method? I'm not too familiar with Android development, maybe it's the best to put into thecatch
block.Calling
String.valueOf(numberOfTries)
seem unnecessary. I could be simplyLog.i(TAG, "executing for the " + numberOfTries + " time");
I'd use a loop instead of recursion. Two links on the topic: