Question

My JAX WS web service is deployed on weblogic server 12. Its a ear file which contains war archive. I used @Resource WebServiceContext wsContxt; to get client IP. When i deploy this WAR file on glassfish , WebServiceContext is working well. But it seems It is not functioning on weblogic. Is there anything i have missed. Please advice. Thanks in Advance, Kevin.

EDIT:-

Problem solved after i re-construct the ear file as instructed in this site enter link description here

But using WebServiceContext i can only get client IP , Username is getting null. See my code below.

MessageContext msgCtxt = wsCtxt.getMessageContext();
HttpServletRequest req = (HttpServletRequest)msgCtxt.get(MessageContext.SERVLET_REQUEST); 
String clientIP = req.getRemoteAddr(); // Working
req.getUserPrincipal().getName() // Not Working

Please advice

Was it helpful?

Solution

Somehow i manage to get userid like below.

MessageContext msgCtxt = wsCtxt.getMessageContext();
Subject subj = SubjectAccessor.getRequesterSubject(msgCtxt);
Set set = subj.getPrincipals();
Iterator i = set.iterator();
while (i.hasNext()) {
   Principal p = (Principal) i.next();
   username = p.getName();
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top