--- build.gradle
+++ build.gradle
... | ... | @@ -30,7 +30,6 @@ |
| 30 | 30 |
implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:3.0.3' |
| 31 | 31 |
compileOnly 'org.projectlombok:lombok' |
| 32 | 32 |
developmentOnly 'org.springframework.boot:spring-boot-devtools' |
| 33 |
-// runtimeOnly 'org.mariadb.jdbc:mariadb-java-client' |
|
| 34 | 33 |
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor' |
| 35 | 34 |
annotationProcessor 'org.projectlombok:lombok' |
| 36 | 35 |
testImplementation 'org.springframework.boot:spring-boot-starter-test' |
--- src/main/java/com/munjaon/client/config/RunnerConfiguration.java
+++ src/main/java/com/munjaon/client/config/RunnerConfiguration.java
... | ... | @@ -25,16 +25,7 @@ |
| 25 | 25 |
System.setProperty("ROOTPATH", serverConfig.getServerRootPath());
|
| 26 | 26 |
System.setProperty("DBMS", serverConfig.getString("DB.DBMS"));
|
| 27 | 27 |
PropertyLoader.load(); |
| 28 |
-// try {
|
|
| 29 |
-// String[] array = serverConfig.getStringArray("test.list");
|
|
| 30 |
-// if (array != null && array.length > 0) {
|
|
| 31 |
-// for (String s : array) {
|
|
| 32 |
-// System.out.println("List : " + s);
|
|
| 33 |
-// } |
|
| 34 |
-// } |
|
| 35 |
-// } catch (ConfigurationException e) {
|
|
| 36 |
-// throw new RuntimeException(e); |
|
| 37 |
-// } |
|
| 28 |
+ |
|
| 38 | 29 |
return args -> System.out.println("Runner Bean #1 : " + serverConfig.getServerProperyFile());
|
| 39 | 30 |
} |
| 40 | 31 |
|
... | ... | @@ -49,6 +40,7 @@ |
| 49 | 40 |
} catch (Exception e) {
|
| 50 | 41 |
throw new RuntimeException(e); |
| 51 | 42 |
} |
| 43 |
+ |
|
| 52 | 44 |
return args -> System.out.println("Runner Bean #2");
|
| 53 | 45 |
} |
| 54 | 46 |
|
... | ... | @@ -63,6 +55,7 @@ |
| 63 | 55 |
} catch (Exception e) {
|
| 64 | 56 |
throw new RuntimeException(e); |
| 65 | 57 |
} |
| 58 |
+ |
|
| 66 | 59 |
return args -> System.out.println("Runner Bean #2");
|
| 67 | 60 |
} |
| 68 | 61 |
|
... | ... | @@ -77,6 +70,7 @@ |
| 77 | 70 |
} catch (Exception e) {
|
| 78 | 71 |
throw new RuntimeException(e); |
| 79 | 72 |
} |
| 73 |
+ |
|
| 80 | 74 |
return args -> System.out.println("Runner Bean #2");
|
| 81 | 75 |
} |
| 82 | 76 |
|
... | ... | @@ -91,6 +85,7 @@ |
| 91 | 85 |
} catch (Exception e) {
|
| 92 | 86 |
throw new RuntimeException(e); |
| 93 | 87 |
} |
| 88 |
+ |
|
| 94 | 89 |
return args -> System.out.println("Runner Bean #2");
|
| 95 | 90 |
} |
| 96 | 91 |
|
... | ... | @@ -105,6 +100,7 @@ |
| 105 | 100 |
} catch (Exception e) {
|
| 106 | 101 |
throw new RuntimeException(e); |
| 107 | 102 |
} |
| 103 |
+ |
|
| 108 | 104 |
return args -> System.out.println("Runner Bean #2");
|
| 109 | 105 |
} |
| 110 | 106 |
|
... | ... | @@ -118,6 +114,7 @@ |
| 118 | 114 |
} catch (Exception e) {
|
| 119 | 115 |
throw new RuntimeException(e); |
| 120 | 116 |
} |
| 117 |
+ |
|
| 121 | 118 |
return args -> System.out.println("Runner Bean #2");
|
| 122 | 119 |
} |
| 123 | 120 |
|
... | ... | @@ -131,6 +128,7 @@ |
| 131 | 128 |
} catch (Exception e) {
|
| 132 | 129 |
throw new RuntimeException(e); |
| 133 | 130 |
} |
| 131 |
+ |
|
| 134 | 132 |
return args -> System.out.println("Runner Bean #2");
|
| 135 | 133 |
} |
| 136 | 134 |
} |
--- src/main/java/com/munjaon/client/server/service/CollectClientService.java
+++ src/main/java/com/munjaon/client/server/service/CollectClientService.java
... | ... | @@ -183,15 +183,6 @@ |
| 183 | 183 |
this.deliverList = new ArrayList<>(); |
| 184 | 184 |
} |
| 185 | 185 |
this.deliverList.add(msgId); |
| 186 |
-// if (this.deliverBuilder == null) {
|
|
| 187 |
-// return; |
|
| 188 |
-// } |
|
| 189 |
-// |
|
| 190 |
-// if (this.deliverBuilder.isEmpty()) {
|
|
| 191 |
-// this.deliverBuilder.append(msgId); |
|
| 192 |
-// } else {
|
|
| 193 |
-// this.deliverBuilder.append(",").append(msgId);
|
|
| 194 |
-// } |
|
| 195 | 186 |
} |
| 196 | 187 |
|
| 197 | 188 |
private void messageService() {
|
... | ... | @@ -605,7 +596,6 @@ |
| 605 | 596 |
|
| 606 | 597 |
private void linkCheckService() {
|
| 607 | 598 |
if (System.currentTimeMillis() - lastPacketSendTime < Packet.LINK_CHECK_CYCLE) {
|
| 608 |
-// saveSystemLog("LinkCheck Is Not");
|
|
| 609 | 599 |
return; |
| 610 | 600 |
} |
| 611 | 601 |
|
--- src/main/java/com/munjaon/client/server/service/Server.java
... | ... | @@ -1,195 +0,0 @@ |
| 1 | -package com.munjaon.client.server.service; | |
| 2 | - | |
| 3 | -import com.munjaon.client.server.packet.Packet; | |
| 4 | - | |
| 5 | -import java.io.IOException; | |
| 6 | -import java.net.InetSocketAddress; | |
| 7 | -import java.net.Socket; | |
| 8 | -import java.net.SocketAddress; | |
| 9 | -import java.nio.ByteBuffer; | |
| 10 | -import java.nio.channels.SelectionKey; | |
| 11 | -import java.nio.channels.Selector; | |
| 12 | -import java.nio.channels.ServerSocketChannel; | |
| 13 | -import java.nio.channels.SocketChannel; | |
| 14 | -import java.util.Iterator; | |
| 15 | -import java.util.concurrent.Executors; | |
| 16 | - | |
| 17 | -public class Server implements Runnable { | |
| 18 | - private InetSocketAddress listenAddress; | |
| 19 | - // 메시지는 개행으로 구분한다. | |
| 20 | - private static char CR = (char) 0x0D; | |
| 21 | - private static char LF = (char) 0x0A; | |
| 22 | - // ip와 port 설정 | |
| 23 | - public Server(String address, int port) { | |
| 24 | - listenAddress = new InetSocketAddress(address, port); | |
| 25 | - } | |
| 26 | - // Thread 실행. | |
| 27 | - public void run() { | |
| 28 | - // 셀렉터 설정 | |
| 29 | - try (Selector selector = Selector.open()) { | |
| 30 | - // 채널 설정 | |
| 31 | - try (ServerSocketChannel serverChannel = ServerSocketChannel.open()) { | |
| 32 | - System.out.println("ServerSocketChannel is open"); | |
| 33 | - // non-Blocking 설정 | |
| 34 | - serverChannel.configureBlocking(false); | |
| 35 | - System.out.println("serverChannel.configureBlocking(false) >> "); | |
| 36 | - // 서버 ip, port 설정 | |
| 37 | - serverChannel.socket().bind(listenAddress); | |
| 38 | - System.out.println("serverChannel.socket().bind(listenAddress) >> "); | |
| 39 | - // 채널에 accept 대기 설정 | |
| 40 | - serverChannel.register(selector, SelectionKey.OP_ACCEPT); | |
| 41 | - System.out.println("serverChannel.register(selector, SelectionKey.OP_ACCEPT) >> "); | |
| 42 | - // 셀렉터가 있을 경우. | |
| 43 | -// while (selector.select() > 0) { | |
| 44 | - while (true) { | |
| 45 | - if (selector.select(10000) == 0) { | |
| 46 | - System.out.println("selector.select() == 0"); | |
| 47 | - continue; | |
| 48 | - } | |
| 49 | - System.out.println("selector.select() > 0 >> "); | |
| 50 | - // 셀렉터 키 셋를 가져온다. | |
| 51 | - Iterator<SelectionKey> keys = selector.selectedKeys().iterator(); | |
| 52 | - // 키가 있으면.. | |
| 53 | - while (keys.hasNext()) { | |
| 54 | - SelectionKey key = keys.next(); | |
| 55 | - //키 셋에서 제거. | |
| 56 | - keys.remove(); | |
| 57 | - if (!key.isValid()) { | |
| 58 | - continue; | |
| 59 | - } | |
| 60 | - // 접속일 경우.. | |
| 61 | - if (key.isAcceptable()) { | |
| 62 | - this.accept(selector, key); | |
| 63 | - // 수신일 경우.. | |
| 64 | - } else if (key.isReadable()) { | |
| 65 | - this.receive(selector, key); | |
| 66 | - // 발신일 경우.. | |
| 67 | - } else if (key.isWritable()) { | |
| 68 | - this.send(selector, key); | |
| 69 | - } | |
| 70 | - } | |
| 71 | - } | |
| 72 | - } | |
| 73 | - } catch (IOException e) { | |
| 74 | - e.printStackTrace(); | |
| 75 | - } | |
| 76 | - } | |
| 77 | - // 접속시 호출 함수.. | |
| 78 | - private void accept(Selector selector, SelectionKey key) { | |
| 79 | - try { | |
| 80 | - // 키 채널을 가져온다. | |
| 81 | - ServerSocketChannel serverChannel = (ServerSocketChannel) key.channel(); | |
| 82 | - // accept을 해서 Socket 채널을 가져온다. | |
| 83 | - SocketChannel channel = serverChannel.accept(); | |
| 84 | - channel.configureBlocking(false); | |
| 85 | - // 소켓 취득 | |
| 86 | - Socket socket = channel.socket(); | |
| 87 | - SocketAddress remoteAddr = socket.getRemoteSocketAddress(); | |
| 88 | - System.out.println("Connected to: " + remoteAddr); | |
| 89 | - // 접속 Socket 단위로 사용되는 Buffer; | |
| 90 | - StringBuffer sb = new StringBuffer(); | |
| 91 | - sb.append("Welcome server!\r\n>"); | |
| 92 | - // Socket 채널을 channel에 송신 등록한다 | |
| 93 | - channel.register(selector, SelectionKey.OP_WRITE, sb); | |
| 94 | - } catch (IOException e) { | |
| 95 | - e.printStackTrace(); | |
| 96 | - } | |
| 97 | - } | |
| 98 | - // 수신시 호출 함수.. | |
| 99 | - private void receive(Selector selector, SelectionKey key) { | |
| 100 | - try { | |
| 101 | - // 키 채널을 가져온다. | |
| 102 | - SocketChannel channel = (SocketChannel) key.channel(); | |
| 103 | - // 연결이 끊겼는지 확인 | |
| 104 | - if ((channel.isConnected() || channel.isOpen()) == false) { | |
| 105 | - System.out.println("java connection reset by client: "); | |
| 106 | - // 키 닫기 | |
| 107 | - key.cancel(); | |
| 108 | - // 소켓 채널 닫기 | |
| 109 | - channel.close(); | |
| 110 | - // 종료 | |
| 111 | - return; | |
| 112 | - } | |
| 113 | - // 채널 Non-blocking 설정 | |
| 114 | - channel.configureBlocking(false); | |
| 115 | - // 소켓 취득 | |
| 116 | - Socket socket = channel.socket(); | |
| 117 | - // Byte 버퍼 생성 | |
| 118 | - ByteBuffer buffer = ByteBuffer.allocate(1024); | |
| 119 | - // ***데이터 수신*** | |
| 120 | - int size = channel.read(buffer); | |
| 121 | - // 수신 크기가 없으면 소켓 접속 종료. | |
| 122 | - if (size == -1) { | |
| 123 | - SocketAddress remoteAddr = socket.getRemoteSocketAddress(); | |
| 124 | - System.out.println("Connection closed by client: " + remoteAddr); | |
| 125 | - // 소켓 채널 닫기 | |
| 126 | - channel.close(); | |
| 127 | - // 소켓 닫기 | |
| 128 | - socket.close(); | |
| 129 | - // 키 닫기 | |
| 130 | - key.attach(null); | |
| 131 | - key.cancel(); | |
| 132 | - return; | |
| 133 | - } | |
| 134 | - // ByteBuffer -> byte[] | |
| 135 | - byte[] data = new byte[size]; | |
| 136 | - System.arraycopy(buffer.array(), 0, data, 0, size); | |
| 137 | - // StringBuffer 취득 | |
| 138 | - StringBuffer sb = (StringBuffer) key.attachment(); | |
| 139 | - // 버퍼에 수신된 데이터 추가 | |
| 140 | - sb.append(new String(data)); | |
| 141 | - // 데이터 끝이 개행 일 경우. | |
| 142 | - if (sb.length() > 2 && sb.charAt(sb.length() - 2) == CR && sb.charAt(sb.length() - 1) == LF) { | |
| 143 | - // 개행 삭제 | |
| 144 | - sb.setLength(sb.length() - 2); | |
| 145 | - // 메시지를 콘솔에 표시한다. | |
| 146 | - String msg = sb.toString(); | |
| 147 | - System.out.println(msg); | |
| 148 | - // exit 경우 접속을 종료한다. | |
| 149 | - if ("exit".equals(msg)) { | |
| 150 | - // 소켓 채널 닫기 | |
| 151 | - channel.close(); | |
| 152 | - // 소켓 닫기 | |
| 153 | - socket.close(); | |
| 154 | - // 키 닫기 | |
| 155 | - key.cancel(); | |
| 156 | - return; | |
| 157 | - } | |
| 158 | - // Echo - 메시지> 의 형태로 재 전송. | |
| 159 | - sb.insert(0, "Echo - "); | |
| 160 | - sb.append("\r\n>"); | |
| 161 | - // Socket 채널을 channel에 송신 등록한다 | |
| 162 | - channel.register(selector, SelectionKey.OP_WRITE, sb); | |
| 163 | - } | |
| 164 | - } catch (IOException e) { | |
| 165 | - e.printStackTrace(); | |
| 166 | - } | |
| 167 | - } | |
| 168 | - // 발신시 호출 함수 | |
| 169 | - private void send(Selector selector, SelectionKey key) { | |
| 170 | - try { | |
| 171 | - // 키 채널을 가져온다. | |
| 172 | - SocketChannel channel = (SocketChannel) key.channel(); | |
| 173 | - // 채널 Non-blocking 설정 | |
| 174 | - channel.configureBlocking(false); | |
| 175 | - // StringBuffer 취득 | |
| 176 | - StringBuffer sb = (StringBuffer) key.attachment(); | |
| 177 | - String data = sb.toString(); | |
| 178 | - // StringBuffer 초기화 | |
| 179 | - sb.setLength(0); | |
| 180 | - // byte 형식으로 변환 | |
| 181 | - ByteBuffer buffer = ByteBuffer.wrap(data.getBytes(Packet.AGENT_CHARACTER_SET)); | |
| 182 | - // ***데이터 송신*** | |
| 183 | - channel.write(buffer); | |
| 184 | - // Socket 채널을 channel에 수신 등록한다 | |
| 185 | - channel.register(selector, SelectionKey.OP_READ, sb); | |
| 186 | - } catch (IOException e) { | |
| 187 | - e.printStackTrace(); | |
| 188 | - } | |
| 189 | - } | |
| 190 | - // 시작 함수 | |
| 191 | - public static void main(String[] args) { | |
| 192 | - // 포트는 10000을 Listen한다. | |
| 193 | - Executors.newSingleThreadExecutor().execute(new Server("localhost", 10000)); | |
| 194 | - } | |
| 195 | -} |
--- src/main/java/com/munjaon/client/util/XmlUtil.java
... | ... | @@ -1,125 +0,0 @@ |
| 1 | -package com.munjaon.client.util; | |
| 2 | - | |
| 3 | -import org.jdom2.Document; | |
| 4 | -import org.jdom2.Element; | |
| 5 | -import org.jdom2.JDOMException; | |
| 6 | -import org.jdom2.input.SAXBuilder; | |
| 7 | -import org.jdom2.output.Format; | |
| 8 | -import org.jdom2.output.XMLOutputter; | |
| 9 | - | |
| 10 | -import java.io.File; | |
| 11 | -import java.io.FileOutputStream; | |
| 12 | -import java.io.IOException; | |
| 13 | -import java.io.StringReader; | |
| 14 | -import java.util.List; | |
| 15 | - | |
| 16 | -public class XmlUtil { | |
| 17 | -// private static Document getDOMParsedDocument(final String fileName) { | |
| 18 | -// Document document = null; | |
| 19 | -// try { | |
| 20 | -// | |
| 21 | -// DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); | |
| 22 | -// //If want to make namespace aware. | |
| 23 | -// //factory.setNamespaceAware(true); | |
| 24 | -// DocumentBuilder documentBuilder = factory.newDocumentBuilder(); | |
| 25 | -// document = documentBuilder.parse(new File("C:\\Docs\\JDS\\ITN\\MMS01Header.xml")); | |
| 26 | -// | |
| 27 | -// NodeList nodeList = document.getDocumentElement().getChildNodes(); | |
| 28 | -// for (int i = 0; i < nodeList.getLength(); i++) { | |
| 29 | -// Node node = nodeList.item(i); | |
| 30 | -// if (node.getNodeType() == Node.ELEMENT_NODE) { | |
| 31 | -// Element elem = (Element) node; | |
| 32 | -// System.out.println("createDate : " + elem.getAttribute("createDate")); | |
| 33 | -// System.out.println("getTagName : " + elem.getTagName()); | |
| 34 | -// System.out.println("getNodeName : " + elem.getNodeName()); | |
| 35 | -// System.out.println("getTextContent : " + elem.getTextContent()); | |
| 36 | -//// String createDate = elem.getElementsByTagName("createDate").item(0).getChildNodes().item(0).getNodeValue(); | |
| 37 | -//// System.out.println("createDate : " + createDate); | |
| 38 | -//// String PopCounter = elem.getElementsByTagName("PopCounter").item(0).getChildNodes().item(0).getNodeValue(); | |
| 39 | -//// System.out.println("PopCounter : " + PopCounter); | |
| 40 | -//// Double salary = Double.parseDouble(elem.getElementsByTagName("salary").item(0).getChildNodes().item(0).getNodeValue()); | |
| 41 | -// } | |
| 42 | -// } | |
| 43 | -// } | |
| 44 | -// catch (IOException | SAXException | ParserConfigurationException e) { | |
| 45 | -// e.printStackTrace(); | |
| 46 | -// } | |
| 47 | -// return document; | |
| 48 | -// } | |
| 49 | - | |
| 50 | - private static Document getSaxParsedDocument(final String fileName) { | |
| 51 | - Document document = null; | |
| 52 | - | |
| 53 | - String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" | |
| 54 | - + " <catalog>\r\n" | |
| 55 | - + " <book id=\"bk101\">" | |
| 56 | - + " <author>Gambardella, Matthew</author> " | |
| 57 | - + "<title>XML Developer's Guide</title>" | |
| 58 | - + " <genre>Computer</genre>" | |
| 59 | - + " <price>44.95</price> " | |
| 60 | - + "<publish_date>2000-10-01</publish_date> " | |
| 61 | - + "<description>An in-depth look at creating applications with XML.</description> " | |
| 62 | - + "</book>" | |
| 63 | - + " <book id=\"bk102\">" | |
| 64 | - + " <author>Ralls, Kim</author>" | |
| 65 | - + " <title>Midnight Rain</title>" | |
| 66 | - + " <genre>Fantasy</genre>" | |
| 67 | - + " <price>5.95</price>" | |
| 68 | - + " <publish_date>2000-12-16</publish_date>" | |
| 69 | - + " <description>A former architect battles corporate zombies, an evil sorceress, and her own childhood to become queen of the world.</description>" | |
| 70 | - + " </book> \r\n" | |
| 71 | - + "</catalog>\r\n"; | |
| 72 | - try { | |
| 73 | - | |
| 74 | - SAXBuilder sax = new SAXBuilder(); | |
| 75 | - // String that contains XML | |
| 76 | - Document doc = (Document) sax.build(new File("C:\\Docs\\JDS\\ITN\\MMS01Header.xml")); | |
| 77 | -// org.jdom2.Document doc = sax.build(new StringReader(xml)); | |
| 78 | - | |
| 79 | - Element rootNode = doc.getRootElement(); | |
| 80 | - List<Element> bookElements = rootNode.getChildren(); | |
| 81 | - System.out.println("bookElements: " + bookElements); | |
| 82 | - for(Element bookElement : bookElements){ | |
| 83 | - String name = bookElement.getName(); | |
| 84 | - String value = bookElement.getValue(); | |
| 85 | - System.out.println(name + " : " + value); | |
| 86 | - } | |
| 87 | - | |
| 88 | - } catch (IOException | JDOMException e) { | |
| 89 | - e.printStackTrace(); | |
| 90 | - } | |
| 91 | - return document; | |
| 92 | - } | |
| 93 | - | |
| 94 | - private static void writeSimpleXml() throws JDOMException, IOException { | |
| 95 | - | |
| 96 | - String xml = "<root><child id=\"100\">mkyong</child></root>"; | |
| 97 | - SAXBuilder sb = new SAXBuilder(); | |
| 98 | - Document doc = sb.build(new StringReader(xml)); | |
| 99 | - | |
| 100 | - | |
| 101 | - Document docFile = new Document(); | |
| 102 | - | |
| 103 | - Element rootElement = new Element("ReadQueue"); | |
| 104 | - rootElement.addContent(new Element("createDate").setText("20240527")); | |
| 105 | - rootElement.addContent(new Element("PopCounter").setText(Integer.toString(0))); | |
| 106 | - | |
| 107 | - docFile.setRootElement(rootElement); | |
| 108 | - | |
| 109 | - // default in compact mode | |
| 110 | - // XMLOutputter xmlOutputter = new XMLOutputter(); | |
| 111 | - | |
| 112 | - // pretty print format | |
| 113 | - XMLOutputter xmlOutputter = new XMLOutputter(Format.getPrettyFormat()); | |
| 114 | - | |
| 115 | - // output to console | |
| 116 | - FileOutputStream fileOutputStream = new FileOutputStream("C:\\Docs\\JDS\\ITN\\file.xml"); | |
| 117 | - xmlOutputter.output(docFile, fileOutputStream); | |
| 118 | - | |
| 119 | - } | |
| 120 | - public static void main(String[] args) throws IOException, JDOMException { | |
| 121 | -// XmlUtil.getDOMParsedDocument("C:\\Docs\\JDS\\ITN\\MMS01Header.xml"); | |
| 122 | - XmlUtil.getSaxParsedDocument("C:\\Docs\\JDS\\ITN\\MMS01Header.xml"); | |
| 123 | - XmlUtil.writeSimpleXml(); | |
| 124 | - } | |
| 125 | -} |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?