Skip to content

Commit

Permalink
Prepend context path to service URL (#17573)
Browse files Browse the repository at this point in the history
Change-Id: Ie163e97bccace95beec73f3aa9b275b0d77301a0
  • Loading branch information
Henri Sara committed Apr 27, 2015
1 parent 352b5d5 commit d914f73
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ protected ServletRegistrationBean createServletRegistrationBean() {
// applications to co-exist in the same global "namespace"
if (servlet instanceof SpringVaadinServlet && isMappedToRoot()) {
SpringVaadinServlet vaadinServlet = (SpringVaadinServlet) servlet;
vaadinServlet.setServiceUrl(DEFAULT_SERVLET_URL_BASE);
vaadinServlet.setServiceUrlPath(DEFAULT_SERVLET_URL_BASE);
vaadinServlet.setClearServletPath(true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class SpringVaadinServlet extends VaadinServlet {

private static final long serialVersionUID = 5371983676318947478L;

private String serviceUrl = null;
private String serviceUrlPath = null;

private boolean clearServletPath = false;

Expand Down Expand Up @@ -100,26 +100,31 @@ public void sessionInit(SessionInitEvent sessionInitEvent)
}

/**
* Return the service URL (URL for all client-server communication) to use
* if customized, null for the default service URL.
* Return the path of the service URL (URL for all client-server
* communication) relative to the context path. A value of null means that
* the default service path of Vaadin should be used. The path should start
* with a slash.
*
* @return service URL or null to use the default
* @return service URL path relative to context path (starting with slash)
* or null to use the default
*/
public String getServiceUrl() {
return serviceUrl;
public String getServiceUrlPath() {
return serviceUrlPath;
}

/**
* Set the service URL (URL for all client-server communication) to use,
* null to use the default service URL. The service URL must be set before
* servlet service instances are created, i.e. before the servlet is placed
* into service by the servlet container.
* Set the path of the service URL (URL for all client-server communication)
* to use, relative to the context path. The value null means that the
* default service URL of Vaadin should be used. The service URL path must
* be set before servlet service instances are created, i.e. before the
* servlet is placed into service by the servlet container.
*
* @param serviceUrl
* to use or null for default
* @param serviceUrlPath
* service URL path relative to the context path (starting with a
* slash) or null for default
*/
public void setServiceUrl(String serviceUrl) {
this.serviceUrl = serviceUrl;
public void setServiceUrlPath(String serviceUrlPath) {
this.serviceUrlPath = serviceUrlPath;
}

/**
Expand Down Expand Up @@ -154,10 +159,10 @@ public void setClearServletPath(boolean clearServletPath) {
@Override
protected VaadinServletService createServletService(
DeploymentConfiguration deploymentConfiguration)
throws ServiceException {
throws ServiceException {
// this is needed when using a custom service URL
SpringVaadinServletService service = new SpringVaadinServletService(
this, deploymentConfiguration, getServiceUrl());
this, deploymentConfiguration, getServiceUrlPath());
service.init();
return service;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public class SpringVaadinServletService extends VaadinServletService {
* @param servlet
* @param deploymentConfiguration
* @param serviceUrl
* custom service URL to use or null for default
* custom service URL to use (relative to context path, starting
* with a slash) or null for default
* @throws ServiceException
*/
public SpringVaadinServletService(VaadinServlet servlet,
Expand All @@ -61,7 +62,8 @@ protected List<RequestHandler> createRequestHandlers()
handlers.set(i, new ServletBootstrapHandler() {
@Override
protected String getServiceUrl(BootstrapContext context) {
return serviceUrl;
return context.getRequest().getContextPath()
+ serviceUrl;
}
});
}
Expand Down

0 comments on commit d914f73

Please sign in to comment.