@SuppressWarnings({ "rawtypes", "unchecked" })
protected void sendRequest(final RequestBuilder requestBuilder, final String body,
final ResponseDemarshallingCallback demarshallingCallback) {
final RemoteCallback remoteCallback = getRemoteCallback();
try {
// Allow overriding of request body in client-side interceptors
String requestBody =
(requestBuilder.getRequestData() != null) ? requestBuilder.getRequestData() : body;
requestBuilder.sendRequest(requestBody, new RequestCallback() {
@Override
public void onError(Request request, Throwable throwable) {
handleError(throwable, request, 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 {
Throwable throwable = null;
ErrorCallback<?> errorCallback = getErrorCallback();