Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
4b9cd322
D
dragonwell8_jdk
项目概览
openanolis
/
dragonwell8_jdk
通知
4
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell8_jdk
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
4b9cd322
编写于
6月 05, 2013
作者:
C
chegar
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8011719: Properties.loadFromXML fails with a chunked HTTP connection
Reviewed-by: michaelm
上级
13a5a0ba
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
198 addition
and
1 deletion
+198
-1
src/share/classes/sun/net/www/protocol/http/HttpURLConnection.java
.../classes/sun/net/www/protocol/http/HttpURLConnection.java
+13
-1
test/sun/net/www/protocol/http/HttpStreams.java
test/sun/net/www/protocol/http/HttpStreams.java
+185
-0
未找到文件。
src/share/classes/sun/net/www/protocol/http/HttpURLConnection.java
浏览文件 @
4b9cd322
...
...
@@ -3158,6 +3158,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
private
boolean
marked
=
false
;
private
int
inCache
=
0
;
private
int
markCount
=
0
;
private
boolean
closed
;
// false
public
HttpInputStream
(
InputStream
is
)
{
super
(
is
);
...
...
@@ -3233,8 +3234,14 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
}
}
private
void
ensureOpen
()
throws
IOException
{
if
(
closed
)
throw
new
IOException
(
"stream is closed"
);
}
@Override
public
int
read
()
throws
IOException
{
ensureOpen
();
try
{
byte
[]
b
=
new
byte
[
1
];
int
ret
=
read
(
b
);
...
...
@@ -3254,6 +3261,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
@Override
public
int
read
(
byte
[]
b
,
int
off
,
int
len
)
throws
IOException
{
ensureOpen
();
try
{
int
newLen
=
super
.
read
(
b
,
off
,
len
);
int
nWrite
;
...
...
@@ -3291,7 +3299,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
@Override
public
long
skip
(
long
n
)
throws
IOException
{
ensureOpen
();
long
remaining
=
n
;
int
nr
;
if
(
skipBuffer
==
null
)
...
...
@@ -3317,6 +3325,9 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
@Override
public
void
close
()
throws
IOException
{
if
(
closed
)
return
;
try
{
if
(
outputStream
!=
null
)
{
if
(
read
()
!=
-
1
)
{
...
...
@@ -3332,6 +3343,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
}
throw
ioex
;
}
finally
{
closed
=
true
;
HttpURLConnection
.
this
.
http
=
null
;
checkResponseCredentials
(
true
);
}
...
...
test/sun/net/www/protocol/http/HttpStreams.java
0 → 100644
浏览文件 @
4b9cd322
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* @test
* @bug 8011719
* @summary Basic checks to verify behavior of returned input streams
*/
import
com.sun.net.httpserver.HttpExchange
;
import
com.sun.net.httpserver.HttpHandler
;
import
com.sun.net.httpserver.HttpServer
;
import
java.io.*
;
import
java.net.*
;
import
java.nio.charset.StandardCharsets
;
import
java.util.*
;
public
class
HttpStreams
{
void
client
(
String
u
)
throws
Exception
{
byte
[]
ba
=
new
byte
[
5
];
HttpURLConnection
urlc
=
(
HttpURLConnection
)(
new
URL
(
u
)).
openConnection
();
int
resp
=
urlc
.
getResponseCode
();
InputStream
is
;
if
(
resp
==
200
)
is
=
urlc
.
getInputStream
();
else
is
=
urlc
.
getErrorStream
();
expectNoThrow
(()
->
{
is
.
read
();
},
"read on open stream should not throw :"
+
u
);
expectNoThrow
(()
->
{
is
.
close
();
},
"close should never throw: "
+
u
);
expectNoThrow
(()
->
{
is
.
close
();
},
"close should never throw: "
+
u
);
expectThrow
(()
->
{
is
.
read
();
},
"read on closed stream should throw: "
+
u
);
expectThrow
(()
->
{
is
.
read
(
ba
);
},
"read on closed stream should throw: "
+
u
);
expectThrow
(()
->
{
is
.
read
(
ba
,
0
,
2
);
},
"read on closed stream should throw: "
+
u
);
}
void
test
()
throws
Exception
{
HttpServer
server
=
null
;
try
{
server
=
startHttpServer
();
String
baseUrl
=
"http://localhost:"
+
server
.
getAddress
().
getPort
()
+
"/"
;
client
(
baseUrl
+
"chunked/"
);
client
(
baseUrl
+
"fixed/"
);
client
(
baseUrl
+
"error/"
);
client
(
baseUrl
+
"chunkedError/"
);
// Test with a response cache
ResponseCache
ch
=
ResponseCache
.
getDefault
();
ResponseCache
.
setDefault
(
new
TrivialCacheHandler
());
try
{
client
(
baseUrl
+
"chunked/"
);
client
(
baseUrl
+
"fixed/"
);
client
(
baseUrl
+
"error/"
);
client
(
baseUrl
+
"chunkedError/"
);
}
finally
{
ResponseCache
.
setDefault
(
ch
);
}
}
finally
{
if
(
server
!=
null
)
server
.
stop
(
0
);
}
System
.
out
.
println
(
"passed: "
+
pass
+
", failed: "
+
fail
);
if
(
fail
>
0
)
throw
new
RuntimeException
(
"some tests failed check output"
);
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
(
new
HttpStreams
()).
test
();
}
// HTTP Server
HttpServer
startHttpServer
()
throws
IOException
{
HttpServer
httpServer
=
HttpServer
.
create
(
new
InetSocketAddress
(
0
),
0
);
httpServer
.
createContext
(
"/chunked/"
,
new
ChunkedHandler
());
httpServer
.
createContext
(
"/fixed/"
,
new
FixedHandler
());
httpServer
.
createContext
(
"/error/"
,
new
ErrorHandler
());
httpServer
.
createContext
(
"/chunkedError/"
,
new
ChunkedErrorHandler
());
httpServer
.
start
();
return
httpServer
;
}
static
abstract
class
AbstractHandler
implements
HttpHandler
{
@Override
public
void
handle
(
HttpExchange
t
)
throws
IOException
{
try
(
InputStream
is
=
t
.
getRequestBody
())
{
while
(
is
.
read
()
!=
-
1
);
}
t
.
sendResponseHeaders
(
respCode
(),
length
());
try
(
OutputStream
os
=
t
.
getResponseBody
())
{
os
.
write
(
message
());
}
t
.
close
();
}
abstract
int
respCode
();
abstract
int
length
();
abstract
byte
[]
message
();
}
static
class
ChunkedHandler
extends
AbstractHandler
{
static
final
byte
[]
ba
=
"Hello there from chunked handler!"
.
getBytes
(
StandardCharsets
.
US_ASCII
);
int
respCode
()
{
return
200
;
}
int
length
()
{
return
0
;
}
byte
[]
message
()
{
return
ba
;
}
}
static
class
FixedHandler
extends
AbstractHandler
{
static
final
byte
[]
ba
=
"Hello there from fixed handler!"
.
getBytes
(
StandardCharsets
.
US_ASCII
);
int
respCode
()
{
return
200
;
}
int
length
()
{
return
ba
.
length
;
}
byte
[]
message
()
{
return
ba
;
}
}
static
class
ErrorHandler
extends
AbstractHandler
{
static
final
byte
[]
ba
=
"This is an error mesg from the server!"
.
getBytes
(
StandardCharsets
.
US_ASCII
);
int
respCode
()
{
return
400
;
}
int
length
()
{
return
ba
.
length
;
}
byte
[]
message
()
{
return
ba
;
}
}
static
class
ChunkedErrorHandler
extends
ErrorHandler
{
int
length
()
{
return
0
;
}
}
static
class
TrivialCacheHandler
extends
ResponseCache
{
public
CacheResponse
get
(
URI
uri
,
String
rqstMethod
,
Map
rqstHeaders
)
{
return
null
;
}
public
CacheRequest
put
(
URI
uri
,
URLConnection
conn
)
{
return
new
TrivialCacheRequest
();
}
}
static
class
TrivialCacheRequest
extends
CacheRequest
{
ByteArrayOutputStream
baos
=
new
ByteArrayOutputStream
();
public
void
abort
()
{}
public
OutputStream
getBody
()
throws
IOException
{
return
baos
;
}
}
static
interface
ThrowableRunnable
{
void
run
()
throws
IOException
;
}
void
expectThrow
(
ThrowableRunnable
r
,
String
msg
)
{
try
{
r
.
run
();
fail
(
msg
);
}
catch
(
IOException
x
)
{
pass
();
}
}
void
expectNoThrow
(
ThrowableRunnable
r
,
String
msg
)
{
try
{
r
.
run
();
pass
();
}
catch
(
IOException
x
)
{
fail
(
msg
,
x
);
}
}
private
int
pass
;
private
int
fail
;
void
pass
()
{
pass
++;
}
void
fail
(
String
msg
,
Exception
x
)
{
System
.
out
.
println
(
msg
);
x
.
printStackTrace
();
fail
++;
}
void
fail
(
String
msg
)
{
System
.
out
.
println
(
msg
);
Thread
.
dumpStack
();
fail
++;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录