private static void writePostReply(HttpExchange msg, byte[] buf) throws Exception { msg.getResponseHeaders().add("Content-Type", "text/xml"); msg.sendResponseHeaders(200, buf.length); OutputStream out = msg.getResponseBody(); out.write(buf); out.close(); }
/* (non-Javadoc) * @see com.sun.net.httpserver.HttpHandler#handle(com.sun.net.httpserver.HttpExchange) */ @Override public void handle(HttpExchange exchange) throws IOException { Search_Params params = (Search_Params) xmlStream.fromXML(exchange.getRequestBody()); Search_Result results = new Search_Result(); try { results = ServerFacade.search(params); } catch (ServerException e) { logger.log(Level.SEVERE, e.getMessage(), e); exchange.sendResponseHeaders(HttpURLConnection.HTTP_INTERNAL_ERROR, -1); return; } exchange.sendResponseHeaders(HttpURLConnection.HTTP_OK, 0); xmlStream.toXML(results, exchange.getResponseBody()); exchange.getResponseBody().close(); }
@Override public void handle(HttpExchange t) throws IOException { if (RemoteUtil.deny(t)) { throw new IOException("Access denied"); } String id = RemoteUtil.getId("thumb/", t); LOGGER.trace("web thumb req " + id); if (id.contains("logo")) { RemoteUtil.sendLogo(t); return; } RootFolder root = parent.getRoot(RemoteUtil.userName(t), t); if (root == null) { LOGGER.debug("weird root in thumb req"); throw new IOException("Unknown root"); } final DLNAResource r = root.getDLNAResource(id, root.getDefaultRenderer()); if (r == null) { // another error LOGGER.debug("media unknown"); throw new IOException("Bad id"); } InputStream in; if (!configuration.isShowCodeThumbs() && !r.isCodeValid(r)) { // we shouldn't show the thumbs for coded objects // unless the code is entered in = r.getGenericThumbnailInputStream(null); } else { r.checkThumbnail(); in = r.getThumbnailInputStream(); } Headers hdr = t.getResponseHeaders(); hdr.add("Content-Type", r.getThumbnailContentType()); hdr.add("Accept-Ranges", "bytes"); hdr.add("Connection", "keep-alive"); t.sendResponseHeaders(200, in.available()); OutputStream os = t.getResponseBody(); LOGGER.trace("input is {} output is {}", in, os); RemoteUtil.dump(in, os); }
public void handle(HttpExchange t) throws IOException { // System.out.println(t.getRequestURI().toString()); /* * InputStream is = t.getRequestBody(); byte[] temp = new * byte[is.available()]; is.read(temp); String title=new String(temp); */ String title_str = t.getRequestURI().toString(); // System.out.println("title_str:" + title_str); /* * Pattern tit_pat=Pattern.compile("\\/cate_db\\/do\\?t\\=(.*?)\\="); * Matcher tit_mat=tit_pat.matcher(title_str); String tt=""; * while(tit_mat.find()) { tt=tit_mat.group(1); * System.out.println("title:"+tt); } */ title_str = title_str.replaceFirst("/cate_tb/do\\?t=", ""); // System.out.println("title_str:" + title_str); String de_title = new String(Base64.decode(title_str)); System.out.println("de_title:" + de_title); String res = ""; try { res = my_ewa.predict_from_seg_line(de_title); } catch (Exception e) { } ; System.out.println("res is :" + res); // res=res.replace("\001", "$"); String encode_res = Base64.encodeBytes(res.getBytes()); encode_res = encode_res.replaceAll("\\s+", ""); System.out.println("encode_res:" + encode_res); String response = encode_res; t.sendResponseHeaders(200, response.length()); OutputStream os = t.getResponseBody(); os.write(response.getBytes()); os.close(); }