Created
October 22, 2015 09:24
-
-
Save senneco/da19dc7ea6da6d6ae6b3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RestAdapter restAdapter = RestApi.init(this, sCurrentUrl); | |
final ServiceApi serverApi = restAdapter.create(ServiceApi.class); | |
mServiceApi = (ServiceApi) Proxy.newProxyInstance(ServiceApi.class.getClassLoader(), new Class<?>[]{ServiceApi.class}, | |
new InvocationHandler() | |
{ | |
@Override | |
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable | |
{ | |
final Method serviceApiMethod = serviceApi.getClass().getMethod(method.getName(), method.getParameterTypes()); | |
final Object result = serviceApiMethod.invoke(serviceApi, args); | |
Exception exception = null; | |
if (result instanceof IServiceResponseData) | |
{ | |
final IServiceResponseData responseData = (IServiceResponseData) result; | |
final ResponseHeader responseHeader = responseData.getHeader(); | |
if (responseHeader.getStatusCode() != ResponseCode.Success) | |
{ | |
if (responseHeader.getStatusCode() == ResponseCode.SystemOffline) | |
{ | |
throw RetrofitError.unexpectedError(null, new SystemOfflineException(responseHeader.getStatusCode(), "Sorry, System is offline. Try again later.")); | |
} | |
throw RetrofitError.unexpectedError(null, new ServerCodeException(responseHeader.getStatusCode(), "Sorry, some problem occur. Please, try again later")); | |
} | |
if (responseData instanceof ICustomerRequest) | |
{ | |
//TODO process result | |
final CustomerActionResult customerActionResult = ((ICustomerRequest) responseData).getResult(); | |
if (customerActionResult != CustomerActionResult.Success) | |
{ | |
throw RetrofitError.unexpectedError(null, new CustomerActionException(customerActionResult, responseData)); | |
} | |
} | |
} | |
return result; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment