Quantcast
Channel: Quality Center / ALM Practitioners Forum topics
Viewing all articles
Browse latest Browse all 5491

Authorization problem via ALM API in java 401 Unauthorized

$
0
0

Hello,

I'm having this problem to Authorized my app via java,

I'm using QC 11, rest API, java(1.7) and windows 64 bit.

My code is looking like that :

 

Java Code

 

CookieManager cm = new CookieManager();

URL url = new URL("http://"+ALMServer+"/qcbin/rest/is-authenticated");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Accept", "application/json");
conn.connect();

conn.getResponseCode();

 

url = new URL("http://"+ALMServer+"/qcbin/authentication-point/login.jsp?redirect url=http://"+ALMServer+"/qcbin/start_a.jsp");//myUiResource.jsp" );
conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Accept", "application/json");

cm.setCookies(conn);
if(conn.getResponseMessage()!=null) {
    System.out.println(conn.getResponseMessage());
    System.out.println(conn.getResponseCode());
    System.out.println(conn.getHeaderFields());
}

 

url = new URL("http://"+ALMServer+"/qcbin/rest/domains/"+DOMAIN_NAME+"/projects/"+PROJECT_NAME+"/defects");//myUiResource.jsp" );
conn = (HttpURLConnection) url.openConnection();
cm.setCookies(conn);
conn.setRequestMethod("GET");
conn.setRequestProperty("Accept", "application/xml");
conn.setRequestProperty("Content-Type", "application/xml");
if(conn.getResponseMessage()!=null) {
    System.out.println(conn.getResponseMessage());
    System.out.println(conn.getResponseCode());
    System.out.println(conn.getHeaderFields());
}

 

 

url = new URL("http://"+ALMServer+"/qcbin/authentication-point/authenticate");
conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");

conn.setRequestProperty("Authorization", USER+" "+PASSWORD);

cm.setCookies(conn);
System.out.println(conn.getResponseMessage());
System.out.println(conn.getResponseCode());
System.out.println(conn.getHeaderFields());

 

 

this is the output :

 

OK
200
{null=[HTTP/1.1 200 OK], Date=[Mon, 01 Jul 2013 12:53:25 GMT], Content-Length=[7227], Content-Type=[text/html;charset=ISO-8859-1], X-Powered-By=[Servlet 2.5; JBoss-5.0/JBossWeb-2.1], Server=[Apache-Coyote/1.1]}
Unauthorized
401
{null=[HTTP/1.1 401 Unauthorized], WWW-Authenticate=[LWSSO realm="http://qc11:8080/qcbin/authentication-point"], Date=[Mon, 01 Jul 2013 12:53:25 GMT], Content-Length=[1319], Content-Type=[text/html;charset=utf-8], X-Powered-By=[Servlet 2.5; JBoss-5.0/JBossWeb-2.1], Server=[Apache-Coyote/1.1]}
This is the important answer!!!
Unauthorized
401
{null=[HTTP/1.1 401 Unauthorized], WWW-Authenticate=[Basic realm="Please enter your ALM user credentials"], Date=[Mon, 01 Jul 2013 12:53:25 GMT], Content-Length=[1133], Content-Type=[text/html;charset=utf-8], X-Powered-By=[Servlet 2.5; JBoss-5.0/JBossWeb-2.1], Server=[Apache-Coyote/1.1]}

 

 

Why am I still  : 401 Unauthorized

Thanks,

Or


Viewing all articles
Browse latest Browse all 5491

Trending Articles