@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { resp.setHeader("Plugins-Status", status); pluginProps.setProperty("Active Mock Bundle 1", "1.1.1"); pluginProps.setProperty("Active Mock Bundle 2", "2.2.2"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); pluginProps.store(baos, "Go Plugins for Testing"); resp.getOutputStream().write(baos.toByteArray()); baos.close(); } }
/** * Write the given temporary OutputStream to the HTTP response. * @param response current HTTP response * @param baos the temporary OutputStream to write * @throws IOException if writing/flushing failed */ protected void writeToResponse(HttpServletResponse response, ByteArrayOutputStream baos) throws IOException { // Write content type and also length (determined via byte array). response.setContentType(getContentType()); response.setContentLength(baos.size()); // Flush byte array to servlet output stream. ServletOutputStream out = response.getOutputStream(); baos.writeTo(out); out.flush(); }
String responseString = "TRACE "+ req.getRequestURI()+ " " + req.getProtocol(); Enumeration reqHeaderEnum = req.getHeaderNames(); while( reqHeaderEnum.hasMoreElements() ) { String headerName = (String)reqHeaderEnum.nextElement(); responseString += CRLF + headerName + ": " + req.getHeader(headerName); resp.setContentType("message/http"); resp.setContentLength(responseLength); ServletOutputStream out = resp.getOutputStream(); out.print(responseString); out.close(); return;
/** * Writes a <code>String</code> to the client, * followed by a carriage return-line feed (CRLF). * * * @param s the <code>String</code> to write to the client * * @exception IOException if an input or output exception occurred * */ public void println(String s) throws IOException { print(s); println(); }
/** * Write the DataBuffer to the response body OutputStream. * Invoked only when {@link ServletOutputStream#isReady()} returns "true" * and the readable bytes in the DataBuffer is greater than 0. * @return the number of bytes written */ protected int writeToOutputStream(DataBuffer dataBuffer) throws IOException { ServletOutputStream outputStream = this.outputStream; InputStream input = dataBuffer.asInputStream(); int bytesWritten = 0; byte[] buffer = new byte[this.bufferSize]; int bytesRead; while (outputStream.isReady() && (bytesRead = input.read(buffer)) != -1) { outputStream.write(buffer, 0, bytesRead); bytesWritten += bytesRead; } return bytesWritten; }
public void handle(String s, org.eclipse.jetty.server.Request r, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException, ServletException { Enumeration<?> e = httpRequest.getHeaderNames(); String param; while (e.hasMoreElements()) { param = e.nextElement().toString(); httpResponse.addHeader(param, httpRequest.getHeader(param)); } httpResponse.setStatus(200); httpResponse.getOutputStream().flush(); httpResponse.getOutputStream().close(); } }
throws IOException { LOGGER.debug("Echo received request {} on path {}", httpRequest, httpRequest.getServletContext().getContextPath()); if (httpRequest.getHeader("X-HEAD") != null) { httpResponse.setContentLength(1); if (httpRequest.getHeader("X-ISO") != null) { httpResponse.setContentType(TestUtils.TEXT_HTML_CONTENT_TYPE_WITH_ISO_8859_1_CHARSET); } else { httpResponse.setContentType(TestUtils.TEXT_HTML_CONTENT_TYPE_WITH_UTF_8_CHARSET); Enumeration<String> i = httpRequest.getParameterNames(); if (i.hasMoreElements()) { StringBuilder requestBody = new StringBuilder(); while (i.hasMoreElements()) { httpResponse.getOutputStream().write(body.getBytes()); final AsyncContext context = httpRequest.startAsync(); final ServletInputStream input = httpRequest.getInputStream(); final ByteArrayOutputStream baos = new ByteArrayOutputStream();
public void handle(String s, Request r, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException, ServletException { Enumeration<?> e = httpRequest.getHeaderNames(); String param; while (e.hasMoreElements()) { param = e.nextElement().toString(); httpResponse.addHeader("X-" + param, httpRequest.getHeader(param)); } int size = 10 * 1024; if (httpRequest.getContentLength() > 0) { size = httpRequest.getContentLength(); } byte[] bytes = new byte[size]; if (bytes.length > 0) { final InputStream in = httpRequest.getInputStream(); final OutputStream out = httpResponse.getOutputStream(); int read; while ((read = in.read(bytes)) != -1) { out.write(bytes, 0, read); } } httpResponse.setStatus(200); httpResponse.getOutputStream().flush(); httpResponse.getOutputStream().close(); } }
Query post = RemoteAccess.evaluate(request); if (post.isDoS_blackout()) { // DoS protection response.sendError(503, "your request frequency is too high"); return; response.sendError(503, "a screen_name must be submitted"); return; response.sendError(503, "an id_str must be submitted"); return; ByteArrayOutputStream data = new ByteArrayOutputStream(); byte[] b = new byte[2048]; InputStream is = new BufferedInputStream(new FileInputStream(assetFile)); int c; try { while ((c = is.read(b)) > 0) { data.write(b, 0, c); ServletOutputStream sos = response.getOutputStream(); sos.write(data.toByteArray());
public void handle(String s, Request r, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { if ("POST".equalsIgnoreCase(request.getMethod())) { byte[] bytes = new byte[3]; ByteArrayOutputStream bos = new ByteArrayOutputStream(); int read = 0; while (read > -1) { read = request.getInputStream().read(bytes); if (read > 0) { bos.write(bytes, 0, read); } } response.setStatus(HttpServletResponse.SC_OK); response.addHeader("X-Param", new String(bos.toByteArray())); } else { // this handler is to handle POST request response.sendError(HttpServletResponse.SC_FORBIDDEN); } response.getOutputStream().flush(); response.getOutputStream().close(); } }
@Override protected void handle0(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { String delay = request.getHeader("X-Delay"); if (delay != null) { try { Thread.sleep(Long.parseLong(delay)); } catch (NumberFormatException | InterruptedException e1) { throw new ServletException(e1); response.setStatus(200); if (request.getMethod().equalsIgnoreCase("OPTIONS")) { response.addHeader("Allow", "GET,HEAD,POST,OPTIONS,TRACE"); response.setContentType(request.getHeader("X-IsoCharset") != null ? TEXT_HTML_CONTENT_TYPE_WITH_ISO_8859_1_CHARSET : TEXT_HTML_CONTENT_TYPE_WITH_UTF_8_CHARSET); response.addHeader("X-ClientPort", String.valueOf(request.getRemotePort())); Enumeration<String> headerNames = request.getHeaderNames(); while (headerNames.hasMoreElements()) { String headerName = headerNames.nextElement(); response.addHeader("X-" + headerName, request.getHeader(headerName)); response.getOutputStream().write(requestBody.toString().getBytes()); read = request.getInputStream().read(bytes); if (read > 0) { response.getOutputStream().write(bytes, 0, read);
HttpServletResponse response) throws ServletException, IOException { if (!DAO.writeDump) { response.sendError(HttpServletResponse.SC_FORBIDDEN, "Dump generation is disabled on this peer"); String path = request.getPathInfo(); final long now = System.currentTimeMillis(); response.setContentType("text/html"); response.setCharacterEncoding("UTF-8"); response.setStatus(HttpServletResponse.SC_OK); response.sendError(404, request.getContextPath() + " " + limitedMessage); return; File dump = ownDumps.size() == 0 ? null : new File(ownDumps.iterator().next().getParentFile(), path); if (dump == null || !dump.exists()) { response.sendError(404, request.getContextPath() + " not available"); byte[] buffer = new byte[65536]; int c; while ((c = fis.read(buffer)) > 0) { response.getOutputStream().write(buffer, 0, c); fis.close(); } catch (Throwable e) { DAO.severe(e);
if (request.getHeader("Authorization") != null) { String a = request.getHeader("Authorization"); if (a.startsWith("Bearer")) { token = a.substring(7); response.sendError(403, "Token required"); throw new ServletException("Service \"" + serviceName + "\" not found for this user"); response.setContentLength(bimBotsOutput.getData().length); response.setHeader("Output-Type", bimBotsOutput.getSchemaName()); response.setHeader("Data-Title", bimBotsOutput.getTitle()); response.setHeader("Content-Type", bimBotsOutput.getContentType()); response.setHeader("Context-Id", bimBotsOutput.getContextId()); response.getOutputStream().write(bimBotsOutput.getData()); response.setHeader("Output-Type", "Async"); response.setHeader("Topic-Id", "" + topicKey.getId()); ByteArrayOutputStream baos = new ByteArrayOutputStream(); IOUtils.copy(inputStream, baos); getBimServer().getExecutorService().submit(new BimBotRunner(getBimServer(), new ByteArrayInputStream(baos.toByteArray()), contextId, inputType, authorization, foundService, bimBotsServiceInterface, endPoint.getStreamingSocketInterface(), topicKey.getId(), endPoint.getEndPointId())); throw new ServletException("Service \"" + serviceName + "\" does not implement the BimBotsServiceInterface");
res.setStatus(404); return false; res.setStatus(200); res.setContentType(contentType); res.setContentLengthLong(file.length()); int bytesRead = inputStream.read(buffer); outputStream.write(buffer, 0, bytesRead); inputStream.close(); outputStream.close(); request.end();
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { InputStream inputStream = getServletContext().getResourceAsStream(req.getPathInfo()); if(null != inputStream){ String fileName = req.getServletPath(); String mimeType = getServletContext().getMimeType(fileName); if(null == mimeType){ mimeType = "text/plain"; } resp.setContentType(mimeType); ServletOutputStream outputStream = resp.getOutputStream(); int c; while((c = inputStream.read())>0){ outputStream.write(c); } inputStream.close(); outputStream.close(); } else { resp.sendError(404, "not found"); } }
response.sendError(HttpServletResponse.SC_NOT_FOUND); return; response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; long ifModifiedSince = request.getDateHeader("If-Modified-Since"); if (ifNoneMatch == null && ifModifiedSince != -1 && ifModifiedSince + 1000 > lastModified) { response.setHeader("ETag", fileName); // Required in 304. String ifMatch = request.getHeader("If-Match"); if (ifMatch != null && !HttpUtils.matches(ifMatch, fileName)) { response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED); logger.info("Return multi part of file : from ({}) to ({})", r.start, r.end); sos.println(); sos.println("--" + MULTIPART_BOUNDARY); sos.println("Content-Type: " + contentType); sos.println("Content-Range: bytes " + r.start + "-" + r.end + "/" + r.total); sos.println(); sos.println("--" + MULTIPART_BOUNDARY + "--"); input.skip(start); long toRead = length;
@Override protected void renderMergedOutputModel(Map<String, Object> model, // HttpServletRequest request, // HttpServletResponse response) throws Exception { Object value = filterModel(model); String jsonpParameterValue = getJsonpParameterValue(request); if(jsonpParameterValue != null) { JSONPObject jsonpObject = new JSONPObject(jsonpParameterValue); jsonpObject.addParameter(value); value = jsonpObject; } ByteArrayOutputStream outnew = new ByteArrayOutputStream(); int len = JSON.writeJSONString(outnew, // fastJsonConfig.getCharset(), // value, // fastJsonConfig.getSerializeConfig(), // fastJsonConfig.getSerializeFilters(), // fastJsonConfig.getDateFormat(), // JSON.DEFAULT_GENERATE_FEATURE, // fastJsonConfig.getSerializerFeatures()); if (this.updateContentLength) { // Write content length (determined via byte array). response.setContentLength(len); } // Flush byte array to servlet output stream. ServletOutputStream out = response.getOutputStream(); outnew.writeTo(out); outnew.close(); out.flush(); }
@Override public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { String requestURI = req.getRequestURI().substring(req.getContextPath().length()).replace("..", ""); setResponseHeaders(req, res, requestURI); InputStream inputStream = null; try { inputStream = getClass().getClassLoader().getResourceAsStream(StringUtils.removeStart(requestURI, "/")); if (inputStream == null) { res.sendError(HttpServletResponse.SC_NOT_FOUND); return; } IOUtils.copy(inputStream, res.getOutputStream()); res.getOutputStream().flush(); res.flushBuffer(); } finally { try { if (inputStream != null) { inputStream.close(); } } catch (IOException ioe) { // ignore } } }
public void handle(String s, Request r, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException, ServletException { try { Thread.sleep(20 * 1000); } catch (InterruptedException e) { e.printStackTrace(); } httpResponse.setStatus(200); httpResponse.getOutputStream().flush(); httpResponse.getOutputStream().close(); } }