Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    DynamicDSGenerator: getServerName()

    Hi Isomorphic,

    can you please help me with this.

    Is it possible to get "server name" inside of DynamicDSGenerator constructor in case when dsRequest is null?
    Code:
            DynamicDSGenerator aggTableGenerator = new DynamicDSGenerator() {
                @Override
                public DataSource getDataSource(String id, DSRequest dsRequest) {
                    DataSource ds = null;
                    try {
                    String serverName = null;
                    if (dsRequest != null && dsRequest.getHttpServletRequest() != null)
                        serverName=dsRequest.getHttpServletRequest().getServerName();
                    else
                        // need some other way
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
                    return ds;
                }
            };
    Best regards
    Pavo
    Last edited by pavo123; 24 Oct 2018, 03:55.

    #2
    If there is no request that means the DS is being used in a static context so no httpServletRequest is available.

    However if server name doesn’t change in your deployment, you can simply store it statically and access it statically.

    Comment


      #3
      The server name changes, that's the biggest problem.
      With "server name" criteria I fetch data from DB and depending on that data modify datasources.
      Now I have that data in customer ".properties" file, but we have to get rid of all customer ".properties" files because of many reasons.

      If ServletContext is always available
      Code:
      ServletContext servletContext = getServletContext();
      so why not to have server name always available?

      This is very important to me, every help is welcome.
      Last edited by pavo123; 25 Oct 2018, 03:55.

      Comment


        #4
        That’s what we told you to do. As long as the serverName doesn’t change *per-request* you can access it statically.

        Comment

        Working...
        X