List of usage examples for com.vaadin.server VaadinRequest getParameter
public String getParameter(String parameter);
From source file:annis.gui.CommonUI.java
License:Apache License
private boolean checkUrlShortenerRedirect(VaadinRequest request, VaadinResponse response) { String id = request.getParameter("id"); if (id == null) { return false; }/*from w w w . j a v a 2s . co m*/ // get the actual URL WebResource res = Helper.getAnnisWebResource(); res = res.path("shortener").path(id); String longURL = res.get(String.class); // redirects only work in http servlets if (response instanceof VaadinServletResponse) { ServletResponse servletResponse = ((VaadinServletResponse) response).getResponse(); if (servletResponse instanceof HttpServletResponse) { HttpServletResponse httpResponse = (HttpServletResponse) servletResponse; httpResponse.setHeader("Location", request.getContextPath() + longURL); httpResponse.setStatus(307); // temporary redirect return true; } } return false; }
From source file:annis.gui.EmbeddedVisUI.java
License:Apache License
@Override protected void init(VaadinRequest request) { super.init(request); String rawPath = request.getPathInfo(); List<String> splittedPath = new LinkedList<>(); if (rawPath != null) { rawPath = rawPath.substring(URL_PREFIX.length()); splittedPath = Splitter.on("/").omitEmptyStrings().trimResults().limit(3).splitToList(rawPath); }/*from w w w .j a v a 2 s. co m*/ if (splittedPath.size() == 1) { // a visualizer definition which get the results from a remote salt file String saltUrl = request.getParameter(KEY_SALT); if (saltUrl == null) { displayGeneralHelp(); } else { generateVisFromRemoteURL(splittedPath.get(0), saltUrl, request.getParameterMap()); } } else if (splittedPath.size() >= 3) { // a visualizer definition visname/corpusname/documentname if ("htmldoc".equals(splittedPath.get(0))) { showHtmlDoc(splittedPath.get(1), splittedPath.get(2), request.getParameterMap()); } else { displayMessage("Unknown visualizer \"" + splittedPath.get(0) + "\"", "Only \"htmldoc\" is supported yet."); } } else { displayGeneralHelp(); } addStyleName("loaded-embedded-vis"); }
From source file:annis.gui.requesthandler.LoginServletRequestHandler.java
License:Apache License
private void doPost(VaadinSession session, VaadinRequest request, VaadinResponse response) throws IOException { response.setContentType("text/html"); String username = request.getParameter("annis-login-user"); String password = request.getParameter("annis-login-password"); if (username != null && password != null) { // forget any old user information session.getSession().removeAttribute(AnnisBaseUI.USER_KEY); session.getSession().removeAttribute(AnnisBaseUI.USER_LOGIN_ERROR); // get the URL for the REST service Object annisServiceURLObject = session.getSession().getAttribute(AnnisBaseUI.WEBSERVICEURL_KEY); if (annisServiceURLObject == null || !(annisServiceURLObject instanceof String)) { log.warn("AnnisWebService.URL was not set as init parameter in web.xml"); }//w w w . j a v a 2s . c om String webserviceURL = (String) annisServiceURLObject; try { AnnisUser user = new AnnisUser(username, password); WebResource res = user.getClient().resource(webserviceURL).path("admin").path("is-authenticated"); if ("true".equalsIgnoreCase(res.get(String.class))) { // everything ok, save this user configuration for re-use Helper.setUser(user); } } catch (ClientHandlerException ex) { session.getSession().setAttribute(AnnisBaseUI.USER_LOGIN_ERROR, "Authentification error: " + ex.getMessage()); response.setStatus(502); // bad gateway } catch (LoginDataLostException ex) { session.getSession().setAttribute(AnnisBaseUI.USER_LOGIN_ERROR, "Lost password in memory. Sorry."); response.setStatus(500); // server error } catch (UniformInterfaceException ex) { if (ex.getResponse().getStatus() == Response.Status.UNAUTHORIZED.getStatusCode()) { session.getSession().setAttribute(AnnisBaseUI.USER_LOGIN_ERROR, "Username or password wrong"); response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode()); } else if (ex.getResponse().getStatus() == Response.Status.FORBIDDEN.getStatusCode()) { session.getSession().setAttribute(AnnisBaseUI.USER_LOGIN_ERROR, "Account has expired"); response.setStatus(Response.Status.FORBIDDEN.getStatusCode()); // Forbidden } else { log.error(null, ex); session.getSession().setAttribute(AnnisBaseUI.USER_LOGIN_ERROR, "Unexpected exception: " + ex.getMessage()); response.setStatus(500); } } try (OutputStreamWriter writer = new OutputStreamWriter(response.getOutputStream(), Charsets.UTF_8)) { String html = Resources.toString(LoginServletRequestHandler.class.getResource("closelogin.html"), Charsets.UTF_8); CharStreams.copy(new StringReader(html), writer); } } // end if login attempt }
From source file:annis.gui.requesthandler.ShortenerRequestHandler.java
License:Apache License
@Override public boolean handleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response) throws IOException { String id = request.getParameter("id"); if (id == null) { return false; }//from www . j av a 2 s . co m // get the actual URL WebResource res = Helper.getAnnisWebResource(); res = res.path("shortener").path(id); String longURL = res.get(String.class); // redirects only work in http servlets if (response instanceof VaadinServletResponse) { ServletResponse servletResponse = ((VaadinServletResponse) response).getResponse(); if (servletResponse instanceof HttpServletResponse) { HttpServletResponse httpResponse = (HttpServletResponse) servletResponse; httpResponse.setHeader("Location", request.getContextPath() + longURL); httpResponse.setStatus(307); // temporary redirect return true; } } return false; }
From source file:by.bigvova.LoginUI.java
License:Apache License
@Override protected void init(VaadinRequest request) { getPage().setTitle("Vaadin Shared Security Demo Login"); FormLayout loginForm = new FormLayout(); loginForm.setSizeUndefined();/* w w w . j a v a 2 s .c o m*/ userName = new TextField("Username"); passwordField = new PasswordField("Password"); rememberMe = new CheckBox("Remember me"); login = new Button("Login"); Label label = new Label("Name: User / Password: password"); loginForm.addComponent(userName); loginForm.addComponent(passwordField); loginForm.addComponent(rememberMe); loginForm.addComponent(login); login.addStyleName(ValoTheme.BUTTON_PRIMARY); login.setDisableOnClick(true); login.setClickShortcut(ShortcutAction.KeyCode.ENTER); login.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { login(); } }); VerticalLayout loginLayout = new VerticalLayout(); loginLayout.setSpacing(true); loginLayout.setSizeUndefined(); if (request.getParameter("logout") != null) { loggedOutLabel = new Label("You have been logged out!"); loggedOutLabel.addStyleName(ValoTheme.LABEL_SUCCESS); loggedOutLabel.setSizeUndefined(); loginLayout.addComponent(loggedOutLabel); loginLayout.setComponentAlignment(loggedOutLabel, Alignment.BOTTOM_CENTER); } loginLayout.addComponent(loginFailedLabel = new Label()); loginLayout.setComponentAlignment(loginFailedLabel, Alignment.BOTTOM_CENTER); loginFailedLabel.setSizeUndefined(); loginFailedLabel.addStyleName(ValoTheme.LABEL_FAILURE); loginFailedLabel.setVisible(false); loginLayout.addComponent(label); loginLayout.addComponent(loginForm); loginLayout.setComponentAlignment(loginForm, Alignment.TOP_CENTER); VerticalLayout rootLayout = new VerticalLayout(loginLayout); rootLayout.setSizeFull(); rootLayout.setComponentAlignment(loginLayout, Alignment.MIDDLE_CENTER); setContent(rootLayout); setSizeFull(); }
From source file:com.cavisson.gui.dashboard.components.controls.ValoThemeUI.java
License:Apache License
@Override protected void init(final VaadinRequest request) { if (request.getParameter("test") != null) { testMode = true;//from w w w .j a va 2 s .com if (browserCantRenderFontsConsistently()) { getPage().getStyles().add(".v-app.v-app.v-app {font-family: Sans-Serif;}"); } } if (getPage().getWebBrowser().isIE() && getPage().getWebBrowser().getBrowserMajorVersion() == 9) { menu.setWidth("320px"); } // Show .v-app-loading valo-menu-badge // try { // Thread.sleep(2000); // } catch (InterruptedException e) { // e.printStackTrace(); // } if (!testMode) { Responsive.makeResponsive(this); } getPage().setTitle("Valo Theme Test"); setContent(root); root.setWidth("100%"); root.addMenu(buildMenu()); navigator = new Navigator(this, viewDisplay); navigator.addView("common", CommonParts.class); navigator.addView("labels", Labels.class); navigator.addView("buttons-and-links", ButtonsAndLinks.class); navigator.addView("textfields", TextFields.class); navigator.addView("datefields", DateFields.class); navigator.addView("comboboxes", ComboBoxes.class); navigator.addView("checkboxes", CheckBoxes.class); navigator.addView("sliders", Sliders.class); navigator.addView("menubars", MenuBars.class); navigator.addView("panels", Panels.class); navigator.addView("trees", Trees.class); navigator.addView("tables", Tables.class); navigator.addView("splitpanels", SplitPanels.class); navigator.addView("tabs", Tabsheets.class); navigator.addView("accordions", Accordions.class); navigator.addView("colorpickers", ColorPickers.class); navigator.addView("selects", NativeSelects.class); navigator.addView("calendar", CalendarTest.class); navigator.addView("forms", Forms.class); navigator.addView("popupviews", PopupViews.class); navigator.addView("dragging", Dragging.class); final String f = Page.getCurrent().getUriFragment(); if (f == null || f.equals("")) { navigator.navigateTo("common"); } navigator.setErrorView(CommonParts.class); navigator.addViewChangeListener(new ViewChangeListener() { @Override public boolean beforeViewChange(final ViewChangeEvent event) { return true; } @Override public void afterViewChange(final ViewChangeEvent event) { for (final Iterator<Component> it = menuItemsLayout.iterator(); it.hasNext();) { it.next().removeStyleName("selected"); } for (final Entry<String, String> item : menuItems.entrySet()) { if (event.getViewName().equals(item.getKey())) { for (final Iterator<Component> it = menuItemsLayout.iterator(); it.hasNext();) { final Component c = it.next(); if (c.getCaption() != null && c.getCaption().startsWith(item.getValue())) { c.addStyleName("selected"); break; } } break; } } menu.removeStyleName("valo-menu-visible"); } }); }
From source file:com.gmail.volodymyrdotsenko.cms.fe.vaadin.LoginUI.java
License:Apache License
@Override protected void init(VaadinRequest request) { langRepo.findAll().forEach(e -> { langSet.add(e.getCode());/*from w w w .j a v a 2 s .com*/ }); lang = new ComboBox("Language", langSet); getPage().setTitle("CMS"); FormLayout loginForm = new FormLayout(); loginForm.setSizeUndefined(); loginForm.addComponent(userName = new TextField("Username")); userName.setRequired(true); loginForm.addComponent(passwordField = new PasswordField("Password")); passwordField.setRequired(true); loginForm.addComponent(rememberMe = new CheckBox("Remember me")); loginForm.addComponent(lang); lang.setRequired(true); lang.setNullSelectionAllowed(false); loginForm.addComponent(login = new Button("Login")); login.addStyleName(ValoTheme.BUTTON_PRIMARY); login.setDisableOnClick(true); login.setClickShortcut(ShortcutAction.KeyCode.ENTER); login.addClickListener(e -> { login(); }); VerticalLayout loginLayout = new VerticalLayout(); loginLayout.setSpacing(true); loginLayout.setSizeUndefined(); if (request.getParameter("logout") != null) { loggedOutLabel = new Label("You have been logged out!"); loggedOutLabel.addStyleName(ValoTheme.LABEL_SUCCESS); loggedOutLabel.setSizeUndefined(); loginLayout.addComponent(loggedOutLabel); loginLayout.setComponentAlignment(loggedOutLabel, Alignment.BOTTOM_CENTER); } loginLayout.addComponent(loginFailedLabel = new Label()); loginLayout.setComponentAlignment(loginFailedLabel, Alignment.BOTTOM_CENTER); loginFailedLabel.setSizeUndefined(); loginFailedLabel.addStyleName(ValoTheme.LABEL_FAILURE); loginFailedLabel.setVisible(false); loginLayout.addComponent(loginForm); loginLayout.setComponentAlignment(loginForm, Alignment.TOP_CENTER); VerticalLayout rootLayout = new VerticalLayout(loginLayout); rootLayout.setSizeFull(); rootLayout.setComponentAlignment(loginLayout, Alignment.MIDDLE_CENTER); setContent(rootLayout); setSizeFull(); String currentLang = getLocale().getLanguage(); if (langSet.contains(currentLang)) lang.select(currentLang); else lang.select("en"); }
From source file:de.sebastianrothbucher.vaadin.meetup.userauth.FakeUserAuthentication.java
License:Apache License
@Override public void processCurrentRequest(VaadinRequest request, Map<String, Object> context) { if (request.getParameter("fakeid") != null && request.getParameter("fakeuser") != null && request.getParameter("fakemember") != null) { context.put(UserAuthentication.CURRENT_USER_CONTEXT_KEY, new User(Integer.parseInt(request.getParameter("fakeid")), request.getParameter("fakeuser"), Boolean.parseBoolean(request.getParameter("fakemember")))); }/*w w w. j av a 2 s .c o m*/ }
From source file:de.sebastianrothbucher.vaadin.meetup.userauth.MeetupUserAuthentication.java
License:Apache License
@Override public void processCurrentRequest(VaadinRequest request, Map<String, Object> context) { User lastUser = (User) session.getAttribute(LAST_USER_SESSION_ATTR); if (lastUser != null) { // already a user in the session - put it back & no further action context.put(UserAuthentication.CURRENT_USER_CONTEXT_KEY, lastUser); return;/*from w w w . j a v a 2s. com*/ } String code = request.getParameter(CODE_REQUEST_PARAM); // System.out.println("doing for code=" + code); if (code != null) { String lastCode = (String) session.getAttribute(LAST_CODE_SESSION_ATTR); if (lastCode != null && code.equals(lastCode)) { // we have inited with this code already - no further action return; } session.setAttribute(LAST_CODE_SESSION_ATTR, code); // System.out.println(OAUTH_KEY_PROP); // System.out.println(OAUTH_SECRET_PROP); // System.out.println(VAADIN_GERMANY_GROUPID_PROP); try { Map<String, String> tokenInfoHeaders = new HashMap<String, String>(); tokenInfoHeaders.put("Content-type", "application/x-www-form-urlencoded"); JSONObject tokenInfo = curl("POST", "https://secure.meetup.com/oauth2/access", tokenInfoHeaders, "client_id=" + OAUTH_KEY_PROP + "&client_secret=" + OAUTH_SECRET_PROP + "&grant_type=authorization_code&redirect_uri=" + APPLICATION_ADDRESS + "&code=" + code); Map<String, String> bearerHeaders = new HashMap<String, String>(); bearerHeaders.put("Authorization", "Bearer " + tokenInfo.getString("access_token")); JSONObject userInfo = curl("GET", "https://api.meetup.com/2/member/self/", bearerHeaders); JSONObject groupsInfo = curl("GET", "https://api.meetup.com/2/groups?member_id=" + userInfo.getInt("id"), bearerHeaders); boolean isMember = false; JSONArray groupsArray = groupsInfo.getJSONArray("results"); for (int i = 0; i < groupsArray.length(); i++) { if (VAADIN_GERMANY_GROUPID_PROP == groupsArray.getJSONObject(i).getInt("id")) { isMember = true; break; } } User res = new User(userInfo.getInt("id"), abbreviateName(userInfo.getString("name")), isMember); session.setAttribute(LAST_USER_SESSION_ATTR, res); context.put(UserAuthentication.CURRENT_USER_CONTEXT_KEY, res); } catch (JSONException e) { throw new TechnicalException(e); } } }
From source file:de.uni_tuebingen.qbic.qbicmainportlet.ProxyForGenomeViewerRestApi.java
License:Open Source License
@Override public boolean handleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response) throws IOException { if (UI.getCurrent() != null && UI.getCurrent().getPage() != null && UI.getCurrent().getPage().getUriFragment() != null) { System.out.println(UI.getCurrent().getPage().getUriFragment()); }//from w ww .j a v a2 s .com System.out.println("is handling request"); System.out.println(request.getPathInfo()); System.out.println(request.getContextPath()); PortletRequest portletRequest = VaadinPortletService.getCurrentPortletRequest(); Map<String, String[]> para = request.getParameterMap(); Set<Entry<String, String[]>> s = para.entrySet(); Iterator<Entry<String, String[]>> it = s.iterator(); while (it.hasNext()) { Entry<String, String[]> en = it.next(); System.out.println("Key: " + en.getKey()); System.out.println("Value:"); for (int i = 0; i < en.getValue().length; i++) { System.out.println(en.getValue()[i]); } System.out.println("Next"); } Enumeration<String> enu = portletRequest.getParameterNames(); while (enu.hasMoreElements()) { String su = enu.nextElement(); System.out.println(su + " " + portletRequest.getParameter(su)); } enu = portletRequest.getPropertyNames(); while (enu.hasMoreElements()) { String su = enu.nextElement(); System.out.println(su + " " + portletRequest.getProperty(su)); } HttpServletRequest httpRequest = PortalUtil.getHttpServletRequest(portletRequest); System.out.println(httpRequest.getPathInfo()); enu = httpRequest.getParameterNames(); while (enu.hasMoreElements()) { String su = enu.nextElement(); System.out.println(su + " " + httpRequest.getParameter(su)); } System.out.println(httpRequest.getQueryString()); enu = PortalUtil.getOriginalServletRequest(httpRequest).getParameterNames(); System.out.println(PortalUtil.getOriginalServletRequest(httpRequest).getPathInfo()); while (enu.hasMoreElements()) { String su = enu.nextElement(); System.out.println(su + " " + PortalUtil.getOriginalServletRequest(httpRequest).getParameter(su)); } if (!String.valueOf(session).equals(request.getPathInfo())) { return false; } String fileId = request.getParameter("fileId"); String filepaths = request.getParameter("filepath"); String removeZeroGenotypes = request.getParameter("removeZeroGenotypes"); String region = request.getParameter("region"); String interval = request.getParameter("interval"); String histogram = request.getParameter("histogram"); URL u; try { StringBuilder sb = new StringBuilder(); sb.append(ConfigurationManagerFactory.getInstance().getGenomeViewerRestApiUrl()); sb.append(fileId); sb.append("/fetch?filepaths="); sb.append(filepaths); sb.append("®ion="); sb.append(region); if (interval != null) { sb.append("&interval="); sb.append(interval); } if (histogram != null) { sb.append("&histogram="); sb.append(histogram); } if (removeZeroGenotypes != null) { sb.append(""); } u = new URL(sb.toString()); // u = new // URL("http://localhost:7777/vizrest/rest/data/QBAMS001AB.bam/fetch?filepaths=/store/1/0EEF79A2-8140-4FC7-BA67-E51908FE4619/f0/91/36/20141116104428925-3161/original/QBAMS001AB.bam&removeZeroGenotypes=false®ion=9:117163200-117164799,9:117164800-117166399,9:117166400-117167999,9:117168000-117169599&interval=1600&h"); URLConnection urlConnection = u.openConnection(); urlConnection.setUseCaches(false); urlConnection.setDoOutput(false); urlConnection.connect(); InputStream is = urlConnection.getInputStream(); response.setContentType("application/json"); response.setHeader("Content-Type", "application/json"); OutputStream out = response.getOutputStream(); byte[] buffer = new byte[com.vaadin.server.Constants.DEFAULT_BUFFER_SIZE]; while (true) { int readCount = is.read(buffer); if (readCount < 0) { break; } out.write(buffer, 0, readCount); } } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return true; }