Example usage for java.io PrintWriter write

List of usage examples for java.io PrintWriter write

Introduction

In this page you can find the example usage for java.io PrintWriter write.

Prototype

public void write(String s) 

Source Link

Document

Writes a string.

Usage

From source file:org.dhara.portal.web.northToAiravataConnector.WorkflowExecutionServlet.java

@RequestMapping(value = { "/connect/ExecutionServlet",
        "/connect/ExecutionServlet/" }, method = RequestMethod.GET)
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws javax.servlet.ServletException, IOException {
    PrintWriter pw = response.getWriter();
    String workflowId = request.getParameter("workflowId");
    try {//from   w  w  w  .  j av a 2 s  . c  om
        ApplicationContext context = WebApplicationContextUtils
                .getRequiredWebApplicationContext(getServletContext());
        AiravataClientAPIService airavataClientAPIService = (AiravataClientAPIService) context
                .getBean("airavataAPIService");
        Map<String, Object> inputs = new HashMap<String, Object>();
        Workflow workflow = airavataClientAPIService.getWorkflow(workflowId);
        for (WorkflowInput workflowInput : workflow.getWorkflowInputs()) {
            inputs.put(workflowInput.getName(), request.getParameter(workflowInput.getName()));
        }
        outputs = airavataClientAPIService.executeWorkflow(inputs, workflowId); //     _52NorthExecuteWorkFlowTest
        JSONObject jsonObject = new JSONObject(outputs);
        PrintWriter printWriter = response.getWriter();
        printWriter.write(jsonObject.toJSONString());
    } catch (URISyntaxException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:com.esofthead.mycollab.servlet.EmailValidationServlet.java

protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String smtpUserName = request.getParameter("smtpUserName");
    String smtpPassword = request.getParameter("smtpPassword");
    String smtpHost = request.getParameter("smtpHost");
    String smtpPort = request.getParameter("smtpPort");
    String tls = request.getParameter("tls");

    int mailServerPort;
    try {//  w  w w  . j ava2  s .c o m
        mailServerPort = Integer.parseInt(smtpPort);
    } catch (Exception e) {
        PrintWriter out = response.getWriter();
        out.write("Port must be an integer value");
        return;
    }
    try {
        Email email = new SimpleEmail();
        email.setHostName(smtpHost);
        email.setSmtpPort(mailServerPort);
        email.setAuthenticator(new DefaultAuthenticator(smtpUserName, smtpPassword));
        if (tls.equals("true")) {
            email.setSSLOnConnect(true);
        } else {
            email.setSSLOnConnect(false);
        }
        email.setFrom(smtpUserName);
        email.setSubject("MyCollab Test Email");
        email.setMsg("This is a test mail ... :-)");
        email.addTo(smtpUserName);
        email.send();
    } catch (EmailException e) {
        PrintWriter out = response.getWriter();
        out.write("Cannot establish SMTP connection. Please recheck your config.");
        return;
    }
}

From source file:com.bitranger.parknshop.seller.controller.SellerManageItemCtrl.java

@RequestMapping(value = "/seller/deleteItem", method = RequestMethod.GET)
public void delete(HttpServletRequest request, HttpServletResponse response) throws IOException {

    String itemId = request.getParameter("id");

    psItemDAO.delete(psItemDAO.findById(Integer.parseInt(itemId)));

    PrintWriter out = response.getWriter();
    out.write("success");
    out.flush();// www . j a  v a 2 s. c  o  m
    out.close();

}

From source file:com.googlecode.android_scripting.jsonrpc.JsonRpcServer.java

private void send(PrintWriter writer, JSONObject result) {
    writer.write(result + "\n");
    writer.flush();//from www  . j  a v a 2s. c o m
    Log.v("Sent: " + result);
}

From source file:org.commonjava.indy.ftest.core.content.SetContentTypeFromUpstreamIfExistsTest.java

@Test
public void run() throws Exception {
    final String content = "This is some content " + System.currentTimeMillis() + "." + System.nanoTime();
    final String path = "org/foo/foo-project/1/foo-1.jar";

    server.expect("GET", server.formatUrl(STORE, path), (request, response) -> {
        response.setStatus(200);/*from   ww  w. ja  v a 2 s . c o m*/
        response.setHeader("Content-Length", Integer.toString(content.length()));
        response.setHeader("Content-Type", "application/java-archive; charset=UTF-8");
        PrintWriter writer = response.getWriter();

        writer.write(content);
    });

    client.stores().create(new RemoteRepository(STORE, server.formatUrl(STORE)), "adding remote",
            RemoteRepository.class);

    try (HttpResources httpResources = client.module(IndyRawHttpModule.class).getHttp()
            .getRaw(client.content().contentPath(remote, STORE, path))) {
        HttpResponse response = httpResources.getResponse();
        String contentType = response.getFirstHeader("Content-Type").getValue();
        assertThat(contentType, equalTo("application/java-archive;charset=UTF-8"));
    }
}

From source file:org.opendatakit.aggregate.servlet.GetGrantedRolesServlet.java

/**
 * Handler for HTTP Get request that returns the list of roles assigned to this user.
 * /*from  www  .  ja v a  2 s . co  m*/
 * Assumed to return a entity body that is a JSON serialization of a list.
 *
 * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest,
 *      javax.servlet.http.HttpServletResponse)
 */
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    CallingContext cc = ContextFactory.getCallingContext(this, req);

    Set<GrantedAuthority> grants = cc.getCurrentUser().getDirectAuthorities();
    RoleHierarchy rh = (RoleHierarchy) cc.getBean(SecurityBeanDefs.ROLE_HIERARCHY_MANAGER);
    Collection<? extends GrantedAuthority> roles = rh.getReachableGrantedAuthorities(grants);
    ArrayList<String> roleNames = new ArrayList<String>();
    for (GrantedAuthority a : roles) {
        if (a.getAuthority().startsWith(GrantedAuthorityName.ROLE_PREFIX)) {
            roleNames.add(a.getAuthority());
        }
    }

    resp.addHeader(ApiConstants.OPEN_DATA_KIT_VERSION_HEADER, ApiConstants.OPEN_DATA_KIT_VERSION);
    resp.addHeader("Access-Control-Allow-Origin", "*");
    resp.addHeader("Access-Control-Allow-Credentials", "true");
    resp.addHeader(HttpHeaders.HOST, cc.getServerURL());
    resp.setContentType(HtmlConsts.RESP_TYPE_JSON);
    resp.setCharacterEncoding(HtmlConsts.UTF8_ENCODE);

    PrintWriter out = resp.getWriter();
    out.write(mapper.writeValueAsString(roleNames));
    out.flush();

    resp.setStatus(HttpStatus.SC_OK);
}

