Rest Client Logging For Androidannotations
Solution 1:
Here we see that AndroidAnnotations is a wrapper around the Spring Android RestTemplate Module. The code for the RestTemplate
is here. So we can find out which TAG is used for logging:
privatestaticfinalStringTAG="RestTemplate";
Are you not able to see log entries for this TAG? Which converter / extractor are you using? Please post the call stack.
In the wiki they recommend to use a Interceptor
for logging request / response. So you could implement your own interceptor like:
publicclassLoggingInterceptorimplementsClientHttpRequestInterceptor {
@Overridepublic ClientHttpResponse intercept(HttpRequest request, byte[] data, ClientHttpRequestExecution execution)throws IOException {
logRequest(request);
ClientHttpResponseresponse= execution.execute(request, data);
logResponse(response);
return response;
}
privatevoidlogRequest(HttpRequest request) {
// log it
}
privatevoidlogResponse(ClientHttpResponse response) {
// log it
}
}
You enable the interceptor in the @Rest
annotation (field interceptors
).
Solution 2:
While I do not use AndroidAnnotations
and cannot answer your question directly, I would like to propose an alternative solution. You could use a great little utility program called Fiddler. It can do wonders for debugging networking activity, whether it be requests, responses, HTTP headers or practically anything else that would matter in a REST API communication.
You can find a full tutorial on how to setup your environment to use Fiddler here, but to name a few crucial steps (credit goes to the linked page, you can also find helpful pictures there)
Setup Fiddler:
- Click menu Tools | Fiddler Options, then select the Connections tab
- Make note of the “Fiddler listens on” port (normally it’s 8888)
- Make sure the check box for “Allow remote computer to connect” is checked
- Switch to the HTTPS tab
- Make sure the check boxes for “Capture HTTPS Connects” and “Decrypt HTTPS traffic” are both checked
- Restart Fiddler
- Make note of the PC’s IP address Close non essential apps on the Windows PC (to minimize web traffic being routed through Fiddler)
Setup your device:
- Tap on Settings, then Wi-Fi
- Find the network on which you’re connected (normally the first one listed), then tap and hold Choose Modify network from the pop-up
- Scroll down and enable “Show advanced options”
- Change “Proxy settings” to Manual
- Under “Proxy host name” enter the Windows PC IP address from above
- Under “Proxy port” enter the Fiddler port from above (usually 8888)
- Tap Save and wait a moment for the network to reconnect
Now you will see all the needed details for your REST API calls which makes debugging much easier.
Post a Comment for "Rest Client Logging For Androidannotations"