• 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

Post to an URL using HttpURLConnection

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ranchers,

I want to post some xml content and add an attachment (may be multiple files - docs etc) to an URL. This is to test a webservice call. I am using HttpURLConnection to achieve this and wirting the file contents to the output stream. This does not work as I am getting a 500 error. Please suggest me how do I post the files as attachment as well as the xml content(mandatory post content) to the stream(Output Stream).

Regards
Shashikant
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use Apache Commons HTTP Client instead.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A 500 error is "Internal Server Error" so your code may be working but the webservice isn't.

Is this a SOAP web service you are calling? Where are you getting information on what the service wants to see?

Bill
 
Nagavarapu Shashikant
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bill,

This is not a SOAP call. The webservice is up and i want to lookup the service using java code.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What does "lookup the service" mean? Are you trying to access to service, or its WSDL, or something else?

Also, when you're posting to the service, are you certain that the XML you're sending is exactly what the service is expecting?

And finally, as Bill said a 500 signifies a server error. If available, check the server logs for any error massages.
 
Nagavarapu Shashikant
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have checked the service spec and it asks for a specific format of xml. I have prepared the xml file and reading data from it. The service just returns a service code 200 if all is fine..
 
Nagavarapu Shashikant
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The other problem i am facing is how to send attachments using the stream. I have multi pdf documents which i need to send.. please update me with any ideas.
 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Rob Prime:
Use Apache Commons HTTP Client instead.


Have you tried that one already? It's PostMethod can take call the setRequestEntity method with an instance of MultipartRequestEntity. This in turn can be created using a Part[], and guess what - there are subclasses of Part called FilePart and StringPart.
[ October 06, 2008: Message edited by: Rob Prime ]
 
Nagavarapu Shashikant
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks,

I will try this.. I was trying the attachments posting using Java mail API..
 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That doesn't make sense to me. Email is totally unrelated to HTTP(S).

Also, could you please check our naming policy?
 
No more fooling around. Read this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic