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; 023 024import javax.ws.rs.DefaultValue; 025import javax.ws.rs.GET; 026import javax.ws.rs.Path; 027import javax.ws.rs.PathParam; 028import javax.ws.rs.Produces; 029import javax.ws.rs.QueryParam; 030import javax.ws.rs.core.MediaType; 031import javax.ws.rs.core.Response; 032 033import org.eclipse.jetty.util.ajax.JSON; 034import org.slf4j.Logger; 035import org.slf4j.LoggerFactory; 036 037/** 038 * A simple Jersey resource class TestHttpServer. 039 * The servlet simply puts the path and the op parameter in a map 040 * and return it in JSON format in the response. 041 */ 042@Path("") 043public class JerseyResource { 044 private static final Logger LOG = LoggerFactory.getLogger(JerseyResource.class); 045 046 public static final String PATH = "path"; 047 public static final String OP = "op"; 048 049 @GET 050 @Path("{" + PATH + ":.*}") 051 @Produces({MediaType.APPLICATION_JSON}) 052 public Response get( 053 @PathParam(PATH) @DefaultValue("UNKNOWN_" + PATH) final String path, 054 @QueryParam(OP) @DefaultValue("UNKNOWN_" + OP) final String op 055 ) throws IOException { 056 LOG.info("get: " + PATH + "=" + path + ", " + OP + "=" + op); 057 058 final Map<String, Object> m = new TreeMap<>(); 059 m.put(PATH, path); 060 m.put(OP, op); 061 final String js = JSON.toString(m); 062 return Response.ok(js).type(MediaType.APPLICATION_JSON).build(); 063 } 064}