Example usage for com.vaadin.server VaadinRequest getParameterMap

List of usage examples for com.vaadin.server VaadinRequest getParameterMap

Introduction

In this page you can find the example usage for com.vaadin.server VaadinRequest getParameterMap.

Prototype

public Map<String, String[]> getParameterMap();

Source Link

Document

Gets all the parameters of the request.

Usage

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);
    }// ww  w .j a va 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.BinaryRequestHandler.java

License:Apache License

public void sendResponse(VaadinSession session, VaadinRequest request, VaadinResponse pureResponse,
        boolean sendContent) throws IOException {
    if (!(pureResponse instanceof VaadinServletResponse)) {
        pureResponse.sendError(500, "Binary requests only work with servlets");
    }/*  w ww  .j  ava 2s .  c  o m*/

    VaadinServletResponse response = (VaadinServletResponse) pureResponse;

    Map<String, String[]> binaryParameter = request.getParameterMap();
    String toplevelCorpusName = binaryParameter.get("toplevelCorpusName")[0];
    String documentName = binaryParameter.get("documentName")[0];

    String mimeType = null;
    if (binaryParameter.containsKey("mime")) {
        mimeType = binaryParameter.get("mime")[0];
    }
    try {
        // always set the buffer size to the same one we will use for coyping, 
        // otherwise we won't notice any client disconnection
        response.reset();
        response.setCacheTime(-1);
        response.resetBuffer();
        response.setBufferSize(BUFFER_SIZE); // 4K

        String requestedRangeRaw = request.getHeader("Range");

        WebResource binaryRes = Helper.getAnnisWebResource().path("query").path("corpora")
                .path(urlPathEscape.escape(toplevelCorpusName)).path(urlPathEscape.escape(documentName))
                .path("binary");

        WebResource metaBinaryRes = Helper.getAnnisWebResource().path("meta").path("binary")
                .path(urlPathEscape.escape(toplevelCorpusName)).path(urlPathEscape.escape(documentName));

        // tell client that we support byte ranges
        response.setHeader("Accept-Ranges", "bytes");

        Preconditions.checkNotNull(mimeType, "No mime type given (parameter \"mime\"");

        AnnisBinaryMetaData meta = getMatchingMetadataFromService(metaBinaryRes, mimeType);
        if (meta == null) {
            response.sendError(404, "Binary file not found");
            return;
        }

        ContentRange fullRange = new ContentRange(0, meta.getLength() - 1, meta.getLength());

        ContentRange r = fullRange;
        try {
            if (requestedRangeRaw != null) {
                List<ContentRange> requestedRanges = ContentRange.parseFromHeader(requestedRangeRaw,
                        meta.getLength(), 1);

                if (!requestedRanges.isEmpty()) {
                    r = requestedRanges.get(0);
                }
            }

            long contentLength = (r.getEnd() - r.getStart() + 1);

            boolean useContentRange = !fullRange.equals(r);

            response.setContentType(meta.getMimeType());
            if (useContentRange) {
                response.setHeader("Content-Range", r.toString());
            }
            response.setContentLength((int) contentLength);
            response.setStatus(useContentRange ? 206 : 200);

            response.flushBuffer();
            if (sendContent) {
                try (OutputStream out = response.getOutputStream();) {
                    writeFromServiceToClient(r.getStart(), contentLength, binaryRes, out, mimeType);
                }
            }

        } catch (ContentRange.InvalidRangeException ex) {
            response.setHeader("Content-Range", "bytes */" + meta.getLength());
            response.sendError(416, "Requested range not satisfiable: " + ex.getMessage());
            return;
        }

    } catch (IOException ex) {
        log.warn("IOException in BinaryRequestHandler", ex);
        response.setStatus(500);
    } catch (ClientHandlerException | UniformInterfaceException ex) {
        log.error(null, ex);
        response.setStatus(500);
    }
}

From source file:de.catma.ui.CatmaApplication.java

License:Open Source License

