제주은행 메신저 발송
This commit is contained in:
@@ -0,0 +1,131 @@
|
||||
package com.eactive.ext.djb.ums;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.hc.client5.http.config.RequestConfig;
|
||||
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
|
||||
import org.apache.hc.client5.http.impl.classic.HttpClients;
|
||||
import org.apache.hc.core5.util.Timeout;
|
||||
|
||||
import com.eactive.apim.portal.template.entity.MessageCode;
|
||||
import com.eactive.apim.portal.template.entity.MessageRequest;
|
||||
import com.eactive.ext.kjb.common.KjbProperty;
|
||||
import com.eactive.ext.kjb.common.KjbPropertyHolder;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
public class DjbMessengerService {
|
||||
public final static int[] ALLOW_CHANNELS = { MessageCode.Channels.MESSENGER.getValue() };
|
||||
|
||||
|
||||
private static volatile DjbMessengerService instance;
|
||||
|
||||
|
||||
private DjbMessengerService() {
|
||||
// 싱글톤
|
||||
}
|
||||
|
||||
public static DjbMessengerService getInstance() {
|
||||
if (instance == null) {
|
||||
synchronized (DjbMessengerService.class) {
|
||||
if (instance == null) {
|
||||
instance = new DjbMessengerService();
|
||||
}
|
||||
}
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
private KjbProperty getProperty() {
|
||||
return KjbPropertyHolder.get();
|
||||
}
|
||||
|
||||
private boolean isRealMode() {
|
||||
String url = getProperty().getUmsHostUrl();
|
||||
return url != null && StringUtils.isNotEmpty(url.trim());
|
||||
}
|
||||
|
||||
private CloseableHttpClient createHttpClient() {
|
||||
return HttpClients.createDefault();
|
||||
}
|
||||
|
||||
private RequestConfig createRequestConfig() {
|
||||
KjbProperty prop = getProperty();
|
||||
return RequestConfig.custom()
|
||||
.setConnectTimeout(Timeout.ofSeconds(prop.getUmsConnectionTimeout()))
|
||||
.setResponseTimeout(Timeout.ofSeconds(prop.getUmsResponseTimeout()))
|
||||
.build();
|
||||
}
|
||||
|
||||
public static boolean isAllowChannel(MessageRequest message) {
|
||||
for (int channel : ALLOW_CHANNELS) {
|
||||
if ((message.getMessageCode().getChannels() & channel) == channel) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public boolean send(MessageRequest messageRequest) throws Exception {
|
||||
if (messageRequest == null) {
|
||||
throw new IllegalArgumentException("messageRequest is null");
|
||||
}
|
||||
|
||||
if (MessageCode.Channels.MESSENGER.getValue() != (messageRequest.getMessageCode().getChannels() & MessageCode.Channels.MESSENGER.getValue())) {
|
||||
log.error("지원하지 않는 발송 채널 - {}", messageRequest.getMessageCode().toString());
|
||||
throw new IllegalArgumentException("지원하지 않는 발송 채널 - " + messageRequest.getMessageCode().toString());
|
||||
}
|
||||
|
||||
this.httpConnection(messageRequest);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private void httpConnection(MessageRequest messageRequest) throws Exception {
|
||||
|
||||
URL url = new URL(getProperty().getSwingUrl());
|
||||
int timeoutvalue = 5 * 1000; // 타임아웃 설정을 위한 값 (단위: ms)
|
||||
// Charset charset = Charset.forName("UTF-8");
|
||||
Charset charset = Charset.forName("MS949");
|
||||
HttpURLConnection conn = null;
|
||||
BufferedReader br = null;
|
||||
StringBuffer sb = null;
|
||||
// String bodyData = this.makeBodyData(cnslDivCdval);
|
||||
|
||||
|
||||
// String responseData = "";
|
||||
// String method = bodyData != "" ? "POST" : "GET";
|
||||
// conn " (HttpURL Connection) url.openConnection();
|
||||
// conn.setRequestMethod(method); // w #4
|
||||
// // conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
|
||||
// conn.setRequestProperty("Content-Type", "application/json; charset=MS949");
|
||||
// conn.setConnectTimeout(timeoutValue); // Cz EGoR 48(5=)
|
||||
// conn.setReadTimeout(timeoutValue); // 8 #gOR N8(5s)
|
||||
// conn.setDoOutput(true);
|
||||
// // POst 40
|
||||
// if (method.equals("POST")) (
|
||||
// Outputstream os = conn.getOutputStream();
|
||||
// byte requestData[] - bodyData.getBytes(charset);
|
||||
// os.write(requestData);
|
||||
// os.close();
|
||||
// ph
|
||||
// System.out.println("getContentType():"t conn.getContentType());
|
||||
// System,out.println("getResponseCode();" t conn.getResponseCode());
|
||||
// System.out.println("getResponseMessage();" + conn.getResponseMessage());
|
||||
// if (LOG_DEBUG, isDebugEnabled()) (
|
||||
// LOG_DEBUG. debug("getContentType();" + conn.getContentType()); // 5 0= 5 #7
|
||||
// LOG_DEBUG. debug("getResponsecode();" + conn.getResponseCode()); // ## #5 7#7|
|
||||
// LOG_DEBUG. debug("getResponseMessage():" + conn.getResponseMessage()); //
|
||||
}
|
||||
|
||||
private String makeBodyData() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user