summaryrefslogtreecommitdiffstats
path: root/server/src/com/vaadin
diff options
context:
space:
mode:
authorLeif Åstrand <leif@vaadin.com>2012-09-24 11:52:10 +0300
committerLeif Åstrand <leif@vaadin.com>2012-09-24 11:52:10 +0300
commita4ba2868153ca06d827324655dbb10e5213c9b2d (patch)
tree0bf271880f7dd456f5edaa48eccf80917bfd22fe /server/src/com/vaadin
parent3e9c88f9d8e9ebfcb71e30eba18525b2821e7c25 (diff)
downloadvaadin-framework-a4ba2868153ca06d827324655dbb10e5213c9b2d.tar.gz
vaadin-framework-a4ba2868153ca06d827324655dbb10e5213c9b2d.zip
Rename to VaadinServletService and move to its own file (#9718)
Diffstat (limited to 'server/src/com/vaadin')
-rw-r--r--server/src/com/vaadin/server/LegacyVaadinPortlet.java2
-rw-r--r--server/src/com/vaadin/server/LegacyVaadinServlet.java2
-rw-r--r--server/src/com/vaadin/server/VaadinPortlet.java206
-rw-r--r--server/src/com/vaadin/server/VaadinPortletRequest.java7
-rw-r--r--server/src/com/vaadin/server/VaadinPortletResponse.java7
-rw-r--r--server/src/com/vaadin/server/VaadinPortletService.java221
-rw-r--r--server/src/com/vaadin/server/VaadinServlet.java186
-rw-r--r--server/src/com/vaadin/server/VaadinServletRequest.java7
-rw-r--r--server/src/com/vaadin/server/VaadinServletResponse.java7
-rw-r--r--server/src/com/vaadin/server/VaadinServletService.java198
-rw-r--r--server/src/com/vaadin/server/VaadinServletSession.java3
11 files changed, 447 insertions, 399 deletions
diff --git a/server/src/com/vaadin/server/LegacyVaadinPortlet.java b/server/src/com/vaadin/server/LegacyVaadinPortlet.java
index 113cae6bf7..f433b14478 100644
--- a/server/src/com/vaadin/server/LegacyVaadinPortlet.java
+++ b/server/src/com/vaadin/server/LegacyVaadinPortlet.java
@@ -29,7 +29,7 @@ public class LegacyVaadinPortlet extends VaadinPortlet {
VaadinPortlet portlet = VaadinPortlet.getCurrent();
if (portlet instanceof LegacyVaadinPortlet) {
LegacyVaadinPortlet legacyPortlet = (LegacyVaadinPortlet) portlet;
- PortletRequest request = PortletService
+ PortletRequest request = VaadinPortletService
.getCurrentPortletRequest();
if (legacyPortlet.shouldCreateApplication(request)) {
try {
diff --git a/server/src/com/vaadin/server/LegacyVaadinServlet.java b/server/src/com/vaadin/server/LegacyVaadinServlet.java
index 18911dc96e..3a44df517d 100644
--- a/server/src/com/vaadin/server/LegacyVaadinServlet.java
+++ b/server/src/com/vaadin/server/LegacyVaadinServlet.java
@@ -31,7 +31,7 @@ public class LegacyVaadinServlet extends VaadinServlet {
VaadinServlet servlet = VaadinServlet.getCurrent();
if (servlet instanceof LegacyVaadinServlet) {
LegacyVaadinServlet legacyServlet = (LegacyVaadinServlet) servlet;
- HttpServletRequest request = ServletService
+ HttpServletRequest request = VaadinServletService
.getCurrentServletRequest();
try {
if (legacyServlet.shouldCreateApplication(request)) {
diff --git a/server/src/com/vaadin/server/VaadinPortlet.java b/server/src/com/vaadin/server/VaadinPortlet.java
index 5849d77c4d..d862a13945 100644
--- a/server/src/com/vaadin/server/VaadinPortlet.java
+++ b/server/src/com/vaadin/server/VaadinPortlet.java
@@ -16,7 +16,6 @@
package com.vaadin.server;
import java.io.BufferedWriter;
-import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -25,12 +24,10 @@ import java.io.PrintWriter;
import java.io.Serializable;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
-import java.net.URL;
import java.security.GeneralSecurityException;
import java.util.Enumeration;
import java.util.Map;
import java.util.Properties;
-import java.util.logging.Level;
import java.util.logging.Logger;
import javax.portlet.ActionRequest;
@@ -74,199 +71,12 @@ public class VaadinPortlet extends GenericPortlet implements Constants {
@Deprecated
public static final String RESOURCE_URL_ID = "APP";
- public static class PortletService extends VaadinService {
- private final VaadinPortlet portlet;
-
- public PortletService(VaadinPortlet portlet,
- DeploymentConfiguration deploymentConfiguration) {
- super(deploymentConfiguration);
- this.portlet = portlet;
- }
-
- protected VaadinPortlet getPortlet() {
- return portlet;
- }
-
- @Override
- public String getConfiguredWidgetset(VaadinRequest request) {
-
- String widgetset = getDeploymentConfiguration()
- .getApplicationOrSystemProperty(PARAMETER_WIDGETSET, null);
-
- if (widgetset == null) {
- // If no widgetset defined for the application, check the
- // portal property
- widgetset = VaadinPortletRequest.cast(request)
- .getPortalProperty(PORTAL_PARAMETER_VAADIN_WIDGETSET);
- }
-
- if (widgetset == null) {
- // If no widgetset defined for the portal, use the default
- widgetset = DEFAULT_WIDGETSET;
- }
-
- return widgetset;
- }
-
- @Override
- public String getConfiguredTheme(VaadinRequest request) {
-
- // is the default theme defined by the portal?
- String themeName = VaadinPortletRequest.cast(request)
- .getPortalProperty(Constants.PORTAL_PARAMETER_VAADIN_THEME);
-
- if (themeName == null) {
- // no, using the default theme defined by Vaadin
- themeName = DEFAULT_THEME_NAME;
- }
-
- return themeName;
- }
-
- @Override
- public boolean isStandalone(VaadinRequest request) {
- return false;
- }
-
- @Override
- public String getStaticFileLocation(VaadinRequest request) {
- String staticFileLocation = VaadinPortletRequest.cast(request)
- .getPortalProperty(
- Constants.PORTAL_PARAMETER_VAADIN_RESOURCE_PATH);
- if (staticFileLocation != null) {
- // remove trailing slash if any
- while (staticFileLocation.endsWith(".")) {
- staticFileLocation = staticFileLocation.substring(0,
- staticFileLocation.length() - 1);
- }
- return staticFileLocation;
- } else {
- // default for Liferay
- return "/html";
- }
- }
-
- @Override
- public String getMimeType(String resourceName) {
- return getPortlet().getPortletContext().getMimeType(resourceName);
- }
-
- @Override
- public SystemMessages getSystemMessages() {
- return ServletPortletHelper.DEFAULT_SYSTEM_MESSAGES;
- }
-
- @Override
- public File getBaseDirectory() {
- PortletContext context = getPortlet().getPortletContext();
- String resultPath = context.getRealPath("/");
- if (resultPath != null) {
- return new File(resultPath);
- } else {
- try {
- final URL url = context.getResource("/");
- return new File(url.getFile());
- } catch (final Exception e) {
- // FIXME: Handle exception
- getLogger()
- .log(Level.INFO,
- "Cannot access base directory, possible security issue "
- + "with Application Server or Servlet Container",
- e);
- }
- }
- return null;
- }
-
- @Override
- protected boolean requestCanCreateSession(VaadinRequest request) {
- RequestType requestType = getRequestType(request);
- if (requestType == RequestType.RENDER) {
- // In most cases the first request is a render request that
- // renders the HTML fragment. This should create a Vaadin
- // session unless there is already one.
- return true;
- } else if (requestType == RequestType.EVENT) {
- // A portlet can also be sent an event even though it has not
- // been rendered, e.g. portlet on one page sends an event to a
- // portlet on another page and then moves the user to that page.
- return true;
- }
- return false;
- }
-
- /**
- * Gets the request type for the request.
- *
- * @param request
- * the request to get a request type for
- * @return the request type
- *
- * @deprecated might be refactored or removed before 7.0.0
- */
- @Deprecated
- protected RequestType getRequestType(VaadinRequest request) {
- RequestType type = (RequestType) request
- .getAttribute(RequestType.class.getName());
- if (type == null) {
- type = getPortlet().getRequestType(
- VaadinPortletRequest.cast(request));
- request.setAttribute(RequestType.class.getName(), type);
- }
- return type;
- }
-
- @Override
- protected AbstractCommunicationManager createCommunicationManager(
- VaadinSession session) {
- return new PortletCommunicationManager(session);
- }
-
- public static PortletRequest getCurrentPortletRequest() {
- VaadinRequest currentRequest = VaadinService.getCurrentRequest();
- try {
- VaadinPortletRequest request = VaadinPortletRequest
- .cast(currentRequest);
- if (request != null) {
- return request.getPortletRequest();
- } else {
- return null;
- }
- } catch (ClassCastException e) {
- return null;
- }
- }
-
- public static VaadinPortletResponse getCurrentResponse() {
- return (VaadinPortletResponse) VaadinService.getCurrentResponse();
- }
-
- @Override
- protected VaadinSession createVaadinSession(VaadinRequest request)
- throws ServiceException {
- return new VaadinPortletSession();
- }
-
- @Override
- public String getServiceName() {
- return getPortlet().getPortletName();
- }
-
- /**
- * Always preserve UIs in portlets to make portlet actions work.
- */
- @Override
- public boolean preserveUIOnRefresh(VaadinRequest request, UI ui,
- UIProvider provider) {
- return true;
- }
- }
-
public static class VaadinHttpAndPortletRequest extends
VaadinPortletRequest {
public VaadinHttpAndPortletRequest(PortletRequest request,
- HttpServletRequest originalRequest, PortletService vaadinService) {
+ HttpServletRequest originalRequest,
+ VaadinPortletService vaadinService) {
super(request, vaadinService);
this.originalRequest = originalRequest;
}
@@ -308,7 +118,7 @@ public class VaadinPortlet extends GenericPortlet implements Constants {
public static class VaadinGateinRequest extends VaadinHttpAndPortletRequest {
public VaadinGateinRequest(PortletRequest request,
- PortletService vaadinService) {
+ VaadinPortletService vaadinService) {
super(request, getOriginalRequest(request), vaadinService);
}
@@ -331,7 +141,7 @@ public class VaadinPortlet extends GenericPortlet implements Constants {
VaadinHttpAndPortletRequest {
public VaadinLiferayRequest(PortletRequest request,
- PortletService vaadinService) {
+ VaadinPortletService vaadinService) {
super(request, getOriginalRequest(request), vaadinService);
}
@@ -409,7 +219,7 @@ public class VaadinPortlet extends GenericPortlet implements Constants {
// TODO Can we close the application when the portlet is removed? Do we know
// when the portlet is removed?
- private PortletService vaadinService;
+ private VaadinPortletService vaadinService;
private AddonContext addonContext;
@Override
@@ -455,9 +265,9 @@ public class VaadinPortlet extends GenericPortlet implements Constants {
return new DefaultDeploymentConfiguration(getClass(), initParameters);
}
- protected PortletService createPortletService(
+ protected VaadinPortletService createPortletService(
DeploymentConfiguration deploymentConfiguration) {
- return new PortletService(this, deploymentConfiguration);
+ return new VaadinPortletService(this, deploymentConfiguration);
}
@Override
@@ -705,7 +515,7 @@ public class VaadinPortlet extends GenericPortlet implements Constants {
}
- protected PortletService getVaadinService() {
+ protected VaadinPortletService getVaadinService() {
return vaadinService;
}
diff --git a/server/src/com/vaadin/server/VaadinPortletRequest.java b/server/src/com/vaadin/server/VaadinPortletRequest.java
index c1bca824ef..3290c49950 100644
--- a/server/src/com/vaadin/server/VaadinPortletRequest.java
+++ b/server/src/com/vaadin/server/VaadinPortletRequest.java
@@ -26,7 +26,6 @@ import javax.portlet.PortletRequest;
import javax.portlet.PortletSession;
import javax.portlet.ResourceRequest;
-import com.vaadin.server.VaadinPortlet.PortletService;
import com.vaadin.shared.ApplicationConstants;
/**
@@ -41,7 +40,7 @@ import com.vaadin.shared.ApplicationConstants;
public class VaadinPortletRequest implements VaadinRequest {
private final PortletRequest request;
- private final PortletService vaadinService;
+ private final VaadinPortletService vaadinService;
/**
* Wraps a portlet request and an associated vaadin service
@@ -52,7 +51,7 @@ public class VaadinPortletRequest implements VaadinRequest {
* the associated vaadin service
*/
public VaadinPortletRequest(PortletRequest request,
- PortletService vaadinService) {
+ VaadinPortletService vaadinService) {
this.request = request;
this.vaadinService = vaadinService;
}
@@ -203,7 +202,7 @@ public class VaadinPortletRequest implements VaadinRequest {
}
@Override
- public PortletService getVaadinService() {
+ public VaadinPortletService getVaadinService() {
return vaadinService;
}
diff --git a/server/src/com/vaadin/server/VaadinPortletResponse.java b/server/src/com/vaadin/server/VaadinPortletResponse.java
index 5ca1ba580e..efec091bb3 100644
--- a/server/src/com/vaadin/server/VaadinPortletResponse.java
+++ b/server/src/com/vaadin/server/VaadinPortletResponse.java
@@ -29,7 +29,6 @@ import javax.portlet.MimeResponse;
import javax.portlet.PortletResponse;
import javax.portlet.ResourceResponse;
-import com.vaadin.server.VaadinPortlet.PortletService;
/**
* Wrapper for {@link PortletResponse} and its subclasses.
@@ -48,7 +47,7 @@ public class VaadinPortletResponse implements VaadinResponse {
}
private final PortletResponse response;
- private PortletService vaadinService;
+ private VaadinPortletService vaadinService;
/**
* Wraps a portlet response and an associated vaadin service
@@ -59,7 +58,7 @@ public class VaadinPortletResponse implements VaadinResponse {
* the associated vaadin service
*/
public VaadinPortletResponse(PortletResponse response,
- PortletService vaadinService) {
+ VaadinPortletService vaadinService) {
this.response = response;
this.vaadinService = vaadinService;
}
@@ -116,7 +115,7 @@ public class VaadinPortletResponse implements VaadinResponse {
}
@Override
- public PortletService getVaadinService() {
+ public VaadinPortletService getVaadinService() {
return vaadinService;
}
} \ No newline at end of file
diff --git a/server/src/com/vaadin/server/VaadinPortletService.java b/server/src/com/vaadin/server/VaadinPortletService.java
new file mode 100644
index 0000000000..9940cb5a79
--- /dev/null
+++ b/server/src/com/vaadin/server/VaadinPortletService.java
@@ -0,0 +1,221 @@
+/*
+ * Copyright 2011 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package com.vaadin.server;
+
+import java.io.File;
+import java.net.URL;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.portlet.PortletContext;
+import javax.portlet.PortletRequest;
+
+import com.vaadin.server.VaadinPortlet.RequestType;
+import com.vaadin.ui.UI;
+
+public class VaadinPortletService extends VaadinService {
+ private final VaadinPortlet portlet;
+
+ public VaadinPortletService(VaadinPortlet portlet,
+ DeploymentConfiguration deploymentConfiguration) {
+ super(deploymentConfiguration);
+ this.portlet = portlet;
+ }
+
+ protected VaadinPortlet getPortlet() {
+ return portlet;
+ }
+
+ @Override
+ public String getConfiguredWidgetset(VaadinRequest request) {
+
+ String widgetset = getDeploymentConfiguration()
+ .getApplicationOrSystemProperty(
+ VaadinPortlet.PARAMETER_WIDGETSET, null);
+
+ if (widgetset == null) {
+ // If no widgetset defined for the application, check the
+ // portal property
+ widgetset = VaadinPortletRequest.cast(request).getPortalProperty(
+ VaadinPortlet.PORTAL_PARAMETER_VAADIN_WIDGETSET);
+ }
+
+ if (widgetset == null) {
+ // If no widgetset defined for the portal, use the default
+ widgetset = VaadinPortlet.DEFAULT_WIDGETSET;
+ }
+
+ return widgetset;
+ }
+
+ @Override
+ public String getConfiguredTheme(VaadinRequest request) {
+
+ // is the default theme defined by the portal?
+ String themeName = VaadinPortletRequest.cast(request)
+ .getPortalProperty(Constants.PORTAL_PARAMETER_VAADIN_THEME);
+
+ if (themeName == null) {
+ // no, using the default theme defined by Vaadin
+ themeName = VaadinPortlet.DEFAULT_THEME_NAME;
+ }
+
+ return themeName;
+ }
+
+ @Override
+ public boolean isStandalone(VaadinRequest request) {
+ return false;
+ }
+
+ @Override
+ public String getStaticFileLocation(VaadinRequest request) {
+ String staticFileLocation = VaadinPortletRequest.cast(request)
+ .getPortalProperty(
+ Constants.PORTAL_PARAMETER_VAADIN_RESOURCE_PATH);
+ if (staticFileLocation != null) {
+ // remove trailing slash if any
+ while (staticFileLocation.endsWith(".")) {
+ staticFileLocation = staticFileLocation.substring(0,
+ staticFileLocation.length() - 1);
+ }
+ return staticFileLocation;
+ } else {
+ // default for Liferay
+ return "/html";
+ }
+ }
+
+ @Override
+ public String getMimeType(String resourceName) {
+ return getPortlet().getPortletContext().getMimeType(resourceName);
+ }
+
+ @Override
+ public SystemMessages getSystemMessages() {
+ return ServletPortletHelper.DEFAULT_SYSTEM_MESSAGES;
+ }
+
+ @Override
+ public File getBaseDirectory() {
+ PortletContext context = getPortlet().getPortletContext();
+ String resultPath = context.getRealPath("/");
+ if (resultPath != null) {
+ return new File(resultPath);
+ } else {
+ try {
+ final URL url = context.getResource("/");
+ return new File(url.getFile());
+ } catch (final Exception e) {
+ // FIXME: Handle exception
+ getLogger()
+ .log(Level.INFO,
+ "Cannot access base directory, possible security issue "
+ + "with Application Server or Servlet Container",
+ e);
+ }
+ }
+ return null;
+ }
+
+ private static final Logger getLogger() {
+ return Logger.getLogger(VaadinPortletService.class.getName());
+ }
+
+ @Override
+ protected boolean requestCanCreateSession(VaadinRequest request) {
+ RequestType requestType = getRequestType(request);
+ if (requestType == RequestType.RENDER) {
+ // In most cases the first request is a render request that
+ // renders the HTML fragment. This should create a Vaadin
+ // session unless there is already one.
+ return true;
+ } else if (requestType == RequestType.EVENT) {
+ // A portlet can also be sent an event even though it has not
+ // been rendered, e.g. portlet on one page sends an event to a
+ // portlet on another page and then moves the user to that page.
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Gets the request type for the request.
+ *
+ * @param request
+ * the request to get a request type for
+ * @return the request type
+ *
+ * @deprecated might be refactored or removed before 7.0.0
+ */
+ @Deprecated
+ protected RequestType getRequestType(VaadinRequest request) {
+ RequestType type = (RequestType) request.getAttribute(RequestType.class
+ .getName());
+ if (type == null) {
+ type = getPortlet().getRequestType(
+ VaadinPortletRequest.cast(request));
+ request.setAttribute(RequestType.class.getName(), type);
+ }
+ return type;
+ }
+
+ @Override
+ protected AbstractCommunicationManager createCommunicationManager(
+ VaadinSession session) {
+ return new PortletCommunicationManager(session);
+ }
+
+ public static PortletRequest getCurrentPortletRequest() {
+ VaadinRequest currentRequest = VaadinService.getCurrentRequest();
+ try {
+ VaadinPortletRequest request = VaadinPortletRequest
+ .cast(currentRequest);
+ if (request != null) {
+ return request.getPortletRequest();
+ } else {
+ return null;
+ }
+ } catch (ClassCastException e) {
+ return null;
+ }
+ }
+
+ public static VaadinPortletResponse getCurrentResponse() {
+ return (VaadinPortletResponse) VaadinService.getCurrentResponse();
+ }
+
+ @Override
+ protected VaadinSession createVaadinSession(VaadinRequest request)
+ throws ServiceException {
+ return new VaadinPortletSession();
+ }
+
+ @Override
+ public String getServiceName() {
+ return getPortlet().getPortletName();
+ }
+
+ /**
+ * Always preserve UIs in portlets to make portlet actions work.
+ */
+ @Override
+ public boolean preserveUIOnRefresh(VaadinRequest request, UI ui,
+ UIProvider provider) {
+ return true;
+ }
+} \ No newline at end of file
diff --git a/server/src/com/vaadin/server/VaadinServlet.java b/server/src/com/vaadin/server/VaadinServlet.java
index 60f385146a..c8f85020d5 100644
--- a/server/src/com/vaadin/server/VaadinServlet.java
+++ b/server/src/com/vaadin/server/VaadinServlet.java
@@ -16,7 +16,6 @@
package com.vaadin.server;
import java.io.BufferedWriter;
-import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -52,181 +51,6 @@ import com.vaadin.util.CurrentInstance;
@SuppressWarnings("serial")
public class VaadinServlet extends HttpServlet implements Constants {
- public static class ServletService extends VaadinService {
- private final VaadinServlet servlet;
-
- public ServletService(VaadinServlet servlet,
- DeploymentConfiguration deploymentConfiguration) {
- super(deploymentConfiguration);
- this.servlet = servlet;
- }
-
- protected VaadinServlet getServlet() {
- return servlet;
- }
-
- @Override
- public String getStaticFileLocation(VaadinRequest request) {
- HttpServletRequest servletRequest = VaadinServletRequest
- .cast(request);
- String staticFileLocation;
- // if property is defined in configurations, use that
- staticFileLocation = getDeploymentConfiguration()
- .getApplicationOrSystemProperty(PARAMETER_VAADIN_RESOURCES,
- null);
- if (staticFileLocation != null) {
- return staticFileLocation;
- }
-
- // the last (but most common) option is to generate default location
- // from request
-
- // if context is specified add it to widgetsetUrl
- String ctxPath = servletRequest.getContextPath();
-
- // FIXME: ctxPath.length() == 0 condition is probably unnecessary
- // and
- // might even be wrong.
-
- if (ctxPath.length() == 0
- && request
- .getAttribute("javax.servlet.include.context_path") != null) {
- // include request (e.g portlet), get context path from
- // attribute
- ctxPath = (String) request
- .getAttribute("javax.servlet.include.context_path");
- }
-
- // Remove heading and trailing slashes from the context path
- ctxPath = removeHeadingOrTrailing(ctxPath, "/");
-
- if (ctxPath.equals("")) {
- return "";
- } else {
- return "/" + ctxPath;
- }
- }
-
- @Override
- public String getConfiguredWidgetset(VaadinRequest request) {
- return getDeploymentConfiguration().getApplicationOrSystemProperty(
- VaadinServlet.PARAMETER_WIDGETSET,
- VaadinServlet.DEFAULT_WIDGETSET);
- }
-
- @Override
- public String getConfiguredTheme(VaadinRequest request) {
- // Use the default
- return VaadinServlet.getDefaultTheme();
- }
-
- @Override
- public boolean isStandalone(VaadinRequest request) {
- return true;
- }
-
- @Override
- public String getMimeType(String resourceName) {
- return getServlet().getServletContext().getMimeType(resourceName);
- }
-
- @Override
- public SystemMessages getSystemMessages() {
- return ServletPortletHelper.DEFAULT_SYSTEM_MESSAGES;
- }
-
- @Override
- public File getBaseDirectory() {
- final String realPath = VaadinServlet.getResourcePath(
- servlet.getServletContext(), "/");
- if (realPath == null) {
- return null;
- }
- return new File(realPath);
- }
-
- @Override
- protected boolean requestCanCreateSession(VaadinRequest request) {
- RequestType requestType = getRequestType(request);
- if (requestType == RequestType.BROWSER_DETAILS) {
- // This is the first request if you are embedding by writing the
- // embedding code yourself
- return true;
- } else if (requestType == RequestType.OTHER) {
- /*
- * I.e URIs that are not RPC calls or static (theme) files.
- */
- return true;
- }
-
- return false;
- }
-
- /**
- * Gets the request type for the request.
- *
- * @param request
- * the request to get a request type for
- * @return the request type
- *
- * @deprecated might be refactored or removed before 7.0.0
- */
- @Deprecated
- protected RequestType getRequestType(VaadinRequest request) {
- RequestType type = (RequestType) request
- .getAttribute(RequestType.class.getName());
- if (type == null) {
- type = getServlet().getRequestType(
- VaadinServletRequest.cast(request));
- request.setAttribute(RequestType.class.getName(), type);
- }
- return type;
- }
-
- @Override
- protected URL getApplicationUrl(VaadinRequest request)
- throws MalformedURLException {
- return getServlet().getApplicationUrl(
- VaadinServletRequest.cast(request));
- }
-
- @Override
- protected AbstractCommunicationManager createCommunicationManager(
- VaadinSession session) {
- return new CommunicationManager(session);
- }
-
- public static HttpServletRequest getCurrentServletRequest() {
- VaadinRequest currentRequest = VaadinService.getCurrentRequest();
- try {
- VaadinServletRequest request = VaadinServletRequest
- .cast(currentRequest);
- if (request != null) {
- return request.getHttpServletRequest();
- } else {
- return null;
- }
- } catch (ClassCastException e) {
- return null;
- }
- }
-
- public static VaadinServletResponse getCurrentResponse() {
- return (VaadinServletResponse) VaadinService.getCurrentResponse();
- }
-
- @Override
- protected VaadinSession createVaadinSession(VaadinRequest request)
- throws ServiceException {
- return new VaadinServletSession();
- }
-
- @Override
- public String getServiceName() {
- return getServlet().getServletName();
- }
- }
-
private static class AbstractApplicationServletWrapper implements Callback {
private final VaadinServlet servlet;
@@ -250,7 +74,7 @@ public class VaadinServlet extends HttpServlet implements Constants {
private final String resourcePath = null;
- private ServletService servletService;
+ private VaadinServletService servletService;
private AddonContext addonContext;
@@ -350,9 +174,9 @@ public class VaadinServlet extends HttpServlet implements Constants {
return new DefaultDeploymentConfiguration(getClass(), initParameters);
}
- protected ServletService createServletService(
+ protected VaadinServletService createServletService(
DeploymentConfiguration deploymentConfiguration) {
- return new ServletService(this, deploymentConfiguration);
+ return new VaadinServletService(this, deploymentConfiguration);
}
@Override
@@ -525,7 +349,7 @@ public class VaadinServlet extends HttpServlet implements Constants {
*
* @return the vaadin service
*/
- protected ServletService getVaadinService() {
+ protected VaadinServletService getVaadinService() {
return servletService;
}
@@ -1263,7 +1087,7 @@ public class VaadinServlet extends HttpServlet implements Constants {
* @param what
* @return
*/
- private static String removeHeadingOrTrailing(String string, String what) {
+ static String removeHeadingOrTrailing(String string, String what) {
while (string.startsWith(what)) {
string = string.substring(1);
}
diff --git a/server/src/com/vaadin/server/VaadinServletRequest.java b/server/src/com/vaadin/server/VaadinServletRequest.java
index e9d673a1f3..ece7d187bc 100644
--- a/server/src/com/vaadin/server/VaadinServletRequest.java
+++ b/server/src/com/vaadin/server/VaadinServletRequest.java
@@ -20,7 +20,6 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import javax.servlet.http.HttpSession;
-import com.vaadin.server.VaadinServlet.ServletService;
/**
* Wrapper for {@link HttpServletRequest}.
@@ -34,7 +33,7 @@ import com.vaadin.server.VaadinServlet.ServletService;
public class VaadinServletRequest extends HttpServletRequestWrapper implements
VaadinRequest {
- private final ServletService vaadinService;
+ private final VaadinServletService vaadinService;
/**
* Wraps a http servlet request and associates with a vaadin service
@@ -45,7 +44,7 @@ public class VaadinServletRequest extends HttpServletRequestWrapper implements
* the associated vaadin service
*/
public VaadinServletRequest(HttpServletRequest request,
- ServletService vaadinService) {
+ VaadinServletService vaadinService) {
super(request);
this.vaadinService = vaadinService;
}
@@ -80,7 +79,7 @@ public class VaadinServletRequest extends HttpServletRequestWrapper implements
}
@Override
- public ServletService getVaadinService() {
+ public VaadinServletService getVaadinService() {
return vaadinService;
}
diff --git a/server/src/com/vaadin/server/VaadinServletResponse.java b/server/src/com/vaadin/server/VaadinServletResponse.java
index b21ca34249..f999a470dd 100644
--- a/server/src/com/vaadin/server/VaadinServletResponse.java
+++ b/server/src/com/vaadin/server/VaadinServletResponse.java
@@ -19,7 +19,6 @@ package com.vaadin.server;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;
-import com.vaadin.server.VaadinServlet.ServletService;
/**
* Wrapper for {@link HttpServletResponse}.
@@ -33,7 +32,7 @@ import com.vaadin.server.VaadinServlet.ServletService;
public class VaadinServletResponse extends HttpServletResponseWrapper implements
VaadinResponse {
- private ServletService vaadinService;
+ private VaadinServletService vaadinService;
/**
* Wraps a http servlet response and an associated vaadin service
@@ -44,7 +43,7 @@ public class VaadinServletResponse extends HttpServletResponseWrapper implements
* the associated vaadin service
*/
public VaadinServletResponse(HttpServletResponse response,
- ServletService vaadinService) {
+ VaadinServletService vaadinService) {
super(response);
this.vaadinService = vaadinService;
}
@@ -80,7 +79,7 @@ public class VaadinServletResponse extends HttpServletResponseWrapper implements
}
@Override
- public ServletService getVaadinService() {
+ public VaadinServletService getVaadinService() {
return vaadinService;
}
} \ No newline at end of file
diff --git a/server/src/com/vaadin/server/VaadinServletService.java b/server/src/com/vaadin/server/VaadinServletService.java
new file mode 100644
index 0000000000..6c9e3eddaa
--- /dev/null
+++ b/server/src/com/vaadin/server/VaadinServletService.java
@@ -0,0 +1,198 @@
+/*
+ * Copyright 2011 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package com.vaadin.server;
+
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import javax.servlet.http.HttpServletRequest;
+
+import com.vaadin.server.VaadinServlet.RequestType;
+
+public class VaadinServletService extends VaadinService {
+ private final VaadinServlet servlet;
+
+ public VaadinServletService(VaadinServlet servlet,
+ DeploymentConfiguration deploymentConfiguration) {
+ super(deploymentConfiguration);
+ this.servlet = servlet;
+ }
+
+ protected VaadinServlet getServlet() {
+ return servlet;
+ }
+
+ @Override
+ public String getStaticFileLocation(VaadinRequest request) {
+ HttpServletRequest servletRequest = VaadinServletRequest.cast(request);
+ String staticFileLocation;
+ // if property is defined in configurations, use that
+ staticFileLocation = getDeploymentConfiguration()
+ .getApplicationOrSystemProperty(
+ VaadinServlet.PARAMETER_VAADIN_RESOURCES, null);
+ if (staticFileLocation != null) {
+ return staticFileLocation;
+ }
+
+ // the last (but most common) option is to generate default location
+ // from request
+
+ // if context is specified add it to widgetsetUrl
+ String ctxPath = servletRequest.getContextPath();
+
+ // FIXME: ctxPath.length() == 0 condition is probably unnecessary
+ // and
+ // might even be wrong.
+
+ if (ctxPath.length() == 0
+ && request.getAttribute("javax.servlet.include.context_path") != null) {
+ // include request (e.g portlet), get context path from
+ // attribute
+ ctxPath = (String) request
+ .getAttribute("javax.servlet.include.context_path");
+ }
+
+ // Remove heading and trailing slashes from the context path
+ ctxPath = VaadinServlet.removeHeadingOrTrailing(ctxPath, "/");
+
+ if (ctxPath.equals("")) {
+ return "";
+ } else {
+ return "/" + ctxPath;
+ }
+ }
+
+ @Override
+ public String getConfiguredWidgetset(VaadinRequest request) {
+ return getDeploymentConfiguration().getApplicationOrSystemProperty(
+ VaadinServlet.PARAMETER_WIDGETSET,
+ VaadinServlet.DEFAULT_WIDGETSET);
+ }
+
+ @Override
+ public String getConfiguredTheme(VaadinRequest request) {
+ // Use the default
+ return VaadinServlet.getDefaultTheme();
+ }
+
+ @Override
+ public boolean isStandalone(VaadinRequest request) {
+ return true;
+ }
+
+ @Override
+ public String getMimeType(String resourceName) {
+ return getServlet().getServletContext().getMimeType(resourceName);
+ }
+
+ @Override
+ public SystemMessages getSystemMessages() {
+ return ServletPortletHelper.DEFAULT_SYSTEM_MESSAGES;
+ }
+
+ @Override
+ public File getBaseDirectory() {
+ final String realPath = VaadinServlet.getResourcePath(
+ servlet.getServletContext(), "/");
+ if (realPath == null) {
+ return null;
+ }
+ return new File(realPath);
+ }
+
+ @Override
+ protected boolean requestCanCreateSession(VaadinRequest request) {
+ RequestType requestType = getRequestType(request);
+ if (requestType == RequestType.BROWSER_DETAILS) {
+ // This is the first request if you are embedding by writing the
+ // embedding code yourself
+ return true;
+ } else if (requestType == RequestType.OTHER) {
+ /*
+ * I.e URIs that are not RPC calls or static (theme) files.
+ */
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Gets the request type for the request.
+ *
+ * @param request
+ * the request to get a request type for
+ * @return the request type
+ *
+ * @deprecated might be refactored or removed before 7.0.0
+ */
+ @Deprecated
+ protected RequestType getRequestType(VaadinRequest request) {
+ RequestType type = (RequestType) request.getAttribute(RequestType.class
+ .getName());
+ if (type == null) {
+ type = getServlet().getRequestType(
+ VaadinServletRequest.cast(request));
+ request.setAttribute(RequestType.class.getName(), type);
+ }
+ return type;
+ }
+
+ @Override
+ protected URL getApplicationUrl(VaadinRequest request)
+ throws MalformedURLException {
+ return getServlet().getApplicationUrl(
+ VaadinServletRequest.cast(request));
+ }
+
+ @Override
+ protected AbstractCommunicationManager createCommunicationManager(
+ VaadinSession session) {
+ return new CommunicationManager(session);
+ }
+
+ public static HttpServletRequest getCurrentServletRequest() {
+ VaadinRequest currentRequest = VaadinService.getCurrentRequest();
+ try {
+ VaadinServletRequest request = VaadinServletRequest
+ .cast(currentRequest);
+ if (request != null) {
+ return request.getHttpServletRequest();
+ } else {
+ return null;
+ }
+ } catch (ClassCastException e) {
+ return null;
+ }
+ }
+
+ public static VaadinServletResponse getCurrentResponse() {
+ return (VaadinServletResponse) VaadinService.getCurrentResponse();
+ }
+
+ @Override
+ protected VaadinSession createVaadinSession(VaadinRequest request)
+ throws ServiceException {
+ return new VaadinServletSession();
+ }
+
+ @Override
+ public String getServiceName() {
+ return getServlet().getServletName();
+ }
+} \ No newline at end of file
diff --git a/server/src/com/vaadin/server/VaadinServletSession.java b/server/src/com/vaadin/server/VaadinServletSession.java
index 9a937b401b..fba0707812 100644
--- a/server/src/com/vaadin/server/VaadinServletSession.java
+++ b/server/src/com/vaadin/server/VaadinServletSession.java
@@ -24,7 +24,6 @@ import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.http.HttpSessionBindingListener;
-import com.vaadin.server.VaadinServlet.ServletService;
/**
* Web application context for Vaadin applications.
@@ -59,7 +58,7 @@ public class VaadinServletSession extends VaadinSession {
* to avoid session fixation attacks.
*/
public void reinitializeSession() {
- HttpServletRequest currentRequest = ServletService
+ HttpServletRequest currentRequest = VaadinServletService
.getCurrentServletRequest();
if (currentRequest == null) {
throw new IllegalStateException(