Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
O
oltinspection
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
胡懿
oltinspection
Commits
c9455de3
Commit
c9455de3
authored
Mar 11, 2019
by
huyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改shh登录结果返回信息的对象
parent
44634a1f
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
123 additions
and
20 deletions
+123
-20
myDb.db
myDb.db
+0
-0
sshConnection.properties
oltConfig/sshConnection.properties
+2
-2
FaultLocationController.java
...hkj/oltinspection/controller/FaultLocationController.java
+22
-0
Result.java
src/main/java/com/fhkj/oltinspection/pojo/Result.java
+32
-5
FaultLocationService.java
.../com/fhkj/oltinspection/service/FaultLocationService.java
+8
-0
FaultLocationServiceImpl.java
.../oltinspection/service/impl/FaultLocationServiceImpl.java
+44
-0
FtpServiceImpl.java
...a/com/fhkj/oltinspection/service/impl/FtpServiceImpl.java
+1
-1
FTPUtil.java
src/main/java/com/fhkj/oltinspection/util/FTPUtil.java
+4
-3
ReadProperties.java
...main/java/com/fhkj/oltinspection/util/ReadProperties.java
+3
-2
SSHUtil.java
src/main/java/com/fhkj/oltinspection/util/SSHUtil.java
+7
-7
No files found.
myDb.db
View file @
c9455de3
No preview for this file type
oltConfig/sshConnection.properties
View file @
c9455de3
connectionTimeout
=
60000
returnTimeout
=
1000L
\ No newline at end of file
returnTimeout
=
1000
\ No newline at end of file
src/main/java/com/fhkj/oltinspection/controller/FaultLocationController.java
0 → 100644
View file @
c9455de3
package
com
.
fhkj
.
oltinspection
.
controller
;
import
com.fhkj.oltinspection.service.FaultLocationService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
@RestController
@RequestMapping
(
value
=
"/faultLocation"
)
public
class
FaultLocationController
{
@Autowired
private
FaultLocationService
faultLocationService
;
@GetMapping
(
value
=
"test"
)
public
void
testConnection
()
{
System
.
out
.
println
(
"有请求访问ssh连接"
);
System
.
out
.
println
(
faultLocationService
.
test
());
}
}
\ No newline at end of file
src/main/java/com/fhkj/oltinspection/pojo/Result.java
View file @
c9455de3
...
...
@@ -12,14 +12,16 @@ public class Result implements Serializable {
private
Integer
code
;
private
String
msg
;
private
Object
data
;
private
boolean
state
;
public
Result
()
{
super
();
public
Result
()
{
super
();
this
.
code
=
null
;
this
.
msg
=
""
;
this
.
data
=
null
;
}
public
Result
(
Integer
code
)
{
public
Result
(
Integer
code
)
{
this
.
code
=
code
;
}
public
Result
(
String
msg
)
{
...
...
@@ -28,6 +30,9 @@ public class Result implements Serializable {
public
Result
(
Object
data
)
{
this
.
data
=
data
;
}
public
Result
(
boolean
state
)
{
this
.
state
=
state
;
}
public
Result
(
Integer
code
,
String
msg
)
{
this
.
code
=
code
;
this
.
msg
=
msg
;
...
...
@@ -40,12 +45,20 @@ public class Result implements Serializable {
this
.
msg
=
msg
;
this
.
data
=
data
;
}
public
Result
(
String
msg
,
boolean
state
)
{
this
.
msg
=
msg
;
this
.
state
=
state
;
}
public
Result
(
Integer
code
,
String
msg
,
Object
data
)
{
this
.
code
=
code
;
this
.
msg
=
msg
;
this
.
data
=
data
;
}
public
Result
(
String
msg
,
Object
data
,
boolean
state
)
{
this
.
msg
=
msg
;
this
.
data
=
data
;
this
.
state
=
state
;
}
/**
* @return the code
*/
...
...
@@ -83,10 +96,23 @@ public class Result implements Serializable {
public
void
setData
(
Object
data
)
{
this
.
data
=
data
;
}
/**
* @return the state
*/
public
boolean
getState
()
{
return
state
;
}
/**
* @param state the state to set
*/
public
void
setState
(
boolean
state
)
{
this
.
state
=
state
;
}
@Override
public
String
toString
()
{
return
"code:"
+
this
.
code
+
", msg:"
+
this
.
msg
+
", data:"
+
this
.
data
;
return
"code:"
+
this
.
code
+
", msg:"
+
this
.
msg
+
", data:"
+
this
.
data
+
",state:"
+
this
.
state
;
}
}
\ No newline at end of file
src/main/java/com/fhkj/oltinspection/service/FaultLocationService.java
0 → 100644
View file @
c9455de3
package
com
.
fhkj
.
oltinspection
.
service
;
import
com.fhkj.oltinspection.pojo.Result
;
public
interface
FaultLocationService
{
public
Result
test
();
}
\ No newline at end of file
src/main/java/com/fhkj/oltinspection/service/impl/FaultLocationServiceImpl.java
0 → 100644
View file @
c9455de3
package
com
.
fhkj
.
oltinspection
.
service
.
impl
;
import
javax.transaction.Transactional
;
import
com.fhkj.oltinspection.pojo.Result
;
import
com.fhkj.oltinspection.pojo.SshConnection
;
import
com.fhkj.oltinspection.service.FaultLocationService
;
import
com.fhkj.oltinspection.util.SSHUtil
;
import
org.springframework.stereotype.Service
;
@Service
@Transactional
public
class
FaultLocationServiceImpl
implements
FaultLocationService
{
@Override
public
Result
test
()
{
SshConnection
sshConnection
=
new
SshConnection
(
"192.168.21.8"
,
22
,
"root"
,
"root"
);
SSHUtil
sshUtil
=
new
SSHUtil
(
sshConnection
);
Result
result
=
null
;
String
data
=
null
;
result
=
sshUtil
.
initConnection
();
if
(!(
boolean
)
result
.
getState
())
{
return
result
;
}
result
=
sshUtil
.
initInputAndOutput
();
if
((
boolean
)
result
.
getState
())
{
return
result
;
}
result
=
sshUtil
.
sendCommand
(
"showcard"
,
true
);
if
((
boolean
)
result
.
getState
())
{
return
result
;
}
data
=
(
String
)
result
.
getData
();
result
=
sshUtil
.
sshExit
();
if
((
boolean
)
result
.
getState
())
{
return
result
;
}
System
.
out
.
println
(
data
);
return
result
;
}
}
\ No newline at end of file
src/main/java/com/fhkj/oltinspection/service/impl/FtpServiceImpl.java
View file @
c9455de3
...
...
@@ -47,7 +47,7 @@ public class FtpServiceImpl implements FtpService {
return
new
Result
(
"保存成功"
,
true
);
}
}
catch
(
Exception
e
)
{
return
new
Result
(
"保存失败"
,
PackageExceptionUtil
.
exceptionToString
(
e
));
return
new
Result
(
"保存失败"
,
PackageExceptionUtil
.
exceptionToString
(
e
)
,
false
);
}
}
...
...
src/main/java/com/fhkj/oltinspection/util/FTPUtil.java
View file @
c9455de3
...
...
@@ -59,7 +59,7 @@ public class FTPUtil {
return
new
Result
(
"在数据库中未能获取到ftp的连接配置信息"
,
false
);
}
else
{
Result
result
=
validateFtpParameter
(
ftpConfigEntity
);
if
(!(
boolean
)
result
.
get
Data
())
{
if
(!(
boolean
)
result
.
get
State
())
{
return
result
;
}
}
...
...
@@ -78,8 +78,8 @@ public class FTPUtil {
ftpClient
.
disconnect
();
// 关闭连接
}
}
catch
(
IOException
e
)
{
return
new
Result
(
"出现连接异常"
,
PackageExceptionUtil
.
exceptionToString
(
e
));
return
new
Result
(
"出现连接异常"
,
PackageExceptionUtil
.
exceptionToString
(
e
)
,
false
);
}
return
new
Result
();
return
new
Result
(
"连接成功"
,
true
);
}
}
\ No newline at end of file
src/main/java/com/fhkj/oltinspection/util/ReadProperties.java
View file @
c9455de3
...
...
@@ -4,16 +4,17 @@ import java.io.BufferedReader;
import
java.io.File
;
import
java.io.FileReader
;
import
java.io.IOException
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Properties
;
import
org.springframework.util.ResourceUtils
;
public
class
ReadProperties
{
public
static
Map
<
String
,
Object
>
sshConfigMap
=
n
ull
;
public
static
Map
<
String
,
Object
>
sshConfigMap
=
n
ew
HashMap
<
String
,
Object
>
()
;
static
{
try
{
File
file
=
ResourceUtils
.
getFile
(
"
ptnConfig/performancetime
.properties"
);
File
file
=
ResourceUtils
.
getFile
(
"
oltConfig/sshConnection
.properties"
);
Properties
properties
=
new
Properties
();
BufferedReader
bufferedReader
;
bufferedReader
=
new
BufferedReader
(
new
FileReader
(
file
));
...
...
src/main/java/com/fhkj/oltinspection/util/SSHUtil.java
View file @
c9455de3
...
...
@@ -37,7 +37,7 @@ public class SSHUtil {
public
SSHUtil
(
SshConnection
sshConnection
)
{
super
();
Result
result
=
validateSshConnectionParameter
(
sshConnection
);
if
(!(
boolean
)
result
.
get
Data
())
{
if
(!(
boolean
)
result
.
get
State
())
{
throw
new
OltException
(
result
.
getMsg
());
}
this
.
sshConnection
=
sshConnection
;
...
...
@@ -115,7 +115,7 @@ public class SSHUtil {
((
ChannelShell
)
channel
).
setPtyType
(
"vt100"
,
80
,
100
,
640
,
960
);
channel
.
connect
();
}
catch
(
JSchException
e
)
{
return
new
Result
(
"连接异常"
,
PackageExceptionUtil
.
exceptionToString
(
e
));
return
new
Result
(
"连接异常"
,
PackageExceptionUtil
.
exceptionToString
(
e
)
,
false
);
}
return
new
Result
(
"连接成功"
,
true
);
}
...
...
@@ -131,7 +131,7 @@ public class SSHUtil {
this
.
ins
=
channel
.
getInputStream
();
this
.
dos
=
new
DataOutputStream
(
channel
.
getOutputStream
());
}
catch
(
IOException
e
)
{
return
new
Result
(
"开启成功"
,
PackageExceptionUtil
.
exceptionToString
(
e
));
return
new
Result
(
"开启成功"
,
PackageExceptionUtil
.
exceptionToString
(
e
)
,
false
);
}
return
new
Result
(
"开启成功"
,
true
);
}
...
...
@@ -150,7 +150,7 @@ public class SSHUtil {
this
.
dos
.
writeBytes
(
command
+
"\r\n"
);
// 输入命令
this
.
dos
.
flush
();
}
catch
(
IOException
e
)
{
return
new
Result
(
"命令输入异常"
,
PackageExceptionUtil
.
exceptionToString
(
e
));
return
new
Result
(
"命令输入异常"
,
PackageExceptionUtil
.
exceptionToString
(
e
)
,
false
);
}
if
(
isRead
)
{
// isRead是ture时读取设备返回的内容
...
...
@@ -179,9 +179,9 @@ public class SSHUtil {
}
}
}
catch
(
TimeoutException
|
InterruptedException
|
IOException
e
)
{
return
new
Result
(
"读取失败"
,
PackageExceptionUtil
.
exceptionToString
(
e
));
return
new
Result
(
"读取失败"
,
PackageExceptionUtil
.
exceptionToString
(
e
)
,
false
);
}
return
new
Result
(
"读取成功"
,
sb
.
toString
());
return
new
Result
(
"读取成功"
,
sb
.
toString
()
,
false
);
}
else
{
return
new
Result
(
"输入成功"
,
true
);
}
...
...
@@ -204,7 +204,7 @@ public class SSHUtil {
System
.
gc
();
ClearUtil
.
openExe
();
}
catch
(
IOException
e
)
{
return
new
Result
(
"退出失败"
,
PackageExceptionUtil
.
exceptionToString
(
e
));
return
new
Result
(
"退出失败"
,
PackageExceptionUtil
.
exceptionToString
(
e
)
,
false
);
}
return
new
Result
(
"退出成功"
,
true
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment