You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by st...@apache.org on 2009/01/22 01:21:18 UTC

svn commit: r736503 [4/4] - in /hadoop/hbase/trunk: ./ lib/ src/java/org/apache/hadoop/hbase/ src/java/org/apache/hadoop/hbase/io/ src/java/org/apache/hadoop/hbase/regionserver/ src/java/org/apache/hadoop/hbase/rest/ src/java/org/apache/hadoop/hbase/re...

Added: hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/rest/serializer/IRestSerializer.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/rest/serializer/IRestSerializer.java?rev=736503&view=auto
==============================================================================
--- hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/rest/serializer/IRestSerializer.java (added)
+++ hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/rest/serializer/IRestSerializer.java Wed Jan 21 16:21:16 2009
@@ -0,0 +1,173 @@
+/**
+ * Copyright 2007 The Apache Software Foundation
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.rest.serializer;
+
+import org.apache.hadoop.hbase.HColumnDescriptor;
+import org.apache.hadoop.hbase.HTableDescriptor;
+import org.apache.hadoop.hbase.io.Cell;
+import org.apache.hadoop.hbase.io.RowResult;
+import org.apache.hadoop.hbase.rest.DatabaseModel.DatabaseMetadata;
+import org.apache.hadoop.hbase.rest.Status.StatusMessage;
+import org.apache.hadoop.hbase.rest.TableModel.Regions;
+import org.apache.hadoop.hbase.rest.descriptors.ScannerIdentifier;
+import org.apache.hadoop.hbase.rest.descriptors.TimestampsDescriptor;
+import org.apache.hadoop.hbase.rest.exception.HBaseRestException;
+
+/**
+ * 
+ *         Interface that is implemented to return serialized objects back to
+ *         the output stream.
+ */
+public interface IRestSerializer {
+  /**
+   * Serializes an object into the appropriate format and writes it to the
+   * output stream.
+   * 
+   * This is the main point of entry when for an object to be serialized to the
+   * output stream.
+   * 
+   * @param o
+   * @throws HBaseRestException
+   */
+  public void writeOutput(Object o) throws HBaseRestException;
+
+  /**
+   * serialize the database metadata
+   * 
+   * Implementation of this method is optional, IF all the work is done in the
+   * writeOutput(Object o) method
+   * 
+   * @param databaseMetadata
+   * @throws HBaseRestException
+   */
+  public void serializeDatabaseMetadata(DatabaseMetadata databaseMetadata)
+      throws HBaseRestException;
+
+  /**
+   * serialize the HTableDescriptor object
+   * 
+   * Implementation of this method is optional, IF all the work is done in the
+   * writeOutput(Object o) method
+   * 
+   * @param tableDescriptor
+   * @throws HBaseRestException
+   */
+  public void serializeTableDescriptor(HTableDescriptor tableDescriptor)
+      throws HBaseRestException;
+
+  /**
+   * serialize an HColumnDescriptor to the output stream.
+   * 
+   * Implementation of this method is optional, IF all the work is done in the
+   * writeOutput(Object o) method
+   * 
+   * @param column
+   * @throws HBaseRestException
+   */
+  public void serializeColumnDescriptor(HColumnDescriptor column)
+      throws HBaseRestException;
+
+  /**
+   * serialize the region data for a table to the output stream
+   * 
+   * Implementation of this method is optional, IF all the work is done in the
+   * writeOutput(Object o) method
+   * 
+   * @param regions
+   * @throws HBaseRestException
+   */
+  public void serializeRegionData(Regions regions) throws HBaseRestException;
+
+  /**
+   * serialize the status message object to the output stream
+   * 
+   * Implementation of this method is optional, IF all the work is done in the
+   * writeOutput(Object o) method
+   * 
+   * @param message
+   * @throws HBaseRestException
+   */
+  public void serializeStatusMessage(StatusMessage message)
+      throws HBaseRestException;
+
+  /**
+   * serialize the ScannerIdentifier object to the output stream
+   * 
+   * Implementation of this method is optional, IF all the work is done in the
+   * writeOutput(Object o) method
+   * 
+   * @param scannerIdentifier
+   * @throws HBaseRestException
+   */
+  public void serializeScannerIdentifier(ScannerIdentifier scannerIdentifier)
+      throws HBaseRestException;
+
+  /**
+   * serialize a RowResult object to the output stream
+   * 
+   * Implementation of this method is optional, IF all the work is done in the
+   * writeOutput(Object o) method
+   * 
+   * @param rowResult
+   * @throws HBaseRestException
+   */
+  public void serializeRowResult(RowResult rowResult) throws HBaseRestException;
+
+  /**
+   * serialize a RowResult array to the output stream
+   * 
+   * Implementation of this method is optional, IF all the work is done in the
+   * writeOutput(Object o) method
+   * 
+   * @param rows
+   * @throws HBaseRestException
+   */
+  public void serializeRowResultArray(RowResult[] rows)
+      throws HBaseRestException;
+
+  /**
+   * serialize a cell object to the output stream
+   * 
+   * Implementation of this method is optional, IF all the work is done in the
+   * writeOutput(Object o) method
+   * 
+   * @param cell
+   * @throws HBaseRestException
+   */
+  public void serializeCell(Cell cell) throws HBaseRestException;
+  
+  /**
+   * serialize a Cell array to the output stream
+   * 
+   * @param cells
+   * @throws HBaseRestException
+   */
+  public void serializeCellArray(Cell[] cells) throws HBaseRestException;
+  
+  
+  /**
+   * serialize a description of the timestamps available for a row 
+   * to the output stream.
+   * 
+   * @param timestampsDescriptor
+   * @throws HBaseRestException
+   */
+  public void serializeTimestamps(TimestampsDescriptor timestampsDescriptor) throws HBaseRestException;
+}

