gzipOutputStream.close(); } else { resp.getPrintStream().append("agent=" + req.getValues("User-Agent").get(0));
/** * This method is provided for convenience so that the HTTP content * can be written using the <code>print</code> methods provided by * the <code>PrintStream</code>. This will basically wrap the * <code>getOutputStream</code> with a buffer size of zero. * <p> * The retrieved <code>PrintStream</code> uses the charset used to * describe the content, with the Content-Type header. This will * check the charset parameter of the contents MIME type. So if * the Content-Type was <code>text/plain; charset=UTF-8</code> the * resulting <code>PrintStream</code> would encode the written data * using the UTF-8 encoding scheme. Care must be taken to ensure * that bytes written to the stream are correctly encoded. * <p> * Implementations of the <code>Response</code> must guarantee * that this can be invoked repeatedly without effecting any issued * <code>OutputStream</code> or <code>PrintStream</code> object. * * @return a print stream used for writing the response body * * @exception IOException this is thrown if there was an I/O error */ public PrintStream getPrintStream() throws IOException { return response.getPrintStream(); }
/** * This method is provided for convenience so that the HTTP content * can be written using the <code>print</code> methods provided by * the <code>PrintStream</code>. This will basically wrap the * <code>getOutputStream</code> with a buffer size of zero. * <p> * The retrieved <code>PrintStream</code> uses the charset used to * describe the content, with the Content-Type header. This will * check the charset parameter of the contents MIME type. So if * the Content-Type was <code>text/plain; charset=UTF-8</code> the * resulting <code>PrintStream</code> would encode the written data * using the UTF-8 encoding scheme. Care must be taken to ensure * that bytes written to the stream are correctly encoded. * <p> * Implementations of the <code>Response</code> must guarantee * that this can be invoked repeatedly without effecting any issued * <code>OutputStream</code> or <code>PrintStream</code> object. * * @return a print stream used for writing the response body * * @exception IOException this is thrown if there was an I/O error */ public PrintStream getPrintStream() throws IOException { return response.getPrintStream(); }
/** * This method is provided for convenience so that the HTTP content * can be written using the <code>print</code> methods provided by * the <code>PrintStream</code>. This will basically wrap the * <code>getOutputStream</code> with a buffer size of zero. * <p> * The retrieved <code>PrintStream</code> uses the charset used to * describe the content, with the Content-Type header. This will * check the charset parameter of the contents MIME type. So if * the Content-Type was <code>text/plain; charset=UTF-8</code> the * resulting <code>PrintStream</code> would encode the written data * using the UTF-8 encoding scheme. Care must be taken to ensure * that bytes written to the stream are correctly encoded. * <p> * Implementations of the <code>Response</code> must guarantee * that this can be invoked repeatedly without effecting any issued * <code>OutputStream</code> or <code>PrintStream</code> object. * * @return a print stream used for writing the response body * * @exception IOException this is thrown if there was an I/O error */ public PrintStream getPrintStream() throws IOException { return response.getPrintStream(); }
/** * This method is provided for convenience so that the HTTP content * can be written using the <code>print</code> methods provided by * the <code>PrintStream</code>. This will basically wrap the * <code>getOutputStream</code> with a specified buffer size. * <p> * The retrieved <code>PrintStream</code> uses the charset used to * describe the content, with the Content-Type header. This will * check the charset parameter of the contents MIME type. So if * the Content-Type was <code>text/plain; charset=UTF-8</code> the * resulting <code>PrintStream</code> would encode the written data * using the UTF-8 encoding scheme. Care must be taken to ensure * that bytes written to the stream are correctly encoded. * <p> * Implementations of the <code>Response</code> must guarantee * that this can be invoked repeatedly without effecting any issued * <code>OutputStream</code> or <code>PrintStream</code> object. * * @param size the minimum size that the response buffer must be * * @return a print stream used for writing the response body * * @exception IOException this is thrown if there was an I/O error */ public PrintStream getPrintStream(int size) throws IOException { return response.getPrintStream(size); }
/** * This method is provided for convenience so that the HTTP content * can be written using the <code>print</code> methods provided by * the <code>PrintStream</code>. This will basically wrap the * <code>getOutputStream</code> with a specified buffer size. * <p> * The retrieved <code>PrintStream</code> uses the charset used to * describe the content, with the Content-Type header. This will * check the charset parameter of the contents MIME type. So if * the Content-Type was <code>text/plain; charset=UTF-8</code> the * resulting <code>PrintStream</code> would encode the written data * using the UTF-8 encoding scheme. Care must be taken to ensure * that bytes written to the stream are correctly encoded. * <p> * Implementations of the <code>Response</code> must guarantee * that this can be invoked repeatedly without effecting any issued * <code>OutputStream</code> or <code>PrintStream</code> object. * * @param size the minimum size that the response buffer must be * * @return a print stream used for writing the response body * * @exception IOException this is thrown if there was an I/O error */ public PrintStream getPrintStream(int size) throws IOException { return response.getPrintStream(size); }
/** * This method is provided for convenience so that the HTTP content * can be written using the <code>print</code> methods provided by * the <code>PrintStream</code>. This will basically wrap the * <code>getOutputStream</code> with a specified buffer size. * <p> * The retrieved <code>PrintStream</code> uses the charset used to * describe the content, with the Content-Type header. This will * check the charset parameter of the contents MIME type. So if * the Content-Type was <code>text/plain; charset=UTF-8</code> the * resulting <code>PrintStream</code> would encode the written data * using the UTF-8 encoding scheme. Care must be taken to ensure * that bytes written to the stream are correctly encoded. * <p> * Implementations of the <code>Response</code> must guarantee * that this can be invoked repeatedly without effecting any issued * <code>OutputStream</code> or <code>PrintStream</code> object. * * @param size the minimum size that the response buffer must be * * @return a print stream used for writing the response body * * @exception IOException this is thrown if there was an I/O error */ public PrintStream getPrintStream(int size) throws IOException { return response.getPrintStream(size); }
private PrintStream printBody(Response response, String contentType) throws IOException { PrintStream ps = response.getPrintStream(); addStandardHeaders(response, contentType); ps.println(body); ps.flush(); return ps; } }
@Override public void run() { try { if (times > -1 && count >= times) { timer.cancel(); timer.purge(); subscriberResponse.getPrintStream().close(); return; } responseBody.send(subscriberResponse, responseContentType); count++; } catch (Exception e) { logger.error("error sending async response at fixed rate", e); } } }, 0, periodInMillis);
private void errorResponse(final Response response, final int httpCode, final String message) { response.setCode(httpCode); response.set(CONTENT_TYPE, "text/plain;charset=utf-8"); PrintStream body; try { body = response.getPrintStream(); body.print(message); body.close(); } catch (final IOException e) { throw new IllegalStateException("Exception when building response.", e); } }
@Override public void handle(Request request, Response response) { try { if (request.getTarget().startsWith(routerPath)) { router.route( new SimpleRestxRequest(httpSettings, routerPath, request), new SimpleRestxResponse(response)); } else { response.getPrintStream().print("Not found..."); response.getPrintStream().close(); } } catch (IOException e) { throw new RuntimeException(e); } } };
@Override public void handle(Request request, Response response) { try { if (request.getTarget().startsWith(routerPath)) { router.route( new SimpleRestxRequest(httpSettings, routerPath, request), new SimpleRestxResponse(response)); } else { response.getPrintStream().print("Not found..."); response.getPrintStream().close(); } } catch (IOException e) { throw new RuntimeException(e); } } };
private void downloadFile(File f, Request request, Response response) throws IOException { if (f.exists()) { response.setContentType("application/octet-stream"); response.addValue("Server", "SDFS Management Server"); response.setContentLength(f.length()); InputStream in = new FileInputStream(f); OutputStream out = response.getOutputStream(); byte[] buf = new byte[32768]; int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } out.flush(); in.close(); out.close(); } else { response.setCode(404); PrintStream body = response.getPrintStream(); body.println("could not find " + f.getPath()); body.close(); SDFSLogger.getLog().warn("unable to find " + f.getPath()); } }
public void handle(Request request, Response response) { try { PrintStream body = response.getPrintStream(); long time = System.currentTimeMillis(); String msg="";
@Override public void handle(Request request, Response response) { try { PrintStream body = response.getPrintStream(); long time = System.currentTimeMillis(); response.setStatus(status); response.setContentType("text/plain"); response.setDate("Date", time); response.setDate("Last-Modified", time); log.info("mock container returning: status [{}], content [{}]", status, responseContent); body.println(responseContent); body.close(); } catch (Exception e) { e.printStackTrace(); } } }
public void handle(Request request, Response response) { try { PrintStream body = response.getPrintStream(); long time = System.currentTimeMillis();
subscriberResponse.getPrintStream().close(); break;
public void handle( Request req, Response resp ) { try { PrintStream out = resp.getPrintStream(1024); String address = req.getAddress().toString(); if( address.equals(DEFAULT_ENPOINT) ) { String content = readInputStreamAsString(req.getInputStream()); JaxbCommandsRequest cmdsReq = (JaxbCommandsRequest) jaxbSerializationProvider.deserialize(content); String [] headerNames = { TEST_HEADER_NAME, ANOTHER_TEST_HEADER_NAME, NOT_SENT_HEADER_NAME }; List<String> headerValues = new ArrayList<String>(); for( String headerName : headerNames ) { String headerVal = req.getValue(headerName); if( headerVal != null ) { headerValues.add(headerVal); } } String output = handleJaxbCommandsRequest(cmdsReq, headerValues); resp.setCode(HttpURLConnection.HTTP_OK); out.print(output); } else { resp.setCode(HttpURLConnection.HTTP_BAD_REQUEST); } out.close(); } catch( Exception e ) { e.printStackTrace(); } }
@Override public void handle(Request request, Response response) { try { PrintStream body = response.getPrintStream(); long time = System.currentTimeMillis(); response.setValue("Content-Type", "text/plain"); response.setContentType("application/xml;charset=utf-8"); response.setDate("Date", time); response.setDate("Last-Modified", time); String path = request.getAddress().getPath().getPath(); log.trace("request path is {}", path); StatusAndContent statusAndContent = tryMatchPath(path); Status status = statusAndContent.status; response.setStatus(status); String content = statusAndContent.content; log.trace("mock container returning: status [{}], content [{}]", status, content); body.println(content); body.close(); } catch (Exception e) { e.printStackTrace(); response.setStatus(Status.INTERNAL_SERVER_ERROR); try { response.close(); } catch (IOException e1) { throw new RuntimeException(e1); } } }
public void handle( Request req, Response resp ) { try { PrintStream out = resp.getPrintStream(1024); String address = req.getAddress().toString(); if( address.equals(REDIRECT_PATH) ) {