Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
task3.0
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
首航-临时账号
task3.0
Commits
42ea7fdd
Commit
42ea7fdd
authored
Dec 10, 2020
by
java-李谡
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
变更航班动态统计逻辑
parent
ca279209
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
624 additions
and
23 deletions
+624
-23
pom.xml
pom.xml
+5
-21
DspReleaseInfoTask.java
src/main/java/com/foc/DspReleaseInfoTask.java
+18
-0
DspReleaseInfoService.java
src/main/java/com/foc/service/DspReleaseInfoService.java
+133
-0
ApiRequest.java
src/main/java/com/foc/thirdpart/esb/ApiRequest.java
+41
-0
EncodeUtil.java
src/main/java/com/foc/thirdpart/esb/EncodeUtil.java
+98
-0
HttpClient.java
src/main/java/com/foc/thirdpart/esb/HttpClient.java
+10
-0
PageParam.java
src/main/java/com/foc/thirdpart/esb/PageParam.java
+135
-0
TrustedCert.java
src/main/java/com/foc/thirdpart/esb/TrustedCert.java
+25
-0
HttpClientImpl.java
src/main/java/com/foc/thirdpart/esb/nativehttp/HttpClientImpl.java
+153
-0
global.properties
src/main/resources/global.properties
+6
-2
No files found.
pom.xml
View file @
42ea7fdd
...
...
@@ -28,21 +28,11 @@
<version>
3.4.6
</version>
</dependency>
<!--<dependency>-->
<!--<groupId>log4j</groupId>-->
<!--<artifactId>log4j</artifactId>-->
<!--<version>${log4j.version}</version>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>org.slf4j</groupId>-->
<!--<artifactId>slf4j-api</artifactId>-->
<!--<version>${slf4j.version}</version>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>org.slf4j</groupId>-->
<!--<artifactId>slf4j-log4j12</artifactId>-->
<!--<version>${slf4j.version}</version>-->
<!--</dependency>-->
<dependency>
<groupId>
com.google.code.gson
</groupId>
<artifactId>
gson
</artifactId>
<version>
2.7
</version>
</dependency>
<dependency>
<groupId>
org.apache.httpcomponents
</groupId>
...
...
@@ -76,12 +66,6 @@
<optional>
true
</optional>
<version>
1.18.6
</version>
</dependency>
<!-- 封装实体依赖 -->
<!--<dependency>-->
<!--<groupId>org.apache.logging.log4j</groupId>-->
<!--<artifactId>log4j-slf4j-impl</artifactId>-->
<!--<version>2.11.0</version>-->
<!--</dependency>-->
<dependency>
<groupId>
org.slf4j
</groupId>
...
...
src/main/java/com/foc/DspReleaseInfoTask.java
0 → 100644
View file @
42ea7fdd
package
com
.
foc
;
import
com.foc.service.DspReleaseInfoService
;
import
com.foc.service.DynamicFlightService
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
/**
* @author LEGION
*/
public
class
DspReleaseInfoTask
{
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
DspReleaseInfoTask
.
class
);
public
static
void
main
(
String
[]
args
)
throws
Exception
{
DspReleaseInfoService
.
init
();
DspReleaseInfoService
.
buildGatewayRequestString
();
}
}
src/main/java/com/foc/service/DspReleaseInfoService.java
0 → 100644
View file @
42ea7fdd
package
com
.
foc
.
service
;
import
com.foc.thirdpart.esb.ApiRequest
;
import
com.foc.thirdpart.esb.EncodeUtil
;
import
com.foc.thirdpart.esb.HttpClient
;
import
com.foc.thirdpart.esb.PageParam
;
import
com.foc.thirdpart.esb.nativehttp.HttpClientImpl
;
import
com.foc.util.PropertiesUtils
;
import
com.foc.util.StringUtils
;
import
com.google.gson.Gson
;
import
org.apache.ibatis.io.Resources
;
import
org.apache.ibatis.session.SqlSession
;
import
org.apache.ibatis.session.SqlSessionFactory
;
import
org.apache.ibatis.session.SqlSessionFactoryBuilder
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.io.IOException
;
import
java.io.Reader
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Properties
;
/**
* @author LEGION
*/
public
class
DspReleaseInfoService
{
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
DspReleaseInfoService
.
class
);
private
static
Reader
reader
;
private
static
SqlSessionFactory
sqlSessionFactory
;
private
static
SqlSession
session
;
public
static
void
init
()
{
try
{
reader
=
Resources
.
getResourceAsReader
(
"mybatis-config.xml"
);
sqlSessionFactory
=
new
SqlSessionFactoryBuilder
().
build
(
reader
);
session
=
sqlSessionFactory
.
openSession
();
}
catch
(
IOException
e
)
{
log
.
error
(
"连接数据库异常"
);
e
.
printStackTrace
();
}
}
public
static
void
sync
()
{
}
private
static
void
nativeHttpCall
()
{
Properties
properties
=
PropertiesUtils
.
getProperties
();
String
gatewayUatUrl
=
properties
.
getProperty
(
"esb.security.gateway.uat.url"
);
String
key
=
properties
.
getProperty
(
"esb.security.key"
);
if
(
StringUtils
.
isEmpty
(
gatewayUatUrl
)
||
StringUtils
.
isEmpty
(
key
))
{
log
.
error
(
"获取配置文件中机型的文件"
);
return
;
}
log
.
info
(
"**********************************************"
);
log
.
info
(
"----nativeHttpCall-----"
);
try
{
HttpClient
httpClient
=
new
HttpClientImpl
();
Map
<
String
,
String
>
params
=
buildGatewayRequestString
();
String
result
=
httpClient
.
doPost
(
gatewayUatUrl
,
params
,
HttpClientImpl
.
DEFAULT_CHARSET
,
60000
,
60000
);
log
.
info
(
"nativeHttpCall result="
+
result
);
log
.
info
(
"nativeHttpCall decrypt result="
+
EncodeUtil
.
decrypt
(
result
,
key
));
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
log
.
info
(
"**********************************************"
);
}
public
static
Map
<
String
,
String
>
buildGatewayRequestString
()
throws
Exception
{
Properties
properties
=
PropertiesUtils
.
getProperties
();
String
gatewayUatUrl
=
properties
.
getProperty
(
"esb.security.gateway.uat.url"
);
String
key
=
properties
.
getProperty
(
"esb.security.key"
);
String
userAccount
=
properties
.
getProperty
(
"esb.security.account"
);
String
password
=
properties
.
getProperty
(
"esb.security.password"
);
if
(
StringUtils
.
isEmpty
(
gatewayUatUrl
)
||
StringUtils
.
isEmpty
(
key
))
{
log
.
error
(
"获取配置文件中机型的文件"
);
return
null
;
}
Gson
gson
=
new
Gson
();
String
currentTimeMillisStr
=
String
.
valueOf
(
System
.
currentTimeMillis
());
/** step1: 参考接口文档 2.4输入参数说明 章节,并组装成json string **/
ApiRequest
apiRequest
=
new
ApiRequest
();
apiRequest
.
getOptions
().
put
(
"flightNos"
,
"JD0132"
);
apiRequest
.
getOptions
().
put
(
"stdTimeStart"
,
"2020-12-08 00:00:00"
);
apiRequest
.
getOptions
().
put
(
"stdTimeEnd"
,
"2020-12-08 23:59:59"
);
//分页参数
PageParam
pageParam
=
new
PageParam
();
//从第一页开始
pageParam
.
setPageIndex
(
1
);
//每次查询10条记录
pageParam
.
setPageSize
(
10
);
apiRequest
.
getOptions
().
put
(
"pageParam"
,
pageParam
);
String
apiRequestJson
=
gson
.
toJson
(
apiRequest
);
log
.
info
(
"dubbo interface apiRequestJson="
+
apiRequestJson
);
/** step2: 构建 gateway 接口 signature 参数**/
String
signature
=
EncodeUtil
.
generateToken
(
userAccount
,
key
,
apiRequestJson
,
currentTimeMillisStr
);
log
.
info
(
"signature="
+
signature
);
/** step3: 构建外网网关接口参数 **/
Map
<
String
,
String
>
gatewayParam
=
new
HashMap
<>();
//dubbo 接口参数,json 格式
gatewayParam
.
put
(
"inParams"
,
apiRequestJson
);
//接口文档中的 2.1 包名与类名
gatewayParam
.
put
(
"packageName"
,
"com.hnair.opcnet.api.ods.dsp.GetDspReleaseApi"
);
//接口文档中的 2.2 方法名
gatewayParam
.
put
(
"methodName"
,
"getDspReleaseInfoByPage"
);
//hna-esb-security.xml 文件中的password
gatewayParam
.
put
(
"password"
,
password
);
//step2 的签名串
gatewayParam
.
put
(
"signature"
,
signature
);
//当前时间string 串
gatewayParam
.
put
(
"time"
,
currentTimeMillisStr
);
String
gatewayParamStr
=
gson
.
toJson
(
gatewayParam
);
log
.
info
(
"gatewayParamStr="
+
gatewayParamStr
);
//step3 对gatewayParamStr 进行加密,key 来自hna-esb-security.xml 文件中的key
String
requestString
=
EncodeUtil
.
encrypt
(
gatewayParamStr
,
key
);
log
.
info
(
"requestString encrypt="
+
requestString
);
Map
<
String
,
String
>
requstMap
=
new
HashMap
<>();
requstMap
.
put
(
"userName"
,
userAccount
);
requstMap
.
put
(
"requestString"
,
requestString
);
return
requstMap
;
}
}
src/main/java/com/foc/thirdpart/esb/ApiRequest.java
0 → 100644
View file @
42ea7fdd
package
com
.
foc
.
thirdpart
.
esb
;
import
java.io.Serializable
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* @author LEGION
*/
public
class
ApiRequest
implements
Serializable
{
private
final
static
long
serialVersionUID
=
10L
;
protected
Map
<
String
,
Object
>
options
;
protected
PageParam
pageParam
;
public
Map
<
String
,
Object
>
getOptions
()
{
if
(
options
==
null
)
{
options
=
new
HashMap
<
String
,
Object
>();
}
return
this
.
options
;
}
public
void
setOptions
(
Map
<
String
,
Object
>
options
)
{
this
.
options
=
options
;
}
public
void
setOption
(
String
key
,
Object
value
)
{
getOptions
().
put
(
key
,
value
);
}
public
PageParam
getPageParam
()
{
return
pageParam
;
}
public
void
setPageParam
(
PageParam
pageParam
)
{
this
.
pageParam
=
pageParam
;
}
}
src/main/java/com/foc/thirdpart/esb/EncodeUtil.java
0 → 100644
View file @
42ea7fdd
package
com
.
foc
.
thirdpart
.
esb
;
import
javax.crypto.Cipher
;
import
javax.crypto.SecretKey
;
import
javax.crypto.spec.SecretKeySpec
;
import
java.io.UnsupportedEncodingException
;
import
java.security.GeneralSecurityException
;
import
java.security.MessageDigest
;
import
java.security.NoSuchAlgorithmException
;
/**
* @author LEGION
*/
public
class
EncodeUtil
{
private
static
final
String
Algorithm
=
"DESede"
;
public
static
String
generateToken
(
String
account
,
String
key
,
String
requestStr
,
String
DateStr
)
throws
NoSuchAlgorithmException
,
UnsupportedEncodingException
{
StringBuffer
inStrBuffer
=
new
StringBuffer
();
inStrBuffer
.
append
(
DateStr
).
append
(
"*"
);
inStrBuffer
.
append
(
account
).
append
(
"-"
);
inStrBuffer
.
append
(
requestStr
).
append
(
key
);
String
inStr
=
inStrBuffer
.
toString
();
MessageDigest
md5
=
null
;
md5
=
MessageDigest
.
getInstance
(
"MD5"
);
byte
[]
byteArray
=
inStr
.
getBytes
(
"UTF-8"
);
byte
[]
md5Bytes
=
md5
.
digest
(
byteArray
);
StringBuffer
hexValue
=
new
StringBuffer
();
for
(
int
i
=
0
;
i
<
md5Bytes
.
length
;
i
++)
{
int
val
=
md5Bytes
[
i
]
&
0xFF
;
if
(
val
<
16
)
{
hexValue
.
append
(
"0"
);
}
hexValue
.
append
(
Integer
.
toHexString
(
val
));
}
return
hexValue
.
toString
();
}
public
static
String
encrypt
(
String
sSrc
,
String
sKey
)
throws
NoSuchAlgorithmException
,
GeneralSecurityException
,
UnsupportedEncodingException
{
SecretKey
deskey
=
new
SecretKeySpec
(
sKey
.
getBytes
(
"UTF-8"
),
"DESede"
);
Cipher
c1
=
Cipher
.
getInstance
(
"DESede"
);
c1
.
init
(
1
,
deskey
);
byte
[]
encryptByte
=
c1
.
doFinal
(
sSrc
.
getBytes
(
"UTF-8"
));
String
encryptStr
=
bytesToHexString
(
encryptByte
);
return
encryptStr
;
}
public
static
String
decrypt
(
String
sSrc
,
String
sKey
)
throws
NoSuchAlgorithmException
,
GeneralSecurityException
,
UnsupportedEncodingException
{
SecretKey
deskey
=
new
SecretKeySpec
(
sKey
.
getBytes
(
"UTF-8"
),
"DESede"
);
Cipher
c1
=
Cipher
.
getInstance
(
"DESede"
);
c1
.
init
(
2
,
deskey
);
byte
[]
decryptByte
=
c1
.
doFinal
(
hexStringToBytes
(
sSrc
));
String
decryptStr
=
new
String
(
decryptByte
,
"UTF-8"
);
return
decryptStr
;
}
public
static
String
bytesToHexString
(
byte
[]
byteSrc
)
{
StringBuilder
stringBuilder
=
new
StringBuilder
(
""
);
if
((
byteSrc
==
null
)
||
(
byteSrc
.
length
<=
0
))
{
return
null
;
}
for
(
int
i
=
0
;
i
<
byteSrc
.
length
;
i
++)
{
int
v
=
byteSrc
[
i
]
&
0xFF
;
String
hv
=
Integer
.
toHexString
(
v
);
if
(
hv
.
length
()
<
2
)
{
stringBuilder
.
append
(
0
);
}
stringBuilder
.
append
(
hv
);
}
return
stringBuilder
.
toString
();
}
public
static
byte
[]
hexStringToBytes
(
String
hexString
)
{
if
((
hexString
==
null
)
||
(
hexString
.
equals
(
""
)))
{
return
null
;
}
hexString
=
hexString
.
toUpperCase
();
int
length
=
hexString
.
length
()
/
2
;
char
[]
hexChars
=
hexString
.
toCharArray
();
byte
[]
d
=
new
byte
[
length
];
for
(
int
i
=
0
;
i
<
length
;
i
++)
{
int
pos
=
i
*
2
;
d
[
i
]
=
((
byte
)
(
charToByte
(
hexChars
[
pos
])
<<
4
|
charToByte
(
hexChars
[(
pos
+
1
)])));
}
return
d
;
}
private
static
byte
charToByte
(
char
c
)
{
return
(
byte
)
"0123456789ABCDEF"
.
indexOf
(
c
);
}
}
src/main/java/com/foc/thirdpart/esb/HttpClient.java
0 → 100644
View file @
42ea7fdd
package
com
.
foc
.
thirdpart
.
esb
;
import
java.util.Map
;
/**
* @author LEGION
*/
public
interface
HttpClient
{
String
doPost
(
String
url
,
Map
<
String
,
String
>
params
,
String
charset
,
int
connectTimeout
,
int
readTimeout
)
throws
Exception
;
}
src/main/java/com/foc/thirdpart/esb/PageParam.java
0 → 100644
View file @
42ea7fdd
//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.7
// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
// Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2020.06.09 at 10:37:43 AM CST
//
package
com
.
foc
.
thirdpart
.
esb
;
import
javax.xml.bind.annotation.XmlAccessType
;
import
javax.xml.bind.annotation.XmlAccessorType
;
import
javax.xml.bind.annotation.XmlType
;
import
java.io.Serializable
;
/**
* <p>Java class for PageParam complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* <complexType name="PageParam">
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <element name="pageIndex" type="{http://www.w3.org/2001/XMLSchema}int" minOccurs="0"/>
* <element name="pageSize" type="{http://www.w3.org/2001/XMLSchema}int" minOccurs="0"/>
* <element name="orderBy" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
* <element name="orderDir" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
* </sequence>
* </restriction>
* </complexContent>
* </complexType>
* </pre>
*
* @author LEGION
*/
@XmlAccessorType
(
XmlAccessType
.
FIELD
)
@XmlType
(
name
=
"PageParam"
,
propOrder
=
{
"pageIndex"
,
"pageSize"
,
"orderBy"
,
"orderDir"
})
public
class
PageParam
implements
Serializable
{
private
final
static
long
serialVersionUID
=
10L
;
protected
Integer
pageIndex
;
protected
Integer
pageSize
;
protected
String
orderBy
;
protected
String
orderDir
;
/**
* 当前页数,从1开始
*
* @return possible object is
* {@link Integer }
*/
public
Integer
getPageIndex
()
{
return
pageIndex
;
}
/**
* Sets the value of the pageIndex property.
*
* @param value allowed object is
* {@link Integer }
*/
public
void
setPageIndex
(
Integer
value
)
{
this
.
pageIndex
=
value
;
}
/**
* 每页记录数,默认20
*
* @return possible object is
* {@link Integer }
*/
public
Integer
getPageSize
()
{
return
pageSize
;
}
/**
* Sets the value of the pageSize property.
*
* @param value allowed object is
* {@link Integer }
*/
public
void
setPageSize
(
Integer
value
)
{
this
.
pageSize
=
value
;
}
/**
* 排序字段,Entity类的属性名,多字段的话用英文逗号隔开
*
* @return possible object is
* {@link String }
*/
public
String
getOrderBy
()
{
return
orderBy
;
}
/**
* Sets the value of the orderBy property.
*
* @param value allowed object is
* {@link String }
*/
public
void
setOrderBy
(
String
value
)
{
this
.
orderBy
=
value
;
}
/**
* 排序顺序,升序ASC,降序DESC
*
* @return possible object is
* {@link String }
*/
public
String
getOrderDir
()
{
return
orderDir
;
}
/**
* Sets the value of the orderDir property.
*
* @param value allowed object is
* {@link String }
*/
public
void
setOrderDir
(
String
value
)
{
this
.
orderDir
=
value
;
}
}
src/main/java/com/foc/thirdpart/esb/TrustedCert.java
0 → 100644
View file @
42ea7fdd
package
com
.
foc
.
thirdpart
.
esb
;
import
javax.net.ssl.X509TrustManager
;
import
java.security.cert.CertificateException
;
import
java.security.cert.X509Certificate
;
/**
* @author LEGION
*/
public
class
TrustedCert
implements
X509TrustManager
{
@Override
public
void
checkClientTrusted
(
X509Certificate
[]
x509Certificates
,
String
s
)
throws
CertificateException
{
}
@Override
public
void
checkServerTrusted
(
X509Certificate
[]
x509Certificates
,
String
s
)
throws
CertificateException
{
}
@Override
public
X509Certificate
[]
getAcceptedIssuers
()
{
return
new
X509Certificate
[
0
];
}
}
src/main/java/com/foc/thirdpart/esb/nativehttp/HttpClientImpl.java
0 → 100644
View file @
42ea7fdd
package
com
.
foc
.
thirdpart
.
esb
.
nativehttp
;
import
com.foc.thirdpart.esb.HttpClient
;
import
com.foc.thirdpart.esb.TrustedCert
;
import
javax.net.ssl.*
;
import
java.io.*
;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
import
java.security.SecureRandom
;
import
java.util.Map
;
/**
* @author LEGION
*/
public
class
HttpClientImpl
implements
HttpClient
{
public
static
final
String
DEFAULT_CHARSET
=
"utf-8"
;
private
static
final
String
METHOD_POST
=
"POST"
;
@Override
public
String
doPost
(
String
url
,
Map
<
String
,
String
>
params
,
String
charset
,
int
connectTimeout
,
int
readTimeout
)
throws
Exception
{
StringBuffer
parmsString
=
new
StringBuffer
();
for
(
String
key
:
params
.
keySet
())
{
parmsString
.
append
(
key
).
append
(
"="
).
append
(
params
.
get
(
key
)).
append
(
"&"
);
}
//removed the last $
parmsString
.
setLength
(
parmsString
.
length
()
-
1
);
String
ctype
=
"application/x-www-form-urlencoded;charset="
+
charset
;
byte
[]
content
=
{};
if
(
params
!=
null
)
{
content
=
parmsString
.
toString
().
getBytes
(
charset
);
}
return
doPost
(
url
,
ctype
,
content
,
connectTimeout
,
readTimeout
);
}
public
static
String
doPost
(
String
url
,
String
ctype
,
byte
[]
content
,
int
connectTimeout
,
int
readTimeout
)
throws
Exception
{
HttpsURLConnection
conn
=
null
;
OutputStream
out
=
null
;
String
rsp
=
null
;
try
{
try
{
SSLContext
ctx
=
SSLContext
.
getInstance
(
"TLS"
);
ctx
.
init
(
new
KeyManager
[
0
],
new
TrustManager
[]{
new
TrustedCert
()},
new
SecureRandom
());
SSLContext
.
setDefault
(
ctx
);
conn
=
getConnection
(
new
URL
(
url
),
METHOD_POST
,
ctype
);
conn
.
setHostnameVerifier
(
new
HostnameVerifier
()
{
@Override
public
boolean
verify
(
String
hostname
,
SSLSession
session
)
{
return
true
;
}
});
conn
.
setConnectTimeout
(
connectTimeout
);
conn
.
setReadTimeout
(
readTimeout
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
e
;
}
try
{
out
=
conn
.
getOutputStream
();
out
.
write
(
content
);
rsp
=
getResponseAsString
(
conn
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
throw
e
;
}
}
finally
{
if
(
out
!=
null
)
{
out
.
close
();
}
if
(
conn
!=
null
)
{
conn
.
disconnect
();
}
}
return
rsp
;
}
private
static
HttpsURLConnection
getConnection
(
URL
url
,
String
method
,
String
ctype
)
throws
IOException
{
HttpsURLConnection
conn
=
(
HttpsURLConnection
)
url
.
openConnection
();
conn
.
setRequestMethod
(
method
);
conn
.
setDoInput
(
true
);
conn
.
setDoOutput
(
true
);
conn
.
setRequestProperty
(
"Accept"
,
"text/xml,text/javascript,text/html"
);
conn
.
setRequestProperty
(
"User-Agent"
,
"stargate"
);
conn
.
setRequestProperty
(
"Content-Type"
,
ctype
);
return
conn
;
}
private
static
boolean
isEmpty
(
String
str
)
{
return
str
==
null
||
str
.
trim
().
length
()
==
0
;
}
private
static
String
getResponseAsString
(
HttpURLConnection
conn
)
throws
IOException
{
String
charset
=
getResponseCharset
(
conn
.
getContentType
());
InputStream
es
=
conn
.
getErrorStream
();
if
(
es
==
null
)
{
return
getStreamAsString
(
conn
.
getInputStream
(),
charset
);
}
else
{
String
msg
=
getStreamAsString
(
es
,
charset
);
if
(
isEmpty
(
msg
))
{
throw
new
IOException
(
conn
.
getResponseCode
()
+
":"
+
conn
.
getResponseMessage
());
}
else
{
throw
new
IOException
(
msg
);
}
}
}
private
static
String
getStreamAsString
(
InputStream
stream
,
String
charset
)
throws
IOException
{
try
{
BufferedReader
reader
=
new
BufferedReader
(
new
InputStreamReader
(
stream
,
charset
));
StringWriter
writer
=
new
StringWriter
();
char
[]
chars
=
new
char
[
256
];
int
count
=
0
;
while
((
count
=
reader
.
read
(
chars
))
>
0
)
{
writer
.
write
(
chars
,
0
,
count
);
}
return
writer
.
toString
();
}
finally
{
if
(
stream
!=
null
)
{
stream
.
close
();
}
}
}
private
static
String
getResponseCharset
(
String
ctype
)
{
String
charset
=
DEFAULT_CHARSET
;
if
(!
isEmpty
(
ctype
))
{
String
[]
params
=
ctype
.
split
(
";"
);
for
(
String
param
:
params
)
{
param
=
param
.
trim
();
if
(
param
.
startsWith
(
"charset"
))
{
String
[]
pair
=
param
.
split
(
"="
,
2
);
if
(
pair
.
length
==
2
)
{
if
(!
isEmpty
(
pair
[
1
]))
{
charset
=
pair
[
1
].
trim
();
}
}
break
;
}
}
}
return
charset
;
}
}
src/main/resources/global.properties
View file @
42ea7fdd
...
...
@@ -26,4 +26,8 @@ toEmail=zangtao@bbdtek.com
#,lisu@bbdtek.com
#lisu@bbdtek.com
fromName
=
sdhkxxaq
verifyAcType
=
A319/A320,A321,A320neo,A330
\ No newline at end of file
verifyAcType
=
A319/A320,A321,A320neo,A330
esb.security.account
=
JD_FOCIMC_UAT
esb.security.key
=
SkRfRk9DSU1DX1VBVA0ODw==
esb.security.password
=
+ZwiuDzP8swD5XmjLn/Ln/80DBPZ4YvD/e830qPMDbk=
esb.security.gateway.uat.url
=
https://esbgatewaytest.hnair.com/esbforward/getRestInfo
\ No newline at end of file
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