7070public class RangerRESTClient {
7171 private static final Logger LOG = LoggerFactory .getLogger (RangerRESTClient .class );
7272
73+ public enum HttpMethod {
74+ GET ("GET" ),
75+ POST ("POST" ),
76+ PUT ("PUT" ),
77+ DELETE ("DELETE" );
78+
79+ private final String method ;
80+
81+ HttpMethod (String method ) {
82+ this .method = method ;
83+ }
84+
85+ public String getMethod () {
86+ return method ;
87+ }
88+ }
89+
7390 public static final String RANGER_PROP_POLICYMGR_URL = "ranger.service.store.rest.url" ;
7491 public static final String RANGER_PROP_POLICYMGR_SSLCONFIG_FILENAME = "ranger.service.store.rest.ssl.config.file" ;
7592 public static final String RANGER_POLICYMGR_CLIENT_KEY_FILE = "xasecure.policymgr.clientssl.keystore" ;
@@ -367,35 +384,35 @@ public TrustManager[] getTrustManagers(String trustStoreFile, String trustStoreF
367384 }
368385
369386 public Response get (String relativeUrl , Map <String , String > params ) throws Exception {
370- return performRequest (" GET" , relativeUrl , params , null , null );
387+ return performRequest (HttpMethod . GET , relativeUrl , params , null , null );
371388 }
372389
373390 public Response get (String relativeUrl , Map <String , String > params , Cookie sessionId ) throws Exception {
374- return performRequest (" GET" , relativeUrl , params , null , sessionId );
391+ return performRequest (HttpMethod . GET , relativeUrl , params , null , sessionId );
375392 }
376393
377394 public Response post (String relativeUrl , Map <String , String > params , Object obj ) throws Exception {
378- return performRequest (" POST" , relativeUrl , params , obj , null );
395+ return performRequest (HttpMethod . POST , relativeUrl , params , obj , null );
379396 }
380397
381398 public Response post (String relativeURL , Map <String , String > params , Object obj , Cookie sessionId ) throws Exception {
382- return performRequest (" POST" , relativeURL , params , obj , sessionId );
399+ return performRequest (HttpMethod . POST , relativeURL , params , obj , sessionId );
383400 }
384401
385402 public Response delete (String relativeUrl , Map <String , String > params ) throws Exception {
386- return performRequest (" DELETE" , relativeUrl , params , null , null );
403+ return performRequest (HttpMethod . DELETE , relativeUrl , params , null , null );
387404 }
388405
389406 public Response delete (String relativeURL , Map <String , String > params , Cookie sessionId ) throws Exception {
390- return performRequest (" DELETE" , relativeURL , params , null , sessionId );
407+ return performRequest (HttpMethod . DELETE , relativeURL , params , null , sessionId );
391408 }
392409
393410 public Response put (String relativeUrl , Map <String , String > params , Object obj ) throws Exception {
394- return performRequest (" PUT" , relativeUrl , params , obj , null );
411+ return performRequest (HttpMethod . PUT , relativeUrl , params , obj , null );
395412 }
396413
397414 public Response put (String relativeURL , Object request , Cookie sessionId ) throws Exception {
398- return performRequest (" PUT" , relativeURL , null , request , sessionId );
415+ return performRequest (HttpMethod . PUT , relativeURL , null , request , sessionId );
399416 }
400417
401418 public int getLastKnownActiveUrlIndex () {
@@ -481,7 +498,7 @@ private Invocation.Builder createInvocationBuilder(int currentIndex, String rela
481498 return builder ;
482499 }
483500
484- private Response performRequest (String method , String relativeUrl , Map <String , String > params , Object requestBody , Cookie sessionId ) throws Exception {
501+ private Response performRequest (HttpMethod method , String relativeUrl , Map <String , String > params , Object requestBody , Cookie sessionId ) throws Exception {
485502 Response finalResponse = null ;
486503 int startIndex = this .lastKnownActiveUrlIndex ;
487504 int retryAttempt = 0 ;
@@ -492,11 +509,11 @@ private Response performRequest(String method, String relativeUrl, Map<String, S
492509 try {
493510 Invocation .Builder builder = createInvocationBuilder (currentIndex , relativeUrl , params , sessionId );
494511
495- if ("POST" . equalsIgnoreCase ( method ) ) {
512+ if (HttpMethod . POST == method ) {
496513 finalResponse = builder .post (Entity .entity (requestBody , MediaType .APPLICATION_JSON ));
497- } else if ("PUT" . equalsIgnoreCase ( method ) ) {
514+ } else if (HttpMethod . PUT == method ) {
498515 finalResponse = builder .put (Entity .entity (requestBody , MediaType .APPLICATION_JSON ));
499- } else if ("DELETE" . equalsIgnoreCase ( method ) ) {
516+ } else if (HttpMethod . DELETE == method ) {
500517 finalResponse = builder .delete ();
501518 } else {
502519 finalResponse = builder .get ();
@@ -722,12 +739,9 @@ private boolean isSslEnabled(String url) {
722739 }
723740
724741 private KeyManager [] getKeyManagers () {
725- KeyManager [] kmList = null ;
726-
727742 String keyStoreFilepwd = getCredential (mKeyStoreURL , mKeyStoreAlias );
728743
729- kmList = getKeyManagers (mKeyStoreFile , keyStoreFilepwd );
730- return kmList ;
744+ return getKeyManagers (mKeyStoreFile , keyStoreFilepwd );
731745 }
732746
733747 private TrustManager [] getTrustManagers () {
0 commit comments