@Override public OutputStream openStream() { return response.getOutputStream(); } }.asCharSink(Charset.forName(UTF_8)).write(mockResponseBodies.get(numInteractions++));
private void respond(HttpResponse res, RemoteCommand sc, String uniqueId) throws IOException { ByteArrayOutputStream buf = new ByteArrayOutputStream(1000); Writer writer = new OutputStreamWriter(buf, StringUtil.__UTF_8); if (sc!=null) { writer.write(sc.toString()); LOGGER.debug("res to " + uniqueId + ": " + sc.toString()); } else { LOGGER.debug("res empty"); } for (int pad = 998 - buf.size(); pad-- > 0;) { writer.write(" "); } writer.write("\015\012"); writer.close(); OutputStream out = res.getOutputStream(); buf.writeTo(out); }
/** Print the test results out to the HTML response */ private void processResults(HTMLTestResults results, HttpResponse res) throws IOException { res.setContentType("text/html"); OutputStream out = res.getOutputStream(); Writer writer = new OutputStreamWriter(out, StringUtil.__ISO_8859_1); results.write(writer); writer.flush(); }
public void handle(String pathInContext, String pathParams, HttpRequest httpRequest, HttpResponse res) throws HttpException, IOException { if (!"/cachedContentTest".equals(pathInContext)) return; res.setField(HttpFields.__ContentType, "text/html"); setAlwaysCacheHeaders(res); OutputStreamWriter writer = new OutputStreamWriter(res.getOutputStream()); writer.write("<html><body>"); writer.write(Long.toString(System.currentTimeMillis())); writer.write("</body></html>"); writer.flush(); writer.close(); httpRequest.setHandled(true); }
/** Handles the HTTP request and generates the suite table */ public void handle(String pathInContext, String pathParams, HttpRequest request, HttpResponse response) throws HttpException, IOException { if (!pathInContext.startsWith("/singleTest/")) return; request.setHandled(true); String url = pathInContext.substring("/singleTest/".length()); OutputStream outStream = response.getOutputStream(); if (url == null) { outStream.write("No singleTest was specified!".getBytes()); outStream.flush(); return; } response.setContentType("text/html"); String suiteName = getSuiteName(url); Writer writer = new OutputStreamWriter(response.getOutputStream(), StringUtil.__ISO_8859_1); writer.write(MessageFormat.format(HTML, new Object[]{suiteName, url})); writer.flush(); }
private void shutDown(HttpResponse res) { LOGGER.info("Shutdown command received"); Runnable initiateShutDown = new Runnable() { public void run() { LOGGER.info("initiating shutdown"); AsyncExecute.sleepTight(500); System.exit(0); } }; Thread isd = new Thread(initiateShutDown); isd.setName("initiateShutDown"); isd.start(); if (res != null) { try { res.getOutputStream().write("OK".getBytes()); res.commit(); } catch (IOException e) { throw new RuntimeException(e); } } }
public void handle( String string, String string1, HttpRequest httpRequest, HttpResponse httpResponse ) throws IOException { m_Logger.info( "Processing Request. (log4j)" ); m_JdkLogger.info( "Processing Request. (jdk)" ); m_JclLogger.info( "Processing Request. (jcl)" ); m_JuliLogger.info( "Processing Request. (juli)" ); m_Slf4jLogger.info( "Processing Request. (slf4j)" ); httpResponse.setContentType( "text/html" ); OutputStream outputStream = httpResponse.getOutputStream(); OutputStreamWriter osw = new OutputStreamWriter( outputStream, "UTF-8" ); PrintWriter out = new PrintWriter( osw ); out.print( "<html><body><h1>Hello, World!</h1></body></html>" ); out.flush(); httpRequest.setHandled( true ); }
@Override protected void handle(String pathParams, HttpRequest request, HttpResponse response) throws HttpException, IOException { response.setContentType(request.getContentType()); response.addField("X-Test-Header", "test value"); IOUtils.copy(request.getInputStream(), response.getOutputStream()); }
@Override protected void handle(String pathParams, HttpRequest request, HttpResponse response) throws HttpException, IOException { response.setContentType(request.getContentType()); response.addField("X-Test-Header", "test value"); IOUtils.copy(request.getInputStream(), response.getOutputStream()); }
@Override protected void handle(String pathParams, HttpRequest request, HttpResponse response) throws HttpException, IOException { response.setContentType(request.getContentType()); response.addField("X-Test-Header", "test value"); IOUtils.copy(request.getInputStream(), response.getOutputStream()); }
private void handleCommandRequest(HttpRequest req, HttpResponse res, String cmd, String sessionId) { final String results; // If this a Driver Client sending a new command... res.setContentType("text/plain"); hackRemoveConnectionCloseHeader(res); Vector<String> values = parseSeleneseParameters(req); results = doCommand(cmd, values, sessionId, res); // under some conditions, the results variable will be null // (cf http://forums.openqa.org/thread.jspa?threadID=2955&messageID=8085#8085 for an example of this) if (results!=null) { try { res.getOutputStream().write(results.getBytes("UTF-8")); } catch (IOException e) { e.printStackTrace(); } } req.setHandled(true); }
protected void flushHeaders() throws IOException { if (response != null) { copyHeaders(context, response); response.setStatus(HttpURLConnection.HTTP_ACCEPTED, "Accepted"); response.commit(); request.setHandled(true); origOut.resetOut(new BufferedOutputStream(response.getOutputStream(), 1024)); } } }
String result = request.getParameter("result"); if (result == null) { res.getOutputStream().write("No result was specified!".getBytes());
bytesCopied = InjectionHelper.injectJavaScript(request, response, proxy_in, response.getOutputStream(), debugURL); } else { bytesCopied = ModifiedIO.copy(proxy_in, response.getOutputStream()); bytesCopied = ModifiedIO.copy(proxy_in, response.getOutputStream());
responseStream = response.getOutputStream();
private void sendResponse(HttpResponse response, int code, String body) throws IOException { response.setContentType(BPELUnitConstants.TEXT_XML_CONTENT_TYPE); response.setStatus(code); ByteArrayISO8859Writer writer = new ByteArrayISO8859Writer(2048); writer.write(body); writer.flush(); response.setContentLength(writer.size()); writer.writeTo(response.getOutputStream()); writer.destroy(); }
private void sendResponse(HttpResponse response, int code, String body) throws IOException { response.setContentType(BPELUnitConstants.TEXT_XML_CONTENT_TYPE); response.setStatus(code); ByteArrayISO8859Writer writer = new ByteArrayISO8859Writer(2048); writer.write(body); writer.flush(); response.setContentLength(writer.size()); writer.writeTo(response.getOutputStream()); writer.destroy(); }
bus.getWSDLManager().getWSDLFactory().newWSDLWriter().writeWSDL(def, resp.getOutputStream()); resp.getOutputStream().flush(); resp.commit(); req.setHandled(true);
browserResponseSequencer.increaseNum(); res.getOutputStream().write("\r\n\r\n".getBytes()); req.setHandled(true); return;
public void sendData(HttpRequest request, HttpResponse response, String pathInContext, Resource resource, boolean writeHeaders) throws IOException { if (!proxyInjectionMode) { super.sendData(request, response, pathInContext, resource, writeHeaders); return; } ResourceCache.ResourceMetaData metaData = (ResourceCache.ResourceMetaData) resource.getAssociate(); String mimeType = metaData.getMimeType(); response.setContentType(mimeType); if (resource.length() != -1) { response.setField(HttpFields.__ContentLength, metaData.getLength()); } InjectionHelper.injectJavaScript(request, response, resource.getInputStream(), response.getOutputStream(), debugURL); request.setHandled(true); }