Java Code Examples for com.sun.jersey.api.client.ClientResponse#setStatus()
The following examples show how to use
com.sun.jersey.api.client.ClientResponse#setStatus() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TagAdminRESTSink.java From ranger with Apache License 2.0 | 5 votes |
private synchronized ClientResponse uploadTagsWithCred(ServiceTags serviceTags) { if (sessionId == null) { tagRESTClient.resetClient(); ClientResponse response = null; try { response = tagRESTClient.put(REST_URL_IMPORT_SERVICETAGS_RESOURCE, null, serviceTags); } catch (Exception e) { LOG.error("Failed to get response, Error is : "+e.getMessage()); } if (response != null) { if (!(response.toString().contains(REST_URL_IMPORT_SERVICETAGS_RESOURCE))) { response.setStatus(HttpServletResponse.SC_NOT_FOUND); } else if (response.getStatus() == HttpServletResponse.SC_UNAUTHORIZED) { LOG.warn("Credentials response from ranger is 401."); } else if (response.getStatus() == HttpServletResponse.SC_OK || response.getStatus() == HttpServletResponse.SC_NO_CONTENT) { cookieList = response.getCookies(); // save cookie received from credentials session login for (NewCookie cookie : cookieList) { if (cookie.getName().equalsIgnoreCase(rangerAdminCookieName)) { sessionId = cookie.toCookie(); isValidRangerCookie = true; break; } else { isValidRangerCookie = false; } } } } return response; } else { ClientResponse clientResponsebySessionId = uploadTagsWithCookie(serviceTags); if (!(clientResponsebySessionId.toString().contains(REST_URL_IMPORT_SERVICETAGS_RESOURCE))) { clientResponsebySessionId.setStatus(HttpServletResponse.SC_NOT_FOUND); } return clientResponsebySessionId; } }
Example 2
Source File: TagAdminRESTSink.java From ranger with Apache License 2.0 | 5 votes |
private ClientResponse uploadTagsWithCookie(ServiceTags serviceTags) { if (LOG.isDebugEnabled()) { LOG.debug("==> uploadTagsWithCookie"); } ClientResponse response = null; try { response = tagRESTClient.put(REST_URL_IMPORT_SERVICETAGS_RESOURCE, serviceTags, sessionId); } catch (Exception e) { LOG.error("Failed to get response, Error is : "+e.getMessage()); } if (response != null) { if (!(response.toString().contains(REST_URL_IMPORT_SERVICETAGS_RESOURCE))) { response.setStatus(HttpServletResponse.SC_NOT_FOUND); sessionId = null; isValidRangerCookie = false; } else if (response.getStatus() == HttpServletResponse.SC_UNAUTHORIZED) { sessionId = null; isValidRangerCookie = false; } else if (response.getStatus() == HttpServletResponse.SC_NO_CONTENT || response.getStatus() == HttpServletResponse.SC_OK) { List<NewCookie> respCookieList = response.getCookies(); for (NewCookie respCookie : respCookieList) { if (respCookie.getName().equalsIgnoreCase(rangerAdminCookieName)) { if (!(sessionId.getValue().equalsIgnoreCase(respCookie.toCookie().getValue()))) { sessionId = respCookie.toCookie(); } isValidRangerCookie = true; break; } } } } if (LOG.isDebugEnabled()) { LOG.debug("<== uploadTagsWithCookie"); } return response; }
Example 3
Source File: LdapPolicyMgrUserGroupBuilder.java From ranger with Apache License 2.0 | 4 votes |
private void delXGroupUserInfo(String groupName, String userName) { if (LOG.isDebugEnabled()) { LOG.debug("==> LdapPolicyMgrUserGroupBuilder.delXUserGroupInfo()"); } try { ClientResponse response = null; String relativeUrl = PM_DEL_USER_GROUP_LINK_URI.replaceAll(Pattern.quote("${groupName}"), URLEncoderUtil.encodeURIParam(groupName)).replaceAll(Pattern.quote("${userName}"), URLEncoderUtil.encodeURIParam(userName)); if (isRangerCookieEnabled) { if (sessionId != null && isValidRangerCookie) { response = ldapUgSyncClient.delete(relativeUrl, null, sessionId); if (response != null) { if (!(response.toString().contains(relativeUrl))) { response.setStatus(HttpServletResponse.SC_NOT_FOUND); sessionId = null; isValidRangerCookie = false; } else if (response.getStatus() == HttpServletResponse.SC_UNAUTHORIZED) { LOG.warn("response from ranger is 401 unauthorized"); sessionId = null; isValidRangerCookie = false; } else if (response.getStatus() == HttpServletResponse.SC_NO_CONTENT || response.getStatus() == HttpServletResponse.SC_OK) { cookieList = response.getCookies(); for (NewCookie cookie : cookieList) { if (cookie.getName().equalsIgnoreCase(rangerCookieName)) { sessionId = cookie.toCookie(); isValidRangerCookie = true; break; } } } if (response.getStatus() != HttpServletResponse.SC_OK && response.getStatus() != HttpServletResponse.SC_NO_CONTENT && response.getStatus() != HttpServletResponse.SC_BAD_REQUEST) { sessionId = null; isValidRangerCookie = false; } } } } else { response = ldapUgSyncClient.delete(relativeUrl, null); } if ( LOG.isDebugEnabled() ) { LOG.debug("RESPONSE: [" + response.toString() + "]"); } } catch (Exception e) { LOG.warn( "ERROR: Unable to delete GROUP: " + groupName + " from USER:" + userName , e); } if (LOG.isDebugEnabled()) { LOG.debug("<== LdapPolicyMgrUserGroupBuilder.delXUserGroupInfo()"); } }
Example 4
Source File: LdapPolicyMgrUserGroupBuilder.java From ranger with Apache License 2.0 | 4 votes |
private String tryUploadEntityWithCookie(Object obj, String apiURL) { if (LOG.isDebugEnabled()) { LOG.debug("==> LdapPolicyMgrUserGroupBuilder.tryUploadEntityWithCookie()"); } String response = null; ClientResponse clientResp = null; try { clientResp = ldapUgSyncClient.post(apiURL, null, obj, sessionId); } catch(Throwable t){ LOG.error("Failed to get response, Error is : ", t); } if (clientResp != null) { if (!(clientResp.toString().contains(apiURL))) { clientResp.setStatus(HttpServletResponse.SC_NOT_FOUND); sessionId = null; isValidRangerCookie = false; } else if (clientResp.getStatus() == HttpServletResponse.SC_UNAUTHORIZED) { sessionId = null; isValidRangerCookie = false; } else if (clientResp.getStatus() == HttpServletResponse.SC_NO_CONTENT || clientResp.getStatus() == HttpServletResponse.SC_OK) { List<NewCookie> respCookieList = clientResp.getCookies(); for (NewCookie cookie : respCookieList) { if (cookie.getName().equalsIgnoreCase(rangerCookieName)) { if (!(sessionId.getValue().equalsIgnoreCase(cookie.toCookie().getValue()))) { sessionId = cookie.toCookie(); } isValidRangerCookie = true; break; } } } if (clientResp.getStatus() != HttpServletResponse.SC_OK && clientResp.getStatus() != HttpServletResponse.SC_NO_CONTENT && clientResp.getStatus() != HttpServletResponse.SC_BAD_REQUEST) { sessionId = null; isValidRangerCookie = false; } clientResp.bufferEntity(); response = clientResp.getEntity(String.class); } if (LOG.isDebugEnabled()) { LOG.debug("<== LdapPolicyMgrUserGroupBuilder.tryUploadEntityWithCookie()"); } return response; }
Example 5
Source File: LdapPolicyMgrUserGroupBuilder.java From ranger with Apache License 2.0 | 4 votes |
private String tryUploadEntityWithCred(Object obj, String apiURL){ if(LOG.isDebugEnabled()){ LOG.debug("==> LdapPolicyMgrUserGroupBuilder.tryUploadEntityInfoWithCred()"); } String response = null; ClientResponse clientResp = null; Gson gson = new GsonBuilder().create(); String jsonString = gson.toJson(obj); if ( LOG.isDebugEnabled() ) { LOG.debug("USER GROUP MAPPING" + jsonString); } try{ clientResp = ldapUgSyncClient.post(apiURL, null, obj); } catch(Throwable t){ LOG.error("Failed to get response, Error is : ", t); } if (clientResp != null) { if (!(clientResp.toString().contains(apiURL))) { clientResp.setStatus(HttpServletResponse.SC_NOT_FOUND); } else if (clientResp.getStatus() == HttpServletResponse.SC_UNAUTHORIZED) { LOG.warn("Credentials response from ranger is 401."); } else if (clientResp.getStatus() == HttpServletResponse.SC_OK || clientResp.getStatus() == HttpServletResponse.SC_NO_CONTENT) { cookieList = clientResp.getCookies(); for (NewCookie cookie : cookieList) { if (cookie.getName().equalsIgnoreCase(rangerCookieName)) { sessionId = cookie.toCookie(); isValidRangerCookie = true; LOG.info("valid cookie saved "); break; } } } if (clientResp.getStatus() != HttpServletResponse.SC_OK && clientResp.getStatus() != HttpServletResponse.SC_NO_CONTENT && clientResp.getStatus() != HttpServletResponse.SC_BAD_REQUEST) { sessionId = null; isValidRangerCookie = false; } clientResp.bufferEntity(); response = clientResp.getEntity(String.class); } if (LOG.isDebugEnabled()) { LOG.debug("<== LdapPolicyMgrUserGroupBuilder.tryUploadEntityInfoWithCred()"); } return response; }
Example 6
Source File: LdapPolicyMgrUserGroupBuilder.java From ranger with Apache License 2.0 | 4 votes |
private String tryGetEntityWithCred(String apiURL, int retrievedCount) { if(LOG.isDebugEnabled()){ LOG.debug("==> LdapPolicyMgrUserGroupBuilder.tryGetEntityWithCred()"); } String response = null; ClientResponse clientResp = null; Map<String, String> queryParams = new HashMap<String, String>(); queryParams.put("pageSize", recordsToPullPerCall); queryParams.put("startIndex", String.valueOf(retrievedCount)); try{ clientResp = ldapUgSyncClient.get(apiURL, queryParams); } catch(Throwable t){ LOG.error("Failed to get response, Error is : ", t); } if (clientResp != null) { if (!(clientResp.toString().contains(apiURL))) { clientResp.setStatus(HttpServletResponse.SC_NOT_FOUND); } else if (clientResp.getStatus() == HttpServletResponse.SC_UNAUTHORIZED) { LOG.warn("Credentials response from ranger is 401."); } else if (clientResp.getStatus() == HttpServletResponse.SC_OK || clientResp.getStatus() == HttpServletResponse.SC_NO_CONTENT) { cookieList = clientResp.getCookies(); for (NewCookie cookie : cookieList) { if (cookie.getName().equalsIgnoreCase(rangerCookieName)) { sessionId = cookie.toCookie(); isValidRangerCookie = true; LOG.info("valid cookie saved "); break; } } } if (clientResp.getStatus() != HttpServletResponse.SC_OK && clientResp.getStatus() != HttpServletResponse.SC_NO_CONTENT && clientResp.getStatus() != HttpServletResponse.SC_BAD_REQUEST) { sessionId = null; isValidRangerCookie = false; } clientResp.bufferEntity(); response = clientResp.getEntity(String.class); } if (LOG.isDebugEnabled()) { LOG.debug("<== LdapPolicyMgrUserGroupBuilder.tryGetEntityWithCred()"); } return response; }
Example 7
Source File: LdapPolicyMgrUserGroupBuilder.java From ranger with Apache License 2.0 | 4 votes |
private String tryGetEntityWithCookie(String apiURL, int retrievedCount) { if (LOG.isDebugEnabled()) { LOG.debug("==> LdapPolicyMgrUserGroupBuilder.tryGetEntityWithCookie()"); } String response = null; ClientResponse clientResp = null; Map<String, String> queryParams = new HashMap<String, String>(); queryParams.put("pageSize", recordsToPullPerCall); queryParams.put("startIndex", String.valueOf(retrievedCount)); try { clientResp = ldapUgSyncClient.get(apiURL, queryParams, sessionId); } catch(Throwable t){ LOG.error("Failed to get response, Error is : ", t); } if (clientResp != null) { if (!(clientResp.toString().contains(apiURL))) { clientResp.setStatus(HttpServletResponse.SC_NOT_FOUND); sessionId = null; isValidRangerCookie = false; } else if (clientResp.getStatus() == HttpServletResponse.SC_UNAUTHORIZED) { sessionId = null; isValidRangerCookie = false; } else if (clientResp.getStatus() == HttpServletResponse.SC_NO_CONTENT || clientResp.getStatus() == HttpServletResponse.SC_OK) { List<NewCookie> respCookieList = clientResp.getCookies(); for (NewCookie cookie : respCookieList) { if (cookie.getName().equalsIgnoreCase(rangerCookieName)) { if (!(sessionId.getValue().equalsIgnoreCase(cookie.toCookie().getValue()))) { sessionId = cookie.toCookie(); } isValidRangerCookie = true; break; } } } if (clientResp.getStatus() != HttpServletResponse.SC_OK && clientResp.getStatus() != HttpServletResponse.SC_NO_CONTENT && clientResp.getStatus() != HttpServletResponse.SC_BAD_REQUEST) { sessionId = null; isValidRangerCookie = false; } clientResp.bufferEntity(); response = clientResp.getEntity(String.class); } if (LOG.isDebugEnabled()) { LOG.debug("<== LdapPolicyMgrUserGroupBuilder.tryGetEntityWithCookie()"); } return response; }
Example 8
Source File: PolicyMgrUserGroupBuilder.java From ranger with Apache License 2.0 | 4 votes |
private String tryUploadEntityWithCookie(Object obj, String apiURL) { if (LOG.isDebugEnabled()) { LOG.debug("==> PolicyMgrUserGroupBuilder.tryUploadEntityWithCookie()"); } String response = null; ClientResponse clientResp = null; try{ clientResp = uGSyncClient.post(apiURL, null, obj, sessionId); } catch(Throwable t){ LOG.error("Failed to get response, Error is : ", t); } if (clientResp != null) { if (!(clientResp.toString().contains(apiURL))) { clientResp.setStatus(HttpServletResponse.SC_NOT_FOUND); sessionId = null; isValidRangerCookie = false; } else if (clientResp.getStatus() == HttpServletResponse.SC_UNAUTHORIZED) { sessionId = null; isValidRangerCookie = false; } else if (clientResp.getStatus() == HttpServletResponse.SC_NO_CONTENT || clientResp.getStatus() == HttpServletResponse.SC_OK) { List<NewCookie> respCookieList = clientResp.getCookies(); for (NewCookie cookie : respCookieList) { if (cookie.getName().equalsIgnoreCase(RANGER_ADMIN_COOKIE_NAME)) { if (!(sessionId.getValue().equalsIgnoreCase(cookie.toCookie().getValue()))) { sessionId = cookie.toCookie(); } isValidRangerCookie = true; break; } } } if (clientResp.getStatus() != HttpServletResponse.SC_OK && clientResp.getStatus() != HttpServletResponse.SC_NO_CONTENT && clientResp.getStatus() != HttpServletResponse.SC_BAD_REQUEST) { sessionId = null; isValidRangerCookie = false; } clientResp.bufferEntity(); response = clientResp.getEntity(String.class); } if (LOG.isDebugEnabled()) { LOG.debug("<== PolicyMgrUserGroupBuilder.tryUploadEntityWithCookie()"); } return response; }
Example 9
Source File: PolicyMgrUserGroupBuilder.java From ranger with Apache License 2.0 | 4 votes |
private String tryUploadEntityWithCred(Object obj,String apiURL){ if(LOG.isDebugEnabled()){ LOG.debug("==> PolicyMgrUserGroupBuilder.tryUploadEntityInfoWithCred()"); } String response = null; ClientResponse clientResp = null; Gson gson = new GsonBuilder().create(); String jsonString = gson.toJson(obj); if ( LOG.isDebugEnabled() ) { LOG.debug("USER GROUP MAPPING" + jsonString); } try{ clientResp = uGSyncClient.post(apiURL, null, obj); } catch(Throwable t){ LOG.error("Failed to get response, Error is : ", t); } if (clientResp != null) { if (!(clientResp.toString().contains(apiURL))) { clientResp.setStatus(HttpServletResponse.SC_NOT_FOUND); } else if (clientResp.getStatus() == HttpServletResponse.SC_UNAUTHORIZED) { LOG.warn("Credentials response from ranger is 401."); } else if (clientResp.getStatus() == HttpServletResponse.SC_OK || clientResp.getStatus() == HttpServletResponse.SC_NO_CONTENT) { cookieList = clientResp.getCookies(); for (NewCookie cookie : cookieList) { if (cookie.getName().equalsIgnoreCase(RANGER_ADMIN_COOKIE_NAME)) { sessionId = cookie.toCookie(); isValidRangerCookie = true; LOG.info("valid cookie saved "); break; } } } if (clientResp.getStatus() != HttpServletResponse.SC_OK && clientResp.getStatus() != HttpServletResponse.SC_NO_CONTENT && clientResp.getStatus() != HttpServletResponse.SC_BAD_REQUEST) { sessionId = null; isValidRangerCookie = false; } clientResp.bufferEntity(); response = clientResp.getEntity(String.class); } if (LOG.isDebugEnabled()) { LOG.debug("<== PolicyMgrUserGroupBuilder.tryUploadEntityInfoWithCred()"); } return response; }
Example 10
Source File: PolicyMgrUserGroupBuilder.java From ranger with Apache License 2.0 | 4 votes |
private String tryGetEntityWithCred(String apiURL, int retrievedCount) { if(LOG.isDebugEnabled()){ LOG.debug("==> PolicyMgrUserGroupBuilder.tryGetEntityWithCred()"); } String response = null; ClientResponse clientResp = null; Map<String, String> queryParams = new HashMap<String, String>(); queryParams.put("pageSize", recordsToPullPerCall); queryParams.put("startIndex", String.valueOf(retrievedCount)); try{ clientResp = uGSyncClient.get(apiURL, queryParams); } catch(Throwable t){ LOG.error("Failed to get response, Error is : ", t); } if (clientResp != null) { if (!(clientResp.toString().contains(apiURL))) { clientResp.setStatus(HttpServletResponse.SC_NOT_FOUND); } else if (clientResp.getStatus() == HttpServletResponse.SC_UNAUTHORIZED) { LOG.warn("Credentials response from ranger is 401."); } else if (clientResp.getStatus() == HttpServletResponse.SC_OK || clientResp.getStatus() == HttpServletResponse.SC_NO_CONTENT) { cookieList = clientResp.getCookies(); for (NewCookie cookie : cookieList) { if (cookie.getName().equalsIgnoreCase(RANGER_ADMIN_COOKIE_NAME)) { sessionId = cookie.toCookie(); isValidRangerCookie = true; LOG.info("valid cookie saved "); break; } } } if (clientResp.getStatus() != HttpServletResponse.SC_OK && clientResp.getStatus() != HttpServletResponse.SC_NO_CONTENT && clientResp.getStatus() != HttpServletResponse.SC_BAD_REQUEST) { sessionId = null; isValidRangerCookie = false; } clientResp.bufferEntity(); response = clientResp.getEntity(String.class); } if (LOG.isDebugEnabled()) { LOG.debug("<== PolicyMgrUserGroupBuilder.tryGetEntityWithCred()"); } return response; }
Example 11
Source File: PolicyMgrUserGroupBuilder.java From ranger with Apache License 2.0 | 4 votes |
private String tryGetEntityWithCookie(String apiURL, int retrievedCount) { if (LOG.isDebugEnabled()) { LOG.debug("==> PolicyMgrUserGroupBuilder.tryGetEntityWithCookie()"); } String response = null; ClientResponse clientResp = null; Map<String, String> queryParams = new HashMap<String, String>(); queryParams.put("pageSize", recordsToPullPerCall); queryParams.put("startIndex", String.valueOf(retrievedCount)); try{ clientResp = uGSyncClient.get(apiURL, queryParams, sessionId); } catch(Throwable t){ LOG.error("Failed to get response, Error is : ", t); } if (clientResp != null) { if (!(clientResp.toString().contains(apiURL))) { clientResp.setStatus(HttpServletResponse.SC_NOT_FOUND); sessionId = null; isValidRangerCookie = false; } else if (clientResp.getStatus() == HttpServletResponse.SC_UNAUTHORIZED) { sessionId = null; isValidRangerCookie = false; } else if (clientResp.getStatus() == HttpServletResponse.SC_NO_CONTENT || clientResp.getStatus() == HttpServletResponse.SC_OK) { List<NewCookie> respCookieList = clientResp.getCookies(); for (NewCookie cookie : respCookieList) { if (cookie.getName().equalsIgnoreCase(RANGER_ADMIN_COOKIE_NAME)) { if (!(sessionId.getValue().equalsIgnoreCase(cookie.toCookie().getValue()))) { sessionId = cookie.toCookie(); } isValidRangerCookie = true; break; } } } if (clientResp.getStatus() != HttpServletResponse.SC_OK && clientResp.getStatus() != HttpServletResponse.SC_NO_CONTENT && clientResp.getStatus() != HttpServletResponse.SC_BAD_REQUEST) { sessionId = null; isValidRangerCookie = false; } clientResp.bufferEntity(); response = clientResp.getEntity(String.class); } if (LOG.isDebugEnabled()) { LOG.debug("<== PolicyMgrUserGroupBuilder.tryGetEntityWithCookie()"); } return response; }