Changeset 6890 for ComponentRegistry/branches
- Timestamp:
- 01/08/16 09:12:35 (9 years ago)
- Location:
- ComponentRegistry/branches/ComponentRegistry-2.0/ComponentRegistry/src/main
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
ComponentRegistry/branches/ComponentRegistry-2.0/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rest/ComponentRegistryRestService.java
r6887 r6890 1615 1615 1616 1616 /** 1617 * 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 1627 * "http://catalog.clarin.eu/ds/ComponentRegistry". <em>Be aware that this 1628 * can also be null if configured incorrectly!</em> 1617 * 1618 * @see ComponentRegistryRestService#getApplicationBaseURI(javax.servlet.ServletContext, javax.servlet.http.HttpServletRequest) 1629 1619 */ 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"); 1620 private String getApplicationBaseURI() { 1621 return getApplicationBaseURI(servletContext, request); 1656 1622 } 1657 1623 … … 2025 1991 } 2026 1992 1993 /** 1994 * 1995 * @return The application's base URI as defined by the following context 1996 * parameters: 1997 * 1998 * {@link APPLICATION_URL_BASE_PARAM}, 1999 * {@link APPLICATION_URL_PATH_PARAM}, 2000 * {@link APPLICATION_URL_PROTOCOL_HEADER_PARAM}, and 2001 * {@link APPLICATION_URL_HOST_HEADER_PARAM} 2002 * 2003 * If correctly configured, it should look something like 2004 * "http://catalog.clarin.eu/ds/ComponentRegistry". <em>Be aware that this 2005 * can also be null if configured incorrectly!</em> 2006 */ 2007 public static String getApplicationBaseURI(ServletContext servletContext, HttpServletRequest request) { 2008 final String path = servletContext.getInitParameter(APPLICATION_URL_PATH_PARAM); 2009 if (path != null) { 2010 final String protocolHeader = servletContext.getInitParameter(APPLICATION_URL_PROTOCOL_HEADER_PARAM); 2011 final String hostHeader = servletContext.getInitParameter(APPLICATION_URL_HOST_HEADER_PARAM); 2012 if (protocolHeader != null && hostHeader != null) { 2013 2014 return String.format("%s://%s%s", 2015 request.getHeader(protocolHeader), 2016 request.getHeader(hostHeader), 2017 request.getHeader(path) 2018 ); 2019 } else { 2020 final String base = servletContext.getInitParameter(APPLICATION_URL_BASE_PARAM); 2021 return base + path; 2022 } 2023 } 2024 LOG.error("Application URI could not be determined. Information available:\n" 2025 + " {}: {}\n {}: {}\n {}: {}\n {}: {}", 2026 APPLICATION_URL_PATH_PARAM, servletContext.getInitParameter(APPLICATION_URL_PATH_PARAM), 2027 APPLICATION_URL_BASE_PARAM, servletContext.getInitParameter(APPLICATION_URL_BASE_PARAM), 2028 APPLICATION_URL_PROTOCOL_HEADER_PARAM, servletContext.getInitParameter(APPLICATION_URL_PROTOCOL_HEADER_PARAM), 2029 APPLICATION_URL_HOST_HEADER_PARAM, servletContext.getInitParameter(APPLICATION_URL_HOST_HEADER_PARAM) 2030 ); 2031 throw new RuntimeException("Cannot determine application path"); 2032 } 2033 2027 2034 } -
ComponentRegistry/branches/ComponentRegistry-2.0/ComponentRegistry/src/main/webapp/compRegConfig.jsp
r6885 r6890 1 1 <%-- Configuration hosted next to the front end index page, from which it is loaded --%> 2 2 <%@ page import="java.net.URI" %> 3 <%@ page import="clarin.cmdi.componentregistry.rest.ComponentRegistryRestService" %> 3 4 <% 4 5 final String loglevelParam = request.getParameter("loglevel"); … … 9 10 loglevel = "info" ; 10 11 } 12 13 final String appUrl = ComponentRegistryRestService.getApplicationBaseURI(getServletContext(), request); 11 14 %> 12 15 { … … 14 17 "cors": false, 15 18 "REST": { 16 "url": "<%= app lication.getInitParameter("eu.clarin.cmdi.componentregistry.serviceRootUrl")%>"19 "url": "<%= appUrl %>" 17 20 }, 18 21 "backEndVersion": "${project.version}", … … 20 23 "deploy": { 21 24 "path": "<%= 22 URI.create(application.getInitParameter("eu.clarin.cmdi.componentregistry.serviceRootUrl")) 23 .getPath() //at same URL as app, so simply take path 25 URI.create(appUrl).getPath() //at same URL as app, so simply take path 24 26 %>" 25 27 }
Note: See TracChangeset
for help on using the changeset viewer.