Java Code Examples for com.sun.jersey.api.client.ClientResponse#bufferEntity()
The following examples show how to use
com.sun.jersey.api.client.ClientResponse#bufferEntity() .
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: 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 2
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 3
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 4
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 5
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 6
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 7
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 8
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; }