/** @author Yazan Halawa */ @SuppressWarnings("restriction") public class searchHandler implements HttpHandler { private Logger logger = Logger.getLogger("recordIndexer"); private XStream xmlStream = new XStream(new DomDriver()); public searchHandler() {} /* (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(); } }
/* (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); }
public class UpdateContactHandler implements HttpHandler { private Logger logger = Logger.getLogger("contactmanager"); private XStream xmlStream = new XStream(new DomDriver()); @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); } }