Open GoogleCodeExporter opened 9 years ago
Original comment by Mansur...@gmail.com
on 11 Jul 2012 at 7:49
Sample Code :
private static String url =
"http://www.decodethis.com/Default.aspx?tabId=65&vin={0}";
// new method
try {
// Create an HTTP client and set up simple parameters
HttpClient client = new HttpClient();
client.getParams().setCookiePolicy(CookiePolicy.NETSCAPE);
client.getParams().setConnectionManagerTimeout(10000);
client.getParams().setSoTimeout(ASYNC_WAIT_PERIOD);
String formattedUrl = MessageFormat.format(url, "2HNYD28219H518968");
HttpMethod method = new GetMethod(formattedUrl);
int htmlStatus = 0;
String htmlResult = "";
try {
System.out.println("BatchProcessor calling '" + formattedUrl + "'.");
htmlStatus = client.executeMethod(method);
} catch (java.net.SocketTimeoutException ste) {
// This is ok... we are just timing out
if (isAsync) {
System.out.println("... Back to BatchProcessor - Exiting because of ASYNC
mode.");
}
} catch (ConnectException ce) {
System.out.println("Error: Could not connect to Faces page.");
throw new Exception("Could not connect to faces page: " + url);
} catch (Exception e) {
// Not so good. throw this guy
throw e;
}
// Let go of the connection. Otherwise, it just holds on forever.
htmlResult = method.getResponseBodyAsString();
method.releaseConnection();
Pattern pattern = Pattern.compile("Year</td><td>\\d{4}\\s*</td>");
Matcher matcher = pattern.matcher(htmlResult);
while(matcher.find()) {
System.out.println(htmlResult.substring(matcher.start(), matcher.end()));
}
client = null;
if (htmlStatus > 200) {
System.out.println("Error in HTML: " + htmlResult);
result = false;
} else {
if (isAsync) {
result = true;
}
}
System.out.println("BatchProcessor control returned. Result of batch: " +
htmlResult);
System.out.println("Batch task '" + report + "' completed with status Success
");
} catch (Exception e) {
System.out.println("Error: " + e.getMessage());
e.printStackTrace();
}
Original comment by Mansur...@gmail.com
on 11 Jul 2012 at 9:17
Original comment by Mansur...@gmail.com
on 22 Jan 2013 at 7:15
Original issue reported on code.google.com by
Mansur...@gmail.com
on 11 Jul 2012 at 6:43