Before the advent of REST, we services were stateful. There were cookies sent with every HTTP request to maintain the state of the client using the services. When we use HttpURLConnection (Java) we need to discretely mention the cookies in the header and store it somewhere for maintaining the session. Below is an attempt using a singleton class for maintaining the session details and some sample HTTP methods: First our Singleton to maintain the cookies in memory between successive transactions: package singletonCookieManager; import java.net.CookieManager; /** * @author absin * */ public class EaqerInitializedCookieHelper { private static final CookieManager instance = new CookieManager(); // private constructor to avoid client applications to use constructor private EaqerInitializedCookieHelper() { } public static CookieManager getInstance() { return instance; } } Next, wherever you want to use this class initialize it as such private static jav
Comments
Post a Comment