use of com.stanfy.enroscar.rest.RequestMethod in project enroscar by stanfy.
the class DirectRequestExecutor method performRequest.
@Override
public void performRequest(final RequestDescription description) {
final RequestMethod requestMethod = config.getRequestMethod(description);
// final ResponseModelConverter converter = config.getResponseModelConverter(description);
ContentAnalyzer<?, ?> analyzer = null;
final String analyzerBeanName = description.getContentAnalyzer();
if (analyzerBeanName != null) {
analyzer = BeansManager.get(context).getContainer().getBean(analyzerBeanName, ContentAnalyzer.class);
if (analyzer == null) {
throw new RuntimeException("ContentAnalyzer bean with name " + analyzerBeanName + " is not declared.");
}
}
if (Utils.isDebugRest(context)) {
Log.d(TAG, "Process request id " + description.getId());
}
hooks.beforeRequestProcessingStarted(description, requestMethod);
boolean passedToAnalyzer = false;
try {
// execute request method
final RequestResult res = requestMethod.perform(context, description);
// check for cancel
if (description.isCanceled()) {
hooks.onRequestCancel(description, null);
return;
}
// process results
ResponseData<?> response = null;
// check for cancel
if (description.isCanceled()) {
hooks.onRequestCancel(description, response);
return;
}
// analyze
passedToAnalyzer = true;
if (analyzer != null) {
response = analyze(context, analyzer, response, description);
if (response == null) {
throw new IllegalStateException("Analyzer " + analyzer + " returned null response");
}
}
// report results
if (response.isSuccessful()) {
hooks.onRequestSuccess(description, response);
} else {
Log.e(TAG, "Server error: " + response.getErrorCode() + ", " + response.getMessage());
hooks.onRequestError(description, response);
}
} catch (final Exception e) {
//RequestMethodException e) {
Log.e(TAG, "Request method error while processing " + description, e);
//converter.toResponseData(description, e);
ResponseData<?> data = null;
if (analyzer != null && !passedToAnalyzer) {
// try {
// data = analyze(context, analyzer, data, description);
// } catch (RequestMethodException analyzerException) {
// Log.e(TAG, "Analyzer exception analyzerName=" + analyzerBeanName + " for " + description, analyzerException);
// // repack data to use the current exception
// data = converter.toResponseData(description, analyzerException);
// }
}
hooks.onRequestError(description, data);
} finally {
hooks.afterRequestProcessingFinished(description, requestMethod);
}
}
use of com.stanfy.enroscar.rest.RequestMethod in project enroscar by stanfy.
the class AbstractMockServerTest method whenBeansConfigured.
@Override
protected void whenBeansConfigured() {
super.whenBeansConfigured();
BeansManager.get(getApplication()).getContainer().getBean(RemoteServerApiConfiguration.class).setDefaultRequestMethod(new RequestMethod() {
@Override
protected void before(final Context systemContext, final RequestDescription description) {
// do not use TrafficStats
}
@Override
protected void after(final Context systemContext, final RequestDescription description) {
// do not use TrafficStats
}
});
if (config == null) {
config = BeanUtils.getAnnotationFromHierarchy(getClass(), EnroscarNetConfig.class);
}
if (config != null && config.connectionEngineRequired()) {
final Config config = EnroscarConnectionsEngine.config();
configureConnectionsEngine(config);
config.treatFileScheme(false);
config.setup(Robolectric.application);
}
configureServiceBind();
}
Aggregations