Highlighted
New Member.
815 views

How to maintain session with hpsm rest service

How to reuse  the session id to sub sequent requests obtained from the first url connection of rest service in java.

I have tried it with HttpUrlConnection api in java i amgetting only jsession id in cookie(No other cookies are avaible in header). This is tested with Test Hpsm Server.

              URL url = new URL("http://Server/SM/9/rest/interactions_SYNTBOTS/incident_id);
                con = (HttpURLConnection) (url.openConnection()); 
              String authString = new StringBuffer(username).append(":")
                        .append(password).toString();
                byte[] authEncBytes = Base64.encodeBase64(authString.getBytes());
                
                con.setConnectTimeout(40000);
                con.setReadTimeout(40000);
                con.setRequestMethod("GET");
                con.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows 2000)");
                con.setFollowRedirects(true);
                con.setDoOutput(true);
                con.setDoInput(true);
                con.setUseCaches(false);
                con.setAllowUserInteraction(false);
                con.setRequestProperty("Content-Type", "application/json");
                con.setRequestProperty("Authorization", "Basic "+ new String(authEncBytes));
                String cookieId = con.getHeaderField("Set-Cookie"); // here i am getting (JSESSIONID=********, path = /sm )           

and then i am trying ti reuse cookieId as following

   urlConn = (HttpURLConnection) (new URL("<HPSM Reset Service URl>).openConnection());
                urlConn.setRequestMethod("GET");
                urlConn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows 2000)");
                urlConn.setFollowRedirects(true);
                urlConn.setDoOutput(true);
                urlConn.setDoInput(true);
                urlConn.setUseCaches(false);
                urlConn.setAllowUserInteraction(false);
                urlConn.setRequestProperty("Content-Type", "application/json");
                urlConn.setRequestProperty("Content-Language", "en-US");
                urlConn.setRequestProperty("Cookie", cookie);

But unfortunately i am getting unauthorised error. can any one help me on this to achieve session reuse.

0 Likes
1 Reply
Highlighted
New Member.

Re: How to maintain session with hpsm rest service

Hi can any one help on this, i am verifying follwoing tutorial to handle max sessions exceed.

https://ernestodisanto.files.wordpress.com/2015/09/hpsm-9-40-web-services-guide.pdf

I have twenty session, But when i try to access rest service with 21 theads it is giving unauthorised error for single thread, it is giving response for other twenty thread. i need some urgetn help on this. how to maintain sessions with hpsm rest service.

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.