Wrong HTTP methods. Fixed.
authorOleksandr Abakumov <o.abakumov@samsung.com>
Thu, 9 Nov 2017 07:24:11 +0000 (09:24 +0200)
committerOleksandr Abakumov <o.abakumov@samsung.com>
Thu, 9 Nov 2017 07:24:11 +0000 (09:24 +0200)
servers/commons/src/main/java/com/samsung/commons/utils/sender/HttpSender.java
servers/commons/src/main/java/com/samsung/commons/utils/sender/exception/RequestFailedException.java [moved from servers/commons/src/main/java/com/samsung/commons/utils/sender/exception/PostFailedException.java with 85% similarity]
servers/mq/src/main/java/com/samsung/servermq/utils/rest/DsmApiImpl.java

index 6d299c8..9173a30 100644 (file)
@@ -8,7 +8,7 @@ package com.samsung.commons.utils.sender;
 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;
@@ -173,12 +173,12 @@ public class HttpSender {
     }
 
 
-    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());
         }
     }
 
@@ -14,7 +14,7 @@ import org.springframework.http.HttpStatus;
  *
  * @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
@@ -22,7 +22,7 @@ import org.springframework.http.HttpStatus;
  * @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;
 
@@ -32,7 +32,7 @@ public class PostFailedException extends HttpSenderException {
      * @param message message
      * @param status  status
      */
-    public PostFailedException(String message, HttpStatus status) {
+    public RequestFailedException(String message, HttpStatus status) {
         super(message, null);
 
         this.status = status;
index aee03f2..e00a849 100644 (file)
@@ -7,6 +7,7 @@ package com.samsung.servermq.utils.rest;
 
 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;
@@ -53,27 +54,31 @@ public class DsmApiImpl implements DsmApi {
     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);