Example usage for javax.servlet.http HttpServletResponse getOutputStream

List of usage examples for javax.servlet.http HttpServletResponse getOutputStream

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletResponse getOutputStream.

Prototype

public ServletOutputStream getOutputStream() throws IOException;

Source Link

Document

Returns a ServletOutputStream suitable for writing binary data in the response.

Usage

From source file:eu.annocultor.tagger.server.controllers.SolrTaggerController.java

@RequestMapping("/log.html")
public void log(HttpServletResponse response) throws Exception {
    IOUtils.copy(new FileInputStream(new File(fetchAnnoCultorHome(), ENRICHMENT_LOG)),
            response.getOutputStream());
}

From source file:com.seer.datacruncher.spring.ChecksTypeReadController.java

@SuppressWarnings("unchecked")
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    ObjectMapper mapper = new ObjectMapper();
    ServletOutputStream out = null;/*w  w  w  .jav a2s. co m*/
    response.setContentType("application/json");
    out = response.getOutputStream();
    String idSchemaField = request.getParameter("idSchemaField");
    ReadList readList = checksTypeDao.read(-1, -1);
    List<ChecksTypeEntity> checkTypeEntites = (List<ChecksTypeEntity>) readList.getResults();
    if (StringUtils.isNotEmpty(idSchemaField)) {
        String leftPane = request.getParameter("leftPane");
        ReadList assignedReadList = checksTypeDao.readCheckTypeBySchemaFieldId(Long.parseLong(idSchemaField));
        List<ChecksTypeEntity> assignedCheckTypeEntites = (List<ChecksTypeEntity>) assignedReadList
                .getResults();
        if ("true".equalsIgnoreCase(leftPane)) {
            if (CollectionUtils.isNotEmpty(assignedCheckTypeEntites)) {
                checkTypeEntites.removeAll(assignedCheckTypeEntites);
            }
        } else {
            readList.setResults(assignedCheckTypeEntites);
        }
    }
    out.write(mapper.writeValueAsBytes(readList));
    out.flush();
    out.close();
    return null;
}

From source file:com.vaadin.tests.applicationservlet.VaadinRefreshServlet.java

@Override
protected void service(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    if (request.getRequestURI().contains("/UIDL")) {
        InputStream loginHtml = request.getServletContext().getResourceAsStream("/statictestfiles/login.html");
        IOUtils.copy(loginHtml, response.getOutputStream());
        return;/* ww  w . j a  va 2s .  co m*/
    }
    super.service(request, response);
}

From source file:cn.newgxu.lab.core.config.MappingJacksonJsonpView.java

@Override
public void render(Map<String, ?> model, HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    if (request.getMethod().toUpperCase().equals("GET")) {
        if (request.getParameterMap().containsKey("callback")) {
            ServletOutputStream ostream = response.getOutputStream();
            //            try
            ostream.write(new String("try{" + request.getParameter("callback") + "(").getBytes());
            super.render(model, request, response);
            ostream.write(new String(");}catch(e){}").getBytes());
            //            ????closeflushspring?
            //            ?
            ostream.flush();//from   w  w w .ja  v a2s . c  o  m
            ostream.close();
        } else {
            super.render(model, request, response);
        }
    } else {
        super.render(model, request, response);
    }
}

From source file:pt.brunorene.rawgit.Proxy.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
 *
 * @param request  servlet request//from   ww w .  ja  v a 2s .co m
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException      if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String url = ROOT + request.getRequestURI().replace("/rawgit", "");
    try (OutputStream out = response.getOutputStream()) {
        out.write(client.execute(new HttpGet(url), rsp -> {
            try {
                TikaConfig config = TikaConfig.getDefaultConfig();
                Detector detector = config.getDetector();
                byte[] data = EntityUtils.toByteArray(rsp.getEntity());
                TikaInputStream stream = TikaInputStream.get(data);
                Metadata metadata = new Metadata();
                metadata.add(Metadata.RESOURCE_NAME_KEY, url);
                response.setContentType(detector.detect(stream, metadata).toString());
                return data;
            } catch (IOException ex) {
                log.error(null, ex);
                return new byte[0];
            }
        }));
    }
}

From source file:org.inbio.ait.web.ajax.controller.PointsController.java

private ModelAndView writeReponse(HttpServletRequest request, HttpServletResponse response,
        List<Specimen> specimens) throws Exception {

    response.setCharacterEncoding("ISO-8859-1");
    response.setContentType("text/xml");
    ServletOutputStream out = response.getOutputStream();

    StringBuilder result = new StringBuilder();
    result.append("<?xml version='1.0' encoding='ISO-8859-1'?><response><specimens>");

    for (Specimen s : specimens) {
        result.append("<specimen><scientificname>" + s.getScientificname() + "</scientificname>" + "<longitude>"
                + s.getDecimallongitude() + "</longitude>" + "<catalog>" + s.getCatalognumber() + "</catalog>"
                + "<institution>" + s.getInstitutioncode() + "</institution>" + "<latitude>"
                + s.getDecimallatitude() + "</latitude></specimen>");
    }/*from  w  w  w .  j  av a2 s  . c o  m*/
    result.append("</specimens></response>");

    out.println(result.toString());
    out.flush();
    out.close();

    return null;
}

