简体   繁体   English

org.apache.http.impl.client.DefaultRequestDirector方法executeSB(Galaxy S5)

[英]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.

相关问题 org.apache.http.impl.client.CloseableHttpClient代理验证 - org.apache.http.impl.client.CloseableHttpClient Proxy Authentication org.apache.http.client-4.3.6:java.lang.NoClassDefFoundError:org.apache.http.impl.conn.PoolingHttpClientConnectionManager - org.apache.http.client-4.3.6: java.lang.NoClassDefFoundError: org.apache.http.impl.conn.PoolingHttpClientConnectionManager 当org.apache.http.impl.client.CloseableHttpClient返回404 / NOT_FOUND时,wget返回200 / OK - wget returns 200/OK while org.apache.http.impl.client.CloseableHttpClient returns 404/NOT_FOUND Android Studio:Unirest-Java找不到类“ org.apache.http.impl.client.CloseableHttpClient” - Android Studio: Unirest-Java Could not find class 'org.apache.http.impl.client.CloseableHttpClient' 配置org.apache.http.impl.client.DefaultHttpClient使用默认的Authenticator - Configuring org.apache.http.impl.client.DefaultHttpClient to use the default Authenticator 使用org.apache.http.impl.client.ProxyClient通过代理隧道访问HTTPS Web服务 - Accessing HTTPS web services through proxy tunnel using org.apache.http.impl.client.ProxyClient java.lang.ClassNotFoundException:org.apache.http.impl.client.cache.CacheConfig - java.lang.ClassNotFoundException: org.apache.http.impl.client.cache.CacheConfig 三星 Galaxy S5 序列化异常 - Exception on serialization on Samsung Galaxy S5 我如何告诉org.apache.http.impl.client.DefaultHttpClient使用OWASP Zed攻击代理(ZAP) - How do I tell org.apache.http.impl.client.DefaultHttpClient to use the OWASP Zed Attack Proxy (ZAP) 具有PHP,MySQL的Android登录注册系统,错误为“ java.lang.NoSuchMethodError:org.apache.http.impl.client.DefaultHttpClient.execute” - Android Login Registration System with PHP, MySQL with error 'java.lang.NoSuchMethodError: org.apache.http.impl.client.DefaultHttpClient.execute'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM