Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.net.URI;
- import javax.ws.rs.core.UriBuilder;
- import com.vaadin.annotations.Theme;
- import com.vaadin.annotations.Viewport;
- import com.vaadin.server.Page;
- import com.vaadin.server.VaadinRequest;
- import com.vaadin.spring.annotation.SpringUI;
- import com.vaadin.spring.annotation.UIScope;
- import com.vaadin.ui.Button;
- import com.vaadin.ui.TextField;
- import com.vaadin.ui.UI;
- import com.vaadin.ui.VerticalLayout;
- @UIScope
- @SpringUI(path = "/testredirect")
- @Theme(OnePortalTheme.THEME_NAME)
- //@Push(value = PushMode.AUTOMATIC, transport = Transport.WEBSOCKET_XHR)
- @Viewport("width=device-width, initial-scale=1.0")
- public class TestRedirectUI extends UI {
- // TODO remove after test
- @Override
- protected void init(VaadinRequest request) {
- TextField urlField = new TextField("Redirect to", "myapp://auth/callback");
- urlField.setWidth("100%");
- int i = 1;
- Button openButton = new Button(i++
- + ": open(uri, null)", event -> {
- Page.getCurrent().open(urlField.getValue(), null);
- afterRedirect();
- });
- Button open2Button = new Button(i++
- + ": open(uri, _blank)", event -> {
- Page.getCurrent().open(urlField.getValue(), "_blank");
- afterRedirect();
- });
- Button locationButton = new Button(i++
- + ": location(uri)", event -> {
- Page.getCurrent().setLocation(urlField.getValue());
- afterRedirect();
- });
- Button redirectServlet1Button = new Button(i++ + ": Redirection servlet: Code 302", event -> {
- URI uri = UriBuilder.fromPath(RedirectServlet.PATH).queryParam(RedirectServlet.PARAM_REDIRECT_URI, urlField.getValue()).queryParam(RedirectServlet.PARAM_MODE, RedirectServlet.MODE_302_RESPONSE).build();
- Page.getCurrent().setLocation(uri.toString());
- afterRedirect();
- });
- Button redirectServlet2Button = new Button(i++ + ": Redirection servlet: Javascript location", event -> {
- URI uri = UriBuilder.fromPath(RedirectServlet.PATH).queryParam(RedirectServlet.PARAM_REDIRECT_URI, urlField.getValue()).queryParam(RedirectServlet.PARAM_MODE, RedirectServlet.MODE_JAVASCRIPT_LOCATION).build();
- Page.getCurrent().setLocation(uri.toString());
- afterRedirect();
- });
- Button redirectServlet3Button = new Button(i++ + ": Redirection servlet: Meta refresh", event -> {
- URI uri = UriBuilder.fromPath(RedirectServlet.PATH).queryParam(RedirectServlet.PARAM_REDIRECT_URI, urlField.getValue()).queryParam(RedirectServlet.PARAM_MODE, RedirectServlet.MODE_META_REFRESH).build();
- Page.getCurrent().setLocation(uri.toString());
- afterRedirect();
- });
- Button redirectServlet4Button = new Button(i++ + ": Redirection servlet: Link", event -> {
- URI uri = UriBuilder.fromPath(RedirectServlet.PATH).queryParam(RedirectServlet.PARAM_REDIRECT_URI, urlField.getValue()).queryParam(RedirectServlet.PARAM_MODE, RedirectServlet.MODE_LINK).build();
- Page.getCurrent().setLocation(uri.toString());
- afterRedirect();
- });
- Button redirectServlet5Button = new Button(i++ + ": Redirection servlet: Chain js call and 302", event -> {
- URI uri = UriBuilder.fromPath(RedirectServlet.PATH).queryParam(RedirectServlet.PARAM_REDIRECT_URI, urlField.getValue()).queryParam(RedirectServlet.PARAM_MODE, RedirectServlet.MODE_CHAIN_JS_AND_302).build();
- Page.getCurrent().setLocation(uri.toString());
- afterRedirect();
- });
- Button redirectServlet6Button = new Button(i++ + ": Redirection servlet: Link + js click it", event -> {
- URI uri = UriBuilder.fromPath(RedirectServlet.PATH).queryParam(RedirectServlet.PARAM_REDIRECT_URI, urlField.getValue()).queryParam(RedirectServlet.PARAM_MODE, RedirectServlet.MODE_LINK_AUTOCLICK).build();
- Page.getCurrent().setLocation(uri.toString());
- afterRedirect();
- });
- VerticalLayout content = new VerticalLayout(urlField, openButton, open2Button, locationButton, redirectServlet1Button, redirectServlet2Button, redirectServlet3Button, redirectServlet4Button, redirectServlet6Button, redirectServlet5Button);
- setContent(content);
- }
- private void afterRedirect() {
- // getSession().close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment