+/*\r
+ * Copyright 2017 ZTE Corporation.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * 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
+import com.fasterxml.jackson.databind.ObjectMapper;\r
+import javax.ws.rs.client.Client;\r
+import javax.ws.rs.client.ClientBuilder;\r
+import javax.ws.rs.client.Entity;\r
+import javax.ws.rs.client.WebTarget;\r
+import javax.ws.rs.core.MediaType;\r
+import javax.ws.rs.core.Response;\r
+import lombok.Getter;\r
+import lombok.Setter;\r
+import org.glassfish.jersey.client.ClientConfig;\r
+import org.onap.holmes.common.dmaap.entity.PolicyMsg;\r
+import org.onap.holmes.common.exception.CorrelationException;\r
+\r
+@Getter\r
+@Setter\r
+public class Publisher {\r
+\r
+ private String topic;\r
+ private String url;\r
+ private String authInfo;\r
+ 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.", 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
+ return checkStatus(response);\r
+ }\r
+\r
+ private boolean checkStatus(Response response) {\r
+ return false;\r
+ }\r
+}\r