- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 Apache HttpClient 4.5.1 向我们的服务器发送一些请求。为了提高性能,我想为所有这些请求重用相同的 HttpClient 实例。请求(大部分)按顺序发生,因此不涉及多线程。
不幸的是,某些服务器端点出现故障。他们返回 HTTP 204(无内容),但响应正文中仍然有一些数据。尽管这已在最新版本中得到修复,但我们将不得不在相当长的一段时间内处理旧版本。此服务器行为导致 HTTP 客户端在下一个请求时“挂起”(/超时)(有关详细信息,请参阅 Every second request using Apache HTTPClient fails)。
有没有办法在客户端解决这个问题?我试过了
HttpEntity entity = response.getEntity();
if (null != entity) {
EntityUtils.consumeQuietly(entity);
}
但实体似乎为空,所以我无法使用卡在连接套接字中的响应数据。有没有另一种方法可以在不丢弃 HttpClient 实例(及其 HTTP 连接)的情况下清理套接字?
客户端日志如下所示:
DefaultManagedHttpClientConnection - http-outgoing-0: set socket timeout to 90000
MainClientExec - Executing request DELETE /prod/update-rest/private/deleteGroup/AS123 HTTP/1.1
MainClientExec - Target auth state: UNCHALLENGED
MainClientExec - Proxy auth state: UNCHALLENGED
headers - http-outgoing-0 >> DELETE /prod/update-rest/private/deleteGroup/AS123 HTTP/1.1
headers - http-outgoing-0 >> Host: xyz
headers - http-outgoing-0 >> Connection: Keep-Alive
headers - http-outgoing-0 >> User-Agent: Apache-HttpClient/4.5.1 (Java/1.7.0_79)
headers - http-outgoing-0 >> Accept-Encoding: gzip,deflate
wire - http-outgoing-0 >> "DELETE /prod/update-rest/private/deleteGroup/AS123 HTTP/1.1[\r][\n]"
wire - http-outgoing-0 >> "Host: xyz[\r][\n]"
wire - http-outgoing-0 >> "Connection: Keep-Alive[\r][\n]"
wire - http-outgoing-0 >> "User-Agent: Apache-HttpClient/4.5.1 (Java/1.7.0_79)[\r][\n]"
wire - http-outgoing-0 >> "Accept-Encoding: gzip,deflate[\r][\n]"
wire - http-outgoing-0 >> "[\r][\n]"
wire - http-outgoing-0 << "HTTP/1.1 401 Unauthorized[\r][\n]"
wire - http-outgoing-0 << "Date: Mon, 05 Oct 2015 13:30:35 GMT[\r][\n]"
wire - http-outgoing-0 << "Server: Apache/2.2.12 (Linux/SUSE)[\r][\n]"
wire - http-outgoing-0 << "Pragma: No-cache[\r][\n]"
wire - http-outgoing-0 << "Cache-Control: no-cache[\r][\n]"
wire - http-outgoing-0 << "Expires: Thu, 01 Jan 1970 01:00:00 CET[\r][\n]"
wire - http-outgoing-0 << "WWW-Authenticate: Basic realm="ApplicationRealm"[\r][\n]"
wire - http-outgoing-0 << "Content-Length: 958[\r][\n]"
wire - http-outgoing-0 << "Keep-Alive: timeout=15, max=100[\r][\n]"
wire - http-outgoing-0 << "Connection: Keep-Alive[\r][\n]"
wire - http-outgoing-0 << "Content-Type: text/html;charset=utf-8[\r][\n]"
wire - http-outgoing-0 << "[\r][\n]"
headers - http-outgoing-0 << HTTP/1.1 401 Unauthorized
headers - http-outgoing-0 << Date: Mon, 05 Oct 2015 13:30:35 GMT
headers - http-outgoing-0 << Server: Apache/2.2.12 (Linux/SUSE)
headers - http-outgoing-0 << Pragma: No-cache
headers - http-outgoing-0 << Cache-Control: no-cache
headers - http-outgoing-0 << Expires: Thu, 01 Jan 1970 01:00:00 CET
headers - http-outgoing-0 << WWW-Authenticate: Basic realm="ApplicationRealm"
headers - http-outgoing-0 << Content-Length: 958
headers - http-outgoing-0 << Keep-Alive: timeout=15, max=100
headers - http-outgoing-0 << Connection: Keep-Alive
headers - http-outgoing-0 << Content-Type: text/html;charset=utf-8
MainClientExec - Connection can be kept alive for 15000 MILLISECONDS
HttpAuthenticator - Authentication required
HttpAuthenticator - xyz:443 requested authentication
TargetAuthenticationStrategy - Authentication schemes in the order of preference: [Negotiate, Kerberos, NTLM, Digest, Basic]
TargetAuthenticationStrategy - Challenge for Negotiate authentication scheme not available
TargetAuthenticationStrategy - Challenge for Kerberos authentication scheme not available
TargetAuthenticationStrategy - Challenge for NTLM authentication scheme not available
TargetAuthenticationStrategy - Challenge for Digest authentication scheme not available
HttpAuthenticator - Selected authentication options: [BASIC [complete=true]]
wire - http-outgoing-0 << "<html><head><title>JBoss Web/7.0.13.Final - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 401 - </h1><HR size="1" noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b> <u></u></p><p><b>description</b> <u>This request requires HTTP authentication ().</u></p><HR size="1" noshade="noshade"><h3>JBoss Web/7.0.13.Final</h3></body></html>"
DefaultManagedHttpClientConnection - http-outgoing-0: set socket timeout to 90000
MainClientExec - Executing request DELETE /prod/update-rest/private/deleteGroup/AS123 HTTP/1.1
MainClientExec - Target auth state: CHALLENGED
HttpAuthenticator - Generating response to an authentication challenge using basic scheme
MainClientExec - Proxy auth state: UNCHALLENGED
headers - http-outgoing-0 >> DELETE /prod/update-rest/private/deleteGroup/AS123 HTTP/1.1
headers - http-outgoing-0 >> Host: xyz
headers - http-outgoing-0 >> Connection: Keep-Alive
headers - http-outgoing-0 >> User-Agent: Apache-HttpClient/4.5.1 (Java/1.7.0_79)
headers - http-outgoing-0 >> Accept-Encoding: gzip,deflate
headers - http-outgoing-0 >> Authorization: Basic dGN1YWRtaW46c3RhcnQ=
wire - http-outgoing-0 >> "DELETE /prod/update-rest/private/deleteGroup/AS123 HTTP/1.1[\r][\n]"
wire - http-outgoing-0 >> "Host: xyz[\r][\n]"
wire - http-outgoing-0 >> "Connection: Keep-Alive[\r][\n]"
wire - http-outgoing-0 >> "User-Agent: Apache-HttpClient/4.5.1 (Java/1.7.0_79)[\r][\n]"
wire - http-outgoing-0 >> "Accept-Encoding: gzip,deflate[\r][\n]"
wire - http-outgoing-0 >> "Authorization: Basic dGN1YWRtaW46c3RhcnQ=[\r][\n]"
wire - http-outgoing-0 >> "[\r][\n]"
wire - http-outgoing-0 << "HTTP/1.1 204 No Content[\r][\n]"
wire - http-outgoing-0 << "Date: Mon, 05 Oct 2015 13:30:35 GMT[\r][\n]"
wire - http-outgoing-0 << "Server: Apache/2.2.12 (Linux/SUSE)[\r][\n]"
wire - http-outgoing-0 << "Pragma: No-cache[\r][\n]"
wire - http-outgoing-0 << "Cache-Control: no-cache[\r][\n]"
wire - http-outgoing-0 << "Expires: Thu, 01 Jan 1970 01:00:00 CET[\r][\n]"
wire - http-outgoing-0 << "Content-Length: 22[\r][\n]"
wire - http-outgoing-0 << "Keep-Alive: timeout=15, max=99[\r][\n]"
wire - http-outgoing-0 << "Connection: Keep-Alive[\r][\n]"
wire - http-outgoing-0 << "Content-Type: */*[\r][\n]"
wire - http-outgoing-0 << "[\r][\n]"
headers - http-outgoing-0 << HTTP/1.1 204 No Content
headers - http-outgoing-0 << Date: Mon, 05 Oct 2015 13:30:35 GMT
headers - http-outgoing-0 << Server: Apache/2.2.12 (Linux/SUSE)
headers - http-outgoing-0 << Pragma: No-cache
headers - http-outgoing-0 << Cache-Control: no-cache
headers - http-outgoing-0 << Expires: Thu, 01 Jan 1970 01:00:00 CET
headers - http-outgoing-0 << Content-Length: 22
headers - http-outgoing-0 << Keep-Alive: timeout=15, max=99
headers - http-outgoing-0 << Connection: Keep-Alive
headers - http-outgoing-0 << Content-Type: */*
MainClientExec - Connection can be kept alive for 15000 MILLISECONDS
HttpAuthenticator - Authentication succeeded
TargetAuthenticationStrategy - Caching 'basic' auth scheme for https://xyz:443
PoolingHttpClientConnectionManager - Connection [id: 0][route: {s}->https://xyz:443] can be kept alive for 15.0 seconds
PoolingHttpClientConnectionManager - Connection released: [id: 0][route: {s}->https://xyz:443][total kept alive: 1; route allocated: 1 of 20; total allocated: 1 of 20]
RequestAddCookies - CookieSpec selected: default
RequestAuthCache - Auth cache not set in the context
PoolingHttpClientConnectionManager - Connection request: [route: {s}->https://xyz:443][total kept alive: 1; route allocated: 1 of 20; total allocated: 1 of 20]
PoolingHttpClientConnectionManager - Connection leased: [id: 0][route: {s}->https://xyz:443][total kept alive: 0; route allocated: 1 of 20; total allocated: 1 of 20]
DefaultManagedHttpClientConnection - http-outgoing-0: set socket timeout to 90000
MainClientExec - Executing request DELETE /prod/update-rest/private/deleteGroup/AS678 HTTP/1.1
MainClientExec - Target auth state: UNCHALLENGED
MainClientExec - Proxy auth state: UNCHALLENGED
headers - http-outgoing-0 >> DELETE /prod/update-rest/private/deleteGroup/AS678 HTTP/1.1
headers - http-outgoing-0 >> Host: xyz
headers - http-outgoing-0 >> Connection: Keep-Alive
headers - http-outgoing-0 >> User-Agent: Apache-HttpClient/4.5.1 (Java/1.7.0_79)
headers - http-outgoing-0 >> Accept-Encoding: gzip,deflate
wire - http-outgoing-0 >> "DELETE /prod/update-rest/private/deleteGroup/AS678 HTTP/1.1[\r][\n]"
wire - http-outgoing-0 >> "Host: xyz[\r][\n]"
wire - http-outgoing-0 >> "Connection: Keep-Alive[\r][\n]"
wire - http-outgoing-0 >> "User-Agent: Apache-HttpClient/4.5.1 (Java/1.7.0_79)[\r][\n]"
wire - http-outgoing-0 >> "Accept-Encoding: gzip,deflate[\r][\n]"
wire - http-outgoing-0 >> "[\r][\n]"
wire - http-outgoing-0 << "Group AS123 not found!"
wire - http-outgoing-0 << "HTTP/1.1 401 Unauthorized[\r][\n]"
wire - http-outgoing-0 << "Date: Mon, 05 Oct 2015 13:30:36 GMT[\r][\n]"
wire - http-outgoing-0 << "Server: Apache/2.2.12 (Linux/SUSE)[\r][\n]"
wire - http-outgoing-0 << "Pragma: No-cache[\r][\n]"
wire - http-outgoing-0 << "Cache-Control: no-cache[\r][\n]"
wire - http-outgoing-0 << "Expires: Thu, 01 Jan 1970 01:00:00 CET[\r][\n]"
wire - http-outgoing-0 << "WWW-Authenticate: Basic realm="ApplicationRealm"[\r][\n]"
wire - http-outgoing-0 << "Content-Length: 958[\r][\n]"
wire - http-outgoing-0 << "Keep-Alive: timeout=15, max=98[\r][\n]"
wire - http-outgoing-0 << "Connection: Keep-Alive[\r][\n]"
wire - http-outgoing-0 << "Content-Type: text/html;charset=utf-8[\r][\n]"
wire - http-outgoing-0 << "[\r][\n]"
DefaultHttpResponseParser - Garbage in response: Group AS123 not found!HTTP/1.1 401 Unauthorized
DefaultHttpResponseParser - Garbage in response: Date: Mon, 05 Oct 2015 13:30:36 GMT
DefaultHttpResponseParser - Garbage in response: Server: Apache/2.2.12 (Linux/SUSE)
DefaultHttpResponseParser - Garbage in response: Pragma: No-cache
最佳答案
我设法解决了我的问题:
我创建了一个 HttpRequestExecutor 的子类来覆盖 canResponseHaveBody 方法,如下所示:
protected boolean canResponseHaveBody(final HttpRequest request,
final HttpResponse response) {
if ("HEAD".equalsIgnoreCase(request.getRequestLine().getMethod())) {
return false;
}
final int status = response.getStatusLine().getStatusCode();
return status >= HttpStatus.SC_OK
// && status != HttpStatus.SC_NO_CONTENT
&& status != HttpStatus.SC_NOT_MODIFIED
&& status != HttpStatus.SC_RESET_CONTENT;
}
在使用 HttpClients.custom().setRequestExecutor() 注册后,我能够通过 response.getEntity() 检索垃圾并使用它。
之后下一个请求就像魅力一样。
关于java - 让 HttpClient 在下一次请求之前消耗 "garbage",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32943192/
想象一下,您从一种具有 GC 的语言中重复调用另一种语言(例如 Fortran 95)的函数。 Fortran 函数在调用之间的内存中留下了一些分配的东西,从调用者语言来看,这些东西可能被视为未引用的
我知道停止世界、增量、并行、并发、(软/硬)实时垃圾收集器的概念。但我无法理解大部分并发 GC。和并发GC有什么不同吗?有什么不同?为什么它被称为大部分? 最佳答案 I know concepts o
我正在浏览链接 Java - available garbage collection algorithms了解可用的 JVM 垃圾收集算法并感到困惑。 据我了解,不同的 JVM 供应商会实现一些标准
在打印 &a ( cout using namespace std; int main() { char a = 'Z'; cout<
当我在 Xcode 中“构建和分析”这段代码时,我收到一条我不理解的警告。这是有问题的方法: -(void)touchesMoved:(NSSet *)touches withEvent:(UIEve
C 编程语言有什么特点可以打破类型安全并禁止将实用的垃圾收集添加到该语言中?解释。首先,我不明白类型安全和垃圾回收之间的关系。如果有人可以帮助我,我将不胜感激。 最佳答案 您可以在C 中进行垃圾收集。
当成对实现停止和复制垃圾收集器时,我需要两个存储库(旧的和一个免费的新的)。一个存储库由汽车和CDS组成。因此,基本上,当我创建一个新地址时,它是指向thecars和the-cdrs的指针。 分配新内
我在 Ubuntu 18.04 上使用 SBCL 1.4.5。 似乎 SBCL 中的垃圾收集器没有正确释放绑定(bind)到具有符号键和值的哈希表的内存。有趣的是,当键和值是整数时,垃圾回收工作正常。
据说原子不是垃圾收集的。创建原子后,该原子将保留在原子表中,这可能最终导致内存泄漏! 我对Erlang还是很陌生,我的问题是:怎样收集垃圾中的原子?如果不可能的话,如何最大程度地减少这种影响? 最佳答
我一直在使用 Julia 对大量数据进行多线程处理,并观察到一种相互交织的模式。内存使用量(由 htop 报告)缓慢增长,直到进程被操作系统杀死。项目复杂,很难做出合适的MWE,但我做了一个简单的实验
假设堆上的一个对象超出范围。为什么程序不能在范围结束后立即释放内存?或者,如果我们有一个指向一个对象的指针,该指针被一个新对象的地址替换,为什么程序不能在分配新对象之前释放旧对象?我猜不是立即释放它而
我正在编写一个包含分代垃圾收集器的程序。只有两代。我想知道的是:在进行完整收集时,我是否通过首先收集年轻对象,将幸存者提升到老年代,然后收集老年代来获得任何东西(性能方面),或者我应该只是垃圾收集所有
如何在 WinDGB 中设置断点才能看到对 GC.Collect() 的调用?我已经尝试过 bp clr!SVR::GCHeap::GarbageCollect 但它不起作用... 我正在使用 .NE
当我开始时 jvm (jdk 8) ,我找到了这个 cms gc 日志。它显示老年代使用 0K (0K(1747648K)),但 jvm 执行 cms collect 。为什么 ? 2019-01-3
我需要你的帮助来调查 Erlang 内存消耗问题。多么典型,不是吗? 我们有两种不同的部署方案。 在第一个方案中,我们在小型虚拟机(在 Amazon AWS 中)上运行许多相同的节点,每台机器一个节点
所以我尝试通过在Windows上运行这个程序来测试D垃圾收集器是否正常工作。 DMD 2.057 和 2.058 beta 都给出相同的结果,无论我是否指定 -release 、 -inline 、
如果我有 8GB RAM 并且我在 64 位 JVM 上使用以下内容 最大堆大小 6144MB 最大 perm gen 空间 2048MB 堆栈大小 2MB Q1 : perm gen空间是从max
移动垃圾收集器(例如分代收集器)会产生额外的生成代码,以跨GC安全点存储和重新加载引用。有没有人比不动的收集器量化这种开销的性能成本? 我之所以这样问,是因为我有兴趣设计一个收集器,该收集器可以有效地
关闭。这个问题需要更多focused .它目前不接受答案。 想改善这个问题吗?更新问题,使其仅关注一个问题 editing this post . 6年前关闭。 Improve this questi
在复制垃圾收集器中,当我将对象从源空间复制到目标空间时,某些对象可能会被存储在寄存器中的指针引用。当垃圾收集发生时,该寄存器需要更新以指向目标空间。 问题是,垃圾收集是在程序的特定点执行的(比方说当用
我是一名优秀的程序员,十分优秀!