Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
8b6f7071
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看板
提交
8b6f7071
编写于
12月 03, 2013
作者:
M
michaelm
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8029127: Redirected POST request throws IllegalStateException on HttpURLConnection.getInputStream
Reviewed-by: alanb, chegar
上级
dcbdfb9f
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
176 addition
and
1 deletion
+176
-1
src/share/classes/sun/net/www/protocol/http/HttpURLConnection.java
.../classes/sun/net/www/protocol/http/HttpURLConnection.java
+1
-1
test/sun/net/www/protocol/http/RedirectOnPost.java
test/sun/net/www/protocol/http/RedirectOnPost.java
+175
-0
未找到文件。
src/share/classes/sun/net/www/protocol/http/HttpURLConnection.java
浏览文件 @
8b6f7071
...
...
@@ -2594,7 +2594,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
requests
=
new
MessageHeader
();
setRequests
=
false
;
s
etRequestMethod
(
"GET"
);
s
uper
.
setRequestMethod
(
"GET"
);
// avoid the connecting check
poster
=
null
;
if
(!
checkReuseConnection
())
connect
();
...
...
test/sun/net/www/protocol/http/RedirectOnPost.java
0 → 100644
浏览文件 @
8b6f7071
/*
* 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
* @compile ../../../../../com/sun/net/httpserver/SimpleSSLContext.java RedirectOnPost.java
* @run main/othervm RedirectOnPost
* @bug 8029127
* @summary A redirect POST request does not work and illegalStateException on HttpURLConnection.getInputStream
*/
import
java.net.*
;
import
java.io.*
;
import
java.util.*
;
import
com.sun.net.httpserver.*
;
import
java.util.concurrent.*
;
import
javax.net.ssl.*
;
public
class
RedirectOnPost
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
ExecutorService
e
=
Executors
.
newFixedThreadPool
(
5
);
String
keysdir
=
System
.
getProperty
(
"test.src"
)
+
"/../../../../../com/sun/net/httpserver/"
;
SSLContext
ctx
=
new
SimpleSSLContext
(
keysdir
).
get
();
HttpServer
httpServer
=
getHttpServer
(
e
);
HttpsServer
httpsServer
=
getHttpsServer
(
e
,
ctx
);
try
{
// take the keystore from elsewhere in test hierarchy
int
port
=
httpServer
.
getAddress
().
getPort
();
int
sslPort
=
httpsServer
.
getAddress
().
getPort
();
httpServer
.
start
();
httpsServer
.
start
();
runTest
(
"http://127.0.0.1:"
+
port
+
"/test/"
,
null
);
runTest
(
"https://127.0.0.1:"
+
sslPort
+
"/test/"
,
ctx
);
System
.
out
.
println
(
"Main thread waiting"
);
}
finally
{
httpServer
.
stop
(
0
);
httpsServer
.
stop
(
0
);
e
.
shutdownNow
();
}
}
public
static
void
runTest
(
String
baseURL
,
SSLContext
ctx
)
throws
Exception
{
byte
[]
buf
=
"Hello world"
.
getBytes
();
URL
url
=
new
URL
(
baseURL
+
"a"
);
HttpURLConnection
con
=
(
HttpURLConnection
)
url
.
openConnection
();
if
(
con
instanceof
HttpsURLConnection
)
{
HttpsURLConnection
ssl
=
(
HttpsURLConnection
)
con
;
ssl
.
setHostnameVerifier
(
new
HostnameVerifier
()
{
public
boolean
verify
(
String
host
,
SSLSession
sess
)
{
return
true
;
}
});
ssl
.
setSSLSocketFactory
(
ctx
.
getSocketFactory
());
}
con
.
setDoOutput
(
true
);
con
.
setDoInput
(
true
);
con
.
setRequestMethod
(
"POST"
);
try
(
OutputStream
out
=
con
.
getOutputStream
())
{
out
.
write
(
buf
);
}
try
(
InputStream
in
=
con
.
getInputStream
())
{
byte
[]
newBuf
=
readFully
(
in
);
}
}
private
static
byte
[]
readFully
(
InputStream
istream
)
throws
IOException
{
ByteArrayOutputStream
bout
=
new
ByteArrayOutputStream
();
byte
[]
buf
=
new
byte
[
1024
];
int
num
=
0
;
if
(
istream
!=
null
)
{
while
((
num
=
istream
.
read
(
buf
))
!=
-
1
)
{
bout
.
write
(
buf
,
0
,
num
);
}
}
byte
[]
ret
=
bout
.
toByteArray
();
return
ret
;
}
static
class
Handler
implements
HttpHandler
{
String
baseURL
;
Handler
(
String
baseURL
)
{
this
.
baseURL
=
baseURL
;
}
int
calls
=
0
;
public
void
handle
(
HttpExchange
msg
)
{
try
{
String
method
=
msg
.
getRequestMethod
();
System
.
out
.
println
(
"Server: "
+
baseURL
);
if
(
calls
++
==
0
)
{
System
.
out
.
println
(
"Server: redirecting"
);
InputStream
is
=
msg
.
getRequestBody
();
byte
[]
buf
=
readFully
(
is
);
is
.
close
();
Headers
h
=
msg
.
getResponseHeaders
();
h
.
add
(
"Location"
,
baseURL
+
"b"
);
msg
.
sendResponseHeaders
(
302
,
-
1
);
msg
.
close
();
}
else
{
System
.
out
.
println
(
"Server: second call"
);
InputStream
is
=
msg
.
getRequestBody
();
byte
[]
buf
=
readFully
(
is
);
is
.
close
();
msg
.
sendResponseHeaders
(
200
,
-
1
);
msg
.
close
();
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
msg
.
close
();
}
}
}
private
static
HttpServer
getHttpServer
(
ExecutorService
execs
)
throws
Exception
{
InetSocketAddress
inetAddress
=
new
InetSocketAddress
(
0
);
HttpServer
testServer
=
HttpServer
.
create
(
inetAddress
,
15
);
int
port
=
testServer
.
getAddress
().
getPort
();
testServer
.
setExecutor
(
execs
);
String
base
=
"http://127.0.0.1:"
+
port
+
"/test"
;
HttpContext
context
=
testServer
.
createContext
(
"/test"
);
context
.
setHandler
(
new
Handler
(
base
));
return
testServer
;
}
private
static
HttpsServer
getHttpsServer
(
ExecutorService
execs
,
SSLContext
ctx
)
throws
Exception
{
InetSocketAddress
inetAddress
=
new
InetSocketAddress
(
0
);
HttpsServer
testServer
=
HttpsServer
.
create
(
inetAddress
,
15
);
int
port
=
testServer
.
getAddress
().
getPort
();
testServer
.
setExecutor
(
execs
);
testServer
.
setHttpsConfigurator
(
new
HttpsConfigurator
(
ctx
));
String
base
=
"https://127.0.0.1:"
+
port
+
"/test"
;
HttpContext
context
=
testServer
.
createContext
(
"/test"
);
context
.
setHandler
(
new
Handler
(
base
));
return
testServer
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录