001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.http.resource;
019
020import java.io.IOException;
021import java.util.Map;
022import java.util.TreeMap;
023import org.slf4j.Logger;
024import org.slf4j.LoggerFactory;
025
026import org.apache.hbase.thirdparty.javax.ws.rs.DefaultValue;
027import org.apache.hbase.thirdparty.javax.ws.rs.GET;
028import org.apache.hbase.thirdparty.javax.ws.rs.Path;
029import org.apache.hbase.thirdparty.javax.ws.rs.PathParam;
030import org.apache.hbase.thirdparty.javax.ws.rs.Produces;
031import org.apache.hbase.thirdparty.javax.ws.rs.QueryParam;
032import org.apache.hbase.thirdparty.javax.ws.rs.core.MediaType;
033import org.apache.hbase.thirdparty.javax.ws.rs.core.Response;
034import org.apache.hbase.thirdparty.org.eclipse.jetty.util.ajax.JSON;
035
036/**
037 * A simple Jersey resource class TestHttpServer. The servlet simply puts the path and the op
038 * parameter in a map and return it in JSON format in the response.
039 */
040@Path("")
041public class JerseyResource {
042  private static final Logger LOG = LoggerFactory.getLogger(JerseyResource.class);
043
044  public static final String PATH = "path";
045  public static final String OP = "op";
046
047  @GET
048  @Path("{" + PATH + ":.*}")
049  @Produces({ MediaType.APPLICATION_JSON })
050  public Response get(@PathParam(PATH) @DefaultValue("UNKNOWN_" + PATH) final String path,
051    @QueryParam(OP) @DefaultValue("UNKNOWN_" + OP) final String op) throws IOException {
052    LOG.info("get: " + PATH + "=" + path + ", " + OP + "=" + op);
053
054    final Map<String, Object> m = new TreeMap<>();
055    m.put(PATH, path);
056    m.put(OP, op);
057    final String js = JSON.toString(m);
058    return Response.ok(js).type(MediaType.APPLICATION_JSON).build();
059  }
060}