List of usage examples for org.apache.http.client HttpResponseException getStatusCode
public int getStatusCode()
From source file:com.puppetlabs.geppetto.forge.v1.impl.DefaultModuleService.java
@Override public List<ModuleInfo> search(String keyword) throws IOException { List<ModuleInfo> modules = null; try {//from w w w .ja va 2s .c o m modules = forgeClient.getV1(Constants.COMMAND_GROUP_MODULES, keyword == null ? null : Collections.singletonMap("q", keyword), LIST_MODULE_INFO); } catch (HttpResponseException e) { if (e.getStatusCode() != HttpStatus.SC_NOT_FOUND) throw e; } if (modules == null) modules = Collections.emptyList(); return modules; }
From source file:com.puppetlabs.geppetto.forge.v1.service.ModuleService.java
/** * @param keyword/*from www . ja v a2 s.com*/ * KeyWord to use in the search. May be <code>null</code> to get all modules. * @return All Modules that matches the given keyword * @throws IOException */ public List<ModuleInfo> search(String keyword) throws IOException { List<ModuleInfo> modules = null; try { modules = forgeClient.getV1(Constants.COMMAND_GROUP_MODULES, keyword == null ? null : Collections.singletonMap("q", keyword), Constants.LIST_MODULE_INFO); } catch (HttpResponseException e) { if (e.getStatusCode() != HttpStatus.SC_NOT_FOUND) throw e; } if (modules == null) modules = Collections.emptyList(); return modules; }
From source file:com.puppetlabs.geppetto.forge.api.it.ModuleTestDelete.java
@Test public void testDeleteModule() throws IOException { ModuleService service = getTestUserForge().createModuleService(); service.delete(TEST_USER, TEST_MODULE); try {// w w w. java 2 s . c om service.get(TEST_USER, TEST_MODULE); fail("Expected 404"); } catch (HttpResponseException e) { assertEquals("Wrong response code", 404, e.getStatusCode()); } }
From source file:com.puppetlabs.geppetto.forge.api.it.ReleaseTestDelete.java
@Test public void testDeleteRelease() throws IOException { ReleaseService service = getTestUserForge().createReleaseService(); service.delete(TEST_USER, TEST_MODULE, TEST_RELEASE_VERSION); try {// w w w . j a v a2s.c o m service.get(TEST_USER, TEST_MODULE, TEST_RELEASE_VERSION); fail("Expected 404"); } catch (HttpResponseException e) { assertEquals("Wrong response code", 404, e.getStatusCode()); } }
From source file:net.oneandone.shared.artifactory.SearchLatestVersion.java
/** * Searches for the latest version./* ww w. j a v a 2 s.co m*/ * * @param repositoryName to search in. * @param groupId of the artifact. * @param artifactId of the artifact. * @return the latest version of the artifact in repositoryName. * * @throws NotFoundException when no artifact was found. */ public String search(String repositoryName, String groupId, String artifactId) throws NotFoundException { final URI searchUri = buildSearchUri(repositoryName, groupId, artifactId); final HttpGet get = new HttpGet(searchUri); try { return client.execute(get, new BasicResponseHandler()); } catch (HttpResponseException e) { if (e.getStatusCode() == HttpStatus.SC_NOT_FOUND) { throw new NotFoundException(searchUri); } else { throw new RuntimeException("searchUri=" + searchUri.toString(), e); } } catch (IOException e) { throw new RuntimeException("searchUri=" + searchUri.toString(), e); } }
From source file:com.puppetlabs.geppetto.forge.v2.service.UserService.java
/** * @param name//from ww w . ja va 2s . c o m * The name of the user * @param listPreferences * Pagination preferences or <code>null</code> to get all in no particular order * @return Modules for a particular user * @throws IOException */ public List<Module> getModules(String name, ListPreferences listPreferences) throws IOException { List<Module> modules = null; try { modules = getClient(false).get(getUserPath(name) + "/modules", toQueryMap(listPreferences), Constants.LIST_MODULE); } catch (HttpResponseException e) { if (e.getStatusCode() != HttpStatus.SC_NOT_FOUND) throw e; } if (modules == null) modules = Collections.emptyList(); return modules; }
From source file:com.puppetlabs.geppetto.forge.v2.service.UserService.java
/** * @param name/*from w ww .ja v a 2 s. c om*/ * The name of the user * @param listPreferences * Pagination preferences or <code>null</code> to get all in no particular order * @return Releases for a particular user * @throws IOException */ public List<Release> getReleases(String name, ListPreferences listPreferences) throws IOException { List<Release> releases = null; try { releases = getClient(false).get(getUserPath(name) + "/releases", toQueryMap(listPreferences), Constants.LIST_RELEASE); } catch (HttpResponseException e) { if (e.getStatusCode() != HttpStatus.SC_NOT_FOUND) throw e; } if (releases == null) releases = Collections.emptyList(); return releases; }
From source file:com.puppetlabs.geppetto.forge.v2.service.UserService.java
/** * @param listPreferences/*from w w w.jav a 2 s. c om*/ * @return All users * @throws IOException */ public List<User> list(ListPreferences listPreferences) throws IOException { List<User> users = null; try { users = getClient(false).get(Constants.COMMAND_GROUP_USERS, toQueryMap(listPreferences), Constants.LIST_USER); } catch (HttpResponseException e) { if (e.getStatusCode() != HttpStatus.SC_NOT_FOUND) throw e; } if (users == null) users = Collections.emptyList(); return users; }
From source file:com.github.horrorho.liquiddonkey.cloud.client.AuthClient.java
/** * Queries the server and returns an Authenticate property list. * * @param client// ww w.j ava 2s .co m * @param id * @param password * @return Authenticate property list, not null * @throws BadDataException * @throws IOException */ public byte[] get(HttpClient client, String id, String password) throws IOException { logger.trace("<< get() < id: {} password: {}", id, password); try { String authBasic = headers.basicToken(id, password); logger.debug("-- get() > auth header: {}", authBasic); HttpGet get = new HttpGet("https://setup.icloud.com/setup/authenticate/$APPLE_ID$"); get.addHeader(headers.mmeClientInfo()); get.addHeader(headers.authorization(authBasic)); byte[] data = client.execute(get, byteArrayResponseHandler); logger.trace(">> get() > bytes: {}", data.length); return data; } catch (HttpResponseException ex) { if (ex.getStatusCode() == 401) { throw new HttpResponseException(401, "Bad appleId/ password or not an iCloud account"); } if (ex.getStatusCode() == 409) { throw new HttpResponseException(401, "Is two-step authentication enabled?"); } throw ex; } }
From source file:org.obm.locator.LocatorClientImpl.java
@Override public String getServiceLocation(String serviceSlashProperty, String loginAtDomain) throws LocatorClientException { try {/* w w w . j a v a2s. com*/ String responseBody = Request.Get(buildFullServiceUrl(serviceSlashProperty, loginAtDomain)) .connectTimeout(timeoutInMS).socketTimeout(timeoutInMS).execute().returnContent().asString(); return Iterables.get(Splitter.on(RESPONSE_SEPARATOR).split(responseBody), 0); } catch (HttpResponseException e) { if (e.getStatusCode() == HTTP_CODE_NOT_FOUND) { throw new ServiceNotFoundException( String.format("Service %s for %s not found", serviceSlashProperty, loginAtDomain)); } else { throw new LocatorClientException( String.format("HTTP error %d: %s", e.getStatusCode(), e.getMessage()), e); } } catch (MalformedURLException e) { throw new LocatorClientException(e.getMessage(), e); } catch (SocketTimeoutException e) { throw new LocatorClientException(e.getMessage(), e); } catch (IOException e) { throw new LocatorClientException(e.getMessage(), e); } }