modify http request bug
[holmes/common.git] / holmes-actions / src / main / java / org / onap / holmes / common / dmaap / Publisher.java
index eaeaf43..0f96181 100644 (file)
@@ -13,7 +13,6 @@
  * See the License for the specific language governing permissions and\r
  * limitations under the License.\r
  */\r
-\r
 package org.onap.holmes.common.dmaap;\r
 \r
 import com.fasterxml.jackson.core.JsonProcessingException;\r
@@ -26,12 +25,15 @@ import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;\r
 import lombok.Getter;\r
 import lombok.Setter;\r
+import org.apache.http.HttpStatus;\r
 import org.glassfish.jersey.client.ClientConfig;\r
+import org.jvnet.hk2.annotations.Service;\r
 import org.onap.holmes.common.dmaap.entity.PolicyMsg;\r
 import org.onap.holmes.common.exception.CorrelationException;\r
 \r
 @Getter\r
 @Setter\r
+@Service\r
 public class Publisher {\r
 \r
     private String topic;\r
@@ -46,17 +48,21 @@ public class Publisher {
         try {\r
             content = mapper.writeValueAsString(msg);\r
         } catch (JsonProcessingException e) {\r
-            throw new CorrelationException("Failed to convert the message object to a json string.", e);\r
+            throw new CorrelationException("Failed to convert the message object to a json string.",\r
+                    e);\r
         }\r
-\r
         WebTarget webTarget = client.target(url);\r
-        Response response = webTarget.request(MediaType.APPLICATION_JSON)\r
-                .post(Entity.entity(content, MediaType.APPLICATION_JSON));\r
-\r
+        Response response = null;\r
+        try {\r
+            response = webTarget.request(MediaType.APPLICATION_JSON)\r
+                    .post(Entity.entity(content, MediaType.APPLICATION_JSON));\r
+        } catch (Exception e) {\r
+            throw new CorrelationException("Failed to connect dcae.", e);\r
+        }\r
         return checkStatus(response);\r
     }\r
 \r
     private boolean checkStatus(Response response) {\r
-        return false;\r
+        return (response.getStatus() == HttpStatus.SC_OK) ? true : false;\r
     }\r
 }\r