@Override
public Response fetchData(String url, Method method) {
try {
URL aUrl = new URL(url);
HTTPMethod httpMethod = HTTPMethod.GET;
switch (method) {
case POST:
httpMethod = HTTPMethod.POST;
break;
}
HTTPRequest httpRequest = new HTTPRequest(aUrl, httpMethod,
doNotValidateCertificate().setDeadline(10d));
URLFetchService service = URLFetchServiceFactory
.getURLFetchService();
HTTPResponse response = service.fetch(httpRequest);
return new Response(new String(response.getContent(), "UTF-8"),
response.getResponseCode(), "");
} catch (MalformedURLException e) {
return new Response("", 400, "Malformed URL: " + url);
} catch (IOException e) {
return new Response("", 500, e.getMessage());
}
}