Forum Discussion

sirba01's avatar
sirba01
Occasional Contributor
15 years ago

Getting and using Jsession ID for my WebService Authenticati

Hi All,

i have a webservice which needs to use the Jsession ID to invoke the operations, i was using the following in JAVA client to get the Jsession ID

String loginPage = "http://" + host+ ":" + port + "/test/service//app/j_acegi_security_check";

PostMethod postMethod = new PostMethod(loginPage);

NameValuePair _username = new NameValuePair("j_username", "admin");
NameValuePair _password = new NameValuePair("j_password", "admin1");
// Add parameters to post
postMethod.addParameter(_username);
postMethod.addParameter(_password);
// Execute method.
client.executeMethod(postMethod);

String redirectLocation = postMethod.getResponseHeader("location").getValue();
String LOGIN_ERROR = "login_error";
// Check whether login failed?
if(redirectLocation.indexOf(LOGIN_ERROR) > -1){
System.out.println("Invalid credentials. Please check the username and password.");
System.exit(-1);
}
String jsessionid = "";
// Get jsessionid from the response
if(redirectLocation.indexOf('=') > 1){
jsessionid = redirectLocation.substring(redirectLocation.indexOf('=') + 1,
redirectLocation.length());
System.out.println("JSession ID: " + jsessionid);
}else{
System.out.println("JSessionID missing.");
System.exit(-1);
}

Is there a way i can do this from UI? i need to get the session ID and need to use that for every webservice request like below

cdo = new ConfigurationDataOutServiceSoapBindingStub(coURL, coWS);
cdo._setProperty(javax.xml.rpc.Stub.SESSION_MAINTAIN_PROPERTY, Boolean.TRUE);
cdo._setProperty(HTTPConstants.HEADER_COOKIE,"JSESSIONID=" + jsessionid);

i am new to SOAP UI, sorry if it is dump question.

Thanks,
Balaji
No RepliesBe the first to reply