Skip to content

Commit

Permalink
Avoid a new public two parameters CTOR for SpringServlet (#375)
Browse files Browse the repository at this point in the history
Introduce a code duplication to avoid breaking API change

Fixes #373
  • Loading branch information
Denis committed Nov 7, 2018
1 parent 75c67ae commit 4580524
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public ServletRegistrationBean<SpringServlet> servletRegistrationBean() {
.makeContextRelative(mapping.replace("*", "")));
}
ServletRegistrationBean<SpringServlet> registration = new ServletRegistrationBean<>(
new SpringServlet(context, rootMapping), mapping);
new SpringServlet(context), mapping);
registration.setInitParameters(initParameters);
registration
.setAsyncSupported(configurationProperties.isAsyncSupported());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ public class SpringServlet extends VaadinServlet {
* @param context
* the Spring application context
*/
public SpringServlet(ApplicationContext context,
public SpringServlet(ApplicationContext context) {
this(context, isForwardingEnforced(context));
}

private SpringServlet(ApplicationContext context,
boolean forwardingEnforced) {
this.context = context;
this.forwardingEnforced = forwardingEnforced;
Expand Down Expand Up @@ -126,4 +130,11 @@ private void setProperty(String envProperty, String initParam,
}
}

private static boolean isForwardingEnforced(ApplicationContext context) {
Environment env = context.getBean(Environment.class);
String mapping = env
.getProperty(RootMappedCondition.URL_MAPPING_PROPERTY, "/*");

return RootMappedCondition.isRootMapping(mapping);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void onStartup(ServletContext servletContext)

Dynamic registration = servletContext.addServlet(
ClassUtils.getShortNameAsProperty(SpringServlet.class),
new SpringServlet(context, rootMapping));
new SpringServlet(context));

Map<String, String> initParameters = new HashMap<>();
if (rootMapping) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public void getI18NProvider_i18nProviderIsABean_i18nProviderIsAvailable()

public static VaadinServletService getService(ApplicationContext context,
Properties configProperties) throws ServletException {
SpringServlet servlet = new SpringServlet(context, false) {
SpringServlet servlet = new SpringServlet(context) {
@Override
protected DeploymentConfiguration createDeploymentConfiguration(
Properties initParameters) {
Expand Down

0 comments on commit 4580524

Please sign in to comment.