Hello All:

I am hoping that somebody with more experience will that a look at this
issue.

I have been tasked with retrieving data from a source using REST.  
When I do the initial request I get back the first "page" of data and the
root
element of this XML tells me how many pages there are in total I.e.
<documents current-page="1" total-page-count="98" total-record-count="9729">

This allows me to set up a loop to fetch the remaining pages with code that
looks 
something that looks like this:

   //Do the initial request 
   cr = new ClientResource( strReq );
   ChallengeScheme scheme = ChallengeScheme.HTTP_BASIC;   
   ChallengeResponse authentication = new ChallengeResponse(scheme, strUser,
strPWord );     
   cr.setChallengeResponse(authentication);
                                 
   // Get the response
   represent = cr.get(MediaType.TEXT_XML);
   qqXML = represent.getText();
   Status status = cr.getStatus();
   if (status != null) {
        System.out.println(status.toString());
   }

   // Now a bit of code to create a DOM and interrogate the root element
   // This will give us the page count (total_page_count )
   
   for(int p=2; p<= total_page_count; p++){
        
      System.out.println( strReq +"?page=" + new  Integer(p).toString() ); 
      cr = new ClientResource( strReq +"?page=" + new  Integer(p).toString()
); 
      cr.setChallengeResponse(authentication);
      // Get the response
      represent = cr.get(MediaType.TEXT_XML);
      qqXML = represent.getText();
      if (qqXML != null) {
            System.out.println("XML has been returned");
      }
                
     // Get the Status
     status = cr.getStatus();
     if (status != null) {
         System.out.println(status.toString());
     }
     
     System.out.println("** ** ** ** ** ** ** ** ** \n");
                        
                        
                        
  }   //for  total page count 
                   

So I have code that will get the job done, maybe not pretty, but it works.
The process takes over eight minutes.  Seems like a long time to me.
And raises a couple of questions.

On the console I see messages (see below) regarding
org.restlet.engine.http.connector.HttpClientHelper 
starting and stopping. Is there a way reuse the underlying HttpClient or
does a new one have to be
created for each ClientResource?

Should I release the Represent  and  ClientResource after each request?
Or in short am I doing this right?

Thanks in advance for your assistance.

KD



https://qqq-test.databridge.com/api/v1/documents.xml?page=5
May 17, 2011 11:57:16 AM org.restlet.engine.http.connector.HttpClientHelper
start
INFO: Starting the default HTTP client
XML has been returned
OK (200) - OK
** ** ** ** ** ** ** ** ** 

https://qqq-test.databridge.com/api/v1/documents.xml?page=6
May 17, 2011 11:57:21 AM org.restlet.engine.http.connector.HttpClientHelper
start
INFO: Starting the default HTTP client
XML has been returned
OK (200) - OK
** ** ** ** ** ** ** ** ** 

https://qqq-test.databridge.com/api/v1/documents.xml?page=7
May 17, 2011 11:57:26 AM org.restlet.engine.http.connector.HttpClientHelper
start
INFO: Starting the default HTTP client
May 17, 2011 11:57:26 AM org.restlet.engine.http.connector.HttpClientHelper
stop
INFO: Stopping the default HTTP client
May 17, 2011 11:57:26 AM org.restlet.engine.http.connector.HttpClientHelper
stop
INFO: Stopping the default HTTP client
May 17, 2011 11:57:26 AM org.restlet.engine.http.connector.HttpClientHelper
stop
INFO: Stopping the default HTTP client
May 17, 2011 11:57:26 AM org.restlet.engine.http.connector.HttpClientHelper
stop
INFO: Stopping the default HTTP client
XML has been returned
OK (200) - OK
** ** ** ** ** ** ** ** ** 


--
View this message in context: 
http://restlet-discuss.1400322.n2.nabble.com/Restlet-2-0-multiple-get-requests-tp6369368p6373701.html
Sent from the Restlet Discuss mailing list archive at Nabble.com.

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2739361

Reply via email to