Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
b11d345c
S
spring-framework
项目概览
爱吃血肠
/
spring-framework
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b11d345c
编写于
2月 10, 2016
作者:
R
Rossen Stoyanchev
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Common base class for [Unknown]HttpStatusCodeException
Issue: SPR-13928
上级
901c2d5f
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
126 addition
and
130 deletion
+126
-130
spring-web/src/main/java/org/springframework/web/client/HttpStatusCodeException.java
...g/springframework/web/client/HttpStatusCodeException.java
+13
-66
spring-web/src/main/java/org/springframework/web/client/RestClientResponseException.java
...ringframework/web/client/RestClientResponseException.java
+108
-0
spring-web/src/main/java/org/springframework/web/client/UnknownHttpStatusCodeException.java
...gframework/web/client/UnknownHttpStatusCodeException.java
+5
-64
未找到文件。
spring-web/src/main/java/org/springframework/web/client/HttpStatusCodeException.java
浏览文件 @
b11d345c
/*
* Copyright 2002-201
4
the original author or authors.
* Copyright 2002-201
6
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -16,7 +16,6 @@
package
org.springframework.web.client
;
import
java.io.UnsupportedEncodingException
;
import
java.nio.charset.Charset
;
import
org.springframework.http.HttpHeaders
;
...
...
@@ -27,29 +26,19 @@ import org.springframework.http.HttpStatus;
*
* @author Arjen Poutsma
* @author Chris Beams
* @author Rossen Stoyanchev
* @since 3.0
*/
public
abstract
class
HttpStatusCodeException
extends
RestClientException
{
public
abstract
class
HttpStatusCodeException
extends
RestClient
Response
Exception
{
private
static
final
long
serialVersionUID
=
-
5807494703720513267L
;
private
static
final
String
DEFAULT_CHARSET
=
"ISO-8859-1"
;
private
static
final
long
serialVersionUID
=
5696801857651587810L
;
private
final
HttpStatus
statusCode
;
private
final
String
statusText
;
private
final
byte
[]
responseBody
;
private
final
HttpHeaders
responseHeaders
;
private
final
String
responseCharset
;
/**
* Construct a new instance of {@code HttpStatusCodeException} based on an
* {@link HttpStatus}.
* Construct a new instance with an {@link HttpStatus}.
* @param statusCode the status code
*/
protected
HttpStatusCodeException
(
HttpStatus
statusCode
)
{
...
...
@@ -57,8 +46,7 @@ public abstract class HttpStatusCodeException extends RestClientException {
}
/**
* Construct a new instance of {@code HttpStatusCodeException} based on an
* {@link HttpStatus} and status text.
* Construct a new instance with an {@link HttpStatus} and status text.
* @param statusCode the status code
* @param statusText the status text
*/
...
...
@@ -67,23 +55,22 @@ public abstract class HttpStatusCodeException extends RestClientException {
}
/**
* Construct a new instance of {@code HttpStatusCodeException} based on an
* {@link HttpStatus}, status text, and response body content.
* Construct instance with an {@link HttpStatus}, status text, and content.
* @param statusCode the status code
* @param statusText the status text
* @param responseBody the response body content, may be {@code null}
* @param responseCharset the response body charset, may be {@code null}
* @since 3.0.5
*/
protected
HttpStatusCodeException
(
HttpStatus
statusCode
,
String
statusText
,
byte
[]
responseBody
,
Charset
responseCharset
)
{
protected
HttpStatusCodeException
(
HttpStatus
statusCode
,
String
statusText
,
byte
[]
responseBody
,
Charset
responseCharset
)
{
this
(
statusCode
,
statusText
,
null
,
responseBody
,
responseCharset
);
}
/**
* Construct
a new instance of {@code HttpStatusCodeException} based on an
*
{@link HttpStatus}, status text, and response body conten
t.
* Construct
instance with an {@link HttpStatus}, status text, content, and
*
a response charse
t.
* @param statusCode the status code
* @param statusText the status text
* @param responseHeaders the response headers, may be {@code null}
...
...
@@ -94,12 +81,9 @@ public abstract class HttpStatusCodeException extends RestClientException {
protected
HttpStatusCodeException
(
HttpStatus
statusCode
,
String
statusText
,
HttpHeaders
responseHeaders
,
byte
[]
responseBody
,
Charset
responseCharset
)
{
super
(
statusCode
.
value
()
+
" "
+
statusText
);
super
(
statusCode
.
value
()
+
" "
+
statusText
,
statusCode
.
value
(),
statusText
,
responseHeaders
,
responseBody
,
responseCharset
);
this
.
statusCode
=
statusCode
;
this
.
statusText
=
statusText
;
this
.
responseHeaders
=
responseHeaders
;
this
.
responseBody
=
responseBody
!=
null
?
responseBody
:
new
byte
[
0
];
this
.
responseCharset
=
responseCharset
!=
null
?
responseCharset
.
name
()
:
DEFAULT_CHARSET
;
}
...
...
@@ -110,41 +94,4 @@ public abstract class HttpStatusCodeException extends RestClientException {
return
this
.
statusCode
;
}
/**
* Return the HTTP status text.
*/
public
String
getStatusText
()
{
return
this
.
statusText
;
}
/**
* Return the HTTP response headers.
* @since 3.1.2
*/
public
HttpHeaders
getResponseHeaders
()
{
return
this
.
responseHeaders
;
}
/**
* Return the response body as a byte array.
* @since 3.0.5
*/
public
byte
[]
getResponseBodyAsByteArray
()
{
return
this
.
responseBody
;
}
/**
* Return the response body as a string.
* @since 3.0.5
*/
public
String
getResponseBodyAsString
()
{
try
{
return
new
String
(
this
.
responseBody
,
this
.
responseCharset
);
}
catch
(
UnsupportedEncodingException
ex
)
{
// should not occur
throw
new
IllegalStateException
(
ex
);
}
}
}
spring-web/src/main/java/org/springframework/web/client/RestClientResponseException.java
0 → 100644
浏览文件 @
b11d345c
/*
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.web.client
;
import
java.io.UnsupportedEncodingException
;
import
java.nio.charset.Charset
;
import
org.springframework.http.HttpHeaders
;
/**
* Abstract base class for exceptions that contain actual HTTP response data.
*
* @author Rossen Stoyanchev
* @since 4.3
*/
public
abstract
class
RestClientResponseException
extends
RestClientException
{
private
static
final
long
serialVersionUID
=
-
8803556342728481792L
;
private
static
final
String
DEFAULT_CHARSET
=
"ISO-8859-1"
;
private
final
int
rawStatusCode
;
private
final
String
statusText
;
private
final
byte
[]
responseBody
;
private
final
HttpHeaders
responseHeaders
;
private
final
String
responseCharset
;
/**
* Construct a new instance of with the given response data.
* @param statusCode the raw status code value
* @param statusText the status text
* @param responseHeaders the response headers, may be {@code null}
* @param responseBody the response body content, may be {@code null}
* @param responseCharset the response body charset, may be {@code null}
*/
public
RestClientResponseException
(
String
message
,
int
statusCode
,
String
statusText
,
HttpHeaders
responseHeaders
,
byte
[]
responseBody
,
Charset
responseCharset
)
{
super
(
message
);
this
.
rawStatusCode
=
statusCode
;
this
.
statusText
=
statusText
;
this
.
responseHeaders
=
responseHeaders
;
this
.
responseBody
=
responseBody
!=
null
?
responseBody
:
new
byte
[
0
];
this
.
responseCharset
=
responseCharset
!=
null
?
responseCharset
.
name
()
:
DEFAULT_CHARSET
;
}
/**
* Return the raw HTTP status code value.
*/
public
int
getRawStatusCode
()
{
return
this
.
rawStatusCode
;
}
/**
* Return the HTTP status text.
*/
public
String
getStatusText
()
{
return
this
.
statusText
;
}
/**
* Return the HTTP response headers.
*/
public
HttpHeaders
getResponseHeaders
()
{
return
this
.
responseHeaders
;
}
/**
* Return the response body as a byte array.
*/
public
byte
[]
getResponseBodyAsByteArray
()
{
return
this
.
responseBody
;
}
/**
* Return the response body as a string.
*/
public
String
getResponseBodyAsString
()
{
try
{
return
new
String
(
this
.
responseBody
,
this
.
responseCharset
);
}
catch
(
UnsupportedEncodingException
ex
)
{
// should not occur
throw
new
IllegalStateException
(
ex
);
}
}
}
spring-web/src/main/java/org/springframework/web/client/UnknownHttpStatusCodeException.java
浏览文件 @
b11d345c
/*
* Copyright 2002-201
4
the original author or authors.
* Copyright 2002-201
6
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -16,7 +16,6 @@
package
org.springframework.web.client
;
import
java.io.UnsupportedEncodingException
;
import
java.nio.charset.Charset
;
import
org.springframework.http.HttpHeaders
;
...
...
@@ -28,21 +27,9 @@ import org.springframework.http.HttpStatus;
* @author Rossen Stoyanchev
* @since 3.2
*/
public
class
UnknownHttpStatusCodeException
extends
RestClientException
{
public
class
UnknownHttpStatusCodeException
extends
RestClient
Response
Exception
{
private
static
final
long
serialVersionUID
=
4702443689088991600L
;
private
static
final
String
DEFAULT_CHARSET
=
"ISO-8859-1"
;
private
final
int
rawStatusCode
;
private
final
String
statusText
;
private
final
byte
[]
responseBody
;
private
final
HttpHeaders
responseHeaders
;
private
final
String
responseCharset
;
private
static
final
long
serialVersionUID
=
7103980251635005491L
;
/**
...
...
@@ -57,54 +44,8 @@ public class UnknownHttpStatusCodeException extends RestClientException {
public
UnknownHttpStatusCodeException
(
int
rawStatusCode
,
String
statusText
,
HttpHeaders
responseHeaders
,
byte
[]
responseBody
,
Charset
responseCharset
)
{
super
(
"Unknown status code ["
+
String
.
valueOf
(
rawStatusCode
)
+
"]"
+
" "
+
statusText
);
this
.
rawStatusCode
=
rawStatusCode
;
this
.
statusText
=
statusText
;
this
.
responseHeaders
=
responseHeaders
;
this
.
responseBody
=
responseBody
!=
null
?
responseBody
:
new
byte
[
0
];
this
.
responseCharset
=
responseCharset
!=
null
?
responseCharset
.
name
()
:
DEFAULT_CHARSET
;
}
/**
* Return the raw HTTP status code value.
*/
public
int
getRawStatusCode
()
{
return
this
.
rawStatusCode
;
}
/**
* Return the HTTP status text.
*/
public
String
getStatusText
()
{
return
this
.
statusText
;
}
/**
* Return the HTTP response headers.
*/
public
HttpHeaders
getResponseHeaders
()
{
return
this
.
responseHeaders
;
}
/**
* Return the response body as a byte array.
*/
public
byte
[]
getResponseBodyAsByteArray
()
{
return
this
.
responseBody
;
}
/**
* Return the response body as a string.
*/
public
String
getResponseBodyAsString
()
{
try
{
return
new
String
(
this
.
responseBody
,
this
.
responseCharset
);
}
catch
(
UnsupportedEncodingException
ex
)
{
// should not occur
throw
new
IllegalStateException
(
ex
);
}
super
(
"Unknown status code ["
+
String
.
valueOf
(
rawStatusCode
)
+
"]"
+
" "
+
statusText
,
rawStatusCode
,
statusText
,
responseHeaders
,
responseBody
,
responseCharset
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录