mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
use protocol from the publicUrl when rendering urls
This commit is contained in:
@@ -1,14 +1,17 @@
|
|||||||
package com.commafeed.frontend;
|
package com.commafeed.frontend;
|
||||||
|
|
||||||
import javax.enterprise.inject.spi.BeanManager;
|
import javax.enterprise.inject.spi.BeanManager;
|
||||||
|
import javax.inject.Inject;
|
||||||
import javax.naming.InitialContext;
|
import javax.naming.InitialContext;
|
||||||
import javax.naming.NamingException;
|
import javax.naming.NamingException;
|
||||||
import javax.servlet.http.Cookie;
|
import javax.servlet.http.Cookie;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.wicket.Application;
|
import org.apache.wicket.Application;
|
||||||
import org.apache.wicket.Component;
|
import org.apache.wicket.Component;
|
||||||
|
import org.apache.wicket.IRequestCycleProvider;
|
||||||
import org.apache.wicket.Page;
|
import org.apache.wicket.Page;
|
||||||
import org.apache.wicket.RuntimeConfigurationType;
|
import org.apache.wicket.RuntimeConfigurationType;
|
||||||
import org.apache.wicket.Session;
|
import org.apache.wicket.Session;
|
||||||
@@ -20,6 +23,7 @@ import org.apache.wicket.authroles.authentication.AbstractAuthenticatedWebSessio
|
|||||||
import org.apache.wicket.authroles.authentication.AuthenticatedWebApplication;
|
import org.apache.wicket.authroles.authentication.AuthenticatedWebApplication;
|
||||||
import org.apache.wicket.authroles.authorization.strategies.role.Roles;
|
import org.apache.wicket.authroles.authorization.strategies.role.Roles;
|
||||||
import org.apache.wicket.cdi.CdiConfiguration;
|
import org.apache.wicket.cdi.CdiConfiguration;
|
||||||
|
import org.apache.wicket.cdi.CdiContainer;
|
||||||
import org.apache.wicket.cdi.ConversationPropagation;
|
import org.apache.wicket.cdi.ConversationPropagation;
|
||||||
import org.apache.wicket.core.request.handler.PageProvider;
|
import org.apache.wicket.core.request.handler.PageProvider;
|
||||||
import org.apache.wicket.core.request.handler.RenderPageRequestHandler;
|
import org.apache.wicket.core.request.handler.RenderPageRequestHandler;
|
||||||
@@ -32,12 +36,15 @@ import org.apache.wicket.request.IRequestHandler;
|
|||||||
import org.apache.wicket.request.Request;
|
import org.apache.wicket.request.Request;
|
||||||
import org.apache.wicket.request.Response;
|
import org.apache.wicket.request.Response;
|
||||||
import org.apache.wicket.request.Url;
|
import org.apache.wicket.request.Url;
|
||||||
|
import org.apache.wicket.request.UrlRenderer;
|
||||||
import org.apache.wicket.request.component.IRequestableComponent;
|
import org.apache.wicket.request.component.IRequestableComponent;
|
||||||
import org.apache.wicket.request.cycle.AbstractRequestCycleListener;
|
import org.apache.wicket.request.cycle.AbstractRequestCycleListener;
|
||||||
import org.apache.wicket.request.cycle.RequestCycle;
|
import org.apache.wicket.request.cycle.RequestCycle;
|
||||||
|
import org.apache.wicket.request.cycle.RequestCycleContext;
|
||||||
import org.apache.wicket.util.cookies.CookieUtils;
|
import org.apache.wicket.util.cookies.CookieUtils;
|
||||||
|
|
||||||
import com.commafeed.backend.services.ApplicationPropertiesService;
|
import com.commafeed.backend.services.ApplicationPropertiesService;
|
||||||
|
import com.commafeed.backend.services.ApplicationSettingsService;
|
||||||
import com.commafeed.frontend.pages.DemoLoginPage;
|
import com.commafeed.frontend.pages.DemoLoginPage;
|
||||||
import com.commafeed.frontend.pages.HomePage;
|
import com.commafeed.frontend.pages.HomePage;
|
||||||
import com.commafeed.frontend.pages.LogoutPage;
|
import com.commafeed.frontend.pages.LogoutPage;
|
||||||
@@ -51,6 +58,9 @@ import com.commafeed.frontend.utils.exception.DisplayExceptionPage;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class CommaFeedApplication extends AuthenticatedWebApplication {
|
public class CommaFeedApplication extends AuthenticatedWebApplication {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
ApplicationSettingsService applicationSettingsService;
|
||||||
|
|
||||||
public CommaFeedApplication() {
|
public CommaFeedApplication() {
|
||||||
super();
|
super();
|
||||||
boolean prod = ApplicationPropertiesService.get().isProduction();
|
boolean prod = ApplicationPropertiesService.get().isProduction();
|
||||||
@@ -60,6 +70,8 @@ public class CommaFeedApplication extends AuthenticatedWebApplication {
|
|||||||
@Override
|
@Override
|
||||||
protected void init() {
|
protected void init() {
|
||||||
super.init();
|
super.init();
|
||||||
|
setupInjection();
|
||||||
|
setupSecurity();
|
||||||
|
|
||||||
mountPage("welcome", WelcomePage.class);
|
mountPage("welcome", WelcomePage.class);
|
||||||
mountPage("demo", DemoLoginPage.class);
|
mountPage("demo", DemoLoginPage.class);
|
||||||
@@ -72,9 +84,6 @@ public class CommaFeedApplication extends AuthenticatedWebApplication {
|
|||||||
|
|
||||||
mountPage("next", NextUnreadRedirectPage.class);
|
mountPage("next", NextUnreadRedirectPage.class);
|
||||||
|
|
||||||
setupInjection();
|
|
||||||
setupSecurity();
|
|
||||||
|
|
||||||
getMarkupSettings().setStripWicketTags(true);
|
getMarkupSettings().setStripWicketTags(true);
|
||||||
getMarkupSettings().setCompressWhitespace(true);
|
getMarkupSettings().setCompressWhitespace(true);
|
||||||
getMarkupSettings().setDefaultMarkupEncoding("UTF-8");
|
getMarkupSettings().setDefaultMarkupEncoding("UTF-8");
|
||||||
@@ -95,6 +104,27 @@ public class CommaFeedApplication extends AuthenticatedWebApplication {
|
|||||||
return new RenderPageRequestHandler(new PageProvider(new DisplayExceptionPage(ex)), policy);
|
return new RenderPageRequestHandler(new PageProvider(new DisplayExceptionPage(ex)), policy);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
setRequestCycleProvider(new IRequestCycleProvider() {
|
||||||
|
@Override
|
||||||
|
public RequestCycle get(RequestCycleContext context) {
|
||||||
|
return new RequestCycle(context) {
|
||||||
|
@Override
|
||||||
|
protected UrlRenderer newUrlRenderer() {
|
||||||
|
return new UrlRenderer(getRequest()) {
|
||||||
|
@Override
|
||||||
|
public String renderUrl(Url url) {
|
||||||
|
String publicUrl = applicationSettingsService.get().getPublicUrl();
|
||||||
|
if (StringUtils.isNotBlank(publicUrl)) {
|
||||||
|
url.setProtocol(Url.parse(publicUrl).getProtocol());
|
||||||
|
}
|
||||||
|
return super.renderUrl(url);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupSecurity() {
|
private void setupSecurity() {
|
||||||
@@ -147,7 +177,8 @@ public class CommaFeedApplication extends AuthenticatedWebApplication {
|
|||||||
protected void setupInjection() {
|
protected void setupInjection() {
|
||||||
try {
|
try {
|
||||||
BeanManager beanManager = (BeanManager) new InitialContext().lookup("java:comp/BeanManager");
|
BeanManager beanManager = (BeanManager) new InitialContext().lookup("java:comp/BeanManager");
|
||||||
new CdiConfiguration(beanManager).setPropagation(ConversationPropagation.NONE).configure(this);
|
CdiContainer container = new CdiConfiguration(beanManager).setPropagation(ConversationPropagation.NONE).configure(this);
|
||||||
|
container.getNonContextualManager().inject(this);
|
||||||
} catch (NamingException e) {
|
} catch (NamingException e) {
|
||||||
log.warn("Could not locate bean manager. CDI is disabled.");
|
log.warn("Could not locate bean manager. CDI is disabled.");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user