Search code examples
javaweb-servicesweblogic12cstateless

WebServiceContext getting null in Stateless web service deployed on Weblogic


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


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();
    }