import com.samsung.commons.utils.sender.exception.BadUrlException;
import com.samsung.commons.utils.sender.exception.HttpSenderException;
import com.samsung.commons.utils.sender.exception.NotAvailableException;
-import com.samsung.commons.utils.sender.exception.PostFailedException;
+import com.samsung.commons.utils.sender.exception.RequestFailedException;
import org.apache.log4j.Logger;
import org.springframework.http.HttpEntity;
import org.springframework.http.ResponseEntity;
}
- private void processStatus(ResponseEntity result) throws PostFailedException {
+ private void processStatus(ResponseEntity result) throws RequestFailedException {
if (!result.getStatusCode().is2xxSuccessful()) {
LOG.warn("(post) request failed, code: " + result.getStatusCode().value());
LOG.warn("(post) request failed, reason: " + result.getStatusCode().getReasonPhrase());
- throw new PostFailedException(MESSAGE_REQUEST_WAS_NOT_SUCCESSFUL, result.getStatusCode());
+ throw new RequestFailedException(MESSAGE_REQUEST_WAS_NOT_SUCCESSFUL, result.getStatusCode());
}
}
*
* @author <A HREF="mailto:o.abakumov@samsung.com">Oleksandr Abakumov</A>
* @version 1.0
- * @file PostFailedException.java
+ * @file RequestFailedException.java
* @brief Post failed
* @date Created : 10/30/2017
* @date Modified : 11/2/2017
* @par LLC "Samsung Electronics Co", Ltd (Seoul, Republic of Korea)
* @par Copyright : (c) Samsung Electronics Co, Ltd 2017. All rights reserved.
*/
-public class PostFailedException extends HttpSenderException {
+public class RequestFailedException extends HttpSenderException {
private final HttpStatus status;
* @param message message
* @param status status
*/
- public PostFailedException(String message, HttpStatus status) {
+ public RequestFailedException(String message, HttpStatus status) {
super(message, null);
this.status = status;
import com.samsung.commons.utils.sender.HttpSender;
import com.samsung.commons.utils.sender.exception.HttpSenderException;
+import com.samsung.commons.utils.sender.exception.RequestFailedException;
import org.apache.log4j.Logger;
import static java.lang.String.format;
public boolean sendNotification(Long reportId) {
LOG.debug(format("Send new report notification with id = %s", reportId));
- return doPost(REST_FOR_NOTIFICATION + reportId);
+ return doGet(REST_FOR_NOTIFICATION + reportId);
}
@Override
public boolean requestPolicy(Long policyId, String deviceId) {
LOG.debug(format("Send request for policy with id = %s", policyId));
- return doPost(REST_FOR_REQUEST_POLICY + policyId + "/device/" + deviceId);
+ return doGet(REST_FOR_REQUEST_POLICY + policyId + "/device/" + deviceId);
}
@Override
public boolean requestPolicyForAgent(Long policyId, String agentId) {
LOG.debug(format("Send request for policy with id = %s", policyId));
- return doPost(REST_FOR_REQUEST_POLICY + policyId + "/agent/" + agentId);
+ return doGet(REST_FOR_REQUEST_POLICY + policyId + "/agent/" + agentId);
}
- private boolean doPost(String url) {
+ private boolean doGet(String url) {
try {
- httpSender.post(url);
+ httpSender.get(url, String.class);
return true;
+ } catch (RequestFailedException e) {
+ LOG.error("Request failed", e);
+
+ return false;
} catch (HttpSenderException e) {
LOG.error("Sender exception", e);