This repository has been archived by the owner on Aug 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HttpRequestExecuter.execute(HttpRequest, ConnectionConfig) 需要显示的abort
httpUriRequest fix #80 HttpRequestExecuter.execute(HttpRequest, ConnectionConfig) 方法删除 ,直接调用 HttpRequestExecuter.execute(HttpUriRequest, ConnectionConfig) fix #81 HttpClientUtil 相关方法可以合并 fix #32
- Loading branch information
1 parent
2669ff8
commit 0816aaa
Showing
7 changed files
with
358 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
...lient4/src/main/java/com/feilong/net/httpclient4/callback/HttpResponseResultCallback.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* Copyright (C) 2008 feilong | ||
* | ||
* 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 com.feilong.net.httpclient4.callback; | ||
|
||
import static com.feilong.core.bean.ConvertUtil.toMap; | ||
|
||
import java.util.Date; | ||
|
||
import org.apache.http.HttpResponse; | ||
import org.apache.http.client.methods.HttpUriRequest; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.feilong.json.jsonlib.JavaToJsonConfig; | ||
import com.feilong.json.jsonlib.JsonUtil; | ||
import com.feilong.json.jsonlib.processor.StringOverLengthJsonValueProcessor; | ||
import com.feilong.net.entity.ConnectionConfig; | ||
import com.feilong.net.entity.HttpRequest; | ||
import com.feilong.net.httpclient4.builder.HttpResponseBuilder; | ||
|
||
import net.sf.json.processors.JsonValueProcessor; | ||
|
||
/** | ||
* 用来解析 全数据 {@link com.feilong.net.entity.HttpResponse} 的 {@link ResultCallback}. | ||
* | ||
* @author <a href="http://feitianbenyue.iteye.com/">feilong</a> | ||
* @since 2.0.3 | ||
*/ | ||
public class HttpResponseResultCallback implements ResultCallback<com.feilong.net.entity.HttpResponse>{ | ||
|
||
/** The Constant LOGGER. */ | ||
private static final Logger LOGGER = LoggerFactory.getLogger(HttpResponseResultCallback.class); | ||
|
||
/** Static instance. */ | ||
// the static instance works for all types | ||
public static final HttpResponseResultCallback INSTANCE = new HttpResponseResultCallback(); | ||
|
||
//--------------------------------------------------------------- | ||
|
||
/** | ||
* On. | ||
* | ||
* @param httpRequest | ||
* the http request | ||
* @param httpUriRequest | ||
* the http uri request | ||
* @param httpResponse | ||
* the http response | ||
* @param useConnectionConfig | ||
* the use connection config | ||
* @param beginDate | ||
* the begin date | ||
* @return the com.feilong.net.entity. http response | ||
*/ | ||
@Override | ||
public com.feilong.net.entity.HttpResponse on( | ||
HttpRequest httpRequest, | ||
HttpUriRequest httpUriRequest, | ||
HttpResponse httpResponse, | ||
ConnectionConfig useConnectionConfig, | ||
Date beginDate){ | ||
|
||
com.feilong.net.entity.HttpResponse resultResponse = HttpResponseBuilder.build(beginDate, httpResponse); | ||
|
||
//--------------------------------------------------------------- | ||
if (LOGGER.isInfoEnabled()){ | ||
String pattern = "request:[{}],useConnectionConfig:[{}],response:[{}]"; | ||
String response = JsonUtil.format( | ||
resultResponse, | ||
new JavaToJsonConfig(toMap("resultString", (JsonValueProcessor) new StringOverLengthJsonValueProcessor()))); | ||
|
||
LOGGER.info(pattern, JsonUtil.format(httpRequest), JsonUtil.format(useConnectionConfig), response); | ||
} | ||
|
||
return resultResponse; | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
...rc/main/java/com/feilong/net/httpclient4/callback/ResponseBodyAsStringResultCallback.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright (C) 2008 feilong | ||
* | ||
* 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 com.feilong.net.httpclient4.callback; | ||
|
||
import java.util.Date; | ||
|
||
import org.apache.http.HttpResponse; | ||
import org.apache.http.client.methods.HttpUriRequest; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.feilong.json.jsonlib.JsonUtil; | ||
import com.feilong.json.jsonlib.processor.StringOverLengthJsonValueProcessor; | ||
import com.feilong.net.entity.ConnectionConfig; | ||
import com.feilong.net.entity.HttpRequest; | ||
import com.feilong.net.httpclient4.builder.HttpResponseUtil; | ||
|
||
/** | ||
* 通常用来解析接口返回的字符串 的 {@link ResultCallback}. | ||
* | ||
* @author <a href="http://feitianbenyue.iteye.com/">feilong</a> | ||
* @since 2.0.3 | ||
*/ | ||
public class ResponseBodyAsStringResultCallback implements ResultCallback<String>{ | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(ResponseBodyAsStringResultCallback.class); | ||
|
||
/** Static instance. */ | ||
// the static instance works for all types | ||
public static final ResponseBodyAsStringResultCallback INSTANCE = new ResponseBodyAsStringResultCallback(); | ||
|
||
//--------------------------------------------------------------- | ||
|
||
@Override | ||
public String on( | ||
HttpRequest httpRequest, | ||
HttpUriRequest httpUriRequest, | ||
HttpResponse httpResponse, | ||
ConnectionConfig useConnectionConfig, | ||
Date beginDate){ | ||
String resultString = HttpResponseUtil.getResultString(httpResponse); | ||
//--------------------------------------------------------------- | ||
if (LOGGER.isInfoEnabled()){ | ||
LOGGER.info( | ||
"request:[{}],useConnectionConfig:[{}],resultString:[{}]", | ||
JsonUtil.format(httpRequest), | ||
JsonUtil.format(useConnectionConfig), | ||
StringOverLengthJsonValueProcessor.format(resultString, 1000)); | ||
} | ||
return resultString; | ||
} | ||
|
||
} |
Oops, something went wrong.