|
44 | 44 |
|
45 | 45 | import java.util.*; |
46 | 46 |
|
| 47 | +import javax.annotation.Nullable; |
47 | 48 | import javax.servlet.http.HttpServletRequest; |
48 | 49 | import javax.servlet.http.HttpSession; |
49 | 50 |
|
@@ -113,10 +114,14 @@ public ModelAndView redirectRootPath(final HttpServletRequest request, |
113 | 114 | ) throws ResourceNotFoundException { |
114 | 115 | String lang = lang(langParam, langCookie, langHeader); |
115 | 116 |
|
116 | | - if (checkPortalExist(portal, !accept.startsWith(ACCEPT_VALUE))) { |
| 117 | + // Throw exception for non-HTML requests instead of redirecting if portal is not found |
| 118 | + boolean throwExceptionOnMissingPortal = accept != null && !accept.startsWith(ACCEPT_VALUE); |
| 119 | + |
| 120 | + if (checkPortalExist(portal, throwExceptionOnMissingPortal)) { |
117 | 121 | return redirectURL(createServiceUrl(request, _homeRedirectUrl, lang, portal)); |
118 | 122 | } else { |
119 | | - if (sourceRepository.findByType(SourceType.portal, null).size() == 0) { |
| 123 | + List<Source> portals = sourceRepository.findByType(SourceType.portal, null); |
| 124 | + if (portals == null || portals.isEmpty()) { |
120 | 125 | return redirectURL(createServiceUrl(request, _homeRedirectUrl, lang, NodeInfo.DEFAULT_NODE)); |
121 | 126 | } |
122 | 127 | // Redirect to list of portal page if more than one or the default if only one |
@@ -147,10 +152,14 @@ public ModelAndView redirectPortalPath(final HttpServletRequest request, |
147 | 152 | final String langHeader) throws ResourceNotFoundException { |
148 | 153 | String lang = lang(langParam, langCookie, langHeader); |
149 | 154 |
|
150 | | - if (checkPortalExist(portal, !accept.startsWith(ACCEPT_VALUE))) { |
| 155 | + // Throw exception for non-HTML requests instead of redirecting if portal is not found |
| 156 | + boolean throwExceptionOnMissingPortal = accept != null && !accept.startsWith(ACCEPT_VALUE); |
| 157 | + |
| 158 | + if (checkPortalExist(portal, throwExceptionOnMissingPortal)) { |
151 | 159 | return redirectURL(createServiceUrl(request, _homeRedirectUrl, lang, portal)); |
152 | 160 | } else { |
153 | | - if (sourceRepository.findByType(SourceType.subportal, null).size() == 0) { |
| 161 | + List<Source> subPortals = sourceRepository.findByType(SourceType.subportal, null); |
| 162 | + if (subPortals == null || subPortals.isEmpty()) { |
154 | 163 | return redirectURL(createServiceUrl(request, _homeRedirectUrl, lang, NodeInfo.DEFAULT_NODE)); |
155 | 164 | } |
156 | 165 | // Redirect to list of portal page if more than one or the default if only one |
|
0 commit comments