Skip to main content

Retrofit to query Gerrit

In this tutorial, we are going to look into the use of the Retrofit library to handle the JSON response of changes in the code after querying Gerrit.
It is a free, web-based team code collaboration tool. Software developers in a team can review each other's modifications on their source code using a browser and approve or reject those changes. It is built on top of the Git version control system.

Code in Action

Hence, without further ado, let's get our hands dirty with some code.
  1. Create a maven project with the appropriate archetype.
  2. Add the following dependencies in the parent pom.xml file.
  3. Create the model class for our JSON response
  4. Now, we need to create the REST API exposed via an interface.
  5. To call the API and handle the response, we need to create a controller.
  6. Finally, create the main class to run the application
Thus, when we run the application, parsed JSON output will be shown in the console.

Conclusion

In this post, we looked into the HTTP call using the retrofit library. You can find the complete code on GitHub. I hope you enjoyed this post. Happy Coding!! 😊

Comments

  1. You have a real ability to write a content that is helpful for us. Thank you for your efforts in sharing such blogs to us.home energy efficiency consultant

    ReplyDelete
  2. Thanks for publishing such great information. You are doing such a great job. This information is very helpful for everyone. Keep it up. Thanks. Read more info about Professional Services Support For Architect

    ReplyDelete
  3. This is important information which is shared by you. This info is meaningful and important for everyone to increase our knowledge about it. Always keep sharing this kind of information. Thank you. Read more info about Retrofit Project Management Service In Ireland

    ReplyDelete

Post a Comment

Popular posts from this blog

Parsing XML using Retrofit

Developing our own type-safe HTTP library to interface with a REST API can be a real pain as we have to handle many aspects - making connections caching retrying failed requests threading response parsing error handling, and more.  Retrofit, on the other hand, is a well-planned, documented and tested library that will save you a lot of precious time and headaches. In this tutorial, we are going to discuss how we can parse the XML response returned from  https://timesofindia.indiatimes.com/rssfeedstopstories.cms  using the Retrofit library. To work with Retrofit, we need three classes -  Model class to map the JSON data Interfaces which defines the possible HTTP operations Retrofit.Builder class - Instance which uses the interface and the Builder API which allows defining the URL endpoint for the HTTP operation. Every method of the above interface represents on possible API call. The request type is specified by using appropriate annotations (GET, POST). The respon

Threads in Java - CountDownLatch (Part 12)

A CountDownLatch is a synchronizer which allows one thread to wait for one or more threads before starts processing. A good application of  CountDownLatch is in Java server-side applications where a thread cannot start execution before all the required services are started. Working A  CountDownLatch is initialized with a given count which is the number of threads it should wait for. This count is decremented by calling countDown() method by the threads once they are finished execution. As soon as the count reaches to zero, the waiting task starts running. Code Example Let us say we require three services, LoginService, DatabaseService and CloudService to be started and ready before the application can start handling requests. Output Cloud Service is up! Login Service is up! Database Service is up! All services are up. Now the waiting thread can start execution. Here, we can see that the main thread is waiting for all the three services to start before starting its own

Threads in Java - Masterclass (Part 0)

Threads in Java Multithreading is a way to introduce concurrency in a program. In any case, if there are parallel paths in our program (parts which do not depend on the result from another part), we can make use of multithreading. One should exploit this feature, especially with all these multiple core machines nowadays. Below are a few reasons why we should use multithreading - 1. Keep a process responsive There was once a time when you would print a document in MS Word and the application would freeze for an annoyingly long amount of time until the job finished. Eventually, Microsoft solved this problem by running a printing job parallel to the main thread/ GUI thread.  To be clear though, not only GUI apps but Network services have to keep an ear to the ground for new clients, dropped connections and cancellation requests. In either case, it is critical to do the heavy lifting on a secondary thread to keep the user satisfied. 2. Keep a processor busy Keeping a proc