I am using Java to get the test case information. I am using the AuthenticateLoginLogoutExample
code as reference.I was able to authenticate the user but I receive the HTTP 401 status code when I use GET method to retrieve simple information like testcase information etc through REST API.
Authentication of HP ALM 12 REST API using Java
2k views Asked by user1955851 At
4
There are 4 answers
0
On
If you are using the AuthenticateLoginLogoutExample as reference it should be OK.
Possible causes of response you recieved:
- The user is not assigned to a project you're interested in;
- You have performed a logout operation;
- Not ideal cookie management. The ALM requires the session keeping on REST interoperation. It is implemented with LWSSO_COOKIE_KEY coolie in request. It is sended with response from server as resul of successful session opening. If you loose it you will be faced with such response code.
0
On
Getting HTTP 401 Status code is normal. In Fact that meas you are able to ping the server. Furthermore try to Capture the response using "{Host}/qcbin/rest/is-authenticated" using "http get" method. You will find http get methond in Rest Connector class in Documentation.
0
On
HP has their own base64encoder.java class that you need to use. You can't use the one that's standard in java. You must use their version. I was getting the same 401 error until I found their encoder class.
public class Base64Encoder {
private final static char[] ALPHABET =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".toCharArray();
private static int[] toInt = new int[128];
static {
for (int i = 0; i < ALPHABET.length; i++) {
toInt[ALPHABET[i]] = i;
}
}
/**
* Translates the specified byte array into Base64 string.
*
* @param buf the byte array (not null)
* @return the translated Base64 string (not null)
*/
public static String encode(byte[] buf) {
int size = buf.length;
char[] ar = new char[((size + 2) / 3) * 4];
int a = 0;
int i = 0;
while (i < size) {
byte b0 = buf[i++];
byte b1 = (i < size) ? buf[i++] : 0;
byte b2 = (i < size) ? buf[i++] : 0;
int mask = 0x3F;
ar[a++] = ALPHABET[(b0 >> 2) & mask];
ar[a++] = ALPHABET[((b0 << 4) | ((b1 & 0xFF) >> 4)) & mask];
ar[a++] = ALPHABET[((b1 << 2) | ((b2 & 0xFF) >> 6)) & mask];
ar[a++] = ALPHABET[b2 & mask];
}
switch (size % 3) {
case 1:
ar[--a] = '=';
case 2:
ar[--a] = '=';
}
return new String(ar);
}
}
Although correctly documented, unfortunately I was not able to deduce a running snippet of code from microfocus's instructions: https://admhelp.microfocus.com/alm/en/12.60/api_refs/REST/Content/REST_API/Authenticate_LWSSO.html#alm_authenticate_Authentication
I was not able to have my tests read or updated in qc following a migration from 11 to 12.60 and I will share how it worked for me:
So it is a simple 2 successive GETs. Think to add the signout in the end, which I am not describing here.