/*\r
- * Copyright 2017 ZTE Corporation.\r
+ * Copyright 2017-2023 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
*/\r
package org.onap.holmes.common.dmaap;\r
\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
-import javax.ws.rs.client.WebTarget;\r
-import javax.ws.rs.core.MediaType;\r
-import javax.ws.rs.core.Response;\r
+import jakarta.ws.rs.client.Entity;\r
import lombok.Getter;\r
import lombok.Setter;\r
-import org.apache.http.HttpStatus;\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
+import org.onap.holmes.common.utils.JerseyClient;\r
+import org.springframework.stereotype.Service;\r
+\r
+import java.util.concurrent.TimeUnit;\r
\r
@Getter\r
@Setter\r
@Service\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();\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 to DCAE.", e);\r
- }\r
- return checkStatus(response);\r
- }\r
+ private JerseyClient client = JerseyClient.newInstance(TimeUnit.SECONDS.toMillis(30));\r
\r
- private boolean checkStatus(Response response) {\r
- return response.getStatus() == HttpStatus.SC_OK;\r
+ public void publish(PolicyMsg msg) {\r
+ client.post(url, Entity.json(msg));\r
}\r
}\r