From 6335562c72fb193a2835a3a09b617aa6c90efea6 Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Thu, 20 Sep 2012 15:33:19 +0300 Subject: Rename WrappedXYZ -> VaadinXYZ but retain WrappedSession (#9633) --- .../com/vaadin/server/AbstractClientConnector.java | 4 +- .../server/AbstractCommunicationManager.java | 70 +++--- .../src/com/vaadin/server/AbstractUIProvider.java | 12 +- .../vaadin/server/BootstrapFragmentResponse.java | 8 +- server/src/com/vaadin/server/BootstrapHandler.java | 36 +-- .../com/vaadin/server/BootstrapPageResponse.java | 12 +- .../src/com/vaadin/server/BootstrapResponse.java | 12 +- server/src/com/vaadin/server/ClientConnector.java | 4 +- server/src/com/vaadin/server/CombinedRequest.java | 14 +- .../vaadin/server/ConnectorResourceHandler.java | 6 +- .../src/com/vaadin/server/DefaultUIProvider.java | 2 +- server/src/com/vaadin/server/DownloadStream.java | 8 +- .../src/com/vaadin/server/DragAndDropService.java | 4 +- .../vaadin/server/DynamicConnectorResource.java | 6 +- server/src/com/vaadin/server/GAEVaadinServlet.java | 18 +- .../com/vaadin/server/GlobalResourceHandler.java | 6 +- .../vaadin/server/LegacyApplicationUIProvider.java | 12 +- .../src/com/vaadin/server/LegacyVaadinPortlet.java | 4 +- .../src/com/vaadin/server/LegacyVaadinServlet.java | 2 +- server/src/com/vaadin/server/Page.java | 4 +- .../vaadin/server/PortletCommunicationManager.java | 14 +- server/src/com/vaadin/server/RequestHandler.java | 4 +- .../com/vaadin/server/ServletPortletHelper.java | 12 +- server/src/com/vaadin/server/UIProvider.java | 22 +- .../vaadin/server/UnsupportedBrowserHandler.java | 6 +- server/src/com/vaadin/server/VaadinPortlet.java | 128 +++++----- .../com/vaadin/server/VaadinPortletRequest.java | 228 +++++++++++++++++ .../com/vaadin/server/VaadinPortletResponse.java | 122 +++++++++ .../com/vaadin/server/VaadinPortletSession.java | 8 +- server/src/com/vaadin/server/VaadinRequest.java | 278 +++++++++++++++++++++ server/src/com/vaadin/server/VaadinResponse.java | 159 ++++++++++++ server/src/com/vaadin/server/VaadinService.java | 58 ++--- server/src/com/vaadin/server/VaadinServlet.java | 83 +++--- .../com/vaadin/server/VaadinServletRequest.java | 126 ++++++++++ .../com/vaadin/server/VaadinServletResponse.java | 86 +++++++ server/src/com/vaadin/server/VaadinSession.java | 24 +- .../server/VaadinSessionInitializeEvent.java | 6 +- server/src/com/vaadin/server/WebBrowser.java | 4 +- .../vaadin/server/WrappedHttpServletRequest.java | 126 ---------- .../vaadin/server/WrappedHttpServletResponse.java | 86 ------- .../com/vaadin/server/WrappedPortletRequest.java | 228 ----------------- .../com/vaadin/server/WrappedPortletResponse.java | 122 --------- server/src/com/vaadin/server/WrappedRequest.java | 278 --------------------- server/src/com/vaadin/server/WrappedResponse.java | 159 ------------ server/src/com/vaadin/ui/AbstractMedia.java | 8 +- server/src/com/vaadin/ui/LoginForm.java | 6 +- server/src/com/vaadin/ui/UI.java | 30 +-- 47 files changed, 1323 insertions(+), 1332 deletions(-) create mode 100644 server/src/com/vaadin/server/VaadinPortletRequest.java create mode 100644 server/src/com/vaadin/server/VaadinPortletResponse.java create mode 100644 server/src/com/vaadin/server/VaadinRequest.java create mode 100644 server/src/com/vaadin/server/VaadinResponse.java create mode 100644 server/src/com/vaadin/server/VaadinServletRequest.java create mode 100644 server/src/com/vaadin/server/VaadinServletResponse.java delete mode 100644 server/src/com/vaadin/server/WrappedHttpServletRequest.java delete mode 100644 server/src/com/vaadin/server/WrappedHttpServletResponse.java delete mode 100644 server/src/com/vaadin/server/WrappedPortletRequest.java delete mode 100644 server/src/com/vaadin/server/WrappedPortletResponse.java delete mode 100644 server/src/com/vaadin/server/WrappedRequest.java delete mode 100644 server/src/com/vaadin/server/WrappedResponse.java (limited to 'server/src') diff --git a/server/src/com/vaadin/server/AbstractClientConnector.java b/server/src/com/vaadin/server/AbstractClientConnector.java index 0f42c0a28f..278d726451 100644 --- a/server/src/com/vaadin/server/AbstractClientConnector.java +++ b/server/src/com/vaadin/server/AbstractClientConnector.java @@ -570,8 +570,8 @@ public abstract class AbstractClientConnector implements ClientConnector { } @Override - public boolean handleConnectorRequest(WrappedRequest request, - WrappedResponse response, String path) throws IOException { + public boolean handleConnectorRequest(VaadinRequest request, + VaadinResponse response, String path) throws IOException { String[] parts = path.split("/", 2); String key = parts[0]; diff --git a/server/src/com/vaadin/server/AbstractCommunicationManager.java b/server/src/com/vaadin/server/AbstractCommunicationManager.java index 07959b1558..49243a0589 100644 --- a/server/src/com/vaadin/server/AbstractCommunicationManager.java +++ b/server/src/com/vaadin/server/AbstractCommunicationManager.java @@ -117,8 +117,8 @@ public abstract class AbstractCommunicationManager implements Serializable { @Deprecated public interface Callback extends Serializable { - public void criticalNotification(WrappedRequest request, - WrappedResponse response, String cap, String msg, + public void criticalNotification(VaadinRequest request, + VaadinResponse response, String cap, String msg, String details, String outOfSyncURL) throws IOException; } @@ -219,8 +219,8 @@ public abstract class AbstractCommunicationManager implements Serializable { * @param boundary * @throws IOException */ - protected void doHandleSimpleMultipartFileUpload(WrappedRequest request, - WrappedResponse response, StreamVariable streamVariable, + protected void doHandleSimpleMultipartFileUpload(VaadinRequest request, + VaadinResponse response, StreamVariable streamVariable, String variableName, ClientConnector owner, String boundary) throws IOException { // multipart parsing, supports only one file for request, but that is @@ -323,8 +323,8 @@ public abstract class AbstractCommunicationManager implements Serializable { * @param contentLength * @throws IOException */ - protected void doHandleXhrFilePost(WrappedRequest request, - WrappedResponse response, StreamVariable streamVariable, + protected void doHandleXhrFilePost(VaadinRequest request, + VaadinResponse response, StreamVariable streamVariable, String variableName, ClientConnector owner, int contentLength) throws IOException { @@ -501,8 +501,8 @@ public abstract class AbstractCommunicationManager implements Serializable { * @param response * @throws IOException */ - protected void sendUploadResponse(WrappedRequest request, - WrappedResponse response) throws IOException { + protected void sendUploadResponse(VaadinRequest request, + VaadinResponse response) throws IOException { response.setContentType("text/html"); final OutputStream out = response.getOutputStream(); final PrintWriter outWriter = new PrintWriter(new BufferedWriter( @@ -516,7 +516,7 @@ public abstract class AbstractCommunicationManager implements Serializable { * Internally process a UIDL request from the client. * * This method calls - * {@link #handleVariables(WrappedRequest, WrappedResponse, Callback, VaadinSession, UI)} + * {@link #handleVariables(VaadinRequest, VaadinResponse, Callback, VaadinSession, UI)} * to process any changes to variables by the client and then repaints * affected components using {@link #paintAfterVariableChanges()}. * @@ -537,8 +537,8 @@ public abstract class AbstractCommunicationManager implements Serializable { * @throws InvalidUIDLSecurityKeyException * @throws JSONException */ - public void handleUidlRequest(WrappedRequest request, - WrappedResponse response, Callback callback, UI uI) + public void handleUidlRequest(VaadinRequest request, + VaadinResponse response, Callback callback, UI uI) throws IOException, InvalidUIDLSecurityKeyException, JSONException { checkWidgetsetVersion(request); @@ -623,7 +623,7 @@ public abstract class AbstractCommunicationManager implements Serializable { * * @param request */ - private void checkWidgetsetVersion(WrappedRequest request) { + private void checkWidgetsetVersion(VaadinRequest request) { String widgetsetVersion = request.getParameter("wsver"); if (widgetsetVersion == null) { // Only check when the widgetset version is reported. It is reported @@ -752,8 +752,8 @@ public abstract class AbstractCommunicationManager implements Serializable { * @throws IOException * @throws JSONException */ - private void paintAfterVariableChanges(WrappedRequest request, - WrappedResponse response, Callback callback, boolean repaintAll, + private void paintAfterVariableChanges(VaadinRequest request, + VaadinResponse response, Callback callback, boolean repaintAll, final PrintWriter outWriter, UI uI, boolean analyzeLayouts) throws PaintException, IOException, JSONException { openJsonMessage(outWriter, response); @@ -780,7 +780,7 @@ public abstract class AbstractCommunicationManager implements Serializable { * @param request * @return the security key UIDL or "" if the feature is turned off */ - public String getSecurityKeyUIDL(WrappedRequest request) { + public String getSecurityKeyUIDL(VaadinRequest request) { final String seckey = getSecurityKey(request); if (seckey != null) { return "\"" + ApplicationConstants.UIDL_SECURITY_TOKEN_ID + "\":\"" @@ -796,7 +796,7 @@ public abstract class AbstractCommunicationManager implements Serializable { * @param request * @return the security key */ - protected String getSecurityKey(WrappedRequest request) { + protected String getSecurityKey(VaadinRequest request) { String seckey = null; WrappedSession session = request.getWrappedSession(); seckey = (String) session @@ -811,7 +811,7 @@ public abstract class AbstractCommunicationManager implements Serializable { } @SuppressWarnings("unchecked") - public void writeUidlResponse(WrappedRequest request, boolean repaintAll, + public void writeUidlResponse(VaadinRequest request, boolean repaintAll, final PrintWriter outWriter, UI ui, boolean analyzeLayouts) throws PaintException, JSONException { ArrayList dirtyVisibleConnectors = new ArrayList(); @@ -1557,8 +1557,8 @@ public abstract class AbstractCommunicationManager implements Serializable { * * @return true if successful, false if there was an inconsistency */ - private boolean handleVariables(WrappedRequest request, - WrappedResponse response, Callback callback, VaadinSession session, + private boolean handleVariables(VaadinRequest request, + VaadinResponse response, Callback callback, VaadinSession session, UI uI) throws IOException, InvalidUIDLSecurityKeyException, JSONException { boolean success = true; @@ -1646,7 +1646,7 @@ public abstract class AbstractCommunicationManager implements Serializable { * @return true if the processing of the burst was successful and there were * no messages to non-existent components */ - public boolean handleBurst(WrappedRequest source, UI uI, final String burst) { + public boolean handleBurst(VaadinRequest source, UI uI, final String burst) { boolean success = true; try { Set enabledConnectors = new HashSet(); @@ -1908,7 +1908,7 @@ public abstract class AbstractCommunicationManager implements Serializable { * @return * @throws IOException */ - protected String getRequestPayload(WrappedRequest request) + protected String getRequestPayload(VaadinRequest request) throws IOException { int requestLength = request.getContentLength(); @@ -2185,7 +2185,7 @@ public abstract class AbstractCommunicationManager implements Serializable { * @param response */ protected void openJsonMessage(PrintWriter outWriter, - WrappedResponse response) { + VaadinResponse response) { // Sets the response type response.setContentType("application/json; charset=UTF-8"); // some dirt to prevent cross site scripting @@ -2392,7 +2392,7 @@ public abstract class AbstractCommunicationManager implements Serializable { *

* * @param request - * the wrapped request to get information from + * the Vaadin request to get information from * @param response * the response to which data can be written * @return returns true if a {@link RequestHandler} has @@ -2406,8 +2406,8 @@ public abstract class AbstractCommunicationManager implements Serializable { * * @since 7.0 */ - protected boolean handleOtherRequest(WrappedRequest request, - WrappedResponse response) throws IOException { + protected boolean handleOtherRequest(VaadinRequest request, + VaadinResponse response) throws IOException { // Use a copy to avoid ConcurrentModificationException for (RequestHandler handler : new ArrayList( session.getRequestHandlers())) { @@ -2419,8 +2419,8 @@ public abstract class AbstractCommunicationManager implements Serializable { return false; } - public void handleBrowserDetailsRequest(WrappedRequest request, - WrappedResponse response, VaadinSession session) throws IOException { + public void handleBrowserDetailsRequest(VaadinRequest request, + VaadinResponse response, VaadinSession session) throws IOException { session.getLock().lock(); @@ -2428,7 +2428,7 @@ public abstract class AbstractCommunicationManager implements Serializable { assert UI.getCurrent() == null; CombinedRequest combinedRequest = new CombinedRequest(request); - CurrentInstance.set(WrappedRequest.class, combinedRequest); + CurrentInstance.set(VaadinRequest.class, combinedRequest); response.setContentType("application/json; charset=UTF-8"); @@ -2475,7 +2475,7 @@ public abstract class AbstractCommunicationManager implements Serializable { * @throws JSONException * if an exception occurs while encoding output */ - protected String getInitialUIDL(WrappedRequest request, UI uI) + protected String getInitialUIDL(VaadinRequest request, UI uI) throws PaintException, JSONException { // TODO maybe unify writeUidlResponse()? StringWriter sWriter = new StringWriter(); @@ -2505,8 +2505,8 @@ public abstract class AbstractCommunicationManager implements Serializable { * * @throws IOException */ - public void serveConnectorResource(WrappedRequest request, - WrappedResponse response) throws IOException { + public void serveConnectorResource(VaadinRequest request, + VaadinResponse response) throws IOException { String pathInfo = request.getRequestPathInfo(); // + 2 to also remove beginning and ending slashes @@ -2602,8 +2602,8 @@ public abstract class AbstractCommunicationManager implements Serializable { * @throws IOException * @throws InvalidUIDLSecurityKeyException */ - public void handleFileUpload(VaadinSession session, WrappedRequest request, - WrappedResponse response) throws IOException, + public void handleFileUpload(VaadinSession session, VaadinRequest request, + VaadinResponse response) throws IOException, InvalidUIDLSecurityKeyException { /* @@ -2663,8 +2663,8 @@ public abstract class AbstractCommunicationManager implements Serializable { * @param session * @throws IOException */ - public void handleHeartbeatRequest(WrappedRequest request, - WrappedResponse response, VaadinSession session) throws IOException { + public void handleHeartbeatRequest(VaadinRequest request, + VaadinResponse response, VaadinSession session) throws IOException { UI ui = null; try { int uiId = Integer.parseInt(request diff --git a/server/src/com/vaadin/server/AbstractUIProvider.java b/server/src/com/vaadin/server/AbstractUIProvider.java index 5208997a65..32322fde65 100644 --- a/server/src/com/vaadin/server/AbstractUIProvider.java +++ b/server/src/com/vaadin/server/AbstractUIProvider.java @@ -27,7 +27,7 @@ import com.vaadin.ui.UI; public abstract class AbstractUIProvider implements UIProvider { @Override - public UI createInstance(WrappedRequest request, + public UI createInstance(VaadinRequest request, Class type) { try { return type.newInstance(); @@ -75,7 +75,7 @@ public abstract class AbstractUIProvider implements UIProvider { } @Override - public String getTheme(WrappedRequest request, + public String getTheme(VaadinRequest request, Class uiClass) { Theme uiTheme = getAnnotationFor(uiClass, Theme.class); if (uiTheme != null) { @@ -86,7 +86,7 @@ public abstract class AbstractUIProvider implements UIProvider { } @Override - public String getWidgetset(WrappedRequest request, + public String getWidgetset(VaadinRequest request, Class uiClass) { Widgetset uiWidgetset = getAnnotationFor(uiClass, Widgetset.class); if (uiWidgetset != null) { @@ -97,7 +97,7 @@ public abstract class AbstractUIProvider implements UIProvider { } @Override - public boolean isPreservedOnRefresh(WrappedRequest request, + public boolean isPreservedOnRefresh(VaadinRequest request, Class uiClass) { PreserveOnRefresh preserveOnRefresh = getAnnotationFor(uiClass, PreserveOnRefresh.class); @@ -105,7 +105,7 @@ public abstract class AbstractUIProvider implements UIProvider { } @Override - public String getPageTitle(WrappedRequest request, + public String getPageTitle(VaadinRequest request, Class uiClass) { Title titleAnnotation = getAnnotationFor(uiClass, Title.class); if (titleAnnotation == null) { @@ -116,7 +116,7 @@ public abstract class AbstractUIProvider implements UIProvider { } @Override - public UI getExistingUI(WrappedRequest request) { + public UI getExistingUI(VaadinRequest request) { return null; } } diff --git a/server/src/com/vaadin/server/BootstrapFragmentResponse.java b/server/src/com/vaadin/server/BootstrapFragmentResponse.java index ea13a04b8f..0269d1cfc0 100644 --- a/server/src/com/vaadin/server/BootstrapFragmentResponse.java +++ b/server/src/com/vaadin/server/BootstrapFragmentResponse.java @@ -36,13 +36,13 @@ public class BootstrapFragmentResponse extends BootstrapResponse { /** * Crate a new bootstrap fragment response. * - * @see BootstrapResponse#BootstrapResponse(BootstrapHandler, - * WrappedRequest, VaadinSession, Class) + * @see BootstrapResponse#BootstrapResponse(BootstrapHandler, VaadinRequest, + * VaadinSession, Class) * * @param handler * the bootstrap handler that is firing the event * @param request - * the wrapped request for which the bootstrap page should be + * the Vaadin request for which the bootstrap page should be * generated * @param session * the vaadin session for which the bootstrap page should be @@ -54,7 +54,7 @@ public class BootstrapFragmentResponse extends BootstrapResponse { * application HTML */ public BootstrapFragmentResponse(BootstrapHandler handler, - WrappedRequest request, VaadinSession session, + VaadinRequest request, VaadinSession session, Class uiClass, List fragmentNodes) { super(handler, request, session, uiClass); this.fragmentNodes = fragmentNodes; diff --git a/server/src/com/vaadin/server/BootstrapHandler.java b/server/src/com/vaadin/server/BootstrapHandler.java index a25c1860ef..7e4fd653bf 100644 --- a/server/src/com/vaadin/server/BootstrapHandler.java +++ b/server/src/com/vaadin/server/BootstrapHandler.java @@ -54,24 +54,24 @@ public abstract class BootstrapHandler implements RequestHandler { protected class BootstrapContext implements Serializable { - private final WrappedResponse response; + private final VaadinResponse response; private final BootstrapFragmentResponse bootstrapResponse; private String widgetsetName; private String themeName; private String appId; - public BootstrapContext(WrappedResponse response, + public BootstrapContext(VaadinResponse response, BootstrapFragmentResponse bootstrapResponse) { this.response = response; this.bootstrapResponse = bootstrapResponse; } - public WrappedResponse getResponse() { + public VaadinResponse getResponse() { return response; } - public WrappedRequest getRequest() { + public VaadinRequest getRequest() { return bootstrapResponse.getRequest(); } @@ -111,8 +111,8 @@ public abstract class BootstrapHandler implements RequestHandler { } @Override - public boolean handleRequest(VaadinSession session, WrappedRequest request, - WrappedResponse response) throws IOException { + public boolean handleRequest(VaadinSession session, VaadinRequest request, + VaadinResponse response) throws IOException { try { Class uiClass = session.getUIClass(request); @@ -136,8 +136,8 @@ public abstract class BootstrapHandler implements RequestHandler { } private String getBootstrapHtml(BootstrapContext context) { - WrappedRequest request = context.getRequest(); - WrappedResponse response = context.getResponse(); + VaadinRequest request = context.getRequest(); + VaadinResponse response = context.getResponse(); VaadinService vaadinService = request.getVaadinService(); BootstrapFragmentResponse fragmentResponse = context @@ -174,7 +174,7 @@ public abstract class BootstrapHandler implements RequestHandler { } } - private void sendBootstrapHeaders(WrappedResponse response, + private void sendBootstrapHeaders(VaadinResponse response, Map headers) { Set> entrySet = headers.entrySet(); for (Entry header : entrySet) { @@ -190,7 +190,7 @@ public abstract class BootstrapHandler implements RequestHandler { } } - private void writeBootstrapPage(WrappedResponse response, String html) + private void writeBootstrapPage(VaadinResponse response, String html) throws IOException { response.setContentType("text/html"); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter( @@ -250,8 +250,8 @@ public abstract class BootstrapHandler implements RequestHandler { body.addClass(ApplicationConstants.GENERATED_BODY_CLASSNAME); } - private BootstrapContext createContext(WrappedRequest request, - WrappedResponse response, VaadinSession application, + private BootstrapContext createContext(VaadinRequest request, + VaadinResponse response, VaadinSession application, Class uiClass) { BootstrapContext context = new BootstrapContext(response, new BootstrapFragmentResponse(this, request, application, @@ -274,7 +274,7 @@ public abstract class BootstrapHandler implements RequestHandler { protected abstract String getApplicationId(BootstrapContext context); public String getWidgetsetForUI(BootstrapContext context) { - WrappedRequest request = context.getRequest(); + VaadinRequest request = context.getRequest(); String widgetset = context.getVaadinSession() .getUiProvider(context.getRequest(), context.getUIClass()) @@ -331,7 +331,7 @@ public abstract class BootstrapHandler implements RequestHandler { .append("You have to enable javascript in your browser to use an application built with Vaadin."); fragmentNodes.add(mainDiv); - WrappedRequest request = context.getRequest(); + VaadinRequest request = context.getRequest(); VaadinService vaadinService = request.getVaadinService(); String staticFileLocation = vaadinService @@ -423,7 +423,7 @@ public abstract class BootstrapHandler implements RequestHandler { throws JSONException { JSONObject defaults = new JSONObject(); - WrappedRequest request = context.getRequest(); + VaadinRequest request = context.getRequest(); VaadinSession session = context.getVaadinSession(); VaadinService vaadinService = request.getVaadinService(); @@ -486,7 +486,7 @@ public abstract class BootstrapHandler implements RequestHandler { * @return */ public String getThemeUri(BootstrapContext context, String themeName) { - WrappedRequest request = context.getRequest(); + VaadinRequest request = context.getRequest(); final String staticFilePath = request.getVaadinService() .getStaticFileLocation(request); return staticFilePath + "/" + VaadinServlet.THEME_DIRECTORY_PATH @@ -514,7 +514,7 @@ public abstract class BootstrapHandler implements RequestHandler { public String findAndEscapeThemeName(BootstrapContext context) { String themeName = getThemeName(context); if (themeName == null) { - WrappedRequest request = context.getRequest(); + VaadinRequest request = context.getRequest(); themeName = request.getVaadinService().getConfiguredTheme(request); } @@ -525,7 +525,7 @@ public abstract class BootstrapHandler implements RequestHandler { return themeName; } - protected void writeError(WrappedResponse response, Throwable e) + protected void writeError(VaadinResponse response, Throwable e) throws IOException { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getLocalizedMessage()); diff --git a/server/src/com/vaadin/server/BootstrapPageResponse.java b/server/src/com/vaadin/server/BootstrapPageResponse.java index 0b98c59e22..72bc2163e6 100644 --- a/server/src/com/vaadin/server/BootstrapPageResponse.java +++ b/server/src/com/vaadin/server/BootstrapPageResponse.java @@ -38,13 +38,13 @@ public class BootstrapPageResponse extends BootstrapResponse { /** * Crate a new bootstrap page response. * - * @see BootstrapResponse#BootstrapResponse(BootstrapHandler, - * WrappedRequest, VaadinSession, Class) + * @see BootstrapResponse#BootstrapResponse(BootstrapHandler, VaadinRequest, + * VaadinSession, Class) * * @param handler * the bootstrap handler that is firing the event * @param request - * the wrapped request for which the bootstrap page should be + * the Vaadin request for which the bootstrap page should be * generated * @param session * the vaadin session for which the bootstrap page should be @@ -57,7 +57,7 @@ public class BootstrapPageResponse extends BootstrapResponse { * a map into which header data can be added */ public BootstrapPageResponse(BootstrapHandler handler, - WrappedRequest request, VaadinSession session, + VaadinRequest request, VaadinSession session, Class uiClass, Document document, Map headers) { super(handler, request, session, uiClass); @@ -69,7 +69,7 @@ public class BootstrapPageResponse extends BootstrapResponse { * Sets a header value that will be added to the HTTP response. If the * header had already been set, the new value overwrites the previous one. * - * @see WrappedResponse#setHeader(String, String) + * @see VaadinResponse#setHeader(String, String) * * @param name * the name of the header @@ -86,7 +86,7 @@ public class BootstrapPageResponse extends BootstrapResponse { * overwrites the previous one. * * @see #setHeader(String, String) - * @see WrappedResponse#setDateHeader(String, long) + * @see VaadinResponse#setDateHeader(String, long) * * @param name * the name of the header diff --git a/server/src/com/vaadin/server/BootstrapResponse.java b/server/src/com/vaadin/server/BootstrapResponse.java index c0c8d4e699..86b37de22e 100644 --- a/server/src/com/vaadin/server/BootstrapResponse.java +++ b/server/src/com/vaadin/server/BootstrapResponse.java @@ -28,7 +28,7 @@ import com.vaadin.ui.UI; * @since 7.0.0 */ public abstract class BootstrapResponse extends EventObject { - private final WrappedRequest request; + private final VaadinRequest request; private final VaadinSession session; private final Class uiClass; @@ -38,14 +38,14 @@ public abstract class BootstrapResponse extends EventObject { * @param handler * the bootstrap handler that is firing the event * @param request - * the wrapped request for which the bootstrap page should be + * the Vaadin request for which the bootstrap page should be * generated * @param session * the session for which the bootstrap page should be generated * @param uiClass * the class of the UI that will be displayed on the page */ - public BootstrapResponse(BootstrapHandler handler, WrappedRequest request, + public BootstrapResponse(BootstrapHandler handler, VaadinRequest request, VaadinSession session, Class uiClass) { super(handler); this.request = request; @@ -65,14 +65,14 @@ public abstract class BootstrapResponse extends EventObject { /** * Gets the request for which the generated bootstrap HTML will be the * response. This can be used to read request headers and other additional - * information. Please note that {@link WrappedRequest#getBrowserDetails()} + * information. Please note that {@link VaadinRequest#getBrowserDetails()} * will not be available because the bootstrap page is generated before the * bootstrap javascript has had a chance to send any information back to the * server. * - * @return the wrapped request that is being handled + * @return the Vaadin request that is being handled */ - public WrappedRequest getRequest() { + public VaadinRequest getRequest() { return request; } diff --git a/server/src/com/vaadin/server/ClientConnector.java b/server/src/com/vaadin/server/ClientConnector.java index 65c0ca366a..b38f2a9037 100644 --- a/server/src/com/vaadin/server/ClientConnector.java +++ b/server/src/com/vaadin/server/ClientConnector.java @@ -237,6 +237,6 @@ public interface ClientConnector extends Connector, RpcTarget { * @throws IOException * if there is a problem generating a response. */ - public boolean handleConnectorRequest(WrappedRequest request, - WrappedResponse response, String path) throws IOException; + public boolean handleConnectorRequest(VaadinRequest request, + VaadinResponse response, String path) throws IOException; } diff --git a/server/src/com/vaadin/server/CombinedRequest.java b/server/src/com/vaadin/server/CombinedRequest.java index 91c5093ece..0a7da84049 100644 --- a/server/src/com/vaadin/server/CombinedRequest.java +++ b/server/src/com/vaadin/server/CombinedRequest.java @@ -29,17 +29,17 @@ import org.json.JSONException; import org.json.JSONObject; /** - * A {@link WrappedRequest} with path and parameters from one request and - * {@link WrappedRequest.BrowserDetails} extracted from another request. + * A {@link VaadinRequest} with path and parameters from one request and + * {@link VaadinRequest.BrowserDetails} extracted from another request. * * This class is intended to be used for a two request initialization where the * first request fetches the actual application page and the second request * contains information extracted from the browser using javascript. * */ -public class CombinedRequest implements WrappedRequest { +public class CombinedRequest implements VaadinRequest { - private final WrappedRequest secondRequest; + private final VaadinRequest secondRequest; private Map parameterMap; /** @@ -52,7 +52,7 @@ public class CombinedRequest implements WrappedRequest { * @throws JSONException * if the initialParams parameter can not be decoded */ - public CombinedRequest(WrappedRequest secondRequest) throws JSONException { + public CombinedRequest(VaadinRequest secondRequest) throws JSONException { this.secondRequest = secondRequest; HashMap map = new HashMap(); @@ -156,9 +156,9 @@ public class CombinedRequest implements WrappedRequest { * Gets the original second request. This can be used e.g. if a request * parameter from the second request is required. * - * @return the original second wrapped request + * @return the original second Vaadin request */ - public WrappedRequest getSecondRequest() { + public VaadinRequest getSecondRequest() { return secondRequest; } diff --git a/server/src/com/vaadin/server/ConnectorResourceHandler.java b/server/src/com/vaadin/server/ConnectorResourceHandler.java index 50e5377e8d..1edd497d7c 100644 --- a/server/src/com/vaadin/server/ConnectorResourceHandler.java +++ b/server/src/com/vaadin/server/ConnectorResourceHandler.java @@ -25,7 +25,7 @@ public class ConnectorResourceHandler implements RequestHandler { @Override public boolean handleRequest(VaadinSession session, - WrappedRequest request, WrappedResponse response) + VaadinRequest request, VaadinResponse response) throws IOException { String requestPath = request.getRequestPathInfo(); if (requestPath == null) { @@ -68,8 +68,8 @@ public class ConnectorResourceHandler implements RequestHandler { } } - private static boolean error(WrappedRequest request, - WrappedResponse response, String logMessage) throws IOException { + private static boolean error(VaadinRequest request, + VaadinResponse response, String logMessage) throws IOException { getLogger().log(Level.WARNING, logMessage); response.sendError(HttpServletResponse.SC_NOT_FOUND, request.getRequestPathInfo() + " can not be found"); diff --git a/server/src/com/vaadin/server/DefaultUIProvider.java b/server/src/com/vaadin/server/DefaultUIProvider.java index c4a8069269..87bb7d27c2 100644 --- a/server/src/com/vaadin/server/DefaultUIProvider.java +++ b/server/src/com/vaadin/server/DefaultUIProvider.java @@ -21,7 +21,7 @@ import com.vaadin.ui.UI; public class DefaultUIProvider extends AbstractUIProvider { @Override - public Class getUIClass(WrappedRequest request) { + public Class getUIClass(VaadinRequest request) { Object uiClassNameObj = request.getVaadinService() .getDeploymentConfiguration().getInitParameters() .getProperty(VaadinSession.UI_PARAMETER); diff --git a/server/src/com/vaadin/server/DownloadStream.java b/server/src/com/vaadin/server/DownloadStream.java index 0c00f96832..3ba8b3d39a 100644 --- a/server/src/com/vaadin/server/DownloadStream.java +++ b/server/src/com/vaadin/server/DownloadStream.java @@ -220,7 +220,7 @@ public class DownloadStream implements Serializable { } /** - * Writes this download stream to a wrapped response. This takes care of + * Writes this download stream to a Vaadin response. This takes care of * setting response headers according to what is defined in this download * stream ({@link #getContentType()}, {@link #getCacheTime()}, * {@link #getFileName()}) and transferring the data from the stream ( @@ -233,14 +233,14 @@ public class DownloadStream implements Serializable { * @param request * the request for which the response should be written * @param response - * the wrapped response to write this download stream to + * the Vaadin response to write this download stream to * * @throws IOException - * passed through from the wrapped response + * passed through from the Vaadin response * * @since 7.0 */ - public void writeResponse(WrappedRequest request, WrappedResponse response) + public void writeResponse(VaadinRequest request, VaadinResponse response) throws IOException { if (getParameter("Location") != null) { response.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY); diff --git a/server/src/com/vaadin/server/DragAndDropService.java b/server/src/com/vaadin/server/DragAndDropService.java index 2d0a9e73e9..69ab997b18 100644 --- a/server/src/com/vaadin/server/DragAndDropService.java +++ b/server/src/com/vaadin/server/DragAndDropService.java @@ -342,8 +342,8 @@ public class DragAndDropService implements VariableOwner, ClientConnector { } @Override - public boolean handleConnectorRequest(WrappedRequest request, - WrappedResponse response, String path) throws IOException { + public boolean handleConnectorRequest(VaadinRequest request, + VaadinResponse response, String path) throws IOException { return false; } } diff --git a/server/src/com/vaadin/server/DynamicConnectorResource.java b/server/src/com/vaadin/server/DynamicConnectorResource.java index 8269f261f7..264afa3f59 100644 --- a/server/src/com/vaadin/server/DynamicConnectorResource.java +++ b/server/src/com/vaadin/server/DynamicConnectorResource.java @@ -23,7 +23,7 @@ import com.vaadin.service.FileTypeResolver; /** * A resource that is served by calling - * {@link ClientConnector#handleConnectorRequest(WrappedRequest, WrappedResponse, String)} + * {@link ClientConnector#handleConnectorRequest(VaadinRequest, VaadinResponse, String)} * with appropriate parameters. * * @author Vaadin Ltd @@ -39,7 +39,7 @@ public class DynamicConnectorResource implements Resource { /** * Creates a DynamicConnectorResoruce for the given connector that will be * served by calling - * {@link ClientConnector#handleConnectorRequest(WrappedRequest, WrappedResponse, String)} + * {@link ClientConnector#handleConnectorRequest(VaadinRequest, VaadinResponse, String)} * with the given path. * * @param connector @@ -54,7 +54,7 @@ public class DynamicConnectorResource implements Resource { /** * Creates a DynamicConnectorResoruce for the given connector that will be * served by calling - * {@link ClientConnector#handleConnectorRequest(WrappedRequest, WrappedResponse, String)} + * {@link ClientConnector#handleConnectorRequest(VaadinRequest, VaadinResponse, String)} * with the given path and the given request parameters. * * @param connector diff --git a/server/src/com/vaadin/server/GAEVaadinServlet.java b/server/src/com/vaadin/server/GAEVaadinServlet.java index 44aca14fe3..df7daedfb8 100644 --- a/server/src/com/vaadin/server/GAEVaadinServlet.java +++ b/server/src/com/vaadin/server/GAEVaadinServlet.java @@ -133,8 +133,8 @@ public class GAEVaadinServlet extends VaadinServlet { private static final String PROPERTY_APPENGINE_EXPIRES = "_expires"; protected void sendDeadlineExceededNotification( - WrappedHttpServletRequest request, - WrappedHttpServletResponse response) throws IOException { + VaadinServletRequest request, + VaadinServletResponse response) throws IOException { criticalNotification( request, response, @@ -144,8 +144,8 @@ public class GAEVaadinServlet extends VaadinServlet { } protected void sendNotSerializableNotification( - WrappedHttpServletRequest request, - WrappedHttpServletResponse response) throws IOException { + VaadinServletRequest request, + VaadinServletResponse response) throws IOException { criticalNotification( request, response, @@ -156,8 +156,8 @@ public class GAEVaadinServlet extends VaadinServlet { } protected void sendCriticalErrorNotification( - WrappedHttpServletRequest request, - WrappedHttpServletResponse response) throws IOException { + VaadinServletRequest request, + VaadinServletResponse response) throws IOException { criticalNotification( request, response, @@ -171,9 +171,9 @@ public class GAEVaadinServlet extends VaadinServlet { protected void service(HttpServletRequest unwrappedRequest, HttpServletResponse unwrappedResponse) throws ServletException, IOException { - WrappedHttpServletRequest request = new WrappedHttpServletRequest( + VaadinServletRequest request = new VaadinServletRequest( unwrappedRequest, getVaadinService()); - WrappedHttpServletResponse response = new WrappedHttpServletResponse( + VaadinServletResponse response = new VaadinServletResponse( unwrappedResponse, getVaadinService()); if (isCleanupRequest(request)) { @@ -342,7 +342,7 @@ public class GAEVaadinServlet extends VaadinServlet { // will create new context if the above did not try { return getVaadinService().findVaadinSession( - createWrappedRequest(request)); + createVaadinRequest(request)); } catch (Exception e) { throw new ServletException(e); } diff --git a/server/src/com/vaadin/server/GlobalResourceHandler.java b/server/src/com/vaadin/server/GlobalResourceHandler.java index 33a965369d..a7fff8ae64 100644 --- a/server/src/com/vaadin/server/GlobalResourceHandler.java +++ b/server/src/com/vaadin/server/GlobalResourceHandler.java @@ -66,7 +66,7 @@ public class GlobalResourceHandler implements RequestHandler { @Override public boolean handleRequest(VaadinSession session, - WrappedRequest request, WrappedResponse response) + VaadinRequest request, VaadinResponse response) throws IOException { String pathInfo = request.getRequestPathInfo(); if (pathInfo == null) { @@ -225,8 +225,8 @@ public class GlobalResourceHandler implements RequestHandler { return Logger.getLogger(GlobalResourceHandler.class.getName()); } - private static boolean error(WrappedRequest request, - WrappedResponse response, String logMessage) throws IOException { + private static boolean error(VaadinRequest request, + VaadinResponse response, String logMessage) throws IOException { getLogger().log(Level.WARNING, logMessage); response.sendError(HttpServletResponse.SC_NOT_FOUND, request.getRequestPathInfo() + " can not be found"); diff --git a/server/src/com/vaadin/server/LegacyApplicationUIProvider.java b/server/src/com/vaadin/server/LegacyApplicationUIProvider.java index c0f64088b4..0681d0bee1 100644 --- a/server/src/com/vaadin/server/LegacyApplicationUIProvider.java +++ b/server/src/com/vaadin/server/LegacyApplicationUIProvider.java @@ -30,7 +30,7 @@ public abstract class LegacyApplicationUIProvider extends AbstractUIProvider { .compile("^/?([^/]+).*"); @Override - public Class getUIClass(WrappedRequest request) { + public Class getUIClass(VaadinRequest request) { UI uiInstance = getUIInstance(request); if (uiInstance != null) { return uiInstance.getClass(); @@ -39,12 +39,12 @@ public abstract class LegacyApplicationUIProvider extends AbstractUIProvider { } @Override - public UI createInstance(WrappedRequest request, Class type) { + public UI createInstance(VaadinRequest request, Class type) { return getUIInstance(request); } @Override - public String getTheme(WrappedRequest request, Class uiClass) { + public String getTheme(VaadinRequest request, Class uiClass) { LegacyApplication application = getApplication(); if (application != null) { return application.getTheme(); @@ -54,7 +54,7 @@ public abstract class LegacyApplicationUIProvider extends AbstractUIProvider { } @Override - public String getPageTitle(WrappedRequest request, + public String getPageTitle(VaadinRequest request, Class uiClass) { UI uiInstance = getUIInstance(request); if (uiInstance != null) { @@ -64,7 +64,7 @@ public abstract class LegacyApplicationUIProvider extends AbstractUIProvider { } } - private UI getUIInstance(WrappedRequest request) { + private UI getUIInstance(VaadinRequest request) { String pathInfo = request.getRequestPathInfo(); String name = null; if (pathInfo != null && pathInfo.length() > 0) { @@ -94,7 +94,7 @@ public abstract class LegacyApplicationUIProvider extends AbstractUIProvider { * {@inheritDoc} */ @Override - public UI getExistingUI(WrappedRequest request) { + public UI getExistingUI(VaadinRequest request) { UI uiInstance = getUIInstance(request); if (uiInstance == null || uiInstance.getUIId() == -1) { // Not initialized -> Let go through createUIInstance to make it diff --git a/server/src/com/vaadin/server/LegacyVaadinPortlet.java b/server/src/com/vaadin/server/LegacyVaadinPortlet.java index 6aa8fb7165..de970d5c17 100644 --- a/server/src/com/vaadin/server/LegacyVaadinPortlet.java +++ b/server/src/com/vaadin/server/LegacyVaadinPortlet.java @@ -54,7 +54,7 @@ public class LegacyVaadinPortlet extends VaadinPortlet { VaadinSessionInitializeEvent event) throws ServiceException { try { - onVaadinSessionStarted(WrappedPortletRequest + onVaadinSessionStarted(VaadinPortletRequest .cast(event.getRequest()), (VaadinPortletSession) event .getVaadinSession()); @@ -85,7 +85,7 @@ public class LegacyVaadinPortlet extends VaadinPortlet { } } - private void onVaadinSessionStarted(WrappedPortletRequest request, + private void onVaadinSessionStarted(VaadinPortletRequest request, VaadinPortletSession session) throws PortletException { session.addUIProvider(provider); } diff --git a/server/src/com/vaadin/server/LegacyVaadinServlet.java b/server/src/com/vaadin/server/LegacyVaadinServlet.java index ace29e9e1f..69655eba34 100644 --- a/server/src/com/vaadin/server/LegacyVaadinServlet.java +++ b/server/src/com/vaadin/server/LegacyVaadinServlet.java @@ -90,7 +90,7 @@ public class LegacyVaadinServlet extends VaadinServlet { return true; } - private void onVaadinSessionStarted(WrappedRequest wrappedRequest, + private void onVaadinSessionStarted(VaadinRequest request, VaadinSession session) throws ServletException { session.addUIProvider(provider); } diff --git a/server/src/com/vaadin/server/Page.java b/server/src/com/vaadin/server/Page.java index bfbfe53429..e17643eb81 100644 --- a/server/src/com/vaadin/server/Page.java +++ b/server/src/com/vaadin/server/Page.java @@ -24,7 +24,7 @@ import java.util.LinkedList; import java.util.List; import com.vaadin.event.EventRouter; -import com.vaadin.server.WrappedRequest.BrowserDetails; +import com.vaadin.server.VaadinRequest.BrowserDetails; import com.vaadin.shared.ui.BorderStyle; import com.vaadin.shared.ui.ui.PageClientRpc; import com.vaadin.shared.ui.ui.UIConstants; @@ -404,7 +404,7 @@ public class Page implements Serializable { return fragment; } - public void init(WrappedRequest request) { + public void init(VaadinRequest request) { BrowserDetails browserDetails = request.getBrowserDetails(); if (browserDetails != null) { fragment = browserDetails.getUriFragment(); diff --git a/server/src/com/vaadin/server/PortletCommunicationManager.java b/server/src/com/vaadin/server/PortletCommunicationManager.java index c307c50348..449d39b38b 100644 --- a/server/src/com/vaadin/server/PortletCommunicationManager.java +++ b/server/src/com/vaadin/server/PortletCommunicationManager.java @@ -53,9 +53,9 @@ public class PortletCommunicationManager extends AbstractCommunicationManager { return new BootstrapHandler() { @Override public boolean handleRequest(VaadinSession session, - WrappedRequest request, WrappedResponse response) + VaadinRequest request, VaadinResponse response) throws IOException { - PortletRequest portletRequest = WrappedPortletRequest.cast( + PortletRequest portletRequest = VaadinPortletRequest.cast( request).getPortletRequest(); if (portletRequest instanceof RenderRequest) { return super.handleRequest(session, request, response); @@ -66,7 +66,7 @@ public class PortletCommunicationManager extends AbstractCommunicationManager { @Override protected String getApplicationId(BootstrapContext context) { - PortletRequest portletRequest = WrappedPortletRequest.cast( + PortletRequest portletRequest = VaadinPortletRequest.cast( context.getRequest()).getPortletRequest(); /* * We need to generate a unique ID because some portals already @@ -81,7 +81,7 @@ public class PortletCommunicationManager extends AbstractCommunicationManager { } private RenderResponse getRenderResponse(BootstrapContext context) { - PortletResponse response = ((WrappedPortletResponse) context + PortletResponse response = ((VaadinPortletResponse) context .getResponse()).getPortletResponse(); RenderResponse renderResponse = (RenderResponse) response; @@ -115,7 +115,7 @@ public class PortletCommunicationManager extends AbstractCommunicationManager { throws JSONException, IOException { // fixed base theme to use - all portal pages with Vaadin // applications will load this exactly once - String portalTheme = WrappedPortletRequest.cast( + String portalTheme = VaadinPortletRequest.cast( context.getRequest()).getPortalProperty( VaadinPortlet.PORTAL_PARAMETER_VAADIN_THEME); if (portalTheme != null @@ -143,9 +143,9 @@ public class PortletCommunicationManager extends AbstractCommunicationManager { BootstrapContext context) throws JSONException, PaintException { JSONObject parameters = super.getApplicationParameters(context); - WrappedPortletResponse wrappedPortletResponse = (WrappedPortletResponse) context + VaadinPortletResponse response = (VaadinPortletResponse) context .getResponse(); - MimeResponse portletResponse = (MimeResponse) wrappedPortletResponse + MimeResponse portletResponse = (MimeResponse) response .getPortletResponse(); ResourceURL resourceURL = portletResponse.createResourceURL(); resourceURL.setResourceID("browserDetails"); diff --git a/server/src/com/vaadin/server/RequestHandler.java b/server/src/com/vaadin/server/RequestHandler.java index c2409af2d7..8eb2d6d746 100644 --- a/server/src/com/vaadin/server/RequestHandler.java +++ b/server/src/com/vaadin/server/RequestHandler.java @@ -41,7 +41,7 @@ public interface RequestHandler extends Serializable { * handlers should be called, otherwise false * @throws IOException */ - boolean handleRequest(VaadinSession session, WrappedRequest request, - WrappedResponse response) throws IOException; + boolean handleRequest(VaadinSession session, VaadinRequest request, + VaadinResponse response) throws IOException; } diff --git a/server/src/com/vaadin/server/ServletPortletHelper.java b/server/src/com/vaadin/server/ServletPortletHelper.java index 6b686c59c3..536af12239 100644 --- a/server/src/com/vaadin/server/ServletPortletHelper.java +++ b/server/src/com/vaadin/server/ServletPortletHelper.java @@ -77,7 +77,7 @@ class ServletPortletHelper implements Serializable { } } - private static boolean hasPathPrefix(WrappedRequest request, String prefix) { + private static boolean hasPathPrefix(VaadinRequest request, String prefix) { String pathInfo = request.getRequestPathInfo(); if (pathInfo == null) { @@ -95,24 +95,24 @@ class ServletPortletHelper implements Serializable { return false; } - public static boolean isFileUploadRequest(WrappedRequest request) { + public static boolean isFileUploadRequest(VaadinRequest request) { return hasPathPrefix(request, UPLOAD_URL_PREFIX); } - public static boolean isConnectorResourceRequest(WrappedRequest request) { + public static boolean isConnectorResourceRequest(VaadinRequest request) { return hasPathPrefix(request, ApplicationConstants.CONNECTOR_RESOURCE_PREFIX + "/"); } - public static boolean isUIDLRequest(WrappedRequest request) { + public static boolean isUIDLRequest(VaadinRequest request) { return hasPathPrefix(request, ApplicationConstants.UIDL_REQUEST_PATH); } - public static boolean isAppRequest(WrappedRequest request) { + public static boolean isAppRequest(VaadinRequest request) { return hasPathPrefix(request, ApplicationConstants.APP_REQUEST_PATH); } - public static boolean isHeartbeatRequest(WrappedRequest request) { + public static boolean isHeartbeatRequest(VaadinRequest request) { return hasPathPrefix(request, ApplicationConstants.HEARTBEAT_REQUEST_PATH); } diff --git a/server/src/com/vaadin/server/UIProvider.java b/server/src/com/vaadin/server/UIProvider.java index a15a50a42a..81a53fae15 100644 --- a/server/src/com/vaadin/server/UIProvider.java +++ b/server/src/com/vaadin/server/UIProvider.java @@ -20,12 +20,11 @@ import com.vaadin.annotations.Widgetset; import com.vaadin.ui.UI; public interface UIProvider { - public Class getUIClass(WrappedRequest request); + public Class getUIClass(VaadinRequest request); - public UI createInstance(WrappedRequest request, - Class type); + public UI createInstance(VaadinRequest request, Class type); - public String getPageTitle(WrappedRequest request, + public String getPageTitle(VaadinRequest request, Class uiClass); /** @@ -40,7 +39,7 @@ public interface UIProvider { * @return trueif the same UI instance should be reused e.g. * when the browser window is refreshed. */ - public boolean isPreservedOnRefresh(WrappedRequest request, + public boolean isPreservedOnRefresh(VaadinRequest request, Class uiClass); /** @@ -51,14 +50,14 @@ public interface UIProvider { * defined for the UI class. * * @param request - * the wrapped request for which to get a widgetset + * the Vaadin request for which to get a widgetset * @param uiClass * the UI class to get a widgetset for * @return the name of the widgetset, or null if the default * widgetset should be used * */ - public String getWidgetset(WrappedRequest request, + public String getWidgetset(VaadinRequest request, Class uiClass); /** @@ -73,8 +72,7 @@ public interface UIProvider { * should be used * */ - public String getTheme(WrappedRequest request, - Class uiClass); + public String getTheme(VaadinRequest request, Class uiClass); /** * Finds an existing {@link UI} for a request. @@ -85,14 +83,14 @@ public interface UIProvider { *

* If no UI provider returns an existing UI, the framework does also check * the window.name for an existing instance with - * {@link #isPreservedOnRefresh(WrappedRequest, Class)} before falling back to - * bootstrapping and creating a new UI instance. + * {@link #isPreservedOnRefresh(VaadinRequest, Class)} before falling back + * to bootstrapping and creating a new UI instance. * * @param request * the request for which a UI is desired * @return a UI belonging to the request, or null if this UI * provider doesn't have an existing UI for the request. */ - public UI getExistingUI(WrappedRequest request); + public UI getExistingUI(VaadinRequest request); } diff --git a/server/src/com/vaadin/server/UnsupportedBrowserHandler.java b/server/src/com/vaadin/server/UnsupportedBrowserHandler.java index 38ac14b2d2..8525dc29ca 100644 --- a/server/src/com/vaadin/server/UnsupportedBrowserHandler.java +++ b/server/src/com/vaadin/server/UnsupportedBrowserHandler.java @@ -35,7 +35,7 @@ public class UnsupportedBrowserHandler implements RequestHandler { @Override public boolean handleRequest(VaadinSession session, - WrappedRequest request, WrappedResponse response) + VaadinRequest request, VaadinResponse response) throws IOException { if (request.getBrowserDetails() != null) { @@ -62,8 +62,8 @@ public class UnsupportedBrowserHandler implements RequestHandler { * @param response * @throws IOException */ - protected void writeBrowserTooOldPage(WrappedRequest request, - WrappedResponse response) throws IOException { + protected void writeBrowserTooOldPage(VaadinRequest request, + VaadinResponse response) throws IOException { Writer page = response.getWriter(); WebBrowser b = request.getBrowserDetails().getWebBrowser(); diff --git a/server/src/com/vaadin/server/VaadinPortlet.java b/server/src/com/vaadin/server/VaadinPortlet.java index 2027431f0b..83d152d653 100644 --- a/server/src/com/vaadin/server/VaadinPortlet.java +++ b/server/src/com/vaadin/server/VaadinPortlet.java @@ -88,7 +88,7 @@ public class VaadinPortlet extends GenericPortlet implements Constants { } @Override - public String getConfiguredWidgetset(WrappedRequest request) { + public String getConfiguredWidgetset(VaadinRequest request) { String widgetset = getDeploymentConfiguration() .getApplicationOrSystemProperty(PARAMETER_WIDGETSET, null); @@ -96,7 +96,7 @@ public class VaadinPortlet extends GenericPortlet implements Constants { if (widgetset == null) { // If no widgetset defined for the application, check the // portal property - widgetset = WrappedPortletRequest.cast(request) + widgetset = VaadinPortletRequest.cast(request) .getPortalProperty(PORTAL_PARAMETER_VAADIN_WIDGETSET); } @@ -109,10 +109,10 @@ public class VaadinPortlet extends GenericPortlet implements Constants { } @Override - public String getConfiguredTheme(WrappedRequest request) { + public String getConfiguredTheme(VaadinRequest request) { // is the default theme defined by the portal? - String themeName = WrappedPortletRequest.cast(request) + String themeName = VaadinPortletRequest.cast(request) .getPortalProperty(Constants.PORTAL_PARAMETER_VAADIN_THEME); if (themeName == null) { @@ -124,13 +124,13 @@ public class VaadinPortlet extends GenericPortlet implements Constants { } @Override - public boolean isStandalone(WrappedRequest request) { + public boolean isStandalone(VaadinRequest request) { return false; } @Override - public String getStaticFileLocation(WrappedRequest request) { - String staticFileLocation = WrappedPortletRequest.cast(request) + public String getStaticFileLocation(VaadinRequest request) { + String staticFileLocation = VaadinPortletRequest.cast(request) .getPortalProperty( Constants.PORTAL_PARAMETER_VAADIN_RESOURCE_PATH); if (staticFileLocation != null) { @@ -179,7 +179,7 @@ public class VaadinPortlet extends GenericPortlet implements Constants { } @Override - protected boolean requestCanCreateSession(WrappedRequest request) { + protected boolean requestCanCreateSession(VaadinRequest request) { RequestType requestType = getRequestType(request); if (requestType == RequestType.RENDER) { // In most cases the first request is a render request that @@ -205,12 +205,12 @@ public class VaadinPortlet extends GenericPortlet implements Constants { * @deprecated might be refactored or removed before 7.0.0 */ @Deprecated - protected RequestType getRequestType(WrappedRequest request) { + protected RequestType getRequestType(VaadinRequest request) { RequestType type = (RequestType) request .getAttribute(RequestType.class.getName()); if (type == null) { type = getPortlet().getRequestType( - WrappedPortletRequest.cast(request)); + VaadinPortletRequest.cast(request)); request.setAttribute(RequestType.class.getName(), type); } return type; @@ -223,9 +223,9 @@ public class VaadinPortlet extends GenericPortlet implements Constants { } public static PortletRequest getCurrentPortletRequest() { - WrappedRequest currentRequest = VaadinService.getCurrentRequest(); + VaadinRequest currentRequest = VaadinService.getCurrentRequest(); try { - WrappedPortletRequest request = WrappedPortletRequest + VaadinPortletRequest request = VaadinPortletRequest .cast(currentRequest); if (request != null) { return request.getPortletRequest(); @@ -237,21 +237,21 @@ public class VaadinPortlet extends GenericPortlet implements Constants { } } - public static WrappedPortletResponse getCurrentResponse() { - return (WrappedPortletResponse) VaadinService.getCurrentResponse(); + public static VaadinPortletResponse getCurrentResponse() { + return (VaadinPortletResponse) VaadinService.getCurrentResponse(); } @Override - protected VaadinSession createVaadinSession(WrappedRequest request) + protected VaadinSession createVaadinSession(VaadinRequest request) throws ServiceException { return new VaadinPortletSession(); } } - public static class WrappedHttpAndPortletRequest extends - WrappedPortletRequest { + public static class VaadinHttpAndPortletRequest extends + VaadinPortletRequest { - public WrappedHttpAndPortletRequest(PortletRequest request, + public VaadinHttpAndPortletRequest(PortletRequest request, HttpServletRequest originalRequest, PortletService vaadinService) { super(request, vaadinService); this.originalRequest = originalRequest; @@ -292,9 +292,8 @@ public class VaadinPortlet extends GenericPortlet implements Constants { } } - public static class WrappedGateinRequest extends - WrappedHttpAndPortletRequest { - public WrappedGateinRequest(PortletRequest request, + public static class VaadinGateinRequest extends VaadinHttpAndPortletRequest { + public VaadinGateinRequest(PortletRequest request, PortletService vaadinService) { super(request, getOriginalRequest(request), vaadinService); } @@ -314,10 +313,10 @@ public class VaadinPortlet extends GenericPortlet implements Constants { } } - public static class WrappedLiferayRequest extends - WrappedHttpAndPortletRequest { + public static class VaadinLiferayRequest extends + VaadinHttpAndPortletRequest { - public WrappedLiferayRequest(PortletRequest request, + public VaadinLiferayRequest(PortletRequest request, PortletService vaadinService) { super(request, getOriginalRequest(request), vaadinService); } @@ -358,11 +357,11 @@ public class VaadinPortlet extends GenericPortlet implements Constants { } @Override - public void criticalNotification(WrappedRequest request, - WrappedResponse response, String cap, String msg, + public void criticalNotification(VaadinRequest request, + VaadinResponse response, String cap, String msg, String details, String outOfSyncURL) throws IOException { - portlet.criticalNotification(WrappedPortletRequest.cast(request), - (WrappedPortletResponse) response, cap, msg, details, + portlet.criticalNotification(VaadinPortletRequest.cast(request), + (VaadinPortletResponse) response, cap, msg, details, outOfSyncURL); } } @@ -465,30 +464,30 @@ public class VaadinPortlet extends GenericPortlet implements Constants { } /** - * @param wrappedRequest + * @param vaadinRequest * @return * * @deprecated might be refactored or removed before 7.0.0 */ @Deprecated - protected RequestType getRequestType(WrappedPortletRequest wrappedRequest) { - PortletRequest request = wrappedRequest.getPortletRequest(); + protected RequestType getRequestType(VaadinPortletRequest vaadinRequest) { + PortletRequest request = vaadinRequest.getPortletRequest(); if (request instanceof RenderRequest) { return RequestType.RENDER; } else if (request instanceof ResourceRequest) { ResourceRequest resourceRequest = (ResourceRequest) request; - if (ServletPortletHelper.isUIDLRequest(wrappedRequest)) { + if (ServletPortletHelper.isUIDLRequest(vaadinRequest)) { return RequestType.UIDL; } else if (isBrowserDetailsRequest(resourceRequest)) { return RequestType.BROWSER_DETAILS; - } else if (ServletPortletHelper.isFileUploadRequest(wrappedRequest)) { + } else if (ServletPortletHelper.isFileUploadRequest(vaadinRequest)) { return RequestType.FILE_UPLOAD; } else if (ServletPortletHelper - .isConnectorResourceRequest(wrappedRequest)) { + .isConnectorResourceRequest(vaadinRequest)) { return RequestType.CONNECTOR_RESOURCE; - } else if (ServletPortletHelper.isAppRequest(wrappedRequest)) { + } else if (ServletPortletHelper.isAppRequest(vaadinRequest)) { return RequestType.APP; - } else if (ServletPortletHelper.isHeartbeatRequest(wrappedRequest)) { + } else if (ServletPortletHelper.isHeartbeatRequest(vaadinRequest)) { return RequestType.HEARTBEAT; } else if (isDummyRequest(resourceRequest)) { return RequestType.DUMMY; @@ -534,15 +533,15 @@ public class VaadinPortlet extends GenericPortlet implements Constants { AbstractApplicationPortletWrapper portletWrapper = new AbstractApplicationPortletWrapper( this); - WrappedPortletRequest wrappedRequest = createWrappedRequest(request); + VaadinPortletRequest vaadinRequest = createVaadinRequest(request); - WrappedPortletResponse wrappedResponse = new WrappedPortletResponse( + VaadinPortletResponse vaadinResponse = new VaadinPortletResponse( response, getVaadinService()); - getVaadinService().setCurrentInstances(wrappedRequest, - wrappedResponse); + getVaadinService().setCurrentInstances(vaadinRequest, + vaadinResponse); - RequestType requestType = getRequestType(wrappedRequest); + RequestType requestType = getRequestType(vaadinRequest); if (requestType == RequestType.UNKNOWN) { handleUnknownRequest(request, response); @@ -571,7 +570,7 @@ public class VaadinPortlet extends GenericPortlet implements Constants { // redirectToApplication?? vaadinSession = (VaadinPortletSession) getVaadinService() - .findVaadinSession(wrappedRequest); + .findVaadinSession(vaadinRequest); if (vaadinSession == null) { return; } @@ -584,17 +583,17 @@ public class VaadinPortlet extends GenericPortlet implements Constants { if (requestType == RequestType.CONNECTOR_RESOURCE) { communicationManager.serveConnectorResource( - wrappedRequest, wrappedResponse); + vaadinRequest, vaadinResponse); return; } else if (requestType == RequestType.HEARTBEAT) { communicationManager.handleHeartbeatRequest( - wrappedRequest, wrappedResponse, vaadinSession); + vaadinRequest, vaadinResponse, vaadinSession); return; } /* Update browser information from request */ vaadinSession.getBrowser().updateRequestDetails( - wrappedRequest); + vaadinRequest); sessionProcessed = true; @@ -610,7 +609,7 @@ public class VaadinPortlet extends GenericPortlet implements Constants { // Both action requests and render requests are ok // without a UI as they render the initial HTML // and then do a second request - uI = vaadinSession.getUIForRequest(wrappedRequest); + uI = vaadinSession.getUIForRequest(vaadinRequest); break; case BROWSER_DETAILS: // Should not try to find a UI here as the @@ -623,7 +622,7 @@ public class VaadinPortlet extends GenericPortlet implements Constants { // Not related to any UI break; default: - uI = vaadinSession.getUIForRequest(wrappedRequest); + uI = vaadinSession.getUIForRequest(vaadinRequest); } // if window not found, not a problem - use null } finally { @@ -655,19 +654,19 @@ public class VaadinPortlet extends GenericPortlet implements Constants { // UI is resolved in handleFileUpload by // PortletCommunicationManager communicationManager.handleFileUpload(vaadinSession, - wrappedRequest, wrappedResponse); + vaadinRequest, vaadinResponse); return; } else if (requestType == RequestType.BROWSER_DETAILS) { communicationManager.handleBrowserDetailsRequest( - wrappedRequest, wrappedResponse, vaadinSession); + vaadinRequest, vaadinResponse, vaadinSession); return; } else if (requestType == RequestType.UIDL) { // Handles AJAX UIDL requests - communicationManager.handleUidlRequest(wrappedRequest, - wrappedResponse, portletWrapper, uI); + communicationManager.handleUidlRequest(vaadinRequest, + vaadinResponse, portletWrapper, uI); return; } else { - handleOtherRequest(wrappedRequest, wrappedResponse, + handleOtherRequest(vaadinRequest, vaadinResponse, requestType, vaadinSession, communicationManager); } @@ -681,7 +680,7 @@ public class VaadinPortlet extends GenericPortlet implements Constants { getLogger() .fine("General security exception, the security key was probably incorrect."); } catch (final Throwable e) { - handleServiceException(wrappedRequest, wrappedResponse, + handleServiceException(vaadinRequest, vaadinResponse, vaadinSession, e); } finally { @@ -700,22 +699,21 @@ public class VaadinPortlet extends GenericPortlet implements Constants { } /** - * Wraps the request in a (possibly portal specific) wrapped portlet - * request. + * Wraps the request in a (possibly portal specific) Vaadin portlet request. * * @param request * The original PortletRequest * @return A wrapped version of the PorletRequest */ - protected WrappedPortletRequest createWrappedRequest(PortletRequest request) { + protected VaadinPortletRequest createVaadinRequest(PortletRequest request) { String portalInfo = request.getPortalContext().getPortalInfo() .toLowerCase(); if (portalInfo.contains("liferay")) { - return new WrappedLiferayRequest(request, getVaadinService()); + return new VaadinLiferayRequest(request, getVaadinService()); } else if (portalInfo.contains("gatein")) { - return new WrappedGateinRequest(request, getVaadinService()); + return new VaadinGateinRequest(request, getVaadinService()); } else { - return new WrappedPortletRequest(request, getVaadinService()); + return new VaadinPortletRequest(request, getVaadinService()); } } @@ -746,8 +744,8 @@ public class VaadinPortlet extends GenericPortlet implements Constants { * @throws IOException * @throws MalformedURLException */ - private void handleOtherRequest(WrappedPortletRequest request, - WrappedResponse response, RequestType requestType, + private void handleOtherRequest(VaadinPortletRequest request, + VaadinResponse response, RequestType requestType, VaadinSession vaadinSession, PortletCommunicationManager communicationManager) throws PortletException, IOException, MalformedURLException { @@ -832,8 +830,8 @@ public class VaadinPortlet extends GenericPortlet implements Constants { handleRequest(request, response); } - private void handleServiceException(WrappedPortletRequest request, - WrappedPortletResponse response, VaadinSession vaadinSession, + private void handleServiceException(VaadinPortletRequest request, + VaadinPortletResponse response, VaadinSession vaadinSession, Throwable e) throws IOException, PortletException { // TODO Check that this error handler is working when running inside a // portlet @@ -898,8 +896,8 @@ public class VaadinPortlet extends GenericPortlet implements Constants { * @deprecated might be refactored or removed before 7.0.0 */ @Deprecated - void criticalNotification(WrappedPortletRequest request, - WrappedPortletResponse response, String caption, String message, + void criticalNotification(VaadinPortletRequest request, + VaadinPortletResponse response, String caption, String message, String details, String url) throws IOException { // clients JS app is still running, but server application either diff --git a/server/src/com/vaadin/server/VaadinPortletRequest.java b/server/src/com/vaadin/server/VaadinPortletRequest.java new file mode 100644 index 0000000000..b0a16d01a4 --- /dev/null +++ b/server/src/com/vaadin/server/VaadinPortletRequest.java @@ -0,0 +1,228 @@ +/* + * 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.IOException; +import java.io.InputStream; +import java.util.Locale; +import java.util.Map; + +import javax.portlet.ClientDataRequest; +import javax.portlet.PortletRequest; +import javax.portlet.PortletSession; +import javax.portlet.ResourceRequest; + +import com.vaadin.server.VaadinPortlet.PortletService; +import com.vaadin.shared.ApplicationConstants; + +/** + * Wrapper for {@link PortletRequest} and its subclasses. + * + * @author Vaadin Ltd. + * @since 7.0 + * + * @see VaadinRequest + * @see VaadinPortletResponse + */ +public class VaadinPortletRequest implements VaadinRequest { + + private final PortletRequest request; + private final PortletService vaadinService; + + /** + * Wraps a portlet request and an associated vaadin service + * + * @param request + * the portlet request to wrap + * @param vaadinService + * the associated vaadin service + */ + public VaadinPortletRequest(PortletRequest request, + PortletService vaadinService) { + this.request = request; + this.vaadinService = vaadinService; + } + + @Override + public Object getAttribute(String name) { + return request.getAttribute(name); + } + + @Override + public int getContentLength() { + try { + return ((ClientDataRequest) request).getContentLength(); + } catch (ClassCastException e) { + throw new IllegalStateException( + "Content lenght only available for ClientDataRequests"); + } + } + + @Override + public InputStream getInputStream() throws IOException { + try { + return ((ClientDataRequest) request).getPortletInputStream(); + } catch (ClassCastException e) { + throw new IllegalStateException( + "Input data only available for ClientDataRequests"); + } + } + + @Override + public String getParameter(String name) { + return request.getParameter(name); + } + + @Override + public Map getParameterMap() { + return request.getParameterMap(); + } + + @Override + public void setAttribute(String name, Object o) { + request.setAttribute(name, o); + } + + @Override + public String getRequestPathInfo() { + if (request instanceof ResourceRequest) { + ResourceRequest resourceRequest = (ResourceRequest) request; + String resourceID = resourceRequest.getResourceID(); + if (VaadinPortlet.RESOURCE_URL_ID.equals(resourceID)) { + String resourcePath = resourceRequest + .getParameter(ApplicationConstants.V_RESOURCE_PATH); + return resourcePath; + } + return resourceID; + } else { + return null; + } + } + + @Override + public WrappedSession getWrappedSession() { + return getWrappedSession(true); + } + + @Override + public WrappedSession getWrappedSession(boolean allowSessionCreation) { + PortletSession session = request + .getPortletSession(allowSessionCreation); + if (session != null) { + return new WrappedPortletSession(session); + } else { + return null; + } + } + + /** + * Gets the original, unwrapped portlet request. + * + * @return the unwrapped portlet request + */ + public PortletRequest getPortletRequest() { + return request; + } + + @Override + public String getContentType() { + try { + return ((ResourceRequest) request).getContentType(); + } catch (ClassCastException e) { + throw new IllegalStateException( + "Content type only available for ResourceRequests"); + } + } + + @Override + public BrowserDetails getBrowserDetails() { + return new BrowserDetails() { + @Override + public String getUriFragment() { + return null; + } + + @Override + public String getWindowName() { + return null; + } + + @Override + public WebBrowser getWebBrowser() { + VaadinPortletSession context = (VaadinPortletSession) VaadinSession + .getCurrent(); + return context.getBrowser(); + } + }; + } + + @Override + public Locale getLocale() { + return request.getLocale(); + } + + @Override + public String getRemoteAddr() { + return null; + } + + @Override + public boolean isSecure() { + return request.isSecure(); + } + + @Override + public String getHeader(String string) { + return null; + } + + /** + * Reads a portal property from the portal context of the Vaadin request. + * + * @param name + * a string with the name of the portal property to get + * @return a string with the value of the property, or null if + * the property is not defined + */ + public String getPortalProperty(String name) { + return request.getPortalContext().getProperty(name); + } + + @Override + public PortletService getVaadinService() { + return vaadinService; + } + + /** + * Helper method to get a {@link VaadinPortletRequest} from a + * {@link VaadinRequest}. Aside from casting, this method also takes care of + * situations where there's another level of wrapping. + * + * @param request + * a Vaadin request + * @return a Vaadin portlet request + * @throws ClassCastException + * if the Vaadin request doesn't wrap a portlet request + */ + public static VaadinPortletRequest cast(VaadinRequest request) { + if (request instanceof CombinedRequest) { + CombinedRequest combinedRequest = (CombinedRequest) request; + request = combinedRequest.getSecondRequest(); + } + return (VaadinPortletRequest) request; + } +} diff --git a/server/src/com/vaadin/server/VaadinPortletResponse.java b/server/src/com/vaadin/server/VaadinPortletResponse.java new file mode 100644 index 0000000000..5ca1ba580e --- /dev/null +++ b/server/src/com/vaadin/server/VaadinPortletResponse.java @@ -0,0 +1,122 @@ +/* + * 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.IOException; +import java.io.OutputStream; +import java.io.PrintWriter; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Locale; +import java.util.TimeZone; + +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. + * + * @author Vaadin Ltd. + * @since 7.0 + * + * @see VaadinResponse + * @see VaadinPortletRequest + */ +public class VaadinPortletResponse implements VaadinResponse { + private static final DateFormat HTTP_DATE_FORMAT = new SimpleDateFormat( + "EEE, dd MMM yyyy HH:mm:ss zzz", Locale.ENGLISH); + static { + HTTP_DATE_FORMAT.setTimeZone(TimeZone.getTimeZone("GMT")); + } + + private final PortletResponse response; + private PortletService vaadinService; + + /** + * Wraps a portlet response and an associated vaadin service + * + * @param response + * the portlet response to wrap + * @param vaadinService + * the associated vaadin service + */ + public VaadinPortletResponse(PortletResponse response, + PortletService vaadinService) { + this.response = response; + this.vaadinService = vaadinService; + } + + @Override + public OutputStream getOutputStream() throws IOException { + return ((MimeResponse) response).getPortletOutputStream(); + } + + /** + * Gets the original, unwrapped portlet response. + * + * @return the unwrapped portlet response + */ + public PortletResponse getPortletResponse() { + return response; + } + + @Override + public void setContentType(String type) { + ((MimeResponse) response).setContentType(type); + } + + @Override + public PrintWriter getWriter() throws IOException { + return ((MimeResponse) response).getWriter(); + } + + @Override + public void setStatus(int responseStatus) { + response.setProperty(ResourceResponse.HTTP_STATUS_CODE, + Integer.toString(responseStatus)); + } + + @Override + public void setHeader(String name, String value) { + response.setProperty(name, value); + } + + @Override + public void setDateHeader(String name, long timestamp) { + response.setProperty(name, HTTP_DATE_FORMAT.format(new Date(timestamp))); + } + + @Override + public void setCacheTime(long milliseconds) { + VaadinServletResponse.doSetCacheTime(this, milliseconds); + } + + @Override + public void sendError(int errorCode, String message) throws IOException { + setStatus(errorCode); + getWriter().write(message); + } + + @Override + public PortletService getVaadinService() { + return vaadinService; + } +} \ No newline at end of file diff --git a/server/src/com/vaadin/server/VaadinPortletSession.java b/server/src/com/vaadin/server/VaadinPortletSession.java index bb37bbbcf3..e5b512588d 100644 --- a/server/src/com/vaadin/server/VaadinPortletSession.java +++ b/server/src/com/vaadin/server/VaadinPortletSession.java @@ -74,8 +74,8 @@ public class VaadinPortletSession extends VaadinSession { } private PortletResponse getCurrentResponse() { - WrappedPortletResponse currentResponse = (WrappedPortletResponse) CurrentInstance - .get(WrappedResponse.class); + VaadinPortletResponse currentResponse = (VaadinPortletResponse) CurrentInstance + .get(VaadinResponse.class); if (currentResponse != null) { return currentResponse.getPortletResponse(); @@ -85,8 +85,8 @@ public class VaadinPortletSession extends VaadinSession { } public PortletConfig getPortletConfig() { - WrappedPortletResponse response = (WrappedPortletResponse) CurrentInstance - .get(WrappedResponse.class); + VaadinPortletResponse response = (VaadinPortletResponse) CurrentInstance + .get(VaadinResponse.class); return response.getVaadinService().getPortlet().getPortletConfig(); } diff --git a/server/src/com/vaadin/server/VaadinRequest.java b/server/src/com/vaadin/server/VaadinRequest.java new file mode 100644 index 0000000000..0664d53f65 --- /dev/null +++ b/server/src/com/vaadin/server/VaadinRequest.java @@ -0,0 +1,278 @@ +/* + * 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.IOException; +import java.io.InputStream; +import java.io.Serializable; +import java.util.Locale; +import java.util.Map; + +import javax.portlet.PortletRequest; +import javax.servlet.ServletRequest; +import javax.servlet.http.HttpServletRequest; + +import com.vaadin.ui.UI; + +/** + * A generic request to the server, wrapping a more specific request type, e.g. + * HttpServletReqest or PortletRequest. + * + * @author Vaadin Ltd + * @since 7.0.0 + */ +public interface VaadinRequest extends Serializable { + + /** + * Detailed information extracted from the browser. + * + * @see VaadinRequest#getBrowserDetails() + * @deprecated might be refactored or removed before 7.0.0 + */ + @Deprecated + public interface BrowserDetails extends Serializable { + /** + * Gets the URI hash fragment for the request. This is typically used to + * encode navigation within an application. + * + * @return the URI hash fragment + */ + public String getUriFragment(); + + /** + * Gets the value of window.name from the browser. This can be used to + * keep track of the specific window between browser reloads. + * + * @return the string value of window.name in the browser + */ + public String getWindowName(); + + /** + * Gets a reference to the {@link WebBrowser} object containing + * additional information, e.g. screen size and the time zone offset. + * + * @return the web browser object + */ + public WebBrowser getWebBrowser(); + } + + /** + * Gets the named request parameter This is typically a HTTP GET or POST + * parameter, though other request types might have other ways of + * representing parameters. + * + * @see javax.servlet.ServletRequest#getParameter(String) + * @see javax.portlet.PortletRequest#getParameter(String) + * + * @param parameter + * the name of the parameter + * @return The paramter value, or null if no parameter with the + * given name is present + */ + public String getParameter(String parameter); + + /** + * Gets all the parameters of the request. + * + * @see #getParameter(String) + * + * @see javax.servlet.ServletRequest#getParameterMap() + * @see javax.portlet.PortletRequest#getParameter(String) + * + * @return A mapping of parameter names to arrays of parameter values + */ + public Map getParameterMap(); + + /** + * Returns the length of the request content that can be read from the input + * stream returned by {@link #getInputStream()}. + * + * @see javax.servlet.ServletRequest#getContentLength() + * @see javax.portlet.ClientDataRequest#getContentLength() + * + * @return content length in bytes + */ + public int getContentLength(); + + /** + * Returns an input stream from which the request content can be read. The + * request content length can be obtained with {@link #getContentLength()} + * without reading the full stream contents. + * + * @see javax.servlet.ServletRequest#getInputStream() + * @see javax.portlet.ClientDataRequest#getPortletInputStream() + * + * @return the input stream from which the contents of the request can be + * read + * @throws IOException + * if the input stream can not be opened + */ + public InputStream getInputStream() throws IOException; + + /** + * Gets a request attribute. + * + * @param name + * the name of the attribute + * @return the value of the attribute, or null if there is no + * attribute with the given name + * + * @see javax.servlet.ServletRequest#getAttribute(String) + * @see javax.portlet.PortletRequest#getAttribute(String) + */ + public Object getAttribute(String name); + + /** + * Defines a request attribute. + * + * @param name + * the name of the attribute + * @param value + * the attribute value + * + * @see javax.servlet.ServletRequest#setAttribute(String, Object) + * @see javax.portlet.PortletRequest#setAttribute(String, Object) + */ + public void setAttribute(String name, Object value); + + /** + * Gets the path of the requested resource relative to the application. The + * path be null if no path information is available. Does + * always start with / if the path isn't null. + * + * @return a string with the path relative to the application. + * + * @see javax.servlet.http.HttpServletRequest#getPathInfo() + */ + public String getRequestPathInfo(); + + /** + * Gets the session associated with this request, creating a new if there is + * no session. + * + * @see WrappedSession + * @see HttpServletRequest#getSession() + * @see PortletRequest#getPortletSession() + * + * @return the wrapped session for this request + */ + public WrappedSession getWrappedSession(); + + /** + * Gets the session associated with this request, optionally creating a new + * if there is no session. + * + * @param allowSessionCreation + * true to create a new session for this request if + * necessary; false to return null if + * there's no current session + * + * @see WrappedSession + * @see HttpServletRequest#getSession(boolean) + * @see PortletRequest#getPortletSession(boolean) + * + * @return the wrapped session for this request + */ + public WrappedSession getWrappedSession(boolean allowSessionCreation); + + /** + * Returns the MIME type of the body of the request, or null if the type is + * not known. + * + * @return a string containing the name of the MIME type of the request, or + * null if the type is not known + * + * @see javax.servlet.ServletRequest#getContentType() + * @see javax.portlet.ResourceRequest#getContentType() + * + */ + public String getContentType(); + + /** + * Gets detailed information about the browser from which the request + * originated. This consists of information that is not available from + * normal HTTP requests, but requires additional information to be extracted + * for instance using javascript in the browser. + * + * This information is only guaranteed to be available in some special + * cases, for instance in {@link UI#init(VaadinRequest)}. + * + * @return the browser details, or null if details are not + * available + * + * @see BrowserDetails + * @deprecated might be refactored or removed before 7.0.0 + */ + @Deprecated + public BrowserDetails getBrowserDetails(); + + /** + * Gets locale information from the query, e.g. using the Accept-Language + * header. + * + * @return the preferred Locale + * + * @see ServletRequest#getLocale() + * @see PortletRequest#getLocale() + */ + public Locale getLocale(); + + /** + * Returns the IP address from which the request came. This might also be + * the address of a proxy between the server and the original requester. + * + * @return a string containing the IP address, or null if the + * address is not available + * + * @see ServletRequest#getRemoteAddr() + */ + public String getRemoteAddr(); + + /** + * Checks whether the request was made using a secure channel, e.g. using + * https. + * + * @return a boolean indicating if the request is secure + * + * @see ServletRequest#isSecure() + * @see PortletRequest#isSecure() + */ + public boolean isSecure(); + + /** + * Gets the value of a request header, e.g. a http header for a + * {@link HttpServletRequest}. + * + * @param headerName + * the name of the header + * @return the header value, or null if the header is not + * present in the request + * + * @see HttpServletRequest#getHeader(String) + */ + public String getHeader(String headerName); + + /** + * Gets the vaadin service for the context of this request. + * + * @return the vaadin service + * + * @see VaadinService + */ + public VaadinService getVaadinService(); + +} diff --git a/server/src/com/vaadin/server/VaadinResponse.java b/server/src/com/vaadin/server/VaadinResponse.java new file mode 100644 index 0000000000..bfa36015a3 --- /dev/null +++ b/server/src/com/vaadin/server/VaadinResponse.java @@ -0,0 +1,159 @@ +/* + * 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.IOException; +import java.io.OutputStream; +import java.io.PrintWriter; +import java.io.Serializable; + +import javax.portlet.MimeResponse; +import javax.portlet.PortletResponse; +import javax.portlet.ResourceResponse; +import javax.servlet.ServletResponse; +import javax.servlet.http.HttpServletResponse; + +/** + * A generic response from the server, wrapping a more specific response type, + * e.g. HttpServletResponse or PortletResponse. + * + * @since 7.0 + */ +public interface VaadinResponse extends Serializable { + + /** + * Sets the (http) status code for the response. If you want to include an + * error message along the status code, use {@link #sendError(int, String)} + * instead. + * + * @param statusCode + * the status code to set + * @see HttpServletResponse#setStatus(int) + * + * @see ResourceResponse#HTTP_STATUS_CODE + */ + public void setStatus(int statusCode); + + /** + * Sets the content type of this response. If the content type including a + * charset is set before {@link #getWriter()} is invoked, the returned + * PrintWriter will automatically use the defined charset. + * + * @param contentType + * a string specifying the MIME type of the content + * + * @see ServletResponse#setContentType(String) + * @see MimeResponse#setContentType(String) + */ + public void setContentType(String contentType); + + /** + * Sets the value of a generic response header. If the header had already + * been set, the new value overwrites the previous one. + * + * @param name + * the name of the header + * @param value + * the header value. + * + * @see HttpServletResponse#setHeader(String, String) + * @see PortletResponse#setProperty(String, String) + */ + public void setHeader(String name, String value); + + /** + * Properly formats a timestamp as a date header. If the header had already + * been set, the new value overwrites the previous one. + * + * @param name + * the name of the header + * @param timestamp + * the number of milliseconds since epoch + * + * @see HttpServletResponse#setDateHeader(String, long) + */ + public void setDateHeader(String name, long timestamp); + + /** + * Returns a OutputStream for writing binary data in the + * response. + *

+ * Either this method or getWriter() may be called to write the response, + * not both. + * + * @return a OutputStream for writing binary data + * @throws IOException + * if an input or output exception occurred + * + * @see #getWriter() + * @see ServletResponse#getOutputStream() + * @see MimeResponse#getPortletOutputStream() + */ + public OutputStream getOutputStream() throws IOException; + + /** + * Returns a PrintWriter object that can send character text to + * the client. The PrintWriter uses the character encoding defined using + * setContentType. + *

+ * Either this method or getOutputStream() may be called to write the + * response, not both. + * + * @return a PrintWriter for writing character text + * @throws IOException + * if an input or output exception occurred + * + * @see #getOutputStream() + * @see ServletResponse#getWriter() + * @see MimeResponse#getWriter() + */ + public PrintWriter getWriter() throws IOException; + + /** + * Sets cache time in milliseconds, -1 means no cache at all. All required + * headers related to caching in the response are set based on the time. + * + * @param milliseconds + * Cache time in milliseconds + */ + public void setCacheTime(long milliseconds); + + /** + * Sends an error response to the client using the specified status code and + * clears the buffer. In some configurations, this can cause a predefined + * error page to be displayed. + * + * @param errorCode + * the HTTP status code + * @param message + * a message to accompany the error + * @throws IOException + * if an input or output exception occurs + * + * @see HttpServletResponse#sendError(int, String) + */ + public void sendError(int errorCode, String message) throws IOException; + + /** + * Gets the vaadin service for the context of this response. + * + * @return the vaadin service + * + * @see VaadinService + */ + public VaadinService getVaadinService(); +} diff --git a/server/src/com/vaadin/server/VaadinService.java b/server/src/com/vaadin/server/VaadinService.java index 4b176d5f67..766ae47fdb 100644 --- a/server/src/com/vaadin/server/VaadinService.java +++ b/server/src/com/vaadin/server/VaadinService.java @@ -97,7 +97,7 @@ public abstract class VaadinService implements Serializable { * @return The location of static resources (should contain the VAADIN * directory). Never ends with a slash (/). */ - public abstract String getStaticFileLocation(WrappedRequest request); + public abstract String getStaticFileLocation(VaadinRequest request); /** * Gets the widgetset that is configured for this deployment, e.g. from a @@ -107,7 +107,7 @@ public abstract class VaadinService implements Serializable { * the request for which a widgetset is required * @return the name of the widgetset */ - public abstract String getConfiguredWidgetset(WrappedRequest request); + public abstract String getConfiguredWidgetset(VaadinRequest request); /** * Gets the theme that is configured for this deployment, e.g. from a portal @@ -117,7 +117,7 @@ public abstract class VaadinService implements Serializable { * the request for which a theme is required * @return the name of the theme */ - public abstract String getConfiguredTheme(WrappedRequest request); + public abstract String getConfiguredTheme(VaadinRequest request); /** * Checks whether the UI will be rendered on its own in the browser or @@ -129,7 +129,7 @@ public abstract class VaadinService implements Serializable { * the request for which the UI is loaded * @return a boolean indicating whether the UI should be standalone */ - public abstract boolean isStandalone(WrappedRequest request); + public abstract boolean isStandalone(VaadinRequest request); /** * Get the class loader to use for loading classes loaded by name, e.g. @@ -307,7 +307,7 @@ public abstract class VaadinService implements Serializable { * session is found and this is a request for which a new session * shouldn't be created. */ - public VaadinSession findVaadinSession(WrappedRequest request) + public VaadinSession findVaadinSession(VaadinRequest request) throws ServiceException, SessionExpiredException { boolean requestCanCreateSession = requestCanCreateSession(request); @@ -356,7 +356,7 @@ public abstract class VaadinService implements Serializable { } - private VaadinSession createAndRegisterSession(WrappedRequest request) + private VaadinSession createAndRegisterSession(VaadinRequest request) throws ServiceException { VaadinSession session = createVaadinSession(request); @@ -397,7 +397,7 @@ public abstract class VaadinService implements Serializable { * @deprecated Only used to support {@link LegacyApplication}. */ @Deprecated - protected URL getApplicationUrl(WrappedRequest request) + protected URL getApplicationUrl(VaadinRequest request) throws MalformedURLException { return null; } @@ -421,10 +421,10 @@ public abstract class VaadinService implements Serializable { * @throws ServletException * @throws MalformedURLException */ - protected abstract VaadinSession createVaadinSession(WrappedRequest request) + protected abstract VaadinSession createVaadinSession(VaadinRequest request) throws ServiceException; - private void onVaadinSessionStarted(WrappedRequest request, + private void onVaadinSessionStarted(VaadinRequest request, VaadinSession session) throws ServiceException { addonContext.fireApplicationStarted(session); eventRouter.fireEvent(new VaadinSessionInitializeEvent(this, session, @@ -444,7 +444,7 @@ public abstract class VaadinService implements Serializable { } } - protected VaadinSession getExistingSession(WrappedRequest request, + protected VaadinSession getExistingSession(VaadinRequest request, boolean allowSessionCreation) throws SessionExpiredException { // Ensures that the session is still valid @@ -472,7 +472,7 @@ public abstract class VaadinService implements Serializable { * @return true if it's valid to create a new Vaadin session * for the request; else false */ - protected abstract boolean requestCanCreateSession(WrappedRequest request); + protected abstract boolean requestCanCreateSession(VaadinRequest request); /** * Gets the currently used Vaadin service. The current service is @@ -485,7 +485,7 @@ public abstract class VaadinService implements Serializable { * @return the current Vaadin service instance if available, otherwise * null * - * @see #setCurrentInstances(WrappedRequest, WrappedResponse) + * @see #setCurrentInstances(VaadinRequest, VaadinResponse) */ public static VaadinService getCurrent() { return CurrentInstance.get(VaadinService.class); @@ -493,7 +493,7 @@ public abstract class VaadinService implements Serializable { /** * Sets the this Vaadin service as the current service and also sets the - * current wrapped request and wrapped response. This method is used by the + * current Vaadin request and Vaadin response. This method is used by the * framework to set the current instances when a request related to the * service is processed and they are cleared when the request has been * processed. @@ -504,51 +504,51 @@ public abstract class VaadinService implements Serializable { *

* * @param request - * the wrapped request to set as the current request, or + * the Vaadin request to set as the current request, or * null if no request should be set. * @param response - * the wrapped response to set as the current response, or + * the Vaadin response to set as the current response, or * null if no response should be set. * * @see #getCurrent() * @see #getCurrentRequest() * @see #getCurrentResponse() */ - public void setCurrentInstances(WrappedRequest request, - WrappedResponse response) { + public void setCurrentInstances(VaadinRequest request, + VaadinResponse response) { CurrentInstance.setInheritable(VaadinService.class, this); - CurrentInstance.set(WrappedRequest.class, request); - CurrentInstance.set(WrappedResponse.class, response); + CurrentInstance.set(VaadinRequest.class, request); + CurrentInstance.set(VaadinResponse.class, response); } /** - * Gets the currently processed wrapped request. The current request is + * Gets the currently processed Vaadin request. The current request is * automatically defined when the request is started. The current request * can not be used in e.g. background threads because of the way server * implementations reuse request instances. * - * @return the current wrapped request instance if available, otherwise + * @return the current Vaadin request instance if available, otherwise * null * - * @see #setCurrentInstances(WrappedRequest, WrappedResponse) + * @see #setCurrentInstances(VaadinRequest, VaadinResponse) */ - public static WrappedRequest getCurrentRequest() { - return CurrentInstance.get(WrappedRequest.class); + public static VaadinRequest getCurrentRequest() { + return CurrentInstance.get(VaadinRequest.class); } /** - * Gets the currently processed wrapped request. The current request is + * Gets the currently processed Vaadin request. The current request is * automatically defined when the request is started. The current request * can not be used in e.g. background threads because of the way server * implementations reuse request instances. * - * @return the current wrapped request instance if available, otherwise + * @return the current Vaadin request instance if available, otherwise * null * - * @see #setCurrentInstances(WrappedRequest, WrappedResponse) + * @see #setCurrentInstances(VaadinRequest, VaadinResponse) */ - public static WrappedResponse getCurrentResponse() { - return CurrentInstance.get(WrappedResponse.class); + public static VaadinResponse getCurrentResponse() { + return CurrentInstance.get(VaadinResponse.class); } } diff --git a/server/src/com/vaadin/server/VaadinServlet.java b/server/src/com/vaadin/server/VaadinServlet.java index 54709b41d1..518d26070b 100644 --- a/server/src/com/vaadin/server/VaadinServlet.java +++ b/server/src/com/vaadin/server/VaadinServlet.java @@ -66,8 +66,8 @@ public class VaadinServlet extends HttpServlet implements Constants { } @Override - public String getStaticFileLocation(WrappedRequest request) { - HttpServletRequest servletRequest = WrappedHttpServletRequest + public String getStaticFileLocation(VaadinRequest request) { + HttpServletRequest servletRequest = VaadinServletRequest .cast(request); String staticFileLocation; // if property is defined in configurations, use that @@ -108,20 +108,20 @@ public class VaadinServlet extends HttpServlet implements Constants { } @Override - public String getConfiguredWidgetset(WrappedRequest request) { + public String getConfiguredWidgetset(VaadinRequest request) { return getDeploymentConfiguration().getApplicationOrSystemProperty( VaadinServlet.PARAMETER_WIDGETSET, VaadinServlet.DEFAULT_WIDGETSET); } @Override - public String getConfiguredTheme(WrappedRequest request) { + public String getConfiguredTheme(VaadinRequest request) { // Use the default return VaadinServlet.getDefaultTheme(); } @Override - public boolean isStandalone(WrappedRequest request) { + public boolean isStandalone(VaadinRequest request) { return true; } @@ -146,7 +146,7 @@ public class VaadinServlet extends HttpServlet implements Constants { } @Override - protected boolean requestCanCreateSession(WrappedRequest request) { + 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 @@ -172,22 +172,22 @@ public class VaadinServlet extends HttpServlet implements Constants { * @deprecated might be refactored or removed before 7.0.0 */ @Deprecated - protected RequestType getRequestType(WrappedRequest request) { + protected RequestType getRequestType(VaadinRequest request) { RequestType type = (RequestType) request .getAttribute(RequestType.class.getName()); if (type == null) { type = getServlet().getRequestType( - WrappedHttpServletRequest.cast(request)); + VaadinServletRequest.cast(request)); request.setAttribute(RequestType.class.getName(), type); } return type; } @Override - protected URL getApplicationUrl(WrappedRequest request) + protected URL getApplicationUrl(VaadinRequest request) throws MalformedURLException { return getServlet().getApplicationUrl( - WrappedHttpServletRequest.cast(request)); + VaadinServletRequest.cast(request)); } @Override @@ -197,9 +197,9 @@ public class VaadinServlet extends HttpServlet implements Constants { } public static HttpServletRequest getCurrentServletRequest() { - WrappedRequest currentRequest = VaadinService.getCurrentRequest(); + VaadinRequest currentRequest = VaadinService.getCurrentRequest(); try { - WrappedHttpServletRequest request = WrappedHttpServletRequest + VaadinServletRequest request = VaadinServletRequest .cast(currentRequest); if (request != null) { return request.getHttpServletRequest(); @@ -211,13 +211,12 @@ public class VaadinServlet extends HttpServlet implements Constants { } } - public static WrappedHttpServletResponse getCurrentResponse() { - return (WrappedHttpServletResponse) VaadinService - .getCurrentResponse(); + public static VaadinServletResponse getCurrentResponse() { + return (VaadinServletResponse) VaadinService.getCurrentResponse(); } @Override - protected VaadinSession createVaadinSession(WrappedRequest request) + protected VaadinSession createVaadinSession(VaadinRequest request) throws ServiceException { return new VaadinServletSession(); } @@ -232,12 +231,11 @@ public class VaadinServlet extends HttpServlet implements Constants { } @Override - public void criticalNotification(WrappedRequest request, - WrappedResponse response, String cap, String msg, + public void criticalNotification(VaadinRequest request, + VaadinResponse response, String cap, String msg, String details, String outOfSyncURL) throws IOException { - servlet.criticalNotification( - WrappedHttpServletRequest.cast(request), - ((WrappedHttpServletResponse) response), cap, msg, details, + servlet.criticalNotification(VaadinServletRequest.cast(request), + ((VaadinServletResponse) response), cap, msg, details, outOfSyncURL); } } @@ -381,11 +379,11 @@ public class VaadinServlet extends HttpServlet implements Constants { HttpServletResponse response) throws ServletException, IOException { CurrentInstance.clearAll(); setCurrent(this); - service(createWrappedRequest(request), createWrappedResponse(response)); + service(createVaadinRequest(request), createVaadinResponse(response)); } - private void service(WrappedHttpServletRequest request, - WrappedHttpServletResponse response) throws ServletException, + private void service(VaadinServletRequest request, + VaadinServletResponse response) throws ServletException, IOException { RequestTimer requestTimer = new RequestTimer(); requestTimer.start(); @@ -501,24 +499,22 @@ public class VaadinServlet extends HttpServlet implements Constants { } } - private WrappedHttpServletResponse createWrappedResponse( + private VaadinServletResponse createVaadinResponse( HttpServletResponse response) { - WrappedHttpServletResponse wrappedResponse = new WrappedHttpServletResponse( - response, getVaadinService()); - return wrappedResponse; + return new VaadinServletResponse(response, getVaadinService()); } /** - * Create a wrapped request for a http servlet request. This method can be - * overridden if the wrapped request should have special properties. + * Create a Vaadin request for a http servlet request. This method can be + * overridden if the Vaadin request should have special properties. * * @param request * the original http servlet request - * @return a wrapped request for the original request + * @return a Vaadin request for the original request */ - protected WrappedHttpServletRequest createWrappedRequest( + protected VaadinServletRequest createVaadinRequest( HttpServletRequest request) { - return new WrappedHttpServletRequest(request, getVaadinService()); + return new VaadinServletRequest(request, getVaadinService()); } /** @@ -545,8 +541,8 @@ public class VaadinServlet extends HttpServlet implements Constants { * @throws IOException */ private boolean ensureCookiesEnabled(RequestType requestType, - WrappedHttpServletRequest request, - WrappedHttpServletResponse response) throws IOException { + VaadinServletRequest request, VaadinServletResponse response) + throws IOException { if (requestType == RequestType.UIDL) { // In all other but the first UIDL request a cookie should be // returned by the browser. @@ -592,7 +588,7 @@ public class VaadinServlet extends HttpServlet implements Constants { * @deprecated might be refactored or removed before 7.0.0 */ @Deprecated - protected void criticalNotification(WrappedHttpServletRequest request, + protected void criticalNotification(VaadinServletRequest request, HttpServletResponse response, String caption, String message, String details, String url) throws IOException { @@ -705,8 +701,8 @@ public class VaadinServlet extends HttpServlet implements Constants { return resultPath; } - private void handleServiceException(WrappedHttpServletRequest request, - WrappedHttpServletResponse response, VaadinSession vaadinSession, + private void handleServiceException(VaadinServletRequest request, + VaadinServletResponse response, VaadinSession vaadinSession, Throwable e) throws IOException, ServletException { // if this was an UIDL request, response UIDL back to client if (getRequestType(request) == RequestType.UIDL) { @@ -772,8 +768,8 @@ public class VaadinServlet extends HttpServlet implements Constants { * @deprecated might be refactored or removed before 7.0.0 */ @Deprecated - void handleServiceSessionExpired(WrappedHttpServletRequest request, - WrappedHttpServletResponse response) throws IOException, + void handleServiceSessionExpired(VaadinServletRequest request, + VaadinServletResponse response) throws IOException, ServletException { if (isOnUnloadRequest(request)) { @@ -818,9 +814,8 @@ public class VaadinServlet extends HttpServlet implements Constants { } - private void handleServiceSecurityException( - WrappedHttpServletRequest request, - WrappedHttpServletResponse response) throws IOException, + private void handleServiceSecurityException(VaadinServletRequest request, + VaadinServletResponse response) throws IOException, ServletException { if (isOnUnloadRequest(request)) { /* @@ -1212,7 +1207,7 @@ public class VaadinServlet extends HttpServlet implements Constants { * @deprecated might be refactored or removed before 7.0.0 */ @Deprecated - protected RequestType getRequestType(WrappedHttpServletRequest request) { + protected RequestType getRequestType(VaadinServletRequest request) { if (ServletPortletHelper.isFileUploadRequest(request)) { return RequestType.FILE_UPLOAD; } else if (ServletPortletHelper.isConnectorResourceRequest(request)) { diff --git a/server/src/com/vaadin/server/VaadinServletRequest.java b/server/src/com/vaadin/server/VaadinServletRequest.java new file mode 100644 index 0000000000..e9d673a1f3 --- /dev/null +++ b/server/src/com/vaadin/server/VaadinServletRequest.java @@ -0,0 +1,126 @@ +/* + * 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 javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletRequestWrapper; +import javax.servlet.http.HttpSession; + +import com.vaadin.server.VaadinServlet.ServletService; + +/** + * Wrapper for {@link HttpServletRequest}. + * + * @author Vaadin Ltd. + * @since 7.0 + * + * @see VaadinRequest + * @see VaadinServletResponse + */ +public class VaadinServletRequest extends HttpServletRequestWrapper implements + VaadinRequest { + + private final ServletService vaadinService; + + /** + * Wraps a http servlet request and associates with a vaadin service + * + * @param request + * the http servlet request to wrap + * @param vaadinService + * the associated vaadin service + */ + public VaadinServletRequest(HttpServletRequest request, + ServletService vaadinService) { + super(request); + this.vaadinService = vaadinService; + } + + @Override + public String getRequestPathInfo() { + return getPathInfo(); + } + + @Override + public WrappedSession getWrappedSession() { + return getWrappedSession(true); + } + + @Override + public WrappedSession getWrappedSession(boolean allowSessionCreation) { + HttpSession session = getSession(allowSessionCreation); + if (session != null) { + return new WrappedHttpSession(session); + } else { + return null; + } + } + + /** + * Gets the original, unwrapped HTTP servlet request. + * + * @return the servlet request + */ + public HttpServletRequest getHttpServletRequest() { + return this; + } + + @Override + public ServletService getVaadinService() { + return vaadinService; + } + + @Override + public BrowserDetails getBrowserDetails() { + return new BrowserDetails() { + @Override + public String getUriFragment() { + return null; + } + + @Override + public String getWindowName() { + return null; + } + + @Override + public WebBrowser getWebBrowser() { + return VaadinSession.getCurrent().getBrowser(); + } + }; + } + + /** + * Helper method to get a {@link VaadinServletRequest} from a + * {@link VaadinRequest}. Aside from casting, this method also takes care of + * situations where there's another level of wrapping. + * + * @param request + * a Vaadin request + * @return a Vaadin http servlet request + * @throws ClassCastException + * if the Vaadin request doesn't wrap a http servlet request + */ + public static VaadinServletRequest cast(VaadinRequest request) { + if (request instanceof CombinedRequest) { + CombinedRequest combinedRequest = (CombinedRequest) request; + request = combinedRequest.getSecondRequest(); + } + return (VaadinServletRequest) request; + } + +} \ No newline at end of file diff --git a/server/src/com/vaadin/server/VaadinServletResponse.java b/server/src/com/vaadin/server/VaadinServletResponse.java new file mode 100644 index 0000000000..b21ca34249 --- /dev/null +++ b/server/src/com/vaadin/server/VaadinServletResponse.java @@ -0,0 +1,86 @@ +/* + * 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 javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpServletResponseWrapper; + +import com.vaadin.server.VaadinServlet.ServletService; + +/** + * Wrapper for {@link HttpServletResponse}. + * + * @author Vaadin Ltd. + * @since 7.0 + * + * @see VaadinResponse + * @see VaadinServletRequest + */ +public class VaadinServletResponse extends HttpServletResponseWrapper implements + VaadinResponse { + + private ServletService vaadinService; + + /** + * Wraps a http servlet response and an associated vaadin service + * + * @param response + * the http servlet response to wrap + * @param vaadinService + * the associated vaadin service + */ + public VaadinServletResponse(HttpServletResponse response, + ServletService vaadinService) { + super(response); + this.vaadinService = vaadinService; + } + + /** + * Gets the original unwrapped HttpServletResponse + * + * @return the unwrapped response + */ + public HttpServletResponse getHttpServletResponse() { + return this; + } + + @Override + public void setCacheTime(long milliseconds) { + doSetCacheTime(this, milliseconds); + } + + // Implementation shared with VaadinPortletResponse + static void doSetCacheTime(VaadinResponse response, long milliseconds) { + if (milliseconds <= 0) { + response.setHeader("Cache-Control", "no-cache"); + response.setHeader("Pragma", "no-cache"); + response.setDateHeader("Expires", 0); + } else { + response.setHeader("Cache-Control", "max-age=" + milliseconds + / 1000); + response.setDateHeader("Expires", System.currentTimeMillis() + + milliseconds); + // Required to apply caching in some Tomcats + response.setHeader("Pragma", "cache"); + } + } + + @Override + public ServletService getVaadinService() { + return vaadinService; + } +} \ No newline at end of file diff --git a/server/src/com/vaadin/server/VaadinSession.java b/server/src/com/vaadin/server/VaadinSession.java index 8fbc7af335..c3699bacfa 100644 --- a/server/src/com/vaadin/server/VaadinSession.java +++ b/server/src/com/vaadin/server/VaadinSession.java @@ -42,7 +42,7 @@ import com.vaadin.data.util.converter.Converter; import com.vaadin.data.util.converter.ConverterFactory; import com.vaadin.data.util.converter.DefaultConverterFactory; import com.vaadin.event.EventRouter; -import com.vaadin.server.WrappedRequest.BrowserDetails; +import com.vaadin.server.VaadinRequest.BrowserDetails; import com.vaadin.shared.ui.ui.UIConstants; import com.vaadin.ui.AbstractField; import com.vaadin.ui.Table; @@ -615,18 +615,18 @@ public class VaadinSession implements HttpSessionBindingListener, Serializable { * host page is requested. * * @param request - * the wrapped request for which a UI is needed + * the Vaadin request for which a UI is needed * @return a UI instance to use for the request * * @see UI - * @see WrappedRequest#getBrowserDetails() + * @see VaadinRequest#getBrowserDetails() * * @since 7.0 * * @deprecated might be refactored or removed before 7.0.0 */ @Deprecated - public Class getUIClass(WrappedRequest request) { + public Class getUIClass(VaadinRequest request) { UIProvider uiProvider = getUiProvider(request, null); return uiProvider.getUIClass(request); } @@ -644,7 +644,7 @@ public class VaadinSession implements HttpSessionBindingListener, Serializable { * @deprecated might be refactored or removed before 7.0.0 */ @Deprecated - protected T createUIInstance(WrappedRequest request, + protected T createUIInstance(VaadinRequest request, Class uiClass) { UIProvider uiProvider = getUiProvider(request, uiClass); return uiClass.cast(uiProvider.createInstance(request, uiClass)); @@ -672,7 +672,7 @@ public class VaadinSession implements HttpSessionBindingListener, Serializable { * @deprecated might be refactored or removed before 7.0.0 */ @Deprecated - public UIProvider getUiProvider(WrappedRequest request, Class uiClass) { + public UIProvider getUiProvider(VaadinRequest request, Class uiClass) { UIProvider provider = (UIProvider) request .getAttribute(UIProvider.class.getName()); if (provider != null) { @@ -708,7 +708,7 @@ public class VaadinSession implements HttpSessionBindingListener, Serializable { * @deprecated might be refactored or removed before 7.0.0 */ @Deprecated - private UIProvider doGetUiProvider(WrappedRequest request, Class uiClass) { + private UIProvider doGetUiProvider(VaadinRequest request, Class uiClass) { int providersSize = uiProviders.size(); if (providersSize == 0) { throw new IllegalStateException("There are no UI providers"); @@ -853,14 +853,14 @@ public class VaadinSession implements HttpSessionBindingListener, Serializable { * the request for which a UI is desired * @return a UI belonging to the request * - * @see #createUI(WrappedRequest) + * @see #createUI(VaadinRequest) * * @since 7.0 * * @deprecated might be refactored or removed before 7.0.0 */ @Deprecated - public UI getUIForRequest(WrappedRequest request) { + public UI getUIForRequest(VaadinRequest request) { UI uI = UI.getCurrent(); if (uI != null) { return uI; @@ -890,7 +890,7 @@ public class VaadinSession implements HttpSessionBindingListener, Serializable { * @deprecated might be refactored or removed before 7.0.0 */ @Deprecated - private UI findExistingUi(WrappedRequest request) { + private UI findExistingUi(VaadinRequest request) { // Check if some UI provider has an existing UI available for (int i = uiProviders.size() - 1; i >= 0; i--) { UIProvider provider = uiProviders.get(i); @@ -939,7 +939,7 @@ public class VaadinSession implements HttpSessionBindingListener, Serializable { * @deprecated might be refactored or removed before 7.0.0 */ @Deprecated - public UI createUI(WrappedRequest request) { + public UI createUI(VaadinRequest request) { Class uiClass = getUIClass(request); UI ui = createUIInstance(request, uiClass); @@ -986,7 +986,7 @@ public class VaadinSession implements HttpSessionBindingListener, Serializable { * @deprecated might be refactored or removed before 7.0.0 */ @Deprecated - private static Integer getUIId(WrappedRequest request) { + private static Integer getUIId(VaadinRequest request) { if (request instanceof CombinedRequest) { // Combined requests has the uiId parameter in the second request CombinedRequest combinedRequest = (CombinedRequest) request; diff --git a/server/src/com/vaadin/server/VaadinSessionInitializeEvent.java b/server/src/com/vaadin/server/VaadinSessionInitializeEvent.java index cc4a0990d6..217e3d8f7d 100644 --- a/server/src/com/vaadin/server/VaadinSessionInitializeEvent.java +++ b/server/src/com/vaadin/server/VaadinSessionInitializeEvent.java @@ -35,7 +35,7 @@ import java.util.EventObject; public class VaadinSessionInitializeEvent extends EventObject { private final VaadinSession session; - private final WrappedRequest request; + private final VaadinRequest request; /** * Creates a new event. @@ -48,7 +48,7 @@ public class VaadinSessionInitializeEvent extends EventObject { * the request that triggered the initialization */ public VaadinSessionInitializeEvent(VaadinService service, - VaadinSession session, WrappedRequest request) { + VaadinSession session, VaadinRequest request) { super(service); this.session = session; this.request = request; @@ -82,7 +82,7 @@ public class VaadinSessionInitializeEvent extends EventObject { * * @return the request */ - public WrappedRequest getRequest() { + public VaadinRequest getRequest() { return request; } diff --git a/server/src/com/vaadin/server/WebBrowser.java b/server/src/com/vaadin/server/WebBrowser.java index 6a377a3de9..676375a693 100644 --- a/server/src/com/vaadin/server/WebBrowser.java +++ b/server/src/com/vaadin/server/WebBrowser.java @@ -411,9 +411,9 @@ public class WebBrowser implements Serializable { * properties in the class according to the given information. * * @param request - * the wrapped request to read the information from + * the Vaadin request to read the information from */ - void updateRequestDetails(WrappedRequest request) { + void updateRequestDetails(VaadinRequest request) { locale = request.getLocale(); address = request.getRemoteAddr(); secureConnection = request.isSecure(); diff --git a/server/src/com/vaadin/server/WrappedHttpServletRequest.java b/server/src/com/vaadin/server/WrappedHttpServletRequest.java deleted file mode 100644 index 99e8881ec1..0000000000 --- a/server/src/com/vaadin/server/WrappedHttpServletRequest.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * 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 javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletRequestWrapper; -import javax.servlet.http.HttpSession; - -import com.vaadin.server.VaadinServlet.ServletService; - -/** - * Wrapper for {@link HttpServletRequest}. - * - * @author Vaadin Ltd. - * @since 7.0 - * - * @see WrappedRequest - * @see WrappedHttpServletResponse - */ -public class WrappedHttpServletRequest extends HttpServletRequestWrapper - implements WrappedRequest { - - private final ServletService vaadinService; - - /** - * Wraps a http servlet request and associates with a vaadin service - * - * @param request - * the http servlet request to wrap - * @param vaadinService - * the associated vaadin service - */ - public WrappedHttpServletRequest(HttpServletRequest request, - ServletService vaadinService) { - super(request); - this.vaadinService = vaadinService; - } - - @Override - public String getRequestPathInfo() { - return getPathInfo(); - } - - @Override - public WrappedSession getWrappedSession() { - return getWrappedSession(true); - } - - @Override - public WrappedSession getWrappedSession(boolean allowSessionCreation) { - HttpSession session = getSession(allowSessionCreation); - if (session != null) { - return new WrappedHttpSession(session); - } else { - return null; - } - } - - /** - * Gets the original, unwrapped HTTP servlet request. - * - * @return the servlet request - */ - public HttpServletRequest getHttpServletRequest() { - return this; - } - - @Override - public ServletService getVaadinService() { - return vaadinService; - } - - @Override - public BrowserDetails getBrowserDetails() { - return new BrowserDetails() { - @Override - public String getUriFragment() { - return null; - } - - @Override - public String getWindowName() { - return null; - } - - @Override - public WebBrowser getWebBrowser() { - return VaadinSession.getCurrent().getBrowser(); - } - }; - } - - /** - * Helper method to get a WrappedHttpServletRequest from a - * WrappedRequest. Aside from casting, this method also takes - * care of situations where there's another level of wrapping. - * - * @param request - * a wrapped request - * @return a wrapped http servlet request - * @throws ClassCastException - * if the wrapped request doesn't wrap a http servlet request - */ - public static WrappedHttpServletRequest cast(WrappedRequest request) { - if (request instanceof CombinedRequest) { - CombinedRequest combinedRequest = (CombinedRequest) request; - request = combinedRequest.getSecondRequest(); - } - return (WrappedHttpServletRequest) request; - } - -} \ No newline at end of file diff --git a/server/src/com/vaadin/server/WrappedHttpServletResponse.java b/server/src/com/vaadin/server/WrappedHttpServletResponse.java deleted file mode 100644 index 74a580f874..0000000000 --- a/server/src/com/vaadin/server/WrappedHttpServletResponse.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * 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 javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpServletResponseWrapper; - -import com.vaadin.server.VaadinServlet.ServletService; - -/** - * Wrapper for {@link HttpServletResponse}. - * - * @author Vaadin Ltd. - * @since 7.0 - * - * @see WrappedResponse - * @see WrappedHttpServletRequest - */ -public class WrappedHttpServletResponse extends HttpServletResponseWrapper - implements WrappedResponse { - - private ServletService vaadinService; - - /** - * Wraps a http servlet response and an associated vaadin service - * - * @param response - * the http servlet response to wrap - * @param vaadinService - * the associated vaadin service - */ - public WrappedHttpServletResponse(HttpServletResponse response, - ServletService vaadinService) { - super(response); - this.vaadinService = vaadinService; - } - - /** - * Gets the original unwrapped HttpServletResponse - * - * @return the unwrapped response - */ - public HttpServletResponse getHttpServletResponse() { - return this; - } - - @Override - public void setCacheTime(long milliseconds) { - doSetCacheTime(this, milliseconds); - } - - // Implementation shared with WrappedPortletResponse - static void doSetCacheTime(WrappedResponse response, long milliseconds) { - if (milliseconds <= 0) { - response.setHeader("Cache-Control", "no-cache"); - response.setHeader("Pragma", "no-cache"); - response.setDateHeader("Expires", 0); - } else { - response.setHeader("Cache-Control", "max-age=" + milliseconds - / 1000); - response.setDateHeader("Expires", System.currentTimeMillis() - + milliseconds); - // Required to apply caching in some Tomcats - response.setHeader("Pragma", "cache"); - } - } - - @Override - public ServletService getVaadinService() { - return vaadinService; - } -} \ No newline at end of file diff --git a/server/src/com/vaadin/server/WrappedPortletRequest.java b/server/src/com/vaadin/server/WrappedPortletRequest.java deleted file mode 100644 index d4670cfd92..0000000000 --- a/server/src/com/vaadin/server/WrappedPortletRequest.java +++ /dev/null @@ -1,228 +0,0 @@ -/* - * 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.IOException; -import java.io.InputStream; -import java.util.Locale; -import java.util.Map; - -import javax.portlet.ClientDataRequest; -import javax.portlet.PortletRequest; -import javax.portlet.PortletSession; -import javax.portlet.ResourceRequest; - -import com.vaadin.server.VaadinPortlet.PortletService; -import com.vaadin.shared.ApplicationConstants; - -/** - * Wrapper for {@link PortletRequest} and its subclasses. - * - * @author Vaadin Ltd. - * @since 7.0 - * - * @see WrappedRequest - * @see WrappedPortletResponse - */ -public class WrappedPortletRequest implements WrappedRequest { - - private final PortletRequest request; - private final PortletService vaadinService; - - /** - * Wraps a portlet request and an associated vaadin service - * - * @param request - * the portlet request to wrap - * @param vaadinService - * the associated vaadin service - */ - public WrappedPortletRequest(PortletRequest request, - PortletService vaadinService) { - this.request = request; - this.vaadinService = vaadinService; - } - - @Override - public Object getAttribute(String name) { - return request.getAttribute(name); - } - - @Override - public int getContentLength() { - try { - return ((ClientDataRequest) request).getContentLength(); - } catch (ClassCastException e) { - throw new IllegalStateException( - "Content lenght only available for ClientDataRequests"); - } - } - - @Override - public InputStream getInputStream() throws IOException { - try { - return ((ClientDataRequest) request).getPortletInputStream(); - } catch (ClassCastException e) { - throw new IllegalStateException( - "Input data only available for ClientDataRequests"); - } - } - - @Override - public String getParameter(String name) { - return request.getParameter(name); - } - - @Override - public Map getParameterMap() { - return request.getParameterMap(); - } - - @Override - public void setAttribute(String name, Object o) { - request.setAttribute(name, o); - } - - @Override - public String getRequestPathInfo() { - if (request instanceof ResourceRequest) { - ResourceRequest resourceRequest = (ResourceRequest) request; - String resourceID = resourceRequest.getResourceID(); - if (VaadinPortlet.RESOURCE_URL_ID.equals(resourceID)) { - String resourcePath = resourceRequest - .getParameter(ApplicationConstants.V_RESOURCE_PATH); - return resourcePath; - } - return resourceID; - } else { - return null; - } - } - - @Override - public WrappedSession getWrappedSession() { - return getWrappedSession(true); - } - - @Override - public WrappedSession getWrappedSession(boolean allowSessionCreation) { - PortletSession session = request - .getPortletSession(allowSessionCreation); - if (session != null) { - return new WrappedPortletSession(session); - } else { - return null; - } - } - - /** - * Gets the original, unwrapped portlet request. - * - * @return the unwrapped portlet request - */ - public PortletRequest getPortletRequest() { - return request; - } - - @Override - public String getContentType() { - try { - return ((ResourceRequest) request).getContentType(); - } catch (ClassCastException e) { - throw new IllegalStateException( - "Content type only available for ResourceRequests"); - } - } - - @Override - public BrowserDetails getBrowserDetails() { - return new BrowserDetails() { - @Override - public String getUriFragment() { - return null; - } - - @Override - public String getWindowName() { - return null; - } - - @Override - public WebBrowser getWebBrowser() { - VaadinPortletSession context = (VaadinPortletSession) VaadinSession - .getCurrent(); - return context.getBrowser(); - } - }; - } - - @Override - public Locale getLocale() { - return request.getLocale(); - } - - @Override - public String getRemoteAddr() { - return null; - } - - @Override - public boolean isSecure() { - return request.isSecure(); - } - - @Override - public String getHeader(String string) { - return null; - } - - /** - * Reads a portal property from the portal context of the wrapped request. - * - * @param name - * a string with the name of the portal property to get - * @return a string with the value of the property, or null if - * the property is not defined - */ - public String getPortalProperty(String name) { - return request.getPortalContext().getProperty(name); - } - - @Override - public PortletService getVaadinService() { - return vaadinService; - } - - /** - * Helper method to get a WrappedPortlettRequest from a - * WrappedRequest. Aside from casting, this method also takes - * care of situations where there's another level of wrapping. - * - * @param request - * a wrapped request - * @return a wrapped portlet request - * @throws ClassCastException - * if the wrapped request doesn't wrap a portlet request - */ - public static WrappedPortletRequest cast(WrappedRequest request) { - if (request instanceof CombinedRequest) { - CombinedRequest combinedRequest = (CombinedRequest) request; - request = combinedRequest.getSecondRequest(); - } - return (WrappedPortletRequest) request; - } -} diff --git a/server/src/com/vaadin/server/WrappedPortletResponse.java b/server/src/com/vaadin/server/WrappedPortletResponse.java deleted file mode 100644 index 5888c33b43..0000000000 --- a/server/src/com/vaadin/server/WrappedPortletResponse.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * 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.IOException; -import java.io.OutputStream; -import java.io.PrintWriter; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.Locale; -import java.util.TimeZone; - -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. - * - * @author Vaadin Ltd. - * @since 7.0 - * - * @see WrappedResponse - * @see WrappedPortletRequest - */ -public class WrappedPortletResponse implements WrappedResponse { - private static final DateFormat HTTP_DATE_FORMAT = new SimpleDateFormat( - "EEE, dd MMM yyyy HH:mm:ss zzz", Locale.ENGLISH); - static { - HTTP_DATE_FORMAT.setTimeZone(TimeZone.getTimeZone("GMT")); - } - - private final PortletResponse response; - private PortletService vaadinService; - - /** - * Wraps a portlet response and an associated vaadin service - * - * @param response - * the portlet response to wrap - * @param vaadinService - * the associated vaadin service - */ - public WrappedPortletResponse(PortletResponse response, - PortletService vaadinService) { - this.response = response; - this.vaadinService = vaadinService; - } - - @Override - public OutputStream getOutputStream() throws IOException { - return ((MimeResponse) response).getPortletOutputStream(); - } - - /** - * Gets the original, unwrapped portlet response. - * - * @return the unwrapped portlet response - */ - public PortletResponse getPortletResponse() { - return response; - } - - @Override - public void setContentType(String type) { - ((MimeResponse) response).setContentType(type); - } - - @Override - public PrintWriter getWriter() throws IOException { - return ((MimeResponse) response).getWriter(); - } - - @Override - public void setStatus(int responseStatus) { - response.setProperty(ResourceResponse.HTTP_STATUS_CODE, - Integer.toString(responseStatus)); - } - - @Override - public void setHeader(String name, String value) { - response.setProperty(name, value); - } - - @Override - public void setDateHeader(String name, long timestamp) { - response.setProperty(name, HTTP_DATE_FORMAT.format(new Date(timestamp))); - } - - @Override - public void setCacheTime(long milliseconds) { - WrappedHttpServletResponse.doSetCacheTime(this, milliseconds); - } - - @Override - public void sendError(int errorCode, String message) throws IOException { - setStatus(errorCode); - getWriter().write(message); - } - - @Override - public PortletService getVaadinService() { - return vaadinService; - } -} \ No newline at end of file diff --git a/server/src/com/vaadin/server/WrappedRequest.java b/server/src/com/vaadin/server/WrappedRequest.java deleted file mode 100644 index aeaff2b384..0000000000 --- a/server/src/com/vaadin/server/WrappedRequest.java +++ /dev/null @@ -1,278 +0,0 @@ -/* - * 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.IOException; -import java.io.InputStream; -import java.io.Serializable; -import java.util.Locale; -import java.util.Map; - -import javax.portlet.PortletRequest; -import javax.servlet.ServletRequest; -import javax.servlet.http.HttpServletRequest; - -import com.vaadin.ui.UI; - -/** - * A generic request to the server, wrapping a more specific request type, e.g. - * HttpServletReqest or PortletRequest. - * - * @author Vaadin Ltd - * @since 7.0.0 - */ -public interface WrappedRequest extends Serializable { - - /** - * Detailed information extracted from the browser. - * - * @see WrappedRequest#getBrowserDetails() - * @deprecated might be refactored or removed before 7.0.0 - */ - @Deprecated - public interface BrowserDetails extends Serializable { - /** - * Gets the URI hash fragment for the request. This is typically used to - * encode navigation within an application. - * - * @return the URI hash fragment - */ - public String getUriFragment(); - - /** - * Gets the value of window.name from the browser. This can be used to - * keep track of the specific window between browser reloads. - * - * @return the string value of window.name in the browser - */ - public String getWindowName(); - - /** - * Gets a reference to the {@link WebBrowser} object containing - * additional information, e.g. screen size and the time zone offset. - * - * @return the web browser object - */ - public WebBrowser getWebBrowser(); - } - - /** - * Gets the named request parameter This is typically a HTTP GET or POST - * parameter, though other request types might have other ways of - * representing parameters. - * - * @see javax.servlet.ServletRequest#getParameter(String) - * @see javax.portlet.PortletRequest#getParameter(String) - * - * @param parameter - * the name of the parameter - * @return The paramter value, or null if no parameter with the - * given name is present - */ - public String getParameter(String parameter); - - /** - * Gets all the parameters of the request. - * - * @see #getParameter(String) - * - * @see javax.servlet.ServletRequest#getParameterMap() - * @see javax.portlet.PortletRequest#getParameter(String) - * - * @return A mapping of parameter names to arrays of parameter values - */ - public Map getParameterMap(); - - /** - * Returns the length of the request content that can be read from the input - * stream returned by {@link #getInputStream()}. - * - * @see javax.servlet.ServletRequest#getContentLength() - * @see javax.portlet.ClientDataRequest#getContentLength() - * - * @return content length in bytes - */ - public int getContentLength(); - - /** - * Returns an input stream from which the request content can be read. The - * request content length can be obtained with {@link #getContentLength()} - * without reading the full stream contents. - * - * @see javax.servlet.ServletRequest#getInputStream() - * @see javax.portlet.ClientDataRequest#getPortletInputStream() - * - * @return the input stream from which the contents of the request can be - * read - * @throws IOException - * if the input stream can not be opened - */ - public InputStream getInputStream() throws IOException; - - /** - * Gets a request attribute. - * - * @param name - * the name of the attribute - * @return the value of the attribute, or null if there is no - * attribute with the given name - * - * @see javax.servlet.ServletRequest#getAttribute(String) - * @see javax.portlet.PortletRequest#getAttribute(String) - */ - public Object getAttribute(String name); - - /** - * Defines a request attribute. - * - * @param name - * the name of the attribute - * @param value - * the attribute value - * - * @see javax.servlet.ServletRequest#setAttribute(String, Object) - * @see javax.portlet.PortletRequest#setAttribute(String, Object) - */ - public void setAttribute(String name, Object value); - - /** - * Gets the path of the requested resource relative to the application. The - * path be null if no path information is available. Does - * always start with / if the path isn't null. - * - * @return a string with the path relative to the application. - * - * @see javax.servlet.http.HttpServletRequest#getPathInfo() - */ - public String getRequestPathInfo(); - - /** - * Gets the session associated with this request, creating a new if there is - * no session. - * - * @see WrappedSession - * @see HttpServletRequest#getSession() - * @see PortletRequest#getPortletSession() - * - * @return the wrapped session for this request - */ - public WrappedSession getWrappedSession(); - - /** - * Gets the session associated with this request, optionally creating a new - * if there is no session. - * - * @param allowSessionCreation - * true to create a new session for this request if - * necessary; false to return null if - * there's no current session - * - * @see WrappedSession - * @see HttpServletRequest#getSession(boolean) - * @see PortletRequest#getPortletSession(boolean) - * - * @return the wrapped session for this request - */ - public WrappedSession getWrappedSession(boolean allowSessionCreation); - - /** - * Returns the MIME type of the body of the request, or null if the type is - * not known. - * - * @return a string containing the name of the MIME type of the request, or - * null if the type is not known - * - * @see javax.servlet.ServletRequest#getContentType() - * @see javax.portlet.ResourceRequest#getContentType() - * - */ - public String getContentType(); - - /** - * Gets detailed information about the browser from which the request - * originated. This consists of information that is not available from - * normal HTTP requests, but requires additional information to be extracted - * for instance using javascript in the browser. - * - * This information is only guaranteed to be available in some special - * cases, for instance in {@link UI#init(WrappedRequest)}. - * - * @return the browser details, or null if details are not - * available - * - * @see BrowserDetails - * @deprecated might be refactored or removed before 7.0.0 - */ - @Deprecated - public BrowserDetails getBrowserDetails(); - - /** - * Gets locale information from the query, e.g. using the Accept-Language - * header. - * - * @return the preferred Locale - * - * @see ServletRequest#getLocale() - * @see PortletRequest#getLocale() - */ - public Locale getLocale(); - - /** - * Returns the IP address from which the request came. This might also be - * the address of a proxy between the server and the original requester. - * - * @return a string containing the IP address, or null if the - * address is not available - * - * @see ServletRequest#getRemoteAddr() - */ - public String getRemoteAddr(); - - /** - * Checks whether the request was made using a secure channel, e.g. using - * https. - * - * @return a boolean indicating if the request is secure - * - * @see ServletRequest#isSecure() - * @see PortletRequest#isSecure() - */ - public boolean isSecure(); - - /** - * Gets the value of a request header, e.g. a http header for a - * {@link HttpServletRequest}. - * - * @param headerName - * the name of the header - * @return the header value, or null if the header is not - * present in the request - * - * @see HttpServletRequest#getHeader(String) - */ - public String getHeader(String headerName); - - /** - * Gets the vaadin service for the context of this request. - * - * @return the vaadin service - * - * @see VaadinService - */ - public VaadinService getVaadinService(); - -} diff --git a/server/src/com/vaadin/server/WrappedResponse.java b/server/src/com/vaadin/server/WrappedResponse.java deleted file mode 100644 index 90c9a356e1..0000000000 --- a/server/src/com/vaadin/server/WrappedResponse.java +++ /dev/null @@ -1,159 +0,0 @@ -/* - * 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.IOException; -import java.io.OutputStream; -import java.io.PrintWriter; -import java.io.Serializable; - -import javax.portlet.MimeResponse; -import javax.portlet.PortletResponse; -import javax.portlet.ResourceResponse; -import javax.servlet.ServletResponse; -import javax.servlet.http.HttpServletResponse; - -/** - * A generic response from the server, wrapping a more specific response type, - * e.g. HttpServletResponse or PortletResponse. - * - * @since 7.0 - */ -public interface WrappedResponse extends Serializable { - - /** - * Sets the (http) status code for the response. If you want to include an - * error message along the status code, use {@link #sendError(int, String)} - * instead. - * - * @param statusCode - * the status code to set - * @see HttpServletResponse#setStatus(int) - * - * @see ResourceResponse#HTTP_STATUS_CODE - */ - public void setStatus(int statusCode); - - /** - * Sets the content type of this response. If the content type including a - * charset is set before {@link #getWriter()} is invoked, the returned - * PrintWriter will automatically use the defined charset. - * - * @param contentType - * a string specifying the MIME type of the content - * - * @see ServletResponse#setContentType(String) - * @see MimeResponse#setContentType(String) - */ - public void setContentType(String contentType); - - /** - * Sets the value of a generic response header. If the header had already - * been set, the new value overwrites the previous one. - * - * @param name - * the name of the header - * @param value - * the header value. - * - * @see HttpServletResponse#setHeader(String, String) - * @see PortletResponse#setProperty(String, String) - */ - public void setHeader(String name, String value); - - /** - * Properly formats a timestamp as a date header. If the header had already - * been set, the new value overwrites the previous one. - * - * @param name - * the name of the header - * @param timestamp - * the number of milliseconds since epoch - * - * @see HttpServletResponse#setDateHeader(String, long) - */ - public void setDateHeader(String name, long timestamp); - - /** - * Returns a OutputStream for writing binary data in the - * response. - *

- * Either this method or getWriter() may be called to write the response, - * not both. - * - * @return a OutputStream for writing binary data - * @throws IOException - * if an input or output exception occurred - * - * @see #getWriter() - * @see ServletResponse#getOutputStream() - * @see MimeResponse#getPortletOutputStream() - */ - public OutputStream getOutputStream() throws IOException; - - /** - * Returns a PrintWriter object that can send character text to - * the client. The PrintWriter uses the character encoding defined using - * setContentType. - *

- * Either this method or getOutputStream() may be called to write the - * response, not both. - * - * @return a PrintWriter for writing character text - * @throws IOException - * if an input or output exception occurred - * - * @see #getOutputStream() - * @see ServletResponse#getWriter() - * @see MimeResponse#getWriter() - */ - public PrintWriter getWriter() throws IOException; - - /** - * Sets cache time in milliseconds, -1 means no cache at all. All required - * headers related to caching in the response are set based on the time. - * - * @param milliseconds - * Cache time in milliseconds - */ - public void setCacheTime(long milliseconds); - - /** - * Sends an error response to the client using the specified status code and - * clears the buffer. In some configurations, this can cause a predefined - * error page to be displayed. - * - * @param errorCode - * the HTTP status code - * @param message - * a message to accompany the error - * @throws IOException - * if an input or output exception occurs - * - * @see HttpServletResponse#sendError(int, String) - */ - public void sendError(int errorCode, String message) throws IOException; - - /** - * Gets the vaadin service for the context of this response. - * - * @return the vaadin service - * - * @see VaadinService - */ - public VaadinService getVaadinService(); -} diff --git a/server/src/com/vaadin/ui/AbstractMedia.java b/server/src/com/vaadin/ui/AbstractMedia.java index 219413974b..3cc801817f 100644 --- a/server/src/com/vaadin/ui/AbstractMedia.java +++ b/server/src/com/vaadin/ui/AbstractMedia.java @@ -26,8 +26,8 @@ import java.util.regex.Pattern; import com.vaadin.server.ConnectorResource; import com.vaadin.server.Resource; import com.vaadin.server.ResourceReference; -import com.vaadin.server.WrappedRequest; -import com.vaadin.server.WrappedResponse; +import com.vaadin.server.VaadinRequest; +import com.vaadin.server.VaadinResponse; import com.vaadin.shared.communication.URLReference; import com.vaadin.shared.ui.AbstractMediaState; import com.vaadin.shared.ui.MediaControl; @@ -79,8 +79,8 @@ public abstract class AbstractMedia extends AbstractComponent { } @Override - public boolean handleConnectorRequest(WrappedRequest request, - WrappedResponse response, String path) throws IOException { + public boolean handleConnectorRequest(VaadinRequest request, + VaadinResponse response, String path) throws IOException { Matcher matcher = Pattern.compile("(\\d+)(/.*)?").matcher(path); if (matcher.matches()) { List sources = getState().sources; diff --git a/server/src/com/vaadin/ui/LoginForm.java b/server/src/com/vaadin/ui/LoginForm.java index 69778c4c07..661c24bf56 100644 --- a/server/src/com/vaadin/ui/LoginForm.java +++ b/server/src/com/vaadin/ui/LoginForm.java @@ -28,8 +28,8 @@ import com.vaadin.server.ConnectorResource; import com.vaadin.server.DownloadStream; import com.vaadin.server.RequestHandler; import com.vaadin.server.VaadinSession; -import com.vaadin.server.WrappedRequest; -import com.vaadin.server.WrappedResponse; +import com.vaadin.server.VaadinRequest; +import com.vaadin.server.VaadinResponse; import com.vaadin.shared.ApplicationConstants; /** @@ -84,7 +84,7 @@ public class LoginForm extends CustomComponent { private final RequestHandler requestHandler = new RequestHandler() { @Override public boolean handleRequest(VaadinSession session, - WrappedRequest request, WrappedResponse response) + VaadinRequest request, VaadinResponse response) throws IOException { String requestPathInfo = request.getRequestPathInfo(); if ("/loginHandler".equals(requestPathInfo)) { diff --git a/server/src/com/vaadin/ui/UI.java b/server/src/com/vaadin/ui/UI.java index 0d83f8258d..5beb80ffcd 100644 --- a/server/src/com/vaadin/ui/UI.java +++ b/server/src/com/vaadin/ui/UI.java @@ -41,10 +41,10 @@ import com.vaadin.server.Page.BrowserWindowResizeListener; import com.vaadin.server.PaintException; import com.vaadin.server.PaintTarget; import com.vaadin.server.Resource; +import com.vaadin.server.VaadinRequest; +import com.vaadin.server.VaadinRequest.BrowserDetails; import com.vaadin.server.VaadinServlet; import com.vaadin.server.VaadinSession; -import com.vaadin.server.WrappedRequest; -import com.vaadin.server.WrappedRequest.BrowserDetails; import com.vaadin.shared.EventId; import com.vaadin.shared.MouseEventDetails; import com.vaadin.shared.ui.BorderStyle; @@ -67,21 +67,21 @@ import com.vaadin.util.ReflectTools; *

* When a new UI instance is needed, typically because the user opens a URL in a * browser window which points to {@link VaadinServlet}, - * {@link VaadinSession#getUIForRequest(WrappedRequest)} is invoked to get a UI. + * {@link VaadinSession#getUIForRequest(VaadinRequest)} is invoked to get a UI. * That method does by default create a UI according to the * {@value VaadinSession#UI_PARAMETER} parameter from web.xml. *

*

* After a UI has been created by the application, it is initialized using - * {@link #init(WrappedRequest)}. This method is intended to be overridden by - * the developer to add components to the user interface and initialize + * {@link #init(VaadinRequest)}. This method is intended to be overridden by the + * developer to add components to the user interface and initialize * non-component functionality. The component hierarchy is initialized by * passing a {@link ComponentContainer} with the main layout of the view to * {@link #setContent(ComponentContainer)}. *

* - * @see #init(WrappedRequest) - * @see VaadinSession#createUI(WrappedRequest) + * @see #init(VaadinRequest) + * @see VaadinSession#createUI(VaadinRequest) * * @since 7.0 */ @@ -126,7 +126,7 @@ public abstract class UI extends AbstractComponentContainer implements } @Override - protected void init(WrappedRequest request) { + protected void init(VaadinRequest request) { // Just empty } @@ -748,8 +748,8 @@ public abstract class UI extends AbstractComponentContainer implements * Gets the id of the UI, used to identify this UI within its application * when processing requests. The UI id should be present in every request to * the server that originates from this UI. - * {@link VaadinSession#getUIForRequest(WrappedRequest)} uses this id to - * find the route to which the request belongs. + * {@link VaadinSession#getUIForRequest(VaadinRequest)} uses this id to find + * the route to which the request belongs. * * @return */ @@ -761,7 +761,7 @@ public abstract class UI extends AbstractComponentContainer implements * Adds a window as a subwindow inside this UI. To open a new browser window * or tab, you should instead use {@link open(Resource)} with an url * pointing to this application and ensure - * {@link VaadinSession#createUI(WrappedRequest)} returns an appropriate UI + * {@link VaadinSession#createUI(VaadinRequest)} returns an appropriate UI * for the request. * * @param window @@ -979,7 +979,7 @@ public abstract class UI extends AbstractComponentContainer implements * @param uiId * the id of the new ui */ - public void doInit(WrappedRequest request, int uiId) { + public void doInit(VaadinRequest request, int uiId) { if (this.uiId != -1) { throw new IllegalStateException("UI id has already been defined"); } @@ -999,15 +999,15 @@ public abstract class UI extends AbstractComponentContainer implements * Performing the initialization in a constructor is not suggested as the * state of the UI is not properly set up when the constructor is invoked. *

- * The {@link WrappedRequest} can be used to get information about the + * The {@link VaadinRequest} can be used to get information about the * request that caused this UI to be created. {@link BrowserDetails} will be * available in the request. *

* * @param request - * the wrapped request that caused this UI to be created + * the Vaadin request that caused this UI to be created */ - protected abstract void init(WrappedRequest request); + protected abstract void init(VaadinRequest request); /** * Sets the thread local for the current UI. This method is used by the -- cgit v1.2.3