protected HttpRequestBase createAndPrepareHttpMethod(String uri, IRemoteCall call, IRemoteCallable callable) throws RestException {
HttpRequestBase httpMethod = null;
IRemoteCallableRequestType requestType = callable.getRequestType();
if (requestType == null)
throw new RestException("Request type for call cannot be null"); //$NON-NLS-1$
try {
if (requestType instanceof HttpGetRequestType) {
httpMethod = prepareGetMethod(uri, call, callable);
} else if (requestType instanceof HttpPostRequestType) {
httpMethod = preparePostMethod(uri, call, callable);
} else if (requestType instanceof HttpPutRequestType) {
httpMethod = preparePutMethod(uri, call, callable);
} else if (requestType instanceof HttpDeleteRequestType) {
httpMethod = prepareDeleteMethod(uri, call, callable);
} else {
throw new RestException("HTTP method " + requestType + " not supported"); //$NON-NLS-1$ //$NON-NLS-2$
}
} catch (NotSerializableException e) {
String message = "Could not serialize parameters for uri=" + uri + " call=" + call + " callable=" + callable; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
logException(message, e);
throw new RestException(message);
} catch (UnsupportedEncodingException e) {
String message = "Could not serialize parameters for uri=" + uri + " call=" + call + " callable=" + callable; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
logException(message, e);
throw new RestException(message);
}
// add additional request headers
addRequestHeaders(httpMethod, call, callable);
// handle authentication
setupAuthenticaton(httpClient, httpMethod);