Another attempt to fix the redirect bug which occurs with some user agents...
git-svn-id: https://svn.libreccm.org/ccm/trunk@5095 8810af33-2d31-482b-a856-94f89814c4dfmaster
parent
2055a9f21a
commit
ae645cb299
|
|
@ -93,13 +93,15 @@ import com.arsdigita.kernel.KernelConfig;
|
||||||
public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
|
public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
|
||||||
|
|
||||||
private static final long serialVersionUID = -1495852395804455609L;
|
private static final long serialVersionUID = -1495852395804455609L;
|
||||||
private static final Logger logger = Logger.getLogger(
|
private static final Logger LOGGER = Logger.getLogger(
|
||||||
PublicPersonalProfilesServlet.class);
|
PublicPersonalProfilesServlet.class);
|
||||||
|
|
||||||
private static final String ADMIN = "admin";
|
private static final String ADMIN = "admin";
|
||||||
private static final String PREVIEW = "preview";
|
private static final String PREVIEW = "preview";
|
||||||
private static final String PPP_NS
|
private static final String PPP_NS
|
||||||
= "http://www.arsdigita.com/PublicPersonalProfile/1.0";
|
= "http://www.arsdigita.com/PublicPersonalProfile/1.0";
|
||||||
public static final String SELECTED_NAV_ITEM = "selectedNavItem";
|
public static final String SELECTED_NAV_ITEM = "selectedNavItem";
|
||||||
|
|
||||||
private final PublicPersonalProfileConfig config = PublicPersonalProfiles
|
private final PublicPersonalProfileConfig config = PublicPersonalProfiles
|
||||||
.getConfig();
|
.getConfig();
|
||||||
|
|
||||||
|
|
@ -109,15 +111,31 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
|
||||||
final Application app) throws ServletException,
|
final Application app) throws ServletException,
|
||||||
IOException {
|
IOException {
|
||||||
|
|
||||||
logger.debug("PublicPersonalProfileServlet is starting...");
|
LOGGER.debug("PublicPersonalProfileServlet is starting...");
|
||||||
logger.debug(String.format("pathInfo = '%s'", request.getPathInfo()));
|
LOGGER.debug(String.format("pathInfo = '%s'", request.getPathInfo()));
|
||||||
|
|
||||||
logger.debug("Extracting path from pathInfo by removing leading and "
|
LOGGER.debug("Extracting path from pathInfo by removing leading and "
|
||||||
+ "trailing slashes...");
|
+ "trailing slashes...");
|
||||||
|
|
||||||
if (CMSConfig.getInstanceOf().getUseLanguageExtension()) {
|
if (CMSConfig.getInstanceOf().getUseLanguageExtension()) {
|
||||||
final String pathInfo = request.getPathInfo();
|
final String pathInfo;
|
||||||
|
/*
|
||||||
|
* This is more or less a hack. For some Browsers (even the same
|
||||||
|
* version on different system behave differently) the redirected
|
||||||
|
* URL contains multiple ".." before the index part. If this the
|
||||||
|
* case we replace them...
|
||||||
|
*/
|
||||||
|
if (request.getPathInfo().contains("..")) {
|
||||||
|
LOGGER.warn(String.format("Multipe \".\" in pathInfo \"%s\"!",
|
||||||
|
request.getPathInfo()));
|
||||||
|
pathInfo = request.getPathInfo().replaceAll("\\.{2,}", ".");
|
||||||
|
} else {
|
||||||
|
pathInfo = request.getPathInfo();
|
||||||
|
}
|
||||||
|
|
||||||
if (!pathInfo.matches("(.*)/index\\.[a-zA-Z]{2}")) {
|
if (!pathInfo.matches("(.*)/index\\.[a-zA-Z]{2}")) {
|
||||||
|
LOGGER
|
||||||
|
.debug("pathInfo does not end with index part. Redirecting.");
|
||||||
String lang;
|
String lang;
|
||||||
if (GlobalizationHelper.getSelectedLocale(request) == null) {
|
if (GlobalizationHelper.getSelectedLocale(request) == null) {
|
||||||
lang = GlobalizationHelper
|
lang = GlobalizationHelper
|
||||||
|
|
@ -128,37 +146,46 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
|
||||||
.getSelectedLocale(request)
|
.getSelectedLocale(request)
|
||||||
.getLanguage();
|
.getLanguage();
|
||||||
}
|
}
|
||||||
|
LOGGER.debug(String.format("Current language is: %s",
|
||||||
|
lang));
|
||||||
|
|
||||||
final Path path = new Path(getPath(request));
|
final Path path = new Path(getPath(request));
|
||||||
final PublicPersonalProfile profile = getProfile(SessionManager.getSession(),
|
final PublicPersonalProfile profile = getProfile(
|
||||||
path.getProfileOwner(),
|
SessionManager.getSession(),
|
||||||
path.getPreview(),
|
path.getProfileOwner(),
|
||||||
lang);
|
path.getPreview(),
|
||||||
|
lang);
|
||||||
|
|
||||||
if (profile == null) {
|
if (profile == null) {
|
||||||
lang = KernelConfig.getConfig().getDefaultLanguage();
|
lang = KernelConfig.getConfig().getDefaultLanguage();
|
||||||
}
|
}
|
||||||
|
|
||||||
final StringBuffer redirectTo = new StringBuffer();
|
final StringBuffer redirectTo = new StringBuffer();
|
||||||
|
|
||||||
redirectTo
|
redirectTo
|
||||||
.append(DispatcherHelper.getRequest().getScheme())
|
.append(DispatcherHelper.getRequest().getScheme())
|
||||||
.append("://")
|
.append("://")
|
||||||
.append(DispatcherHelper.getRequest().getServerName());
|
.append(DispatcherHelper.getRequest().getServerName());
|
||||||
|
|
||||||
if (DispatcherHelper.getRequest().getServerPort() != 80
|
if (DispatcherHelper.getRequest().getServerPort() != 80
|
||||||
&& DispatcherHelper.getRequest().getServerPort() != 443) {
|
&& DispatcherHelper.getRequest().getServerPort() != 443) {
|
||||||
|
LOGGER.debug(String
|
||||||
|
.format("None standard port %d used. " + "Adding port",
|
||||||
|
DispatcherHelper.getRequest().getServerPort()));
|
||||||
redirectTo
|
redirectTo
|
||||||
.append(":")
|
.append(":")
|
||||||
.append(DispatcherHelper.getRequest().getServerPort());
|
.append(DispatcherHelper.getRequest().getServerPort());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (DispatcherHelper.getWebappContext() != null
|
if (DispatcherHelper.getWebappContext() != null
|
||||||
&& !DispatcherHelper.getWebappContext().trim().isEmpty()) {
|
&& !DispatcherHelper.getWebappContext().trim().isEmpty()) {
|
||||||
|
LOGGER.debug(String
|
||||||
|
.format("webappContext is not null. Adding "
|
||||||
|
+ "webappContext \"%s\" to redirect URL.",
|
||||||
|
DispatcherHelper.getWebappContext()));
|
||||||
redirectTo.append(DispatcherHelper.getWebappContext());
|
redirectTo.append(DispatcherHelper.getWebappContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
redirectTo
|
redirectTo
|
||||||
.append("/ccm")
|
.append("/ccm")
|
||||||
.append(app.getPath())
|
.append(app.getPath())
|
||||||
|
|
@ -170,19 +197,21 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
|
||||||
.append("index")
|
.append("index")
|
||||||
.append(".")
|
.append(".")
|
||||||
.append(lang);
|
.append(lang);
|
||||||
|
LOGGER.debug(String.format("Redirecting to \"%s\"...",
|
||||||
|
redirectTo.toString()));
|
||||||
response.setHeader("Location", redirectTo.toString());
|
response.setHeader("Location", redirectTo.toString());
|
||||||
response.sendError(HttpServletResponse.SC_MOVED_PERMANENTLY);
|
response.sendError(HttpServletResponse.SC_MOVED_PERMANENTLY);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final String pathStr = getPath(request);
|
final String pathStr = getPath(request);
|
||||||
|
|
||||||
logger.debug(String.format("path = %s", pathStr));
|
LOGGER.debug(String.format("path = %s", pathStr));
|
||||||
|
|
||||||
//Displays a text/plain page with a message.
|
//Displays a text/plain page with a message.
|
||||||
if (pathStr.isEmpty()) {
|
if (pathStr.isEmpty()) {
|
||||||
logger.debug("pathInfo is null, responding with default...");
|
LOGGER.debug("pathInfo is null, responding with default...");
|
||||||
|
|
||||||
response.setContentType("text/plain");
|
response.setContentType("text/plain");
|
||||||
response.getWriter().append("Please choose an application.");
|
response.getWriter().append("Please choose an application.");
|
||||||
|
|
@ -414,10 +443,10 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
|
||||||
IOException {
|
IOException {
|
||||||
String path = "";
|
String path = "";
|
||||||
|
|
||||||
logger.debug("PublicPersonalProfileServlet is starting...");
|
LOGGER.debug("PublicPersonalProfileServlet is starting...");
|
||||||
logger.debug(String.format("pathInfo = '%s'", request.getPathInfo()));
|
LOGGER.debug(String.format("pathInfo = '%s'", request.getPathInfo()));
|
||||||
|
|
||||||
logger.debug("Extracting path from pathInfo by removing leading and "
|
LOGGER.debug("Extracting path from pathInfo by removing leading and "
|
||||||
+ "trailing slashes...");
|
+ "trailing slashes...");
|
||||||
if (request.getPathInfo() != null) {
|
if (request.getPathInfo() != null) {
|
||||||
if ("/".equals(request.getPathInfo())) {
|
if ("/".equals(request.getPathInfo())) {
|
||||||
|
|
@ -436,11 +465,11 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug(String.format("path = %s", path));
|
LOGGER.debug(String.format("path = %s", path));
|
||||||
|
|
||||||
//Displays a text/plain page with a message.
|
//Displays a text/plain page with a message.
|
||||||
if (path.isEmpty()) {
|
if (path.isEmpty()) {
|
||||||
logger.debug("pathInfo is null, responding with default...");
|
LOGGER.debug("pathInfo is null, responding with default...");
|
||||||
|
|
||||||
response.setContentType("text/plain");
|
response.setContentType("text/plain");
|
||||||
response.getWriter().append("Please choose an application.");
|
response.getWriter().append("Please choose an application.");
|
||||||
|
|
@ -745,7 +774,7 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
|
||||||
if (item instanceof ContentPage) {
|
if (item instanceof ContentPage) {
|
||||||
ContentPage contentPage
|
ContentPage contentPage
|
||||||
= (ContentPage) item;
|
= (ContentPage) item;
|
||||||
logger.
|
LOGGER.
|
||||||
error(
|
error(
|
||||||
"contentPage.getContentBundle().hasInstance(GlobalizationHelper.getNegotiatedLocale().getLanguage()) = "
|
"contentPage.getContentBundle().hasInstance(GlobalizationHelper.getNegotiatedLocale().getLanguage()) = "
|
||||||
+ contentPage.
|
+ contentPage.
|
||||||
|
|
@ -767,7 +796,7 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
|
||||||
.getLanguage());
|
.getLanguage());
|
||||||
item = (ContentItem) contentPage;
|
item = (ContentItem) contentPage;
|
||||||
} else {
|
} else {
|
||||||
logger.error(
|
LOGGER.error(
|
||||||
String.
|
String.
|
||||||
format(
|
format(
|
||||||
"Item '%s' not found in a suitable language variant. Negotiated langauge: %s, langugage independent items allowed is %s, language independent code is %s ",
|
"Item '%s' not found in a suitable language variant. Negotiated langauge: %s, langugage independent items allowed is %s, language independent code is %s ",
|
||||||
|
|
@ -811,7 +840,7 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
|
||||||
|
|
||||||
if (item instanceof ContentPage) {
|
if (item instanceof ContentPage) {
|
||||||
ContentPage contentPage = (ContentPage) item;
|
ContentPage contentPage = (ContentPage) item;
|
||||||
logger.
|
LOGGER.
|
||||||
error(
|
error(
|
||||||
"contentPage.getContentBundle().hasInstance(GlobalizationHelper.getNegotiatedLocale().getLanguage()) = "
|
"contentPage.getContentBundle().hasInstance(GlobalizationHelper.getNegotiatedLocale().getLanguage()) = "
|
||||||
+ contentPage.getContentBundle().
|
+ contentPage.getContentBundle().
|
||||||
|
|
@ -828,7 +857,7 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
|
||||||
getLanguage());
|
getLanguage());
|
||||||
item = (ContentItem) contentPage;
|
item = (ContentItem) contentPage;
|
||||||
} else {
|
} else {
|
||||||
logger.error(
|
LOGGER.error(
|
||||||
String.
|
String.
|
||||||
format(
|
format(
|
||||||
"Item '%s' not found in a suitable language variant. Negotiated langauge: %s, langugage independent items allowed is %s, language independent code is %s ",
|
"Item '%s' not found in a suitable language variant. Negotiated langauge: %s, langugage independent items allowed is %s, language independent code is %s ",
|
||||||
|
|
@ -857,7 +886,7 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
|
||||||
"");
|
"");
|
||||||
|
|
||||||
} catch (DataObjectNotFoundException ex) {
|
} catch (DataObjectNotFoundException ex) {
|
||||||
logger.error(String.format(
|
LOGGER.error(String.format(
|
||||||
"Item '%s' not found: ",
|
"Item '%s' not found: ",
|
||||||
itemPath),
|
itemPath),
|
||||||
ex);
|
ex);
|
||||||
|
|
@ -1243,7 +1272,7 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
|
||||||
itemRoot,
|
itemRoot,
|
||||||
"");
|
"");
|
||||||
} catch (DataObjectNotFoundException ex) {
|
} catch (DataObjectNotFoundException ex) {
|
||||||
logger.error(String.format(
|
LOGGER.error(String.format(
|
||||||
"Item '%s' not found: ",
|
"Item '%s' not found: ",
|
||||||
path.getItemPath()),
|
path.getItemPath()),
|
||||||
ex);
|
ex);
|
||||||
|
|
@ -1349,6 +1378,15 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
|
||||||
if (request.getPathInfo() != null) {
|
if (request.getPathInfo() != null) {
|
||||||
|
|
||||||
String pathInfo = request.getPathInfo();
|
String pathInfo = request.getPathInfo();
|
||||||
|
if (pathInfo.contains("..")) {
|
||||||
|
/*
|
||||||
|
* This is more or less a hack. For some Browsers (even the same
|
||||||
|
* version on different system behave differently) the redirected
|
||||||
|
* URL contains multiple ".." before the index part. If this the
|
||||||
|
* case we replace them...
|
||||||
|
*/
|
||||||
|
pathInfo = pathInfo.replaceAll("\\.{2,}", ".");
|
||||||
|
}
|
||||||
if (CMSConfig.getInstanceOf().getUseLanguageExtension()
|
if (CMSConfig.getInstanceOf().getUseLanguageExtension()
|
||||||
&& pathInfo.matches("(.*)/index\\.[a-zA-Z]{2}")) {
|
&& pathInfo.matches("(.*)/index\\.[a-zA-Z]{2}")) {
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue