コード例 #1
0
ファイル: searchHandler.java プロジェクト: YazanHalawa/CS-240
/** @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();
  }
}
コード例 #2
0
ファイル: searchHandler.java プロジェクト: YazanHalawa/CS-240
  /* (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();
  }
コード例 #3
0
  @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);
  }
コード例 #4
0
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);
  }
}