@Override
protected void init(VaadinRequest request) {
    backgroundService = new UIBackgroundService(true);

    storeParameters(request.getParameterMap());

    Page.getCurrent().setTitle("CATMA 5.0 " + MINORVERSION);

    mainLayout = new VerticalLayout();
    mainLayout.setSizeFull();//w  ww. ja v a2 s  .c om

    menuPanel = new Panel();
    menuPanel.addStyleName("menuPanel");
    mainLayout.addComponent(menuPanel);

    contentPanel = new Panel();
    contentPanel.setHeight("100%");
    contentPanel.addStyleName("contentPanel");

    defaultContentPanelLabel = new Label("Please log in to get started");
    defaultContentPanelLabel.addStyleName("defaultContentPanelLabel");
    contentPanel.setContent(defaultContentPanelLabel);

    mainLayout.addComponent(contentPanel);
    mainLayout.setExpandRatio(contentPanel, 1.0f);

    menuLayout = new HorizontalLayout();
    menuLayout.setMargin(true);
    menuLayout.setSpacing(true);

    logoResource = new ThemeResource("catma-logo.png");
    Link logoImage = new Link(null, new ExternalResource("http://www.catma.de"));
    logoImage.setIcon(logoResource);
    logoImage.setTargetName("_blank");
    menuLayout.addComponent(logoImage);

    MenuFactory menuFactory = new MenuFactory();
    try {

        initTempDirectory();
        tagManager = new TagManager();

        repositoryManagerView = new RepositoryManagerView(
                new RepositoryManager(this, tagManager, RepositoryProperties.INSTANCE.getProperties()));

        tagManagerView = new TagManagerView(tagManager);

        taggerManagerView = new TaggerManagerView();

        analyzerManagerView = new AnalyzerManagerView();

        visualizationManagerView = new VisualizationManagerView();

        menu = menuFactory.createMenu(menuLayout, contentPanel,
                new MenuFactory.MenuEntryDefinition("Repository Manager", repositoryManagerView),
                new MenuFactory.MenuEntryDefinition("Tag Type Manager", tagManagerView),
                new MenuFactory.MenuEntryDefinition("Tagger", taggerManagerView),
                new MenuFactory.MenuEntryDefinition("Analyzer", analyzerManagerView),
                new MenuFactory.MenuEntryDefinition("Visualizer", visualizationManagerView));
        addPropertyChangeListener(CatmaApplicationEvent.userChange, menu.userChangeListener);

        Link latestFeaturesLink = new Link("Latest Features",
                new ExternalResource("http://www.catma.de/latestfeatures"));
        latestFeaturesLink.setTargetName("_blank");
        menuLayout.addComponent(latestFeaturesLink);
        menuLayout.setComponentAlignment(latestFeaturesLink, Alignment.TOP_RIGHT);
        menuLayout.setExpandRatio(latestFeaturesLink, 1.0f);

        Link aboutLink = new Link("About", new ExternalResource("http://www.catma.de"));
        aboutLink.setTargetName("_blank");
        menuLayout.addComponent(aboutLink);
        menuLayout.setComponentAlignment(aboutLink, Alignment.TOP_RIGHT);

        Link termsOfUseLink = new Link("Terms of Use", new ExternalResource("http://www.catma.de/termsofuse"));
        termsOfUseLink.setTargetName("_blank");
        menuLayout.addComponent(termsOfUseLink);
        menuLayout.setComponentAlignment(termsOfUseLink, Alignment.TOP_RIGHT);

        Link manualLink = new Link("Manual", new ExternalResource(request.getContextPath() + "/manual/"));
        manualLink.setTargetName("_blank");
        menuLayout.addComponent(manualLink);
        menuLayout.setComponentAlignment(manualLink, Alignment.TOP_RIGHT);

        Link helpLink = new Link("Helpdesk", new ExternalResource("http://www.catma.de/helpdesk/"));
        helpLink.setTargetName("_blank");
        menuLayout.addComponent(helpLink);
        menuLayout.setComponentAlignment(helpLink, Alignment.TOP_RIGHT);
        helpLink.setVisible(false);

        btHelp = new Button(FontAwesome.QUESTION_CIRCLE);
        btHelp.addStyleName("help-button");
        btHelp.addStyleName("application-help-button");

        menuLayout.addComponent(btHelp);

        btHelp.addClickListener(new ClickListener() {

            public void buttonClick(ClickEvent event) {

                if (uiHelpWindow.getParent() == null) {
                    UI.getCurrent().addWindow(uiHelpWindow);
                } else {
                    UI.getCurrent().removeWindow(uiHelpWindow);
                }

            }
        });

        LoginLogoutCommand loginLogoutCommand = new LoginLogoutCommand(menu, repositoryManagerView);
        Button btloginLogout = new Button("Sign in", event -> loginLogoutCommand.menuSelected(null));
        btloginLogout.setStyleName(BaseTheme.BUTTON_LINK);
        btloginLogout.addStyleName("application-loginlink");

        loginLogoutCommand.setLoginLogoutButton(btloginLogout);

        menuLayout.addComponent(btloginLogout);
        menuLayout.setComponentAlignment(btloginLogout, Alignment.TOP_RIGHT);
        menuLayout.setWidth("100%");

        menuPanel.setContent(menuLayout);

        setContent(mainLayout);

        if (getParameter(Parameter.USER_IDENTIFIER) != null) {
            btloginLogout.click();
        }

        setPollInterval(10000);

        if ((getParameter(Parameter.AUTOLOGIN) != null) && (getUser() == null)) {
            getPage().setLocation(repositoryManagerView.createAuthenticationDialog().createLogInClick(this,
                    RepositoryPropertyKey.CATMA_oauthAuthorizationCodeRequestURL.getValue(),
                    RepositoryPropertyKey.CATMA_oauthAccessTokenRequestURL.getValue(),
                    RepositoryPropertyKey.CATMA_oauthClientId.getValue(),
                    RepositoryPropertyKey.CATMA_oauthClientSecret.getValue(), URLEncoder.encode("/", "UTF-8")));
        }

    } catch (Exception e) {
        showAndLogError("The system could not be initialized!", 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 w  w  . j a  v a 2 s . c  om
    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("&region=");
        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&region=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;
}

From source file:org.opennms.features.vaadin.pmatrix.ui.PmatrixApplication.java

License:Open Source License

@Override
protected void init(VaadinRequest request) {
    final VerticalLayout layout = new VerticalLayout();
    layout.setWidth("-1px");
    layout.setHeight("-1px");
    layout.setDefaultComponentAlignment(Alignment.TOP_LEFT);
    layout.setMargin(true);// www  .  j ava 2s  . c  om
    setContent(layout);

    //used to test that detach events are happening
    addDetachListener(new DetachListener() {
        @Override
        public void detach(DetachEvent event) {
            LOG.debug("Pmatrix UI instance detached:" + this);
        }
    });

    Component uiComponent = uiComponentFactory.getUiComponent(request);

    if (uiComponent == null) {

        StringBuilder sb = new StringBuilder(
                "Error: Cannot create the UI because the URL request parameters are not recognised<BR>\n"
                        + "you need to provide atleast '?" + UiComponentFactory.COMPONENT_REQUEST_PARAMETER
                        + "=" + UiComponentFactory.DEFAULT_COMPONENT_REQUEST_VALUE + "'<BR>\n"
                        + "Parameters passed in URL:<BR>\n");
        for (Entry<String, String[]> entry : request.getParameterMap().entrySet()) {
            sb.append("parameter:'" + entry.getKey() + "' value:'");
            for (String s : entry.getValue()) {
                sb.append("{" + s + "}");
            }
            sb.append("'<BR>\n");
        }
        Label label = new Label();
        label.setWidth("600px");
        label.setContentMode(ContentMode.HTML);
        label.setValue(sb.toString());
        layout.addComponent(label);

    } else {
        layout.addComponent(uiComponent);

        // refresh interval to apply to the UI
        int pollInterval = uiComponentFactory.getRefreshRate();
        setPollInterval(pollInterval);

        // display poll interval in seconds
        DecimalFormat dformat = new DecimalFormat("##.##");
        Label label = new Label();
        label.setCaption("(refresh rate:" + dformat.format(pollInterval / 1000) + " seconds)");
        layout.addComponent(label);
    }

}