|
1 | 1 | package root.javafx.Service; |
2 | 2 |
|
3 | 3 | import javafx.concurrent.Task; |
| 4 | +import javafx.scene.control.Alert.AlertType; |
| 5 | +import root.common.server.implement.JschServer; |
4 | 6 | import root.core.domain.JschConnectionInfo; |
| 7 | +import root.utils.AlertUtils; |
5 | 8 |
|
6 | 9 | public class ServerConnectService extends ConnectionTestService { |
7 | 10 |
|
8 | | - public static final String SUCCESS_MSG = "원격서버가 성공적으로 연동되었습니다."; |
| 11 | + public static final String SUCCESS_MSG = "원격서버에 성공적으로 연동되었습니다.\n Host: %s:%s"; |
9 | 12 | public static final String FAIL_MSG = "원격서버 연동에 실패했습니다."; |
10 | 13 |
|
11 | 14 | private JschConnectionInfo jsch; |
| 15 | + private JschServer jschServer; |
12 | 16 |
|
13 | 17 | public ServerConnectService(JschConnectionInfo jsch) { |
14 | 18 | this.jsch = jsch; |
| 19 | + this.jschServer = new JschServer(jsch); |
15 | 20 | } |
16 | 21 |
|
17 | 22 | @Override |
18 | 23 | protected Task<Boolean> createTask() { |
19 | 24 | return new Task<Boolean>() { |
20 | 25 | @Override |
21 | 26 | protected Boolean call() throws Exception { |
22 | | - return true; |
| 27 | + jschServer.init(); |
| 28 | + boolean isConn = JschServer.validateConn(jschServer.getSession()); |
| 29 | + if (!isConn) { |
| 30 | + throw new Exception("Server connection test Failed"); |
| 31 | + } |
| 32 | + return isConn; |
23 | 33 | } |
24 | 34 | }; |
25 | 35 | } |
26 | 36 |
|
27 | 37 | @Override |
28 | 38 | public void alertSucceed() { |
29 | | - // TODO Auto-generated method stub |
30 | | - |
| 39 | + AlertUtils.showAlert(AlertType.INFORMATION, "Server 연동테스트", |
| 40 | + String.format(ServerConnectService.SUCCESS_MSG, jsch.getHost(), jsch.getPort())); |
31 | 41 | } |
32 | 42 |
|
33 | 43 | @Override |
34 | 44 | public void alertFailed() { |
35 | | - // TODO Auto-generated method stub |
36 | | - |
| 45 | + AlertUtils.showAlert(AlertType.ERROR, "Server 연동테스트", |
| 46 | + String.format(ServerConnectService.FAIL_MSG, jsch.getHost(), jsch.getPort())); |
37 | 47 | } |
38 | 48 | } |
0 commit comments