From source file:org.commonjava.indy.ftest.core.content.SetContentTypeNotExistsTest.java

@Test
public void run() throws Exception {
    final String content = "This is some content " + System.currentTimeMillis() + "." + System.nanoTime();
    final String path = "org/foo/foo-project/1/foo-1.jar";

    server.expect("GET", server.formatUrl(STORE, path), (request, response) -> {
        response.setStatus(200);/*from  w ww  . j a  va  2s  .c om*/
        response.setHeader("Content-Length", Integer.toString(content.length()));
        PrintWriter writer = response.getWriter();

        writer.write(content);
    });

    client.stores().create(new RemoteRepository(STORE, server.formatUrl(STORE)), "adding remote",
            RemoteRepository.class);

    try (HttpResources httpResources = client.module(IndyRawHttpModule.class).getHttp()
            .getRaw(client.content().contentPath(remote, STORE, path))) {
        HttpResponse response = httpResources.getResponse();

        String contentType = response.getFirstHeader("Content-Type").getValue();
        assertThat(contentType, equalTo(new MimetypesFileTypeMap().getContentType(path)));
    }
}

From source file:com.mycollab.servlet.EmailValidationServlet.java

protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String smtpUserName = request.getParameter("smtpUserName");
    String smtpPassword = request.getParameter("smtpPassword");
    String smtpHost = request.getParameter("smtpHost");
    String smtpPort = request.getParameter("smtpPort");
    String tls = request.getParameter("tls");
    String ssl = request.getParameter("ssl");

    int mailServerPort = 25;
    try {/*from  www .j  a  v a 2  s.  c  om*/
        mailServerPort = Integer.parseInt(smtpPort);
    } catch (Exception e) {
        LOG.info("The smtp port value is not a number. We will use default port value is 25");
    }
    try {
        Email email = new SimpleEmail();
        email.setHostName(smtpHost);
        email.setSmtpPort(mailServerPort);
        email.setAuthenticator(new DefaultAuthenticator(smtpUserName, smtpPassword));
        if ("true".equals(tls)) {
            email.setStartTLSEnabled(true);
        } else {
            email.setStartTLSEnabled(false);
        }

        if ("true".equals(ssl)) {
            email.setSSLOnConnect(true);
        } else {
            email.setSSLOnConnect(false);
        }
        email.setFrom(smtpUserName);
        email.setSubject("MyCollab Test Email");
        email.setMsg("This is a test mail ... :-)");
        email.addTo(smtpUserName);
        email.send();
    } catch (EmailException e) {
        PrintWriter out = response.getWriter();
        out.write("Cannot establish SMTP connection. Please recheck your config.");
        LOG.warn("Can not login to SMTP", e);
    }
}

From source file:de.undercouch.gradle.tasks.download.SslTest.java

@Override
protected Handler[] makeHandlers() throws IOException {
    ContextHandler sslHandler = new ContextHandler("/" + SSL) {
        @Override//from w w  w  .  j  ava2 s .c  om
        public void handle(String target, HttpServletRequest request, HttpServletResponse response,
                int dispatch) throws IOException, ServletException {
            response.setStatus(200);
            PrintWriter rw = response.getWriter();
            rw.write("Hello");
            rw.close();
        }
    };
    return new Handler[] { sslHandler };
}

From source file:cn.vlabs.umt.ui.servlet.PublicKeyServlet.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String keyString = request.getParameter("keyid");
    if (keyString == null) {
        wrongParameter(response);/* www . ja v a  2  s. com*/
        return;
    }
    try {
        AppService service = (AppService) factory.getBean("ApplicationService");
        int keyid = -1;
        String content;
        if ("umt".equals(keyString)) {
            Application app = service.getApplication("umt");
            keyid = app.getKeyid();
            content = app.getPublicKey();
        } else {
            keyid = Integer.parseInt(keyString);
            content = service.getPublicKey(keyid);
        }
        if (content != null) {
            response.setContentType("text/plain");
            response.setHeader("keyid", Integer.toString(keyid));
            PrintWriter out = response.getWriter();
            out.write(content);
            out.flush();
            out.close();
        } else {
            notFound(response);
        }
    } catch (NumberFormatException e) {
        wrongParameter(response);
        return;
    }
}