@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 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(); }
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)); } } }
/** 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(); }
throw new RuntimeException("Couldn't establish SSL handshake. Try using trustAllSSLCertificates.\n"+e.getLocalizedMessage(), e); response.setStatus(code); response.setReason(http.getResponseMessage()); response.removeField(HttpFields.__Date); response.removeField(HttpFields.__Server); while (hdr != null || val != null) { if (hdr != null && val != null && !_DontProxyHeaders.containsKey(hdr) && (_chained || !_ProxyAuthHeaders.containsKey(hdr))) response.addField(hdr, val); h++; hdr = connection.getHeaderFieldKey(h); response.setField("Via", "1.1 (jetty)"); response.removeField(HttpFields.__ETag); // possible cksum? Stop caching... response.removeField(HttpFields.__LastModified); // Stop caching... 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());
void doService(HttpRequest req, HttpResponse resp) throws IOException { resp.sendRedirect(policy.getRedirectURL()); resp.commit(); req.setHandled(true); return; resp.addField("Content-Type", "text/xml"); bus.getWSDLManager().getWSDLFactory().newWSDLWriter().writeWSDL(def, resp.getOutputStream()); resp.getOutputStream().flush(); resp.commit(); 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); }
@Override public OutputStream openStream() { return response.getOutputStream(); } }.asCharSink(Charset.forName(UTF_8)).write(mockResponseBodies.get(numInteractions++));
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 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); }
protected void copyHeaders(MessageContext context, HttpResponse response) { Map<?, ?> headers = (Map<?, ?>)context.get(MessageContext.HTTP_RESPONSE_HEADERS); if (null != headers) { for (Iterator<?> iter = headers.keySet().iterator(); iter.hasNext();) { String header = (String)iter.next(); List<?> headerList = (List<?>)headers.get(header); for (Object string : headerList) { response.addField(header, (String)string); } } } }
response.setStatus(HttpResponse.__200_OK); response.setContentLength(0); response.sendError(HttpResponse.__500_Internal_Server_Error, e.toString());
public void handle(String pathInContext, String pathParams, HttpRequest req, HttpResponse resp) throws IOException { HTTPDecoupledClientInputStreamContext ctx = new HTTPDecoupledClientInputStreamContext(req); responseCallback.dispatch(ctx); resp.commit(); req.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 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); }
response.addField(option, m2.getProtocolOption(option));
void serviceRequest(final HttpRequest req, final HttpResponse resp) throws IOException { try { if (LOG.isLoggable(Level.INFO)) { LOG.info("Service http request on thread: " + Thread.currentThread()); } HTTPServerInputStreamContext ctx = new HTTPServerInputStreamContext(this) { public void initContext() throws IOException { super.initContext(); inStream = req.getInputStream(); origInputStream = inStream; } }; BindingContextUtils.storeAsyncOnewayDispatch(ctx, true); ctx.put(HTTPServerInputStreamContext.HTTP_REQUEST, req); ctx.put(HTTPServerInputStreamContext.HTTP_RESPONSE, resp); ctx.initContext(); callback.dispatch(ctx, this); resp.commit(); req.setHandled(true); } finally { if (LOG.isLoggable(Level.INFO)) { LOG.info("Finished servicing http request on thread: " + Thread.currentThread()); } } }
@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 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(); }