Please disable your adblock and script blockers to view this page

Search this blog

Tuesday 17 June 2014

Detect browser & platform information (name,version), server and client IP details in Oracle ADF

Hello All,
This is post is about getting browser details (version, name ) , platform details (Operating System details) ,server and client IP addresses in Oracle ADF Application
sometimes we need these small but important details -

Code to get this information-




        RequestContext requestCtx = RequestContext.getCurrentInstance();
        Agent agent = requestCtx.getAgent();
        String version = agent.getAgentVersion();
        String browser = agent.getAgentName();
        String platform = agent.getPlatformName();
        String platformVersion = agent.getPlatformVersion();
        FacesContext fctx = FacesContext.getCurrentInstance();
        HttpServletRequest request = (HttpServletRequest) fctx.getExternalContext().getRequest();
        StringBuilder detailMsg = new StringBuilder("<html><body><b>Browser Agent and Ip address details</b><br>");
        detailMsg.append("<ul><li><b>Browser-</b>" + browser + "</li><li><b>Version-</b>" + version +
                         "</li><li><b>Plateform-</b>" + platform + "</li>");
        detailMsg.append("<li><b>Plateform Version-</b>" + platformVersion + "</li><li><b>Server IP-</b>" +
                         request.getLocalAddr() + "</li><li><b>Client IP-</b>" + request.getRemoteAddr() +
                         "</li></ul>");
        detailMsg.append("</body></html>");
        FacesMessage errMsg = new FacesMessage(detailMsg.toString());
        errMsg.setSeverity(FacesMessage.SEVERITY_INFO);
        fctx.addMessage(null, errMsg);

See the output-
Application running on Mozilla-
Application running on Chrome-
Application running on Internet Explorer-
Cheers :) Happy Learning



12 comments :

  1. Replies
    1. I have shared source code in blog itself , you can use same code in your ADF Application

      Delete
  2. how can i get current URL ??

    ReplyDelete
    Replies
    1. You can use this code to get url of current page

      //Get url of current ViewPort
      String viewId = ControllerContext.getInstance().getCurrentViewPort().getViewId();
      String viewUrl = ControllerContext.getInstance().getGlobalViewActivityURL(viewId);

      See more at: Create shortcut of page on a button click in Oracle ADF using JShortcut library (For windows)

      Delete
  3. i'm using webcenter portal. I want to popup a message for a user who is accessing my portal from specific browser version. How can i do it?

    ReplyDelete
    Replies
    1. Have you tried code mentioned in blog ?
      You can put a condition to check browswer version or name and then write logic to open popup

      Delete
    2. I know the coding part but my problem is where to try that code. I'm new to adf and webcenter portal. I have created a webcenter application in my JDeveloper. It has default login page(login.jspx). In this application where do I need to insert my code?
      Where do I need to make changes? Any components or any properties need to be added?? pls guide me.
      My Jdeveloper version is 11g release 1(11.1.1.5.0 )
      Build JDEVADF_11.1.1.5.0_GENERIC_110409.0025.6013

      Delete
    3. You can call this code on a button click or on page load for detailed answer post your question on OTN Forum

      Delete
  4. thanks a lot to share knowledge and experience :)

    ReplyDelete
  5. Can i get Major version for Chrome instead of this WEBKit 537.36?

    ReplyDelete
  6. code not working correct.. in last it shd say chrome 29 not webkit 537

    ReplyDelete