From source file:org.jeedevframework.jpush.server.console.controller.UserController.java

public ModelAndView getUser(HttpServletRequest request, HttpServletResponse response) throws Exception {
    //response.setHeader("Content-type","text/html;charset=UTF-8");//????????UTF-8
    OutputStream stream = response.getOutputStream();
    String result = "failed";
    request.setCharacterEncoding("UTF-8");
    try {/*from   w  ww  .  j  av a  2 s. c o  m*/
        String data = request.getParameter("userName");

        if (data == null) {
        } else {
            User user = userService.getUserByUsername(data);
            if (user == null) {
            } else {
                result = "success";
            }

        }
    } catch (Exception e) {
    }

    stream.write(result.getBytes("utf-8"));

    //        ModelAndView mav = new ModelAndView();
    //         mav.addObject("userList", userList);
    //         mav.setViewName("index");
    return null;
}

From source file:org.openmrs.module.tracdataquality.web.controller.DownloadController.java

/**
 * Auto generated method comment// ww  w .j  a va 2  s  .  c o m
 * 
 * @param request
 * @param response
 * @param patients
 * @param filename
 * @param title
 * @throws IOException
 */
private void doDownload(HttpServletRequest request, HttpServletResponse response, List<Patient> patients,
        String filename, String title) throws IOException {

    //creating file writer object
    ServletOutputStream outputStream = response.getOutputStream();

    //creating the file
    response.setContentType("text/plain");
    response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");

    //creating file header
    outputStream.println("Report Name, " + title);
    outputStream.println("Author, " + Context.getAuthenticatedUser().getPersonName());
    outputStream.println("Printed on, " + new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss").format(new Date()));
    outputStream.println("Number of Patients, " + patients.size());
    outputStream.println();
    outputStream.println("Identifier,Given Name,Middle Name,Family Name,Age,Gender,Creator");
    outputStream.println();

    //populating content of the report
    for (Patient patient : patients) {
        outputStream.println(patient.getPatientIdentifier() + "," + patient.getGivenName() + ","
                + patient.getMiddleName() + "," + patient.getFamilyName() + "," + patient.getAge() + ","
                + patient.getGender() + "," + patient.getCreator());
    }

    outputStream.flush();
    outputStream.close();
}

From source file:ch.silviowangler.dox.web.DocumentControllerTest.java

@Test
public void getTheDocumentContentExpectNotFound3()
        throws DocumentNotFoundException, DocumentNotInStoreException, IOException {

    HttpServletResponse response = mock(HttpServletResponse.class);
    when(response.getOutputStream()).thenThrow(new IOException());
    long expectedDocumentId = 2L;
    when(documentService.findPhysicalDocument(expectedDocumentId)).thenReturn(new PhysicalDocument());
    controller.getDocument(expectedDocumentId, response);

    verify(response).setStatus(SC_INTERNAL_SERVER_ERROR);
}

From source file:com.sap.dirigible.runtime.registry.RepositoryServlet.java

@Override
protected void doPut(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    String repositoryPath = null;
    final OutputStream out = response.getOutputStream();
    try {/*w w  w  .j  av  a 2s .c  om*/
        repositoryPath = extractRepositoryPath(request);
        IEntity entity = getEntity(repositoryPath, request);
        if (entity == null) {
            doPost(request, response);
        } else {
            if (entity instanceof IResource) {
                ByteArrayOutputStream buff = new ByteArrayOutputStream();
                IOUtils.copy(request.getInputStream(), buff);
                byte[] data = buff.toByteArray();
                IResource resource = (IResource) entity;
                resource.setContent(data);
            } else {
                response.sendError(HttpServletResponse.SC_BAD_REQUEST,
                        THERE_IS_AN_EXISTING_COLLECTION_AT_THE_SAME_LOCATION);
            }
        }
    } catch (IllegalArgumentException ex) {
        logger.error(String.format(REQUEST_PROCESSING_FAILED_S, repositoryPath) + ex.getMessage());
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, ex.getMessage());
    } catch (MissingResourceException ex) {
        logger.error(String.format(REQUEST_PROCESSING_FAILED_S, repositoryPath) + ex.getMessage());
        response.sendError(HttpServletResponse.SC_NO_CONTENT, ex.getMessage());
    } finally {
        out.flush();
        out.close();
    }
}