Check a thread in the Wonder mailing list on July 28, Ted Archibald posted this 
solution to consume REST services:

public static Job fetchJob(String jobNumber){
    Job job = null;
    DefaultHttpClient httpclient = new DefaultHttpClient();
    try {
        HttpHost target = new HttpHost("server.com", 443, "https");
        HttpGet req = new HttpGet("/jobs/" + jobNumber + ".json?key=12345");
        HttpResponse rsp = httpclient.execute(target, req);
        HttpEntity entity = rsp.getEntity();
        String resultString = EntityUtils.toString(entity);
        
        ERXJSONRestParser parser = new ERXJSONRestParser();
        
        ERXStringRestRequest request = new ERXStringRestRequest(resultString);
        
        ERXRestRequestNode requestNode = parser.parseRestRequest(request, null, 
null);
        
        NSDictionary dict = (NSDictionary) requestNode.toNSCollection(null);
        job = new Job(dict);
        job.setJob(jobNumber);
        
    } 
    catch (IOException e1) {
      e1.printStackTrace();
    }
    finally {
        httpclient.getConnectionManager().shutdown();
    }
    return job;
  }

I'm using something similar (for GET and POST requests) in another app. You can 
also look at the RestRouteExample in Wonder, it have a RestClient in there.

> There are lots of packages on this web site which package(s) would you 
> recommend?
> 
> 
> On 2011-08-19, at 12:29 AM, George Domurot wrote:
> 
>> Hi Calven,
>> 
>> If you have a hook to pull down a JSON object, use a package to process this 
>> data into the appropriate object/array:
>> 
>>      http://json.org/
>> 
>> Then, you can easily parse the data and push it into your database.
>> 
>> -G
>> 
>> 
>> On Aug 18, 2011, at 1:06 PM, Calven Eggert wrote:
>> 
>>> Hi, All
>>> 
>>> I'm to write a java app to read data from a url that is JSON encoded.  I'll 
>>> then parse the data and create records in an Oracle database using WO.
>>> 
>>> I've read that there are two ways of doing this, using either the AJAX or 
>>> ERREST framework.
>>> 
>>> I've managed to get this call working via AJAX but I don't know what to do 
>>> next:
>>>     String baseURL = 
>>> "http://allanl-dev.uhnres.utoronto.ca/capcr/capcr/public/service.php/greenlight_list/";;
>>>     Client client = JavaJSONClient.create(baseURL, false);
>>> 
>>> Is this the best approach?  Does someone have an example I can take a look 
>>> at?  (The JSON example in AJAX doesn't seem to help me out)
>>> 
>>> 
>>> Calven
>>> _______________________________________________
>>> Do not post admin requests to the list. They will be ignored.
>>> Webobjects-dev mailing list      ([email protected])
>>> Help/Unsubscribe/Update your Subscription:
>>> http://lists.apple.com/mailman/options/webobjects-dev/george%40boxofficetickets.com
>>> 
>>> This email sent to [email protected]
>> 
>> 
>> 
> 
> 
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Webobjects-dev mailing list      ([email protected])
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/webobjects-dev/probert%40macti.ca
> 
> This email sent to [email protected]

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to