Cisco Cisco Tidal Enterprise Scheduler 6.2 テクニカルリファレンス

ページ / 224
2-15
Cisco Tidal Enterprise Scheduler 6.2.1 REST API Reference Guide
6.2.1
Chapter 2      Using the TES REST API
Java Client REST API Examples
for (int
 i=0; i<10; i++)
{
URL url = 
new
 URL(
"http://www.mycompanyscheduler.com:8080/api/tes-6.2/Job.getList"
);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("
GET
");
conn.setDoInput(
true
);
conn.setDoOutput(
true
);
if
 (sessionID == 
null
)
{
  String userNamePassword = " 
myusername:mypassword 
";
  userNamePassword = 
        
new
 
String(org.apache.commons.codec.binary.Base64.encodeBase64(userNamePassword
.getBytes()));
  conn.setRequestProperty("
Authorization
", userNamePassword);
}
else
{
  conn.setRequestProperty("Cookie", sessionID);
}
conn.connect();
BufferedReader reader = 
new
 BufferedReader(
new
 InputStreamReader(
conn.getInputStream()));
String resp = "";
String next = 
null
;
while
 ((next = reader.readLine()) != 
null
)
   resp += next;
System.
out
.println(resp);
//extract cookie
String setCookies = conn.getHeaderField(
"Set-Cookie"
);
if
 (setCookies != 
null
 && sessionID == 
null
)
{
  String cookies[] = setCookies.split(";");
  
if
 (cookies.
length
 > 0)
  
sessionID = cookies[0];
}
   }
}
Code Example 4 – Execute a Query with Conditions
In Code Example 1, a 
GET request was issued to get a list of all jobs. The GET request can accept 
additional parameters such that the list of jobs returned can be filtered further.
If one needs to get a list of jobs that match a specific name pattern, the 
GET request URL can be 
constructed as follows: 
URL url = 
new
 
URL(
"http://www.mycompanyscheduler.com:8080/api/tes6.2/Job.getList?query=(Job.name LIKE 
'%name%')"
)
In this case a where clause (
Job.name LIKE '%name%'
) is sent. The 
where clause must be URL encoded. 
Similarly, other queries using other field names in the Job object can be constructed.