5 import java.security.NoSuchAlgorithmException;
8 import com.sun.net.httpserver.HttpExchange;
9 import com.sun.net.httpserver.HttpHandler;
10 import com.sun.net.httpserver.HttpServer;
13 public class httpget implements Runnable {
17 public static Map<String, String> splitQuery(String query) throws UnsupportedEncodingException
19 Map<String, String> query_pairs = new LinkedHashMap<String, String>();
20 String[] pairs = query.split("&");
21 for (String pair : pairs)
23 int idx = pair.indexOf("=");
24 query_pairs.put(URLDecoder.decode(pair.substring(0, idx), "UTF-8"), URLDecoder.decode(pair.substring(idx + 1), "UTF-8"));
32 HttpServer server = HttpServer.create(new InetSocketAddress(global.portaHttpServer), 0);
33 server.createContext("/test", new MyHandler());
34 server.setExecutor(null); // creates a default executor
42 static class MyHandler implements HttpHandler
44 public void handle(HttpExchange t) throws IOException
47 /*String response = "This is the response";
48 System.out.println("mannaggia santa");
49 t.sendResponseHeaders(200, response.length());
50 OutputStream os = t.getResponseBody();
51 os.write(response.getBytes());*/
52 URI req=t.getRequestURI();
53 String query=req.getQuery();
54 Map<String, String> result=splitQuery(query);
55 String id=result.get("id");
56 //System.out.println(id);
59 dbConnect request=new dbConnect();
60 String returnQuery=request.dbQuery("3"+id);
61 t.sendResponseHeaders(200, returnQuery.length());
62 OutputStream os = t.getResponseBody();
63 os.write(returnQuery.getBytes());
68 catch(ClassNotFoundException c)
70 catch(IllegalAccessException a)
72 catch(InstantiationException i)
73 {} catch (NoSuchAlgorithmException e) {