Java Code Examples for com.sun.jersey.api.client.Client#destroy()
The following examples show how to use
com.sun.jersey.api.client.Client#destroy() .
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: SqoopClient.java From ranger with Apache License 2.0 | 5 votes |
private static ClientResponse getClientResponse(String sqoopUrl, String sqoopApi, String userName) { ClientResponse response = null; String[] sqoopUrls = sqoopUrl.trim().split("[,;]"); if (ArrayUtils.isEmpty(sqoopUrls)) { return null; } Client client = Client.create(); for (String currentUrl : sqoopUrls) { if (StringUtils.isBlank(currentUrl)) { continue; } String url = currentUrl.trim() + sqoopApi + "?" + PseudoAuthenticator.USER_NAME + "=" + userName; try { response = getClientResponse(url, client); if (response != null) { if (response.getStatus() == HttpStatus.SC_OK) { break; } else { response.close(); } } } catch (Throwable t) { String msgDesc = "Exception while getting sqoop response, sqoopUrl: " + url; LOG.error(msgDesc, t); } } client.destroy(); return response; }
Example 2
Source File: ElasticsearchClient.java From ranger with Apache License 2.0 | 5 votes |
private static ClientResponse getClientResponse(String elasticsearchUrl, String elasticsearchApi, String userName) { String[] elasticsearchUrls = elasticsearchUrl.trim().split("[,;]"); if (ArrayUtils.isEmpty(elasticsearchUrls)) { return null; } ClientResponse response = null; Client client = Client.create(); for (String currentUrl : elasticsearchUrls) { if (StringUtils.isBlank(currentUrl)) { continue; } String url = currentUrl.trim() + elasticsearchApi; try { response = getClientResponse(url, client, userName); if (response != null) { if (response.getStatus() == HttpStatus.SC_OK) { break; } else { response.close(); } } } catch (Throwable t) { String msgDesc = "Exception while getting elasticsearch response, elasticsearchUrl: " + url; LOG.error(msgDesc, t); } } client.destroy(); return response; }
Example 3
Source File: KylinClient.java From ranger with Apache License 2.0 | 5 votes |
private static ClientResponse getClientResponse(String kylinUrl, String userName, String password) { ClientResponse response = null; String[] kylinUrls = kylinUrl.trim().split("[,;]"); if (ArrayUtils.isEmpty(kylinUrls)) { return null; } Client client = Client.create(); String decryptedPwd = PasswordUtils.getDecryptPassword(password); client.addFilter(new HTTPBasicAuthFilter(userName, decryptedPwd)); for (String currentUrl : kylinUrls) { if (StringUtils.isBlank(currentUrl)) { continue; } String url = currentUrl.trim() + KYLIN_LIST_API_ENDPOINT; try { response = getProjectResponse(url, client); if (response != null) { if (response.getStatus() == HttpStatus.SC_OK) { break; } else { response.close(); } } } catch (Throwable t) { String msgDesc = "Exception while getting kylin response, kylinUrl: " + url; LOG.error(msgDesc, t); } } client.destroy(); return response; }
Example 4
Source File: TeamctiyRest.java From TeamcityTriggerHook with GNU Lesser General Public License v3.0 | 5 votes |
/** * Trigger a build on the Teamcity instance using vcs root * * @param repository - {@link Repository} * @param url - url to TeamCity server * @param username - TeamCity user name * @param password - TeamCity user password * @return "OK" if it worked. Otherwise, an error message. */ @GET @Path(value = "testconnection") @Produces("text/plain; charset=UTF-8") public Response testconnection( @Context final Repository repository, @QueryParam("url") final String url, @QueryParam("username") final String username, @QueryParam("password") final String password, @QueryParam("debugon") final String isDebugOn) { String realPasswordValue = password; if (Constant.TEAMCITY_PASSWORD_SAVED_VALUE.equals(realPasswordValue)) { realPasswordValue = this.connectionSettings.getPassword(repository); } final Client restClient = Client.create(Constant.REST_CLIENT_CONFIG); restClient.addFilter(new HTTPBasicAuthFilter(username, realPasswordValue)); try { final ClientResponse response = restClient.resource(url + "/app/rest/builds?locator=lookupLimit:0").accept(MediaType.APPLICATION_XML).get(ClientResponse.class); if (ClientResponse.Status.OK == response.getClientResponseStatus()) { this.connectionSettings.savePassword(realPasswordValue, repository); return Response.ok(Constant.TEAMCITY_PASSWORD_SAVED_VALUE).build(); } else { return Response.status(response.getClientResponseStatus()).entity(response.getEntity(String.class)).build(); } } catch (final UniformInterfaceException | ClientHandlerException e) { return Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build(); } finally { restClient.destroy(); } }
Example 5
Source File: OccurrenceWsClientIT.java From occurrence with Apache License 2.0 | 5 votes |
/** * The Annosys methods are implemented specifically to support Annosys and are not advertised or * documented in the public API. <em>They may be removed at any time without notice</em>. */ @Test public void testAnnosysXml() { Client client = Client.create(); WebResource webResource = client.resource(wsBaseUrl).path(OccurrencePaths.OCCURRENCE_PATH) .path(OccurrenceResource.ANNOSYS_PATH).path("10"); ClientResponse response = webResource.get(ClientResponse.class); assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); assertEquals(MediaType.APPLICATION_XML_TYPE, response.getType()); assertTrue(response.getLength() > 0); client.destroy(); }
Example 6
Source File: OccurrenceWsClientIT.java From occurrence with Apache License 2.0 | 5 votes |
/** * The Annosys methods are implemented specifically to support Annosys and are not advertised or * documented in the public API. <em>They may be removed at any time without notice</em>. */ @Test public void testAnnosysVerbatimXml() { Client client = Client.create(); WebResource webResource = client.resource(wsBaseUrl).path(OccurrencePaths.OCCURRENCE_PATH) .path(OccurrenceResource.ANNOSYS_PATH).path("10").path(OccurrencePaths.VERBATIM_PATH); ClientResponse response = webResource.get(ClientResponse.class); assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); assertEquals(MediaType.APPLICATION_XML_TYPE, response.getType()); assertTrue(response.getLength() > 0); client.destroy(); }