Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 105
Registered: ‎07-24-2008
My Device: Not Specified

REST web services

Hi,

           Has anyone consumded REST webservices from Blackberry JDE  ?

Regards,

Developer
Developer
Posts: 283
Registered: ‎07-22-2008
My Device: Not Specified

Re: REST web services

Hi Abhijit

 

Did you find anything?

I may need to work with REST webservices in the near future.

Usually the payload may use a Jason format.

Wouldn't be just a matter of receiving the payload and parse it etc ...

 

Rab

Developer
Posts: 105
Registered: ‎07-24-2008
My Device: Not Specified

Re: REST web services

Not yet. But please see the following url......let me know when you get some more info please

http://tinyurl.com/q4g5za

Regards,

Abhijit Chandekar

Developer
Posts: 105
Registered: ‎07-24-2008
My Device: Not Specified

Re: REST web services

Hi,

     Is it possible to use Jersey client API to consume Restful web services from Blackberry ?

 

http://java.sun.com/developer/technicalArticles/WebServices/restful/

 

Please see the above URL. 

 

 

Regards,

Abhijit Chandekar

New Developer
Posts: 3
Registered: ‎11-09-2009
My Device: Not Specified

Re: REST web services

Hi,

Did you find anything about ?

Highlighted
Developer
Posts: 166
Registered: ‎01-14-2009
My Device: Curve 8330

Re: REST web services

Hello,

I consumed REST services with my last five applications. I've done it manually with a generic code that open a HTTP Connection. I use URLEncodedPostData to encode the URL and parameters. Then I parse the response with a SAX Default Handler that return a MultiMap <name, value> of the parsed XML documents.

 

I can't give you code snippet as I developed it for work, but I can help you doing something similar.

Thank you, have a nice day.

--
Samuel D.
New Developer
Posts: 3
Registered: ‎11-09-2009
My Device: Not Specified

Re: REST web services

Well I just checked the class URLEncodedPostData but it doesnt help you if you want to use a PUT Method on it.

Since I want my application to access a REST Service, I am looking for apis that allow me to send a PUT Method on a given URL and allow me to send a long string (which could be a XML parsed or a JSON string).

Do you have any ideas about it or could you point me out to some apis I can use ..

I was trying the following:

 

StreamConnection s = (StreamConnection)Connector.open(url);
HttpConnection httpConn = (HttpConnection)s;

httpConn.setRequestMethod("PUT");
httpConn.setRequestProperty("Content-Type", "application/json");

 

But then using that.. how do i send my long JSON string as an Entity to the Rest Service ?, any ideas?

 

Regards

Developer
Posts: 106
Registered: ‎06-18-2009
My Device: Bold

Re: REST web services

Hi, I was just looking at the post on Friday and saw your reply today.  I would think that it should work, given that 'PUT' is possible and doesnt throw an exception, just like a POST. 

 

here is the sample snippet from the HTTPConnection javadoc:

 

            c = (HttpConnection)Connector.open(url);

            // Set the request method and headers
            c.setRequestMethod(HttpConnection.POST);
            c.setRequestProperty("If-Modified-Since",
                "29 Oct 1999 19:43:31 GMT");
            c.setRequestProperty("User-Agent",
                "Profile/MIDP-2.0 Configuration/CLDC-1.0");
            c.setRequestProperty("Content-Language", "en-US");

            // Getting the output stream may flush the headers
            os = c.openOutputStream();
            os.write("LIST games\n".getBytes());
            os.flush();           // Optional, getResponseCode will flush

            // Getting the response code will open the connection,
            // send the request, and read the HTTP response headers.
            // The headers are stored until requested.
            rc = c.getResponseCode();
            if (rc != HttpConnection.HTTP_OK) {
                throw new IOException("HTTP response code: " + rc);
            }

 

 

I am gonna test this out as I need the same functionality for an app and will post back later.

 

Thorben

----
If this helped you, press the thumbs up button (on the far right - '+' thumb icon)
If this post solved the issue, click "Accept as Solution"
Developer
Posts: 106
Registered: ‎06-18-2009
My Device: Bold

Re: REST web services

So, yea I think that it's not a problem using other request methods such as PUT and DELETE.

 

I tested it with the 4.5 as well as 5.0 OS and works on both.  In the 5.0 API, it actually says:

----

Set the method for the URL request, one of:

  • GET
  • POST
  • HEAD
  • PUT
  • DELETE
  • CONNECT
  • TRACE
  • OPTIONS

are legal, subject to protocol restrictions. The default method is GET.

----

Any other JavaDoc for less than 5.0 doesnt list PUT or DELETE but it still compiles and also can make the PUT request sucessfully. 

 

I believe that SamuelD was only using the URLEncodedPostData only to actually encode the data that needs to go to as the request content.  This makes sense to fix up spaces and such when it is processed as a request string. I dont know if it is really required for data that is formatted using JSON. I included a space in my content that I was sending to the server and it seems to work just fine.

 

I'll have to do more testing but I was fooled by the API and believed that HTTPConnection only supported GET, POST and HEAD.

 

mmosa, if you still got trouble getting it to work, post your errors.

 

Thorben

----
If this helped you, press the thumbs up button (on the far right - '+' thumb icon)
If this post solved the issue, click "Accept as Solution"
Trusted Contributor
Posts: 200
Registered: ‎02-22-2010
My Device: BlackBerry 9550
My Carrier: Airtel

Re: REST web services

hi Samuel,

              is there any api or 3rd party library required to consume the RESTful webservices? can u provide any docs or link for the same.

Swapnil G.