@SuppressWarnings({ "rawtypes", "unchecked" })
protected void sendRequest(final RequestBuilder requestBuilder, final String body,
final ResponseDemarshallingCallback demarshallingCallback) {
final RemoteCallback remoteCallback = getRemoteCallback();
try {
requestBuilder.sendRequest(body, new RequestCallback() {
@Override
public void onError(Request request, Throwable throwable) {
handleError(throwable, null);
}
@Override
public void onResponseReceived(Request request, Response response) {
int statusCode = response.getStatusCode();
if ((successCodes == null || successCodes.contains(statusCode)) && (statusCode >= 200 && statusCode < 300)) {
if (remoteCallback instanceof ResponseCallback) {
((ResponseCallback) getRemoteCallback()).callback(response);
}
else if (response.getStatusCode() == 204) {
remoteCallback.callback(null);
}
else {
remoteCallback.callback(demarshallingCallback.demarshallResponse(response.getText()));
}
}
else {
ResponseException throwable = new ResponseException(response.getStatusText(), response);
handleError(throwable, response);