Added: hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/rest/serializer/ISerializable.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/rest/serializer/ISerializable.java?rev=736503&view=auto
==============================================================================
--- hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/rest/serializer/ISerializable.java (added)
+++ hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/rest/serializer/ISerializable.java Wed Jan 21 16:21:16 2009
@@ -0,0 +1,42 @@
+/**
+ * Copyright 2007 The Apache Software Foundation
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.rest.serializer;
+
+import org.apache.hadoop.hbase.rest.exception.HBaseRestException;
+
+/**
+ * 
+ *         Interface for objects that wish to write back to the REST based
+ *         interface output stream. Objects should implement this interface,
+ *         then use the IRestSerializer passed to it to call the appropriate
+ *         serialization method.
+ */
+public interface ISerializable {
+  /**
+   * visitor pattern method where the object implementing this interface will
+   * call back on the IRestSerializer with the correct method to run to
+   * serialize the output of the object to the stream.
+   * 
+   * @param serializer
+   * @throws HBaseRestException
+   */
+  public void restSerialize(IRestSerializer serializer)
+      throws HBaseRestException;
+}

Added: hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/rest/serializer/JSONSerializer.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/rest/serializer/JSONSerializer.java?rev=736503&view=auto
==============================================================================
--- hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/rest/serializer/JSONSerializer.java (added)
+++ hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/rest/serializer/JSONSerializer.java Wed Jan 21 16:21:16 2009
@@ -0,0 +1,213 @@
+/**
+ * Copyright 2007 The Apache Software Foundation
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.rest.serializer;
+
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.hadoop.hbase.HColumnDescriptor;
+import org.apache.hadoop.hbase.HTableDescriptor;
+import org.apache.hadoop.hbase.io.Cell;
+import org.apache.hadoop.hbase.io.RowResult;
+import org.apache.hadoop.hbase.rest.DatabaseModel.DatabaseMetadata;
+import org.apache.hadoop.hbase.rest.Status.StatusMessage;
+import org.apache.hadoop.hbase.rest.TableModel.Regions;
+import org.apache.hadoop.hbase.rest.descriptors.ScannerIdentifier;
+import org.apache.hadoop.hbase.rest.descriptors.TimestampsDescriptor;
+import org.apache.hadoop.hbase.rest.exception.HBaseRestException;
+
+import agilejson.JSON;
+
+/**
+ * 
+ * Serializes objects into JSON strings and prints them back out on the output
+ * stream. It should be noted that this JSON implementation uses annotations on
+ * the objects to be serialized.
+ * 
+ * Since these annotations are used to describe the serialization of the objects
+ * the only method that is implemented is writeOutput(Object o). The other
+ * methods in the interface do not need to be implemented.
+ */
+public class JSONSerializer extends AbstractRestSerializer {
+
+  /**
+   * @param response
+   */
+  public JSONSerializer(HttpServletResponse response) {
+    super(response, false);
+  }
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @see
+   * org.apache.hadoop.hbase.rest.serializer.IRestSerializer#writeOutput(java
+   * .lang.Object, javax.servlet.http.HttpServletResponse)
+   */
+  public void writeOutput(Object o) throws HBaseRestException {
+    response.setContentType("application/json");
+
+    try {
+      // LOG.debug("At top of send data");
+      String data = JSON.toJSON(o);
+      response.setContentLength(data.length());
+      response.getWriter().println(data);
+    } catch (Exception e) {
+      // LOG.debug("Error sending data: " + e.toString());
+      throw new HBaseRestException(e);
+    }
+
+  }
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @seeorg.apache.hadoop.hbase.rest.serializer.IRestSerializer#
+   * serializeColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor)
+   */
+  public void serializeColumnDescriptor(HColumnDescriptor column)
+      throws HBaseRestException {
+    // No implementation needed for the JSON serializer
+
+  }
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @seeorg.apache.hadoop.hbase.rest.serializer.IRestSerializer#
+   * serializeDatabaseMetadata
+   * (org.apache.hadoop.hbase.rest.DatabaseModel.DatabaseMetadata)
+   */
+  public void serializeDatabaseMetadata(DatabaseMetadata databaseMetadata)
+      throws HBaseRestException {
+    // No implementation needed for the JSON serializer
+
+  }
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @see
+   * org.apache.hadoop.hbase.rest.serializer.IRestSerializer#serializeRegionData
+   * (org.apache.hadoop.hbase.rest.TableModel.Regions)
+   */
+  public void serializeRegionData(Regions regions) throws HBaseRestException {
+    // No implementation needed for the JSON serializer
+
+  }
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @seeorg.apache.hadoop.hbase.rest.serializer.IRestSerializer#
+   * serializeTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor)
+   */
+  public void serializeTableDescriptor(HTableDescriptor tableDescriptor)
+      throws HBaseRestException {
+    // No implementation needed for the JSON serializer
+
+  }
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @see
+   * org.apache.hadoop.hbase.rest.serializer.IRestSerializer#serializeStatusMessage
+   * (org.apache.hadoop.hbase.rest.Status.StatusMessage)
+   */
+  public void serializeStatusMessage(StatusMessage message)
+      throws HBaseRestException {
+    // No implementation needed for the JSON serializer
+
+  }
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @seeorg.apache.hadoop.hbase.rest.serializer.IRestSerializer#
+   * serializeScannerIdentifier(org.apache.hadoop.hbase.rest.ScannerIdentifier)
+   */
+  public void serializeScannerIdentifier(ScannerIdentifier scannerIdentifier)
+      throws HBaseRestException {
+    // No implementation needed for the JSON serializer
+
+  }
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @see
+   * org.apache.hadoop.hbase.rest.serializer.IRestSerializer#serializeRowResult
+   * (org.apache.hadoop.hbase.io.RowResult)
+   */
+  public void serializeRowResult(RowResult rowResult) throws HBaseRestException {
+    // No implementation needed for the JSON serializer
+
+  }
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @see
+   * org.apache.hadoop.hbase.rest.serializer.IRestSerializer#serializeRowResultArray
+   * (org.apache.hadoop.hbase.io.RowResult[])
+   */
+  public void serializeRowResultArray(RowResult[] rows)
+      throws HBaseRestException {
+    // No implementation needed for the JSON serializer
+
+  }
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @see
+   * org.apache.hadoop.hbase.rest.serializer.IRestSerializer#serializeCell(org
+   * .apache.hadoop.hbase.io.Cell)
+   */
+  public void serializeCell(Cell cell) throws HBaseRestException {
+    // No implementation needed for the JSON serializer
+
+  }
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @see
+   * org.apache.hadoop.hbase.rest.serializer.IRestSerializer#serializeCellArray
+   * (org.apache.hadoop.hbase.io.Cell[])
+   */
+  public void serializeCellArray(Cell[] cells) throws HBaseRestException {
+    // No implementation needed for the JSON serializer
+
+  }
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @see
+   * org.apache.hadoop.hbase.rest.serializer.IRestSerializer#serializeTimestamps
+   * (org.apache.hadoop.hbase.rest.RowModel.TimestampsDescriptor)
+   */
+  public void serializeTimestamps(TimestampsDescriptor timestampsDescriptor)
+      throws HBaseRestException {
+    // No implementation needed for the JSON serializer
+  }
+
+}

