Example usage for com.vaadin.server VaadinResponse getWriter

List of usage examples for com.vaadin.server VaadinResponse getWriter

Introduction

In this page you can find the example usage for com.vaadin.server VaadinResponse getWriter.

Prototype

public PrintWriter getWriter() throws IOException;

Source Link

Document

Returns a PrintWriter object that can send character text to the client.

Usage

From source file:com.ejt.vaadin.loginform.LoginForm.java

License:Apache License

private void init() {
    if (initialized) {
        return;//from w w  w .ja  va 2s .c o m
    }

    LoginFormState state = getState();
    state.userNameFieldConnector = createUserNameField();
    state.passwordFieldConnector = createPasswordField();
    state.loginButtonConnector = createLoginButton();

    String contextPath = VaadinService.getCurrentRequest().getContextPath();
    if (contextPath.endsWith("/")) {
        contextPath = contextPath.substring(0, contextPath.length() - 1);
    }
    state.contextPath = contextPath;

    VaadinSession.getCurrent().addRequestHandler(new RequestHandler() {
        @Override
        public boolean handleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response)
                throws IOException {
            if (LoginFormConnector.LOGIN_URL.equals(request.getPathInfo())) {
                response.setContentType("text/html; charset=utf-8");
                response.setCacheTime(-1);
                PrintWriter writer = response.getWriter();
                writer.append("<html>Success</html>");
                return true;
            } else {
                return false;
            }
        }
    });

    registerRpc(new LoginFormRpc() {
        @Override
        public void submitCompleted() {
            login();
        }
    });

    initialized = true;

    setContent(createContent(getUserNameField(), getPasswordField(), getLoginButton()));
}

From source file:pl.exsio.plupload.PluploadReceiver.java

License:Open Source License

@Override
public boolean handleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response)
        throws IOException {
    if (request.getPathInfo() != null && request.getPathInfo().endsWith(UPLOAD_ACTION_PATH)) {
        if (request instanceof VaadinServletRequest) {
            VaadinServletRequest vsr = (VaadinServletRequest) request;
            HttpServletRequest req = vsr.getHttpServletRequest();
            if (ServletFileUpload.isMultipartContent(req)) {
                try {
                    synchronized (this) {
                        ServletFileUpload upload = new ServletFileUpload();
                        FileItemIterator items = upload.getItemIterator(req);
                        PluploadChunk chunk = PluploadChunkFactory.create(items);
                        PluploadChunkHandler fileHandler = this.getExpectedFileHandler(chunk.getFileId());
                        fileHandler.handleUploadedChunk(chunk);
                        this.writeResponse(chunk, response);
                    }//from   ww w .  j  a  va 2s .co m
                } catch (Exception ex) {
                    response.getWriter().append("file upload unsuccessful, because of "
                            + ex.getClass().getName() + ":" + ex.getMessage());
                    throw new IOException(
                            "There was a problem during processing of uploaded chunk. Nested exceptions may have more info.",
                            ex);
                }
                return true;
            }
        }
    }
    return false;

}

From source file:pl.exsio.plupload.PluploadReceiver.java

License:Open Source License

protected void writeResponse(PluploadChunk chunk, VaadinResponse response) throws IOException {
    if (chunk.isLast()) {
        response.getWriter().append("file " + chunk.getName() + " uploaded successfuly");
    } else {/*  w  w w .  j av  a  2  s  .c o m*/
        response.getWriter().append(
                "file chunk " + (chunk.getChunk() + 1) + " of " + chunk.getChunks() + " uploaded successfuly");
    }
    response.setContentType("text/plain");
}