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
8d31e511
Commit
8d31e511
authored
Nov 27, 2017
by
Yunlong Liang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
clear http response inputstream and errorstream to reuse connection.
parent
c97d5bb9
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 @
8d31e511
...
...
@@ -70,6 +70,7 @@ public class HttpUtil {
private
<
T
>
HttpResponse
<
T
>
doGetWithSerializeFunction
(
HttpRequest
httpRequest
,
Function
<
String
,
T
>
serializeFunction
)
{
InputStreamReader
isr
=
null
;
InputStreamReader
esr
=
null
;
int
statusCode
;
try
{
HttpURLConnection
conn
=
(
HttpURLConnection
)
new
URL
(
httpRequest
.
getUrl
()).
openConnection
();
...
...
@@ -92,9 +93,18 @@ public class HttpUtil {
conn
.
connect
();
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
)
{
isr
=
new
InputStreamReader
(
conn
.
getInputStream
(),
StandardCharsets
.
UTF_8
);
String
content
=
CharStreams
.
toString
(
isr
);
return
new
HttpResponse
<>(
statusCode
,
serializeFunction
.
apply
(
content
));
}
...
...
@@ -102,17 +112,26 @@ public class HttpUtil {
if
(
statusCode
==
304
)
{
return
new
HttpResponse
<>(
statusCode
,
null
);
}
}
catch
(
Throwable
ex
)
{
throw
new
ApolloConfigException
(
"Could not complete get operation"
,
ex
);
}
finally
{
if
(
isr
!=
null
)
{
try
{
CharStreams
.
toString
(
isr
);
isr
.
close
();
}
catch
(
IOException
e
)
{
// ignore
}
}
if
(
esr
!=
null
)
{
try
{
CharStreams
.
toString
(
esr
);
esr
.
close
();
}
catch
(
Exception
e
)
{
// ignore
}
}
}
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