Added: hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/rest/serializer/RestSerializerFactory.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/rest/serializer/RestSerializerFactory.java?rev=736503&view=auto
==============================================================================
--- hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/rest/serializer/RestSerializerFactory.java (added)
+++ hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/rest/serializer/RestSerializerFactory.java Wed Jan 21 16:21:16 2009
@@ -0,0 +1,56 @@
+/**
+ * Copyright 2007 The Apache Software Foundation
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.rest.serializer;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.hadoop.hbase.rest.Dispatcher.ContentType;
+import org.apache.hadoop.hbase.rest.exception.HBaseRestException;
+
+/**
+ * 
+ *         Factory used to return a Rest Serializer tailored to the HTTP
+ *         Requesters accept type in the header.
+ * 
+ */
+public class RestSerializerFactory {
+
+  public static AbstractRestSerializer getSerializer(
+      HttpServletRequest request, HttpServletResponse response)
+      throws HBaseRestException {
+    ContentType ct = ContentType.getContentType(request.getHeader("accept"));
+    AbstractRestSerializer serializer = null;
+
+    // TODO refactor this so it uses reflection to create the new objects.
+    switch (ct) {
+    case XML:
+      serializer = new SimpleXMLSerializer(response);
+      break;
+    case JSON:
+      serializer = new JSONSerializer(response);
+      break;
+    default:
+      serializer = new SimpleXMLSerializer(response);
+      break;
+    }
+    return serializer;
+  }
+}

Added: hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/rest/serializer/SimpleXMLSerializer.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/rest/serializer/SimpleXMLSerializer.java?rev=736503&view=auto
==============================================================================
--- hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/rest/serializer/SimpleXMLSerializer.java (added)
+++ hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/rest/serializer/SimpleXMLSerializer.java Wed Jan 21 16:21:16 2009
@@ -0,0 +1,464 @@
+/**
+ * Copyright 2007 The Apache Software Foundation
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.rest.serializer;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.hadoop.hbase.HColumnDescriptor;
+import org.apache.hadoop.hbase.HConstants;
+import org.apache.hadoop.hbase.HTableDescriptor;
+import org.apache.hadoop.hbase.io.Cell;
+import org.apache.hadoop.hbase.io.RowResult;
+import org.apache.hadoop.hbase.rest.DatabaseModel.DatabaseMetadata;
+import org.apache.hadoop.hbase.rest.Status.StatusMessage;
+import org.apache.hadoop.hbase.rest.TableModel.Regions;
+import org.apache.hadoop.hbase.rest.descriptors.RestCell;
+import org.apache.hadoop.hbase.rest.descriptors.ScannerIdentifier;
+import org.apache.hadoop.hbase.rest.descriptors.TimestampsDescriptor;
+import org.apache.hadoop.hbase.rest.exception.HBaseRestException;
+import org.apache.hadoop.hbase.util.Bytes;
+
+/**
+ * 
+ * Basic first pass at implementing an XML serializer for the REST interface.
+ * This should probably be refactored into something better.
+ * 
+ */
+public class SimpleXMLSerializer extends AbstractRestSerializer {
+
+  private final AbstractPrinter printer;
+
+  /**
+   * @param response
+   * @throws HBaseRestException
+   */
+  @SuppressWarnings("synthetic-access")
+  public SimpleXMLSerializer(HttpServletResponse response)
+      throws HBaseRestException {
+    super(response, false);
+    printer = new SimplePrinter(response);
+  }
+
+  @SuppressWarnings("synthetic-access")
+  public SimpleXMLSerializer(HttpServletResponse response, boolean prettyPrint)
+      throws HBaseRestException {
+    super(response, prettyPrint);
+    if (prettyPrint) {
+      printer = new PrettyPrinter(response);
+    } else {
+      printer = new SimplePrinter(response);
+    }
+  }
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @see
+   * org.apache.hadoop.hbase.rest.serializer.IRestSerializer#writeOutput(java
+   * .lang.Object, java.io.OutputStream)
+   */
+  public void writeOutput(Object o) throws HBaseRestException {
+    response.setContentType("text/xml");
+    response.setCharacterEncoding(HConstants.UTF8_ENCODING);
+
+    if (o instanceof ISerializable) {
+      ((ISerializable) o).restSerialize(this);
+    } else if (o.getClass().isArray()
+        && o.getClass().getComponentType() == RowResult.class) {
+      this.serializeRowResultArray((RowResult[]) o);
+    } else if (o.getClass().isArray()
+        && o.getClass().getComponentType() == Cell.class) {
+      this.serializeCellArray((Cell[]) o);
+    } else {
+      throw new HBaseRestException(
+          "Object does not conform to the ISerializable "
+              + "interface.  Unable to generate xml output.");
+    }
+  }
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @seeorg.apache.hadoop.hbase.rest.serializer.IRestSerializer#
+   * serializeDatabaseMetadata
+   * (org.apache.hadoop.hbase.rest.DatabaseModel.DatabaseMetadata)
+   */
+  public void serializeDatabaseMetadata(DatabaseMetadata databaseMetadata)
+      throws HBaseRestException {
+    printer.print("<tables>");
+    for (HTableDescriptor table : databaseMetadata.getTables()) {
+      table.restSerialize(this);
+    }
+    printer.print("</tables>");
+    printer.flush();
+  }
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @seeorg.apache.hadoop.hbase.rest.serializer.IRestSerializer#
+   * serializeTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor)
+   */
+  public void serializeTableDescriptor(HTableDescriptor tableDescriptor)
+      throws HBaseRestException {
+    printer.print("<table>");
+    // name element
+    printer.print("<name>");
+    printer.print(tableDescriptor.getNameAsString());
+    printer.print("</name>");
+    // column families
+    printer.print("<columnfamilies>");
+    for (HColumnDescriptor column : tableDescriptor.getColumnFamilies()) {
+      column.restSerialize(this);
+    }
+    printer.print("</columnfamilies>");
+    printer.print("</table>");
+    printer.flush();
+
+  }
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @seeorg.apache.hadoop.hbase.rest.serializer.IRestSerializer#
+   * serializeColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor)
+   */
+  public void serializeColumnDescriptor(HColumnDescriptor column)
+      throws HBaseRestException {
+
+    printer.print("<columnfamily>");
+    // name
+    printer.print("<name>");
+    printer.print(org.apache.hadoop.hbase.util.Base64.encodeBytes(column.getName()));
+    printer.print("</name>");
+    // compression
+    printer.print("<compression>");
+    printer.print(column.getCompression().toString());
+    printer.print("</compression>");
+    // bloomfilter
+    printer.print("<bloomfilter>");
+    printer.print(column.getCompressionType().toString());
+    printer.print("</bloomfilter>");
+    // max-versions
+    printer.print("<max-versions>");
+    printer.print(column.getMaxVersions());
+    printer.print("</max-versions>");
+    // max-length
+    printer.print("<max-length>");
+    printer.print(column.getMaxValueLength());
+    printer.print("</max-length>");
+    printer.print("</columnfamily>");
+    printer.flush();
+  }
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @see
+   * org.apache.hadoop.hbase.rest.serializer.IRestSerializer#serializeRegionData
+   * (org.apache.hadoop.hbase.rest.TableModel.Regions)
+   */
+  public void serializeRegionData(Regions regions) throws HBaseRestException {
+
+    printer.print("<regions>");
+    for (byte[] region : regions.getRegionKey()) {
+      printer.print("<region>");
+      printer.print(Bytes.toString(region));
+      printer.print("</region>");
+    }
+    printer.print("</regions>");
+    printer.flush();
+  }
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @see
+   * org.apache.hadoop.hbase.rest.serializer.IRestSerializer#serializeStatusMessage
+   * (org.apache.hadoop.hbase.rest.Status.StatusMessage)
+   */
+  public void serializeStatusMessage(StatusMessage message)
+      throws HBaseRestException {
+
+    printer.print("<status>");
+    printer.print("<code>");
+    printer.print(message.getStatusCode());
+    printer.print("</code>");
+    printer.print("<message>");
+    printer.print(message.getMessage().toString());
+    printer.print("</message>");
+    printer.print("<error>");
+    printer.print(message.getError());
+    printer.print("</error>");
+    printer.print("</status>");
+    printer.flush();
+
+  }
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @seeorg.apache.hadoop.hbase.rest.serializer.IRestSerializer#
+   * serializeScannerIdentifier(org.apache.hadoop.hbase.rest.ScannerIdentifier)
+   */
+  public void serializeScannerIdentifier(ScannerIdentifier scannerIdentifier)
+      throws HBaseRestException {
+
+    printer.print("<scanner>");
+    printer.print("<id>");
+    printer.print(scannerIdentifier.getId());
+    printer.print("</id>");
+    printer.print("</scanner>");
+    printer.flush();
+  }
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @see
+   * org.apache.hadoop.hbase.rest.serializer.IRestSerializer#serializeRowResult
+   * (org.apache.hadoop.hbase.io.RowResult)
+   */
+  public void serializeRowResult(RowResult rowResult) throws HBaseRestException {
+
+    printer.print("<row>");
+    printer.print("<name>");
+    printer.print(org.apache.hadoop.hbase.util.Base64.encodeBytes(rowResult
+        .getRow()));
+    printer.print("</name>");
+    printer.print("<columns>");
+    for (RestCell cell : rowResult.getCells()) {
+      printer.print("<column>");
+      printer.print("<name>");
+      printer.print(org.apache.hadoop.hbase.util.Base64.encodeBytes(cell
+          .getName()));
+      printer.print("</name>");
+      printer.print("<timestamp>");
+      printer.print(cell.getTimestamp());
+      printer.print("</timestamp>");
+      printer.print("<value>");
+      printer.print(org.apache.hadoop.hbase.util.Base64.encodeBytes(cell
+          .getValue()));
+      printer.print("</value>");
+      printer.print("</column>");
+      printer.flush();
+    }
+    printer.print("</columns>");
+    printer.print("</row>");
+    printer.flush();
+  }
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @see
+   * org.apache.hadoop.hbase.rest.serializer.IRestSerializer#serializeRowResultArray
+   * (org.apache.hadoop.hbase.io.RowResult[])
+   */
+  public void serializeRowResultArray(RowResult[] rows)
+      throws HBaseRestException {
+    printer.print("<rows>");
+    for (RowResult row : rows) {
+      row.restSerialize(this);
+    }
+    printer.print("</rows>");
+  }
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @see
+   * org.apache.hadoop.hbase.rest.serializer.IRestSerializer#serializeCell(org
+   * .apache.hadoop.hbase.io.Cell)
+   */
+  public void serializeCell(Cell cell) throws HBaseRestException {
+    printer.print("<cell>");
+    printer.print("<value>");
+    printer.print(org.apache.hadoop.hbase.util.Base64.encodeBytes(cell
+        .getValue()));
+    printer.print("</value>");
+    printer.print("<timestamp>");
+    printer.print(cell.getTimestamp());
+    printer.print("</timestamp>");
+    printer.print("</cell>");
+  }
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @see
+   * org.apache.hadoop.hbase.rest.serializer.IRestSerializer#serializeCellArray
+   * (org.apache.hadoop.hbase.io.Cell[])
+   */
+  public void serializeCellArray(Cell[] cells) throws HBaseRestException {
+    printer.print("<cells>");
+    for (Cell cell : cells) {
+      cell.restSerialize(this);
+    }
+    printer.print("</cells>");
+  }
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @see
+   * org.apache.hadoop.hbase.rest.serializer.IRestSerializer#serializeTimestamps
+   * (org.apache.hadoop.hbase.rest.RowModel.TimestampsDescriptor)
+   */
+  public void serializeTimestamps(TimestampsDescriptor timestampsDescriptor)
+      throws HBaseRestException {
+    // TODO Auto-generated method stub
+
+  }
+
+  // Private classes used for printing the output
+
+  private interface IPrinter {
+    public void print(String output);
+
+    public void print(int output);
+
+    public void print(long output);
+    
+    public void print(boolean output); 
+
+    public void flush();
+  }
+
+  private abstract class AbstractPrinter implements IPrinter {
+    protected final PrintWriter writer;
+
+    @SuppressWarnings("unused")
+    private AbstractPrinter() {
+      writer = null;
+    }
+
+    public AbstractPrinter(HttpServletResponse response)
+        throws HBaseRestException {
+      try {
+        writer = response.getWriter();
+      } catch (IOException e) {
+        throw new HBaseRestException(e.getMessage(), e);
+      }
+    }
+
+    public void flush() {
+      writer.flush();
+    }
+  }
+
+  private class SimplePrinter extends AbstractPrinter {
+    private SimplePrinter(HttpServletResponse response)
+        throws HBaseRestException {
+      super(response);
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see
+     * org.apache.hadoop.hbase.rest.serializer.SimpleXMLSerializer.Printer#print
+     * (java.io.PrintWriter, java.lang.String)
+     */
+    public void print(final String output) {
+      writer.print(output);
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see
+     * org.apache.hadoop.hbase.rest.serializer.SimpleXMLSerializer.IPrinter#
+     * print(int)
+     */
+    public void print(int output) {
+      writer.print(output);
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see
+     * org.apache.hadoop.hbase.rest.serializer.SimpleXMLSerializer.IPrinter#
+     * print(long)
+     */
+    public void print(long output) {
+      writer.print(output);
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.hadoop.hbase.rest.serializer.SimpleXMLSerializer.IPrinter#print(boolean)
+     */
+    public void print(boolean output) {
+      writer.print(output); 
+    }
+  }
+
+  private class PrettyPrinter extends AbstractPrinter {
+    private PrettyPrinter(HttpServletResponse response)
+        throws HBaseRestException {
+      super(response);
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see
+     * org.apache.hadoop.hbase.rest.serializer.SimpleXMLSerializer.Printer#print
+     * (java.io.PrintWriter, java.lang.String)
+     */
+    public void print(String output) {
+      writer.println(output);
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see
+     * org.apache.hadoop.hbase.rest.serializer.SimpleXMLSerializer.IPrinter#
+     * print(int)
+     */
+    public void print(int output) {
+      writer.println(output);
+
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see
+     * org.apache.hadoop.hbase.rest.serializer.SimpleXMLSerializer.IPrinter#
+     * print(long)
+     */
+    public void print(long output) {
+      writer.println(output);
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.hadoop.hbase.rest.serializer.SimpleXMLSerializer.IPrinter#print(boolean)
+     */
+    public void print(boolean output) {
+      writer.println(output);
+    }
+  }
+}

Modified: hadoop/hbase/trunk/src/webapps/rest/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/webapps/rest/WEB-INF/web.xml?rev=736503&r1=736502&r2=736503&view=diff
==============================================================================
--- hadoop/hbase/trunk/src/webapps/rest/WEB-INF/web.xml (original)
+++ hadoop/hbase/trunk/src/webapps/rest/WEB-INF/web.xml Wed Jan 21 16:21:16 2009
@@ -1,14 +1,14 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
-  <display-name>rest</display-name>
+  <display-name>jsonrest</display-name>
   <servlet>
-    <description>Hbase REST Interface</description>
+    <description>Hbase JSONREST Interface</description>
     <display-name>api</display-name>
     <servlet-name>api</servlet-name>
     <servlet-class>org.apache.hadoop.hbase.rest.Dispatcher</servlet-class>
   </servlet>
   <servlet-mapping>
     <servlet-name>api</servlet-name>
-    <url-pattern>/*</url-pattern>
+    <url-pattern>/api/*</url-pattern>
   </servlet-mapping>
 </web-app>