Skip to main content
Code Review

Return to Answer

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
  1. 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.

  1. 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 the catch block. Anyway, if it is not a slow/costly service I would call at the beginning of the method too.

  2. Calling String.valueOf(numberOfTries) seem unnecessary. I could be simply

    Log.i(TAG, "executing for the " + numberOfTries + " time");
    
  3. I'd use a loop instead of recursion. Two links on the topic:

  1. 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.

  1. 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 the catch block. Anyway, if it is not a slow/costly service I would call at the beginning of the method too.

  2. Calling String.valueOf(numberOfTries) seem unnecessary. I could be simply

    Log.i(TAG, "executing for the " + numberOfTries + " time");
    
  3. I'd use a loop instead of recursion. Two links on the topic:

  1. 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.

  1. 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 the catch block. Anyway, if it is not a slow/costly service I would call at the beginning of the method too.

  2. Calling String.valueOf(numberOfTries) seem unnecessary. I could be simply

    Log.i(TAG, "executing for the " + numberOfTries + " time");
    
  3. I'd use a loop instead of recursion. Two links on the topic:

some clarification
Source Link
palacsint
  • 30.3k
  • 9
  • 82
  • 157
  1. 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.

  1. 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 the catch block. Anyway, if it is not a slow/costly service I would call at the beginning of the method too.

  2. Calling String.valueOf(numberOfTries) seem unnecessary. I could be simply

    Log.i(TAG, "executing for the " + numberOfTries + " time");
    
  3. I'd use a loop instead of recursion. Two links on the topic:

  1. 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.

  1. 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 the catch block.

  2. Calling String.valueOf(numberOfTries) seem unnecessary. I could be simply

    Log.i(TAG, "executing for the " + numberOfTries + " time");
    
  3. I'd use a loop instead of recursion. Two links on the topic:

  1. 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.

  1. 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 the catch block. Anyway, if it is not a slow/costly service I would call at the beginning of the method too.

  2. Calling String.valueOf(numberOfTries) seem unnecessary. I could be simply

    Log.i(TAG, "executing for the " + numberOfTries + " time");
    
  3. I'd use a loop instead of recursion. Two links on the topic:

Source Link
palacsint
  • 30.3k
  • 9
  • 82
  • 157
  1. 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.

  1. 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 the catch block.

  2. Calling String.valueOf(numberOfTries) seem unnecessary. I could be simply

    Log.i(TAG, "executing for the " + numberOfTries + " time");
    
  3. I'd use a loop instead of recursion. Two links on the topic:

lang-java

AltStyle によって変換されたページ (->オリジナル) /