]> source.dussan.org Git - vaadin-framework.git/commitdiff
Reomove DynamicConnectorResource (#10227) 14/314/1
authorLeif Åstrand <leif@vaadin.com>
Wed, 21 Nov 2012 11:17:39 +0000 (13:17 +0200)
committerLeif Åstrand <leif@vaadin.com>
Wed, 21 Nov 2012 11:17:39 +0000 (13:17 +0200)
Change-Id: I9e91f9d57e22d3df621a19e0250339d5d2763827

server/src/com/vaadin/server/DynamicConnectorResource.java [deleted file]
server/src/com/vaadin/server/ResourceReference.java
server/src/com/vaadin/ui/LoginForm.java
uitest/src/com/vaadin/tests/components/javascriptcomponent/BasicJavaScriptComponent.java
uitest/src/com/vaadin/tests/minitutorials/v7a1/DynamicImageUI.java
uitest/src/com/vaadin/tests/resources/ConnectorResourceTest.html [deleted file]
uitest/src/com/vaadin/tests/resources/ConnectorResourceTest.java [deleted file]

diff --git a/server/src/com/vaadin/server/DynamicConnectorResource.java b/server/src/com/vaadin/server/DynamicConnectorResource.java
deleted file mode 100644 (file)
index 0e29b28..0000000
+++ /dev/null
@@ -1,95 +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.util.Collections;
-import java.util.Map;
-
-import com.vaadin.util.FileTypeResolver;
-
-/**
- * A resource that is served by calling
- * {@link ClientConnector#handleConnectorRequest(VaadinRequest, VaadinResponse, String)}
- * with appropriate parameters.
- * 
- * @author Vaadin Ltd
- * @version @VERSION@
- * @since 7.0.0
- */
-public class DynamicConnectorResource implements Resource {
-
-    private final ClientConnector connector;
-    private final String path;
-    private final Map<String, String> parameters;
-
-    /**
-     * Creates a DynamicConnectorResoruce for the given connector that will be
-     * served by calling
-     * {@link ClientConnector#handleConnectorRequest(VaadinRequest, VaadinResponse, String)}
-     * with the given path.
-     * 
-     * @param connector
-     *            the connector that should serve the resource
-     * @param path
-     *            the relative path of the request
-     */
-    public DynamicConnectorResource(ClientConnector connector, String path) {
-        this(connector, path, null);
-    }
-
-    /**
-     * Creates a DynamicConnectorResoruce for the given connector that will be
-     * served by calling
-     * {@link ClientConnector#handleConnectorRequest(VaadinRequest, VaadinResponse, String)}
-     * with the given path and the given request parameters.
-     * 
-     * @param connector
-     *            the connector that should serve the resource
-     * @param path
-     *            the relative path of the request
-     * @param parameters
-     *            the parameters that should be present in the request
-     */
-    public DynamicConnectorResource(ClientConnector connector, String path,
-            Map<String, String> parameters) {
-        this.connector = connector;
-        this.path = path;
-        this.parameters = parameters;
-    }
-
-    @Override
-    public String getMIMEType() {
-        return FileTypeResolver.getMIMEType(path);
-    }
-
-    public String getPath() {
-        return path;
-    }
-
-    public ClientConnector getConnector() {
-        return connector;
-    }
-
-    public Map<String, String> getParameters() {
-        if (parameters == null) {
-            return Collections.emptyMap();
-        } else {
-            return Collections.unmodifiableMap(parameters);
-        }
-    }
-
-}
index b6a0cfda92291edfb21a5fb0aa3c926e01e72c16..fbb8af89c1da037822a7373af9f6b43dd3579700 100644 (file)
@@ -17,8 +17,6 @@ package com.vaadin.server;
 
 import java.io.UnsupportedEncodingException;
 import java.net.URLEncoder;
-import java.util.Map.Entry;
-import java.util.Set;
 
 import com.vaadin.shared.ApplicationConstants;
 import com.vaadin.shared.communication.URLReference;
@@ -44,29 +42,6 @@ public class ResourceReference extends URLReference {
     public String getURL() {
         if (resource instanceof ExternalResource) {
             return ((ExternalResource) resource).getURL();
-        } else if (resource instanceof DynamicConnectorResource) {
-            DynamicConnectorResource dcr = (DynamicConnectorResource) resource;
-
-            String filename = dcr.getPath();
-            StringBuilder builder = new StringBuilder(getConnectorResourceBase(
-                    filename, dcr.getConnector()));
-
-            Set<Entry<String, String>> entrySet = dcr.getParameters()
-                    .entrySet();
-            boolean first = true;
-            for (Entry<String, String> entry : entrySet) {
-                String key = entry.getKey();
-                String value = entry.getValue();
-                if (first) {
-                    builder.append('?');
-                    first = false;
-                } else {
-                    builder.append('&');
-                }
-                // TODO URL encode!!!
-                builder.append(key).append('=').append(value);
-            }
-            return builder.toString();
         } else if (resource instanceof ConnectorResource) {
             ConnectorResource connectorResource = (ConnectorResource) resource;
 
index b1e47414506d189c70b316b2deb756bdc89c5ce4..9c131b9700c66f26c25c6846ddbafb5c2c1404f6 100644 (file)
@@ -22,7 +22,8 @@ import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
 
-import com.vaadin.server.DynamicConnectorResource;
+import com.vaadin.server.ConnectorResource;
+import com.vaadin.server.ExternalResource;
 import com.vaadin.server.VaadinRequest;
 import com.vaadin.server.VaadinResponse;
 import com.vaadin.server.VaadinService;
@@ -108,12 +109,22 @@ public class LoginForm extends CustomComponent {
     public LoginForm() {
         iframe.setType(Embedded.TYPE_BROWSER);
         iframe.setSizeFull();
-        iframe.setSource(new DynamicConnectorResource(this, "login"));
         setSizeFull();
         setCompositionRoot(iframe);
         addStyleName("v-loginform");
     }
 
+    @Override
+    public void beforeClientResponse(boolean initial) {
+        // Generate magic URL now when UI id and connectorId are known
+        iframe.setSource(new ExternalResource(
+                ApplicationConstants.APP_PROTOCOL_PREFIX
+                        + ApplicationConstants.APP_REQUEST_PATH + '/'
+                        + ConnectorResource.CONNECTOR_REQUEST_PATH
+                        + getUI().getUIId() + '/' + getConnectorId() + "/login"));
+        super.beforeClientResponse(initial);
+    }
+
     /**
      * Returns byte array containing login page html. If you need to override
      * the login html, use the default html as basis. Login page sets its target
index aef1ef83d0e306ffbfcdebc9ec33a5bfb940527d..9e316e77f1ef5b68c1621dc538ca9cd85ce13bc5 100644 (file)
@@ -23,7 +23,8 @@ import org.json.JSONArray;
 import org.json.JSONException;
 
 import com.vaadin.annotations.JavaScript;
-import com.vaadin.server.DynamicConnectorResource;
+import com.vaadin.server.ConnectorResource;
+import com.vaadin.server.DownloadStream;
 import com.vaadin.server.Resource;
 import com.vaadin.server.ResourceReference;
 import com.vaadin.server.VaadinRequest;
@@ -109,8 +110,24 @@ public class BasicJavaScriptComponent extends AbstractTestUI {
                     .setMessages(
                             Arrays.asList("First state message",
                                     "Second state message"));
-            Resource resource = new DynamicConnectorResource(this, "test");
-            getState().setUrl(new ResourceReference(resource, null, null));
+            // Dummy resource used to test URL translation
+            Resource resource = new ConnectorResource() {
+                @Override
+                public String getMIMEType() {
+                    return null;
+                }
+
+                @Override
+                public DownloadStream getStream() {
+                    return null;
+                }
+
+                @Override
+                public String getFilename() {
+                    return null;
+                }
+            };
+            getState().setUrl(new ResourceReference(resource, this, "test"));
         }
 
         @Override
index a84a2206ef9cb1c65972a7670681c87665e8c7d4..29bedb40fb164a134974b6fc2c0283f89349bc8c 100644 (file)
@@ -2,25 +2,50 @@ package com.vaadin.tests.minitutorials.v7a1;
 
 import java.awt.image.BufferedImage;
 import java.io.IOException;
-import java.util.HashMap;
 
 import javax.imageio.ImageIO;
 
-import com.vaadin.server.DynamicConnectorResource;
+import com.vaadin.server.ExternalResource;
+import com.vaadin.server.RequestHandler;
+import com.vaadin.server.Resource;
 import com.vaadin.server.VaadinRequest;
 import com.vaadin.server.VaadinResponse;
+import com.vaadin.server.VaadinSession;
 import com.vaadin.tests.components.AbstractTestUI;
 import com.vaadin.ui.Image;
 
 public class DynamicImageUI extends AbstractTestUI {
     public static final String IMAGE_URL = "myimage.png";
 
+    private final RequestHandler requestHandler = new RequestHandler() {
+        @Override
+        public boolean handleRequest(VaadinSession session,
+                VaadinRequest request, VaadinResponse response)
+                throws IOException {
+            if (("/" + IMAGE_URL).equals(request.getPathInfo())) {
+                // Create an image, draw the "text" parameter to it and output
+                // it to the browser.
+                String text = request.getParameter("text");
+                BufferedImage bi = new BufferedImage(100, 30,
+                        BufferedImage.TYPE_3BYTE_BGR);
+                bi.getGraphics().drawChars(text.toCharArray(), 0,
+                        text.length(), 10, 20);
+                response.setContentType("image/png");
+                ImageIO.write(bi, "png", response.getOutputStream());
+
+                return true;
+            }
+            // If the URL did not match our image URL, let the other request
+            // handlers handle it
+            return false;
+        }
+    };
+
     @Override
     public void setup(VaadinRequest request) {
-        HashMap<String, String> parameters = new HashMap<String, String>();
-        parameters.put("text", "Hello!");
-        DynamicConnectorResource resource = new DynamicConnectorResource(this,
-                IMAGE_URL, parameters);
+        Resource resource = new ExternalResource(IMAGE_URL + "?text=Hello!");
+
+        getSession().addRequestHandler(requestHandler);
 
         // Add an image using the resource
         Image image = new Image("A dynamically generated image", resource);
@@ -29,24 +54,11 @@ public class DynamicImageUI extends AbstractTestUI {
     }
 
     @Override
-    public boolean handleConnectorRequest(VaadinRequest request,
-            VaadinResponse response, String path) throws IOException {
-        if ((IMAGE_URL).equals(path)) {
-            // Create an image, draw the "text" parameter to it and output it to
-            // the browser.
-            String text = request.getParameter("text");
-            BufferedImage bi = new BufferedImage(100, 30,
-                    BufferedImage.TYPE_3BYTE_BGR);
-            bi.getGraphics().drawChars(text.toCharArray(), 0, text.length(),
-                    10, 20);
-            response.setContentType("image/png");
-            ImageIO.write(bi, "png", response.getOutputStream());
-
-            return true;
-        }
-        // If the URL did not match our image URL, let the other request
-        // handlers handle it
-        return false;
+    public void detach() {
+        super.detach();
+
+        // Clean up
+        getSession().removeRequestHandler(requestHandler);
     }
 
     @Override
diff --git a/uitest/src/com/vaadin/tests/resources/ConnectorResourceTest.html b/uitest/src/com/vaadin/tests/resources/ConnectorResourceTest.html
deleted file mode 100644 (file)
index f400bac..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-<head profile="http://selenium-ide.openqa.org/profiles/test-case">
-<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
-<link rel="selenium.base" href="" />
-<title>New Test</title>
-</head>
-<body>
-<table cellpadding="1" cellspacing="1" border="1">
-<thead>
-<tr><td rowspan="1" colspan="3">New Test</td></tr>
-</thead><tbody>
-<tr>
-       <td>open</td>
-       <td>/run/com.vaadin.tests.resources.ConnectorResourceTest?restartApplication</td>
-       <td></td>
-</tr>
-<tr>
-       <td>screenCapture</td>
-       <td></td>
-       <td></td>
-</tr>
-
-</tbody></table>
-</body>
-</html>
diff --git a/uitest/src/com/vaadin/tests/resources/ConnectorResourceTest.java b/uitest/src/com/vaadin/tests/resources/ConnectorResourceTest.java
deleted file mode 100644 (file)
index 580188f..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-package com.vaadin.tests.resources;
-
-import java.awt.image.BufferedImage;
-import java.io.IOException;
-import java.util.HashMap;
-
-import javax.imageio.ImageIO;
-
-import com.vaadin.server.DynamicConnectorResource;
-import com.vaadin.server.VaadinRequest;
-import com.vaadin.server.VaadinResponse;
-import com.vaadin.tests.components.AbstractTestUI;
-import com.vaadin.ui.Embedded;
-
-public class ConnectorResourceTest extends AbstractTestUI {
-
-    private static final String DYNAMIC_IMAGE_NAME = "requestImage.png";
-
-    @Override
-    protected void setup(VaadinRequest request) {
-        addComponent(new Embedded(DYNAMIC_IMAGE_NAME,
-                new DynamicConnectorResource(this, DYNAMIC_IMAGE_NAME)));
-        addComponent(new Embedded("Dynamic text", new DynamicConnectorResource(
-                this, DYNAMIC_IMAGE_NAME, new HashMap<String, String>() {
-                    {
-                        put("text", "Dynamic%20text");
-                    }
-                })));
-    }
-
-    @Override
-    protected String getTestDescription() {
-        // Adding description would break screenshots -> too lazy to change
-        return null;
-    }
-
-    @Override
-    protected Integer getTicketNumber() {
-        return Integer.valueOf("9419");
-    }
-
-    @Override
-    public boolean handleConnectorRequest(VaadinRequest request,
-            VaadinResponse response, String path) throws IOException {
-        if (DYNAMIC_IMAGE_NAME.equals(path)) {
-            // Create an image, draw the "text" parameter to it and output it to
-            // the browser.
-            String text = request.getParameter("text");
-            if (text == null) {
-                text = DYNAMIC_IMAGE_NAME;
-            }
-            BufferedImage bi = getImage(text);
-            response.setContentType("image/png");
-            ImageIO.write(bi, "png", response.getOutputStream());
-
-            return true;
-        } else {
-            return super.handleConnectorRequest(request, response, path);
-        }
-    }
-
-    private BufferedImage getImage(String text) {
-        BufferedImage bi = new BufferedImage(150, 30,
-                BufferedImage.TYPE_3BYTE_BGR);
-        bi.getGraphics()
-                .drawChars(text.toCharArray(), 0, text.length(), 10, 20);
-        return bi;
-    }
-
-}