Guest User

Untitled

a guest
Aug 28th, 2018
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.05 KB | None | 0 0
  1. import java.net.URI;
  2.  
  3. import javax.ws.rs.core.UriBuilder;
  4.  
  5. import com.vaadin.annotations.Theme;
  6. import com.vaadin.annotations.Viewport;
  7. import com.vaadin.server.Page;
  8. import com.vaadin.server.VaadinRequest;
  9. import com.vaadin.spring.annotation.SpringUI;
  10. import com.vaadin.spring.annotation.UIScope;
  11. import com.vaadin.ui.Button;
  12. import com.vaadin.ui.TextField;
  13. import com.vaadin.ui.UI;
  14. import com.vaadin.ui.VerticalLayout;
  15.  
  16. @UIScope
  17. @SpringUI(path = "/testredirect")
  18. @Theme(OnePortalTheme.THEME_NAME)
  19. //@Push(value = PushMode.AUTOMATIC, transport = Transport.WEBSOCKET_XHR)
  20. @Viewport("width=device-width, initial-scale=1.0")
  21. public class TestRedirectUI extends UI {
  22.    
  23.     // TODO remove after test
  24.    
  25.     @Override
  26.     protected void init(VaadinRequest request) {
  27.        
  28.         TextField urlField = new TextField("Redirect to", "myapp://auth/callback");
  29.         urlField.setWidth("100%");
  30.        
  31.         int i = 1;
  32.        
  33.         Button openButton = new Button(i++
  34.                 + ": open(uri, null)", event -> {
  35.                     Page.getCurrent().open(urlField.getValue(), null);
  36.                     afterRedirect();
  37.                 });
  38.        
  39.         Button open2Button = new Button(i++
  40.                 + ": open(uri, _blank)", event -> {
  41.                     Page.getCurrent().open(urlField.getValue(), "_blank");
  42.                     afterRedirect();
  43.                 });
  44.        
  45.         Button locationButton = new Button(i++
  46.                 + ": location(uri)", event -> {
  47.                     Page.getCurrent().setLocation(urlField.getValue());
  48.                     afterRedirect();
  49.                 });
  50.        
  51.         Button redirectServlet1Button = new Button(i++ + ": Redirection servlet: Code 302", event -> {
  52.             URI uri = UriBuilder.fromPath(RedirectServlet.PATH).queryParam(RedirectServlet.PARAM_REDIRECT_URI, urlField.getValue()).queryParam(RedirectServlet.PARAM_MODE, RedirectServlet.MODE_302_RESPONSE).build();
  53.             Page.getCurrent().setLocation(uri.toString());
  54.             afterRedirect();
  55.         });
  56.        
  57.         Button redirectServlet2Button = new Button(i++ + ": Redirection servlet: Javascript location", event -> {
  58.             URI uri = UriBuilder.fromPath(RedirectServlet.PATH).queryParam(RedirectServlet.PARAM_REDIRECT_URI, urlField.getValue()).queryParam(RedirectServlet.PARAM_MODE, RedirectServlet.MODE_JAVASCRIPT_LOCATION).build();
  59.             Page.getCurrent().setLocation(uri.toString());
  60.             afterRedirect();
  61.         });
  62.        
  63.         Button redirectServlet3Button = new Button(i++ + ": Redirection servlet: Meta refresh", event -> {
  64.             URI uri = UriBuilder.fromPath(RedirectServlet.PATH).queryParam(RedirectServlet.PARAM_REDIRECT_URI, urlField.getValue()).queryParam(RedirectServlet.PARAM_MODE, RedirectServlet.MODE_META_REFRESH).build();
  65.             Page.getCurrent().setLocation(uri.toString());
  66.             afterRedirect();
  67.         });
  68.        
  69.         Button redirectServlet4Button = new Button(i++ + ": Redirection servlet: Link", event -> {
  70.             URI uri = UriBuilder.fromPath(RedirectServlet.PATH).queryParam(RedirectServlet.PARAM_REDIRECT_URI, urlField.getValue()).queryParam(RedirectServlet.PARAM_MODE, RedirectServlet.MODE_LINK).build();
  71.             Page.getCurrent().setLocation(uri.toString());
  72.             afterRedirect();
  73.         });
  74.        
  75.         Button redirectServlet5Button = new Button(i++ + ": Redirection servlet: Chain js call and 302", event -> {
  76.             URI uri = UriBuilder.fromPath(RedirectServlet.PATH).queryParam(RedirectServlet.PARAM_REDIRECT_URI, urlField.getValue()).queryParam(RedirectServlet.PARAM_MODE, RedirectServlet.MODE_CHAIN_JS_AND_302).build();
  77.             Page.getCurrent().setLocation(uri.toString());
  78.             afterRedirect();
  79.         });
  80.        
  81.         Button redirectServlet6Button = new Button(i++ + ": Redirection servlet: Link + js click it", event -> {
  82.             URI uri = UriBuilder.fromPath(RedirectServlet.PATH).queryParam(RedirectServlet.PARAM_REDIRECT_URI, urlField.getValue()).queryParam(RedirectServlet.PARAM_MODE, RedirectServlet.MODE_LINK_AUTOCLICK).build();
  83.             Page.getCurrent().setLocation(uri.toString());
  84.             afterRedirect();
  85.         });
  86.        
  87.         VerticalLayout content = new VerticalLayout(urlField, openButton, open2Button, locationButton, redirectServlet1Button, redirectServlet2Button, redirectServlet3Button, redirectServlet4Button, redirectServlet6Button, redirectServlet5Button);
  88.        
  89.         setContent(content);
  90.        
  91.     }
  92.    
  93.     private void afterRedirect() {
  94.         // getSession().close();
  95.     }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment