• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

old DefaultHttpClient v CloseableHttpClient

 
Ranch Hand
Posts: 105
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Thanks in advance for any help or advice.

I had a file upload application (from a java swing front-end to a tomcat servlet) - all worked fine. I started the project again (after a break) and found that API’s have been deprecated, and it no longer works. Im not sure where to begin to start getting it working again (what new API's to use).

When it was working the main constructs I had were (client-side):

Below was within my “UploadTask” (extends SwingWorker), in the doInBackground() method:



I have attempted to refactor using CloseableHttpClient, but im not getting very far, and it seems to be stopping when I attempt:



Im not sure how much i need to rewrite / replace.

Any help is much appreciated.

Regards, Sam
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

sam wootton wrote:I had a file upload application (from a java swing front-end to a tomcat servlet) - all worked fine. I started the project again (after a break) and found that API’s have been deprecated, and it no longer works.


That seems odd. Deprecation shouldn't stop a class/method from working; you might just get compiler warnings when you try to update them. Are you sure you've got all the stuff you need (ie, jars, etc) in the CLASSPATH? That might have changed if you're on a new version.

Winston
 
sam wootton
Ranch Hand
Posts: 105
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Winston ,

Thanks for your response.



"BEFORE" will get output to the terminal, but "AFTER" will not. No errors, or warnings or exceptions.

I am using "httpclient-4.0-alpha1.jar", which is what I used when it was working. Literally, nothing else changed.

Regards, Sam

 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

sam wootton wrote:"BEFORE" will get output to the terminal, but "AFTER" will not. No errors, or warnings or exceptions.
I am using "httpclient-4.0-alpha1.jar", which is what I used when it was working. Literally, nothing else changed.


Another possibility: What do you mean by a "terminal"? Are you running an IDE and using its CONSOLE? That might have a bearing - but exactly what I don't know; I do know that an IDE console is NOT the same thing as System.out though.

If the answer to the above question is "yes", then maybe you should try running it from the command line.

Winston
 
sam wootton
Ranch Hand
Posts: 105
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Its same thing; console/terminal etc.

I just cant seem to instantiate any http client without it failing silently, does matte what i try:



or (i know its deprecated, but there doesnt seem to be much out there to help with replacing existing code with the new API).



With httpclient-4.0-alpha1.jar. I'd like to find a recourse that can clearly state what I need, and what changes required to use new API.

But first off, why can't I even instantiate an HTTP Client?

Regards, Sam
 
sam wootton
Ranch Hand
Posts: 105
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I simplify down to basics and just run:



I get...



Looks like it can't find the class?

Regards, Sam
 
sam wootton
Ranch Hand
Posts: 105
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And



Regards, Sam
 
sam wootton
Ranch Hand
Posts: 105
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think it could be dependencies

http://hc.apache.org/httpcomponents-client-4.3.x/httpclient/dependencies.html

Will give it a go and report back.

Regards, Sam
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

sam wootton wrote:Its same thing; console/terminal etc.


Maybe for you, but THEY are NOT.

My suggestion: run this from the command line, and keep doing so until you can get it to work. IDEs hide an awful lot of stuff, including (possibly) messages that you should know about. Once you can run it from the command line, you'll KNOW that you can run it from anywhere; but not otherwise.

Winston
 
sam wootton
Ranch Hand
Posts: 105
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Using the new

httpcomponents-client-4.3.3\lib

that contains:

commons-codec-1.6
commons-logging-1.1.3
httpclient-4.3.3
httpcore-4.3.2

.. seems to have allowed me to progress - got a few other errors, but hopefully unrelated.

Many thanks.

Regards, Sam
 
reply
    Bookmark Topic Watch Topic
  • New Topic