Skip to content

Commit

Permalink
Fixes #243. Make sure http client is not null
Browse files Browse the repository at this point in the history
  • Loading branch information
eyedol committed Mar 3, 2015
1 parent 9722dd8 commit 758bb70
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 30 deletions.
Expand Up @@ -52,9 +52,11 @@ public void lowBatteryLevelRequest(int batteryLevel) {
} catch (Exception e) {
Util.logActivities(prefs.getContext(), e.getMessage());
} finally {
if (HttpStatus.SC_OK == client.responseCode()) {
Util.logActivities(prefs.getContext(), prefs.getContext().getResources()
.getString(R.string.successful_alert_to_server));
if(client !=null) {
if (HttpStatus.SC_OK == client.responseCode()) {
Util.logActivities(prefs.getContext(), prefs.getContext().getResources()
.getString(R.string.successful_alert_to_server));
}
}
}
}
Expand Down Expand Up @@ -95,9 +97,11 @@ public void smsSendFailedRequest(String resultMessage,
} catch (Exception e) {
Util.logActivities(prefs.getContext(), e.getMessage());
} finally {
if (HttpStatus.SC_OK == client.responseCode()) {
Util.logActivities(prefs.getContext(), prefs.getContext().getResources()
.getString(R.string.successful_alert_to_server));
if(client !=null) {
if (HttpStatus.SC_OK == client.responseCode()) {
Util.logActivities(prefs.getContext(), prefs.getContext().getResources()
.getString(R.string.successful_alert_to_server));
}
}
}
}
Expand Down
Expand Up @@ -81,8 +81,10 @@ public void sendMessageResultPOSTRequest(SyncUrl syncUrl, List<MessageResult> re
} catch (Exception e) {
mUtil.log(mContext.getString(R.string.message_processed_failed));
} finally {
if (HttpStatus.SC_OK == client.responseCode()) {
mUtil.log(mContext.getString(R.string.message_processed_success));
if(client !=null) {
if (HttpStatus.SC_OK == client.responseCode()) {
mUtil.log(mContext.getString(R.string.message_processed_success));
}
}
}
}
Expand Down Expand Up @@ -114,19 +116,21 @@ public MessagesUUIDSResponse sendQueuedMessagesPOSTRequest(SyncUrl syncUrl,
mContext.getString(R.string.message_processed_failed) + " " + e
.getMessage());
} finally {
if (HttpStatus.SC_OK == client.responseCode()) {

mUtil.log(mContext.getString(R.string.message_processed_success));
response = parseMessagesUUIDSResponse(client);
response.setSuccess(true);
Util.logActivities(mContext,
mContext.getString(R.string.message_processed_success));

} else {
response = new MessagesUUIDSResponse(client.responseCode());
Util.logActivities(mContext,
mContext.getString(R.string.queued_messages_request_status,
client.responseCode(), client.getResponse()));
if(client !=null) {
if (HttpStatus.SC_OK == client.responseCode()) {

mUtil.log(mContext.getString(R.string.message_processed_success));
response = parseMessagesUUIDSResponse(client);
response.setSuccess(true);
Util.logActivities(mContext,
mContext.getString(R.string.message_processed_success));

} else {
response = new MessagesUUIDSResponse(client.responseCode());
Util.logActivities(mContext,
mContext.getString(R.string.queued_messages_request_status,
client.responseCode(), client.getResponse()));
}
}
}
}
Expand All @@ -141,7 +145,7 @@ public MessagesUUIDSResponse sendQueuedMessagesPOSTRequest(SyncUrl syncUrl,
* or failure and list of message uuids
*/
public MessagesUUIDSResponse sendMessageResultGETRequest(SyncUrl syncUrl) {
MessagesUUIDSResponse response;
MessagesUUIDSResponse response = null;
String newEndPointURL = syncUrl.getUrl().concat(TASK_RESULT_URL_PARAM);

final String urlSecret = syncUrl.getSecret();
Expand Down Expand Up @@ -171,14 +175,16 @@ public MessagesUUIDSResponse sendMessageResultGETRequest(SyncUrl syncUrl) {
Util.logActivities(mContext,
mContext.getString(R.string.message_processed_failed) + " " + e.getMessage());
} finally {
if (HttpStatus.SC_OK == client.responseCode()) {
response = parseMessagesUUIDSResponse(client);
response.setSuccess(true);
} else {
response = new MessagesUUIDSResponse(client.responseCode());
Util.logActivities(mContext,
mContext.getString(R.string.messages_result_request_status,
client.responseCode(), client.getResponse()));
if(client !=null) {
if (HttpStatus.SC_OK == client.responseCode()) {
response = parseMessagesUUIDSResponse(client);
response.setSuccess(true);
} else {
response = new MessagesUUIDSResponse(client.responseCode());
Util.logActivities(mContext,
mContext.getString(R.string.messages_result_request_status,
client.responseCode(), client.getResponse()));
}
}
}
return response;
Expand Down

0 comments on commit 758bb70

Please sign in to comment.