Developer

Supportability

The HttpConversation library supports various supportability features, such as logging and tracing.

Managing HttpConversation Library Logs

The HttpConversation library uses the Supportability library for logging and tracing. You can set the log level and the destination of the logs written by the library. The code below sets the log level to debug and directs the logs both to console and the file system:
ClientLogManager logManager = Supportability.getClientLogManager(context); 
logManager.setLogLevel(ClientLogLevel.DEBUG); 
logManager.setLogDestination( 
   EnumSet.of(ClientLogDestination.FILESYSTEM, ClientLogDestination.CONSOLE ));
The HttpConversation library logs important details of the conversation flow. We recommend that you set the log level to DEBUG and the destination to the CONSOLE during development, so you can track the processing of each request and response.

Logging Responses

The SAPLoggerUtils utility class in the com.sap.smp.client.httpc.utils package supports the interaction between the HttpConversation and the Supportability libraries by providing the logResponseDetails() method . This can be used when a response listener’s onResponseReceived() method gets called and you intend to log the response details in a uniform way. This utility ensures that sensitive information that might be included in the Authorization header of the response is obfuscated. More precisely, the value of the mentioned header is substituted with asterisks preventing the user name or password from being revealed in the logging response.

The code below uses the logResponseDetails() method when a response is received. It checks whether the DEBUG level is enabled in the logger; if it is, the code then calls the utility method that passes the event object, the logger instance, the log level, and the two Boolean flags indicating that both request and response headers are to be dumped into the log message:
public void onResponseReceived(IReceiveEvent event) throws IOException { 
   If (ClientLogLevel.DEBUG.isEnabled(myLogger.getLogLevel())) 
      SAPLoggerUtils.logResponseDetails(event, myLogger, ClientLogLevel.DEBUG, true, true); 
      … 
} 

Tracing Support

The HttpConversation library traces the requests and responses when tracing has been started by the application using the library and wants to collect data about the HTTP conversations taking place in a particular scenario. Consider that the conversation you intend to trace will likely run asynchronously in another thread although the actual case depends on the executor. We recommend that you end the trace transaction where it is guaranteed that the traced flow has reached its conclusion. The onCompletion() method of the conversion’s flow listener is a good place to end the trace transaction. This code illustrates how to achieve this:
E2ETraceManager traceManager = Supportability.getE2ETraceManager (context);
E2ETraceTransaction transaction = traceManager.startTransaction(“myTransaction”);
…
// starting a step at some point
transaction.startStep();
…
// starting conversation…
new MyManagerConfigurator.configure(new HttpConversationManager(context))
	.create(new URL("http://www.example.com"))
	.setMethod(HttpMethod.GET)
	.setResponseListener(new IResponseListener() {
		public Object onResponseReceived(IReceiveEvent event) {
			InputStream stream = event.getStream();
			stream.read(...);
			return null;
		}
})
.setFlowListener(new EmptyFlowListener() {
@Override
public void onCompletion (IOException e) {
		transaction.endTransaction();
	}
})
.start();

Log and Trace Upload

Use the HttpConversation library's SupportabilityUploaderImpl uploader to upload logs or traces from the application. This uploader uses the HTTP conversation library and can be used as the upload method of the Supportability library. To upload a log using HttpConversation library’s uploader, enter:
HttpConversationManager convMan = new HttpConversationManager(ctx);
IHttpConversation conv = convMan.create(logURL);
conv.addHeader(“<headerName>”, “<headerValue>”);
SupportabilityUploaderImpl uploader = new SupportabilityUploaderImpl(conv, ctx);
logManager.uploadClientLogs(uploader, new UploadListener() {
	public void onUploadSuccess() {
		// success case
	}
	public void onUploadFailure(UploadResult result) {
		// failure case
	}
});