Get the FromHeader
and then extract the information you need from it. For instance, if the extension is the user part of the URI:
FromHeader fromHeader = (FromHeader) req.getHeader("From");
Address fromAddress = fromHeader.getAddress();
URI fromURI = fromAddress.getURI();
if (fromURI.isSipURI()) {
SipURI fromSipURI = (SipURI) fromURI;
extension = fromSipURI.getUser();
}