Ejemplo n.º 1
0
  /* (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);
  }