Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
apollo
Project
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
openSource
apollo
Commits
f9cb281d
Unverified
Commit
f9cb281d
authored
Dec 16, 2017
by
Jason Song
Committed by
GitHub
Dec 16, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #863 from xiaoerlyl/keepalive
clear http response inputstream and errorstream to reuse connection.
parents
d0bbf0da
b2f24cb1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
2 deletions
+21
-2
HttpUtil.java
...n/java/com/ctrip/framework/apollo/util/http/HttpUtil.java
+21
-2
No files found.
apollo-client/src/main/java/com/ctrip/framework/apollo/util/http/HttpUtil.java
View file @
f9cb281d
...
@@ -70,6 +70,7 @@ public class HttpUtil {
...
@@ -70,6 +70,7 @@ public class HttpUtil {
private
<
T
>
HttpResponse
<
T
>
doGetWithSerializeFunction
(
HttpRequest
httpRequest
,
private
<
T
>
HttpResponse
<
T
>
doGetWithSerializeFunction
(
HttpRequest
httpRequest
,
Function
<
String
,
T
>
serializeFunction
)
{
Function
<
String
,
T
>
serializeFunction
)
{
InputStreamReader
isr
=
null
;
InputStreamReader
isr
=
null
;
InputStreamReader
esr
=
null
;
int
statusCode
;
int
statusCode
;
try
{
try
{
HttpURLConnection
conn
=
(
HttpURLConnection
)
new
URL
(
httpRequest
.
getUrl
()).
openConnection
();
HttpURLConnection
conn
=
(
HttpURLConnection
)
new
URL
(
httpRequest
.
getUrl
()).
openConnection
();
...
@@ -92,9 +93,18 @@ public class HttpUtil {
...
@@ -92,9 +93,18 @@ public class HttpUtil {
conn
.
connect
();
conn
.
connect
();
statusCode
=
conn
.
getResponseCode
();
statusCode
=
conn
.
getResponseCode
();
try
{
isr
=
new
InputStreamReader
(
conn
.
getInputStream
(),
StandardCharsets
.
UTF_8
);
}
catch
(
Exception
e
)
{
// ignore
}
try
{
esr
=
new
InputStreamReader
(
conn
.
getErrorStream
(),
StandardCharsets
.
UTF_8
);
}
catch
(
Exception
e
)
{
// ignore
}
if
(
statusCode
==
200
)
{
if
(
statusCode
==
200
)
{
isr
=
new
InputStreamReader
(
conn
.
getInputStream
(),
StandardCharsets
.
UTF_8
);
String
content
=
CharStreams
.
toString
(
isr
);
String
content
=
CharStreams
.
toString
(
isr
);
return
new
HttpResponse
<>(
statusCode
,
serializeFunction
.
apply
(
content
));
return
new
HttpResponse
<>(
statusCode
,
serializeFunction
.
apply
(
content
));
}
}
...
@@ -102,17 +112,26 @@ public class HttpUtil {
...
@@ -102,17 +112,26 @@ public class HttpUtil {
if
(
statusCode
==
304
)
{
if
(
statusCode
==
304
)
{
return
new
HttpResponse
<>(
statusCode
,
null
);
return
new
HttpResponse
<>(
statusCode
,
null
);
}
}
}
catch
(
Throwable
ex
)
{
}
catch
(
Throwable
ex
)
{
throw
new
ApolloConfigException
(
"Could not complete get operation"
,
ex
);
throw
new
ApolloConfigException
(
"Could not complete get operation"
,
ex
);
}
finally
{
}
finally
{
if
(
isr
!=
null
)
{
if
(
isr
!=
null
)
{
try
{
try
{
CharStreams
.
toString
(
isr
);
isr
.
close
();
isr
.
close
();
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
// ignore
// ignore
}
}
}
}
if
(
esr
!=
null
)
{
try
{
CharStreams
.
toString
(
esr
);
esr
.
close
();
}
catch
(
Exception
e
)
{
// ignore
}
}
}
}
throw
new
ApolloConfigStatusCodeException
(
statusCode
,
throw
new
ApolloConfigStatusCodeException
(
statusCode
,
...
...
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