HTTP API deprected warnings UTF_8, Scheme, ThreadS

2019-04-30 20:20发布

问题:

I'm new java. I created a java project to call my webservice(Servlet,Tomcat6.0).
To use http i had added the following jar files
1. httpclient-4.2.1
2. httpcore-4.2.1

For methods(In Bold) below i'm getting type deprecated warnings and not able to run the project.

HTTP.**UTF_8**
aSchemeRegistryL.register(new **Scheme**("http", PlainSocketFactory.getSocketFactory(), 80));
ClientConnectionManager ccm = new **ThreadSafeClientConnManager**(aHttpParamsL, aSchemeRegistryL);    

Help me to rectify it.

回答1:

Most of the time - check your java docs - they'll suggest an alternative class. See: ThreadSafeClientManager

And it will suggest instead of ThreadSafeClientManager use: PoolingClientConnectionManager

PoolingClientConnectionManager

As for the Scheme class, if you look at the javadocs, the class itself isn't deprecated, but the constructor you are using is: Scheme



回答2:

For HTTP.UTF_8 the alternative is Consts.UTF_8. It's weird they don't mention that in the docs...



回答3:

ThreadSafeClientConnManager class is deprecated, use PoolingClientConnectionManager and the constructor for Scheme you are using is deprecated too, use the other constructor found in that class.

As for the deprecated warnings, check that in Eclipse (I'm assuming you're using Eclipse, otherwise check for similar options in your IDE) that under Preferences->Java->Compiler->Errors/Warnings you don't have "Deprecated API" set to "Error" status.



标签: java http