Changeset 6887 for ComponentRegistry


Ignore:
Timestamp:
01/08/16 08:27:10 (8 years ago)
Author:
Twan Goosen
Message:

New context parameters and method for determining public application URL
refs #844

Location:
ComponentRegistry/branches/ComponentRegistry-2.0/ComponentRegistry
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • ComponentRegistry/branches/ComponentRegistry-2.0/ComponentRegistry/pom.xml

    r6886 r6887  
    2424        <!-- Properties to configure ComponentRegistry override on commandline
    2525        with -D or change here -->
    26         <serviceRootUrl>http://localhost:8080/${project.artifactId}</serviceRootUrl>
     26        <serviceUrlBase>http://localhost:8080</serviceUrlBase>
     27        <serviceUrlPath>/${project.artifactId}</serviceUrlPath>
    2728        <!-- Will be inserted in context.xml -->
    2829        <webXmlPath>src/main/webapp/WEB-INF/web-test.xml</webXmlPath>
     
    345346                <logging.level>debug</logging.level>
    346347                <logging.appender>CONSOLE</logging.appender>
    347                 <serviceRootUrl>http://localhost:8080/ComponentRegistry</serviceRootUrl>
     348                <serviceUrlBase>http://localhost:8080</serviceUrlBase>
     349                <serviceUrlPath>/ComponentRegistry</serviceUrlPath>
    348350                <!-- Will be inserted in context.xml -->
    349351                <shibLI>http://lux16.mpi.nl/Shibboleth.sso/Login</shibLI>
     
    358360            <id>lux16</id>
    359361            <properties>
    360                 <serviceRootUrl>http://lux16.mpi.nl/ds/ComponentRegistry</serviceRootUrl>
     362                <serviceUrlBase>http://lux16.mpi.nl</serviceUrlBase>
     363                <serviceUrlPath>/ds/ComponentRegistry</serviceUrlPath>
    361364                <!-- Will be inserted in context.xml -->
    362365                <shibLI>https://lux16.mpi.nl/Shibboleth.sso/Login</shibLI>
     
    372375            <properties>
    373376                <logging.level>warn</logging.level>
    374                 <serviceRootUrl>http://catalog.clarin.eu/ds/ComponentRegistry</serviceRootUrl>
     377                <serviceRootUrl></serviceRootUrl>
     378                <serviceUrlBase>http://catalog.clarin.eu</serviceUrlBase>
     379                <serviceUrlPath>/ds/ComponentRegistry</serviceUrlPath>
    375380                <!-- Will be inserted in context.xml -->
    376381                <shibLI>https://catalog.clarin.eu/Shibboleth.sso/Login</shibLI>
  • ComponentRegistry/branches/ComponentRegistry-2.0/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rest/ComponentRegistryRestService.java

    r5973 r6887  
    16161616    /**
    16171617     *
    1618      * @return The application's base URI as configured in the
    1619      * {@link #APPLICATION_BASE_URL_PARAM} context parameter. If correctly
    1620      * configured, it should look something like
     1618     * @return The application's base URI as defined by the following context
     1619     * parameters:
     1620     *
     1621     * {@link APPLICATION_URL_BASE_PARAM},
     1622     *     {@link APPLICATION_URL_PATH_PARAM},
     1623     *     {@link APPLICATION_URL_PROTOCOL_HEADER_PARAM}, and
     1624     * {@link APPLICATION_URL_HOST_HEADER_PARAM}
     1625     *
     1626     * If correctly configured, it should look something like
    16211627     * "http://catalog.clarin.eu/ds/ComponentRegistry". <em>Be aware that this
    16221628     * can also be null if configured incorrectly!</em>
    1623      *
    1624      * @see #APPLICATION_BASE_URL_PARAM
    16251629     */
    1626     private String getApplicationBaseURI() {
    1627         return servletContext.getInitParameter(APPLICATION_BASE_URL_PARAM);
     1630    private synchronized String getApplicationBaseURI() {
     1631        //TODO: Move logic to separate class so that it can also be used in the conig.jsp
     1632        final String path = servletContext.getInitParameter(APPLICATION_URL_PATH_PARAM);
     1633        if (path != null) {
     1634            final String protocolHeader = servletContext.getInitParameter(APPLICATION_URL_PROTOCOL_HEADER_PARAM);
     1635            final String hostHeader = servletContext.getInitParameter(APPLICATION_URL_HOST_HEADER_PARAM);
     1636            if (protocolHeader != null && hostHeader != null) {
     1637
     1638                return String.format("%s://%s%s",
     1639                        request.getHeader(protocolHeader),
     1640                        request.getHeader(hostHeader),
     1641                        request.getHeader(path)
     1642                );
     1643            } else {
     1644                final String base = servletContext.getInitParameter(APPLICATION_URL_BASE_PARAM);
     1645                return base + path;
     1646            }
     1647        }
     1648        LOG.error("Application URI could not be determined. Information available:\n"
     1649                + " {}: {}\n {}: {}\n {}: {}\n {}: {}",
     1650                APPLICATION_URL_PATH_PARAM, servletContext.getInitParameter(APPLICATION_URL_PATH_PARAM),
     1651                APPLICATION_URL_BASE_PARAM, servletContext.getInitParameter(APPLICATION_URL_BASE_PARAM),
     1652                APPLICATION_URL_PROTOCOL_HEADER_PARAM, servletContext.getInitParameter(APPLICATION_URL_PROTOCOL_HEADER_PARAM),
     1653                APPLICATION_URL_HOST_HEADER_PARAM, servletContext.getInitParameter(APPLICATION_URL_HOST_HEADER_PARAM)
     1654        );
     1655        throw new RuntimeException("Cannot determine application path");
    16281656    }
    16291657
     
    19962024        }
    19972025    }
    1998    
     2026
    19992027}
  • ComponentRegistry/branches/ComponentRegistry-2.0/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rest/IComponentRegistryRestService.java

    r5832 r6887  
    3838public interface IComponentRegistryRestService {
    3939
    40     public static final String APPLICATION_BASE_URL_PARAM = "eu.clarin.cmdi.componentregistry.serviceRootUrl";
     40    public static final String APPLICATION_URL_BASE_PARAM = "eu.clarin.cmdi.componentregistry.serviceUrlBase";
     41    public static final String APPLICATION_URL_PATH_PARAM = "eu.clarin.cmdi.componentregistry.serviceUrlPath";
     42    public static final String APPLICATION_URL_PROTOCOL_HEADER_PARAM = "eu.clarin.cmdi.componentregistry.serviceUrlProtocolHeader";
     43    public static final String APPLICATION_URL_HOST_HEADER_PARAM = "eu.clarin.cmdi.componentregistry.serviceUrlHostHeader";
    4144    public static final String DATA_FORM_FIELD = "data";
    4245    public static final String NAME_FORM_FIELD = "name";
  • ComponentRegistry/branches/ComponentRegistry-2.0/ComponentRegistry/src/main/webapp/META-INF/context.xml

    r6871 r6887  
    4141        the '/rest/registry' part will be added by the application.
    4242    -->
    43   <Parameter name="eu.clarin.cmdi.componentregistry.serviceRootUrl" value="${serviceRootUrl}"/>
     43  <Parameter name="eu.clarin.cmdi.componentregistry.serviceUrlBase" value="${serviceUrlBase}"/>
     44  <Parameter name="eu.clarin.cmdi.componentregistry.serviceUrlPath" value="${serviceUrlPath}"/>
     45
     46 <!--
     47  <Parameter name="eu.clarin.cmdi.componentregistry.serviceUrlProtocolHeader" value="${serviceUrlProtocolHeader}"/>
     48  <Parameter name="eu.clarin.cmdi.componentregistry.serviceUrlHostHeader" value="${serviceUrlHostHeader}"/>
     49 -->
     50 
    4451  <!--
    4552        Location that gets redirected to from /documentation.jsp, which in turn is linked to
Note: See TracChangeset for help on using the changeset viewer.