Test Replace Jackson with GSON
[holmes/common.git] / holmes-actions / src / main / java / org / onap / holmes / common / dmaap / Publisher.java
index 0f96181..7201f36 100644 (file)
@@ -15,8 +15,7 @@
  */\r
 package org.onap.holmes.common.dmaap;\r
 \r
-import com.fasterxml.jackson.core.JsonProcessingException;\r
-import com.fasterxml.jackson.databind.ObjectMapper;\r
+import com.alibaba.fastjson.JSON;\r
 import javax.ws.rs.client.Client;\r
 import javax.ws.rs.client.ClientBuilder;\r
 import javax.ws.rs.client.Entity;\r
@@ -26,7 +25,6 @@ import javax.ws.rs.core.Response;
 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
@@ -42,27 +40,20 @@ public class Publisher {
     private String authExpDate;\r
 \r
     public boolean publish(PolicyMsg msg) throws CorrelationException {\r
-        Client client = ClientBuilder.newClient(new ClientConfig());\r
-        ObjectMapper mapper = new ObjectMapper();\r
-        String content = null;\r
-        try {\r
-            content = mapper.writeValueAsString(msg);\r
-        } catch (JsonProcessingException e) {\r
-            throw new CorrelationException("Failed to convert the message object to a json string.",\r
-                    e);\r
-        }\r
+        Client client = ClientBuilder.newClient();\r
+        String content = JSON.toJSONString(msg);\r
         WebTarget webTarget = client.target(url);\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
+            throw new CorrelationException("Failed to connect to DCAE.", e);\r
         }\r
         return checkStatus(response);\r
     }\r
 \r
     private boolean checkStatus(Response response) {\r
-        return (response.getStatus() == HttpStatus.SC_OK) ? true : false;\r
+        return response.getStatus() == HttpStatus.SC_OK;\r
     }\r
 }\r