URL u;
try {
u = new URL(url);
} catch (MalformedURLException ex) {
throw new HttpException("malformedURI", ex);
}
try {
if (AsynchronousRestClientSun.proxy != null) {
http = (HttpURLConnection) u.openConnection(AsynchronousRestClientSun.proxy);
} else {
http = (HttpURLConnection) u.openConnection();
}
http.addRequestProperty("Content-type", contentType);
if (authorizationValue != null) {
http.addRequestProperty("Authorization", AsynchronousRestClientSun.authorizationValue);
}
http.setRequestMethod(method.toString());
http.setDoInput(true);
switch (method) {
case PUT:
case POST:
http.setDoOutput(true);
/* if there is something to put in the requestBody*/
if (requestBody != null && requestBody.length() >= 0) {
DataOutputStream wr = new DataOutputStream(http.getOutputStream());
wr.writeBytes(requestBody);
wr.flush();
wr.close();
}
break;
}
response = FileUtils.readInputStream(http.getInputStream());
//handling the callback
callCallback(callback, httpCode, response);
} catch (IOException ex) {
ex.printStackTrace();
throw new HttpException(ex.getMessage(), ex);
} finally {
clean();
}
}
};