private void run(int port) { try { ServerFacade.initialize(); } catch (ServerException e) { return; } try { server = HttpServer.create(new InetSocketAddress(SERVER_PORT_NUMBER), MAX_WAITING_CONNECTIONS); } catch (IOException e) { return; } server.setExecutor(null); // use the default executor server.createContext("/", downloadFileHandler); server.createContext("/ValidateUser", validateUserHandler); server.createContext("/GetProjects", getProjectsHandler); server.createContext("/GetSampleImage", getSampleImageHandler); server.createContext("/DownloadBatch", downloadBatchHandler); server.createContext("/SubmitBatch", submitBatchHandler); server.createContext("/GetFields", getFieldsHandler); server.createContext("/Search", searchHandler); server.start(); }
/* (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 exchange) throws IOException { UpdateContact_Params params = (UpdateContact_Params) xmlStream.fromXML(exchange.getRequestBody()); Contact contact = params.getContact(); try { ServerFacade.updateContact(contact); } catch (ServerException e) { logger.log(Level.SEVERE, e.getMessage(), e); exchange.sendResponseHeaders(HttpURLConnection.HTTP_INTERNAL_ERROR, -1); return; } exchange.sendResponseHeaders(HttpURLConnection.HTTP_OK, -1); }