From 7d9c4c5e06a95f4aa5eb371a2f5b5418b92fac64 Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Wed, 21 Nov 2012 13:17:39 +0200 Subject: Reomove DynamicConnectorResource (#10227) Change-Id: I9e91f9d57e22d3df621a19e0250339d5d2763827 --- .../BasicJavaScriptComponent.java | 23 ++++++- .../tests/minitutorials/v7a1/DynamicImageUI.java | 60 +++++++++++-------- .../tests/resources/ConnectorResourceTest.html | 27 --------- .../tests/resources/ConnectorResourceTest.java | 70 ---------------------- 4 files changed, 56 insertions(+), 124 deletions(-) delete mode 100644 uitest/src/com/vaadin/tests/resources/ConnectorResourceTest.html delete mode 100644 uitest/src/com/vaadin/tests/resources/ConnectorResourceTest.java (limited to 'uitest/src/com/vaadin/tests') diff --git a/uitest/src/com/vaadin/tests/components/javascriptcomponent/BasicJavaScriptComponent.java b/uitest/src/com/vaadin/tests/components/javascriptcomponent/BasicJavaScriptComponent.java index aef1ef83d0..9e316e77f1 100644 --- a/uitest/src/com/vaadin/tests/components/javascriptcomponent/BasicJavaScriptComponent.java +++ b/uitest/src/com/vaadin/tests/components/javascriptcomponent/BasicJavaScriptComponent.java @@ -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 diff --git a/uitest/src/com/vaadin/tests/minitutorials/v7a1/DynamicImageUI.java b/uitest/src/com/vaadin/tests/minitutorials/v7a1/DynamicImageUI.java index a84a2206ef..29bedb40fb 100644 --- a/uitest/src/com/vaadin/tests/minitutorials/v7a1/DynamicImageUI.java +++ b/uitest/src/com/vaadin/tests/minitutorials/v7a1/DynamicImageUI.java @@ -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 parameters = new HashMap(); - 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 index f400bacffa..0000000000 --- a/uitest/src/com/vaadin/tests/resources/ConnectorResourceTest.html +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - -New Test - - - - - - - - - - - - - - - - - -
New Test
open/run/com.vaadin.tests.resources.ConnectorResourceTest?restartApplication
screenCapture
- - diff --git a/uitest/src/com/vaadin/tests/resources/ConnectorResourceTest.java b/uitest/src/com/vaadin/tests/resources/ConnectorResourceTest.java deleted file mode 100644 index 580188fd9b..0000000000 --- a/uitest/src/com/vaadin/tests/resources/ConnectorResourceTest.java +++ /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() { - { - 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; - } - -} -- cgit v1.2.3