0

This is the second part of my question on converting cURL to Java The first part is titled:

Converting cURL authentication to Java and retrieving & updating data using REST XML (Pt.1)

Third, how can I implement update, create, and delete for the api in Java? For example:

  1. Update: curl -i -X PUT -H "Content-Type:application/xml" -H "Accept: application/xml" -d "<ticket><description>Take this description</description></ticket>" http://user:password@www.assembla.com/spaces/my_space_id/tickets/1
  2. Delete" curl -i -X DELETE -H "Accept: application/xml" http://user:password@www.assembla.com/spaces/my_space_id/tickets/1
  3. Create: curl -i -X POST -H "Content-Type:application/xml" -H "Accept: application/xml" -d "<ticket><summary>This is a Summary</summary><priority>3</priority></ticket>" the weblink

In other words, how can I convert these cURL code into Java?

I would really appreciate your help. Also, a good reference to do such stuff in Java will be awesome too.

Thanks.

mhakeem
  • 46
  • 8

2 Answers2

0

Well, the official API usually helps: Assembla REST API

There is says that you need to use basic authentication.

For accessing REST in Java: Rest clients for Java?

Community
  • 1
  • 1
Peter Knego
  • 79,991
  • 11
  • 123
  • 154
  • Thanks Peter. But my main problem is how to translate this cURL statement `curl -i -X GET -H "Accept: application/xml" http://user:password@www.assembla.com/spaces/my_space_id/tickets` into Java? – mhakeem Mar 09 '11 at 23:44
  • If you'd read the links you'd know: use Jersey client library, set it to use basic authentication and call `www.assembla.com/spaces/my_space_id/tickets` url. – Peter Knego Mar 10 '11 at 09:05
  • This link explains all the steps in one page (including Basic Authentication): http://blogs.sun.com/enterprisetechtips/entry/consuming_restful_web_services_with – Peter Knego Mar 10 '11 at 09:09
0

you should be looking out for Apache HttpClient tutorials.

There's some Samplecode of a Android Rest Client application around, try searching for it. Also, I just discovered "resting". I haven't tried it, but might be worth a look.

Also watching the Developing Android REST client applications video from Google.io is recommended, as it is teaching some very important architectural basics and hints.

I placed a similar question some time ago, and got an answer here at Stackoverflow.

Community
  • 1
  • 1
chris polzer
  • 3,219
  • 3
  • 28
  • 44
  • Thanks. I was able to authenticate successfully and retrieve (GET) data. Now I am having problem with (POST). I don't know how to invoke XML in POST. Example: curl -i -X POST -H "Content-Type:application/xml" -H "Accept: application/xml" -d "This is a Summary3" the weblink – mhakeem Mar 15 '11 at 05:36