[英]org.apache.http.impl.client.DefaultRequestDirector method executeSB (Galaxy S5)
I'm overriding DefaultHttpClient, and pass my Cache mechanism as a RequestInterceptor and ResponseInterceptor 我重写DefaultHttpClient,并通过Cache机制作为RequestInterceptor和ResponseInterceptor
new DefaultHttpClient(new ThreadSafeClientConnManager(params, schemeRegistry), params) {
@Override
protected HttpRequestExecutor createRequestExecutor(){
return cache == null ? super.createRequestExecutor() : cache.createRequestExecutor();
}
@Override
protected BasicHttpProcessor createHttpProcessor() {
BasicHttpProcessor processor = super.createHttpProcessor();
if(null != cache){
processor.addRequestInterceptor(cache);
processor.addResponseInterceptor(cache);
}
return processor;
}
@Override
protected HttpContext createHttpContext() {
// Same as DefaultHttpClient.createHttpContext() minus the
// cookie store.
HttpContext context = new BasicHttpContext();
context.setAttribute(
ClientContext.AUTHSCHEME_REGISTRY,
getAuthSchemes());
context.setAttribute(
ClientContext.COOKIESPEC_REGISTRY,
getCookieSpecs());
context.setAttribute(
ClientContext.CREDS_PROVIDER,
getCredentialsProvider());
return context;
}
};
}
Then I process Response: 然后我处理响应:
private void processResponse(String requestLine, CachedItem item, HttpResponse response, HttpContext context){
... some code
switch(response.getStatusLine().getStatusCode()){
case HttpStatus.SC_NOT_MODIFIED:
Log.v(TAG, "processResponse, not modified");
updateResponseWithCachedFile(response);
break;
case HttpStatus.SC_OK:
Log.v(TAG, "processResponse, updating cache");
saveEntity(response);
break;
}
...some code
}
public synchronized void updateResponseWithCachedFile(HttpResponse response){
response.setStatusCode(HttpStatus.SC_OK);
response.setEntity(new FileEntity(new File(mCachedFilePath), "" /* it is internal, not used */));
}
public synchronized void saveEntity(final HttpResponse response){
try{
File cacheFile = new File(mCachedFilePath);
Utils.delete(TAG + " removing obsolete file", cacheFile);
if(Logger.assertIfFalse(cacheFile.createNewFile(), TAG, "failed to create file " + cacheFile)){
Files.copy(new InputSupplier<InputStream>() {
@Override
public InputStream getInput() throws IOException{
return response.getEntity().getContent();
}
}, cacheFile);
}
}catch (FileNotFoundException e){
e.printStackTrace();
}catch (IOException e){
e.printStackTrace();
}
updateResponseWithCachedFile(response);
}
My problem is on the Galaxy s5. 我的问题是在Galaxy S5上。 I get an Exception:
我得到一个例外:
07-29 21:00:57.227 28164 29824 W System.err: java.lang.ClassCastException: org.apache.http.entity.FileEntity cannot be cast to org.apache.http.entity.BasicHttpEntity 07-29 21:00:57.227 28164 29824 W System.err: at org.apache.http.impl.client.DefaultRequestDirector.executeSB(DefaultRequestDirector.java:880) 07-29 21:00:57.227 28164 29824 W System.err: at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:675) 07-29 21:00:57.227 28164 29824 W System.err: at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:567) 07-29 21:00:57.227 28164 29824 W System.err: at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:491) 07-29 21:00:57.227 28164 29824 W System.err: at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:469) 07-29 21:00:57.227 28164 29824 W System.err: at com.my_application.service.background.HttpRequest$1.run(HttpRequest.java:138) 07-29 21:00:57.227 28164 29824
07-29 21:00:57.227 28164 29824 W System.err:java.lang.ClassCastException:org.apache.http.entity.FileEntity无法转换为org.apache.http.entity.BasicHttpEntity 07-29 21:00: 57.227 28164 29824 W System.err:at org.apache.http.impl.client.DefaultRequestDirector.executeSB(DefaultRequestDirector.java:880)07-29 21:00:57.227 28164 29824 W System.err:at org.apache.http .impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:675)07-29 21:00:57.227 28164 29824 W System.err:at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:567 )07-29 21:00:57.227 28164 29824 W系统。错误:位于org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:491)07-29 21:00:57.227 28164 29824 W系统。错误:在org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:469)07-29 21:00:57.227 28164 29824 W系统错误:在com.my_application.service.background.HttpRequest $ 1。运行(HttpRequest.java:138)07-29 21:00:57.227 28164 29824 W System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 07-29 21:00:57.227 28164 29824 W System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 07-29 21:00:57.227 28164 29824 W System.err: at java.lang.Thread.run(Thread.java:841)
W System.err:at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)07-29 21:00:57.227 28164 29824 W System.err:at java.util.concurrent.ThreadPoolExecutor $ Worker.run( ThreadPoolExecutor.java:587)07-29 21:00:57.227 28164 29824 W System.err:at java.lang.Thread.run(Thread.java:841)
and here i see a method: org.apache.http.impl.client.DefaultRequestDirector.executeSB(DefaultRequestDirector.java:880) 在这里我看到一个方法:org.apache.http.impl.client.DefaultRequestDirector.executeSB(DefaultRequestDirector.java:880)
I didn't found anything about this. 我什么都没找到。 Maybe Samsung has it's own implementations of this classes?
也许三星有自己的此类实现? I Don't have S5 to run this on the device.
我没有S5在设备上运行它。 Why do I get this error?
为什么会出现此错误? Thanks
谢谢
I am not sure if this will help you and I doubt you are still looking for help after all this time but maybe someone else will find this useful. 我不确定这是否会对您有所帮助,并且我怀疑您在这段时间过后仍在寻求帮助,但是也许其他人会觉得有用。 I have found that Apache HTTP does not seem to be very reliable on S5's specifically Verizon S5's.
我发现Apache HTTP在S5特别是Verizon S5上似乎不太可靠。 I encountered this problem while trying to use Restlet clients on an Android application to connect to a JSON server.
尝试在Android应用程序上使用Restlet客户端连接到JSON服务器时遇到此问题。 I continually would receive a connection error to the local host as odd as that was since I was attempting to connect to a remote server.
自从我尝试连接到远程服务器以来,我不断收到与本地主机的连接错误,异常奇怪。
A long process of trial and error led me to believe that Samsung is overriding or providing their own implementation of Apache HTTP at a low level as using the Restlet internal connector and providing no other changes resolves the issue. 漫长的试验和错误过程使我相信,由于使用Restlet内部连接器,而没有提供其他更改来解决此问题,三星将在较低级别上覆盖或提供其自己的Apache HTTP实现。 It appears to be tied into some software update because a factory reset will allow Apache HTTP to work for a short amount of time before stop working again.
它似乎与某些软件更新有关,因为恢复出厂设置将使Apache HTTP在短时间内工作,然后再停止工作。 It would be interesting to see if anyone else encounters this issue.
看看是否还有其他人遇到此问题会很有趣。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.