diff options
author | Leif Åstrand <leif@vaadin.com> | 2012-11-21 13:17:39 +0200 |
---|---|---|
committer | Leif Åstrand <leif@vaadin.com> | 2012-11-21 13:17:39 +0200 |
commit | 7d9c4c5e06a95f4aa5eb371a2f5b5418b92fac64 (patch) | |
tree | 90ff67118b79eff22a05346b6122e3ab210cc847 /uitest/src/com/vaadin/tests/minitutorials | |
parent | 19baf19b7ef1a372154ba8bcbd5e35fb6ec1f3ef (diff) | |
download | vaadin-framework-7d9c4c5e06a95f4aa5eb371a2f5b5418b92fac64.tar.gz vaadin-framework-7d9c4c5e06a95f4aa5eb371a2f5b5418b92fac64.zip |
Reomove DynamicConnectorResource (#10227)
Change-Id: I9e91f9d57e22d3df621a19e0250339d5d2763827
Diffstat (limited to 'uitest/src/com/vaadin/tests/minitutorials')
-rw-r--r-- | uitest/src/com/vaadin/tests/minitutorials/v7a1/DynamicImageUI.java | 60 |
1 files changed, 36 insertions, 24 deletions
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<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 |