List of usage examples for org.apache.http.client HttpResponseException getStatusCode
public int getStatusCode()
From source file:com.puppetlabs.geppetto.forge.v2.service.ModuleService.java
/** * @param owner/*from w ww . j a v a 2 s . c o m*/ * The module owner. * @param name * The name of the module. * @param listPreferences * Pagination preferences or <code>null</code> to get all in no particular order. * @return All releases of the module identified by <code>owner</code> and <code>name</code>. * @throws IOException */ public List<Release> getReleases(String owner, String name, ListPreferences listPreferences) throws IOException { List<Release> releases = null; try { releases = getClient(false).get(getModulePath(owner, 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.ModuleService.java
/** * Returns a list of a list of matching modules. Any module with a name that contains <code>keyword</code> is * considered a match. The <code>keyword</code> can be null in which case a list of all modules * will be returned./*from www.j a va 2 s . com*/ * * @param keyword * A keyword to used for matching or <code>null</code> to get all modules. * @param listPreferences * Pagination preferences or <code>null</code> to get all in no particular order. * @return A list of matching modules. * @throws IOException */ public List<Module> search(String keyword, ListPreferences listPreferences) throws IOException { Map<String, String> map = toQueryMap(listPreferences); if (keyword != null) map.put("keyword", keyword); List<Module> modules = null; try { modules = getClient(false).get(Constants.COMMAND_GROUP_MODULES, map, 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.uber.jenkins.phabricator.uberalls.UberallsClient.java
public String getCoverage(String sha) { URIBuilder builder;/* w w w . ja v a 2 s. c o m*/ try { builder = getBuilder().setParameter("sha", sha).setParameter("repository", repository); HttpClient client = getClient(); HttpMethod request = new GetMethod(builder.build().toString()); int statusCode = client.executeMethod(request); if (statusCode != HttpStatus.SC_OK) { logger.info(TAG, "Call failed: " + request.getStatusLine()); return null; } return request.getResponseBodyAsString(); } catch (HttpResponseException e) { if (e.getStatusCode() != 404) { e.printStackTrace(logger.getStream()); } } catch (Exception e) { e.printStackTrace(logger.getStream()); } return null; }
From source file:aiai.ai.station.actors.DownloadSnippetActor.java
private void logError(String snippetCode, HttpResponseException e) { if (e.getStatusCode() == HttpServletResponse.SC_GONE) { log.warn("Snippet with code {} wasn't found", snippetCode); } else if (e.getStatusCode() == HttpServletResponse.SC_CONFLICT) { log.warn("Snippet with id {} is broken and need to be recreated", snippetCode); } else {/*from w w w . java2 s. c o m*/ log.error("HttpResponseException", e); } }
From source file:com.github.horrorho.liquiddonkey.cloud.Authenticator.java
@GuardedBy("lock") void authenticate(HttpClient client) throws IOException { if (id == null || id.isEmpty() || password == null || password.isEmpty()) { invalid = "Unable to re-authenticate expired token: missing appleId/ password."; } else {//from w w w . j a v a 2 s . c om try { Auth auth = Auth.from(client, id, password); if (auth.dsPrsID().equals(token.auth().dsPrsID())) { token = Token.from(auth); } else { logger.error("-- reauthentication() > mismatched dsPrsID: {} > {}", token.auth().dsPrsID(), auth.dsPrsID()); invalid = "Unable to re-authenticate expired token: account mismatch."; } } catch (HttpResponseException ex) { if (ex.getStatusCode() == 401) { invalid = "Unable to re-authenticate expired token: invalid appleId/ password."; } } } testIsInvalid(); }
From source file:com.tapchatapp.android.app.ui.TapchatServiceStatusBar.java
@Subscribe public void onServiceError(ServiceErrorEvent event) { final Exception error = event.getError(); if (error instanceof HttpResponseException) { HttpResponseException httpError = (HttpResponseException) error; if (httpError.getStatusCode() == 403) { mService.logout();//from ww w. j av a 2s.com Toast.makeText(mActivity, R.string.unauthorized, Toast.LENGTH_LONG).show(); mActivity.startActivity(new Intent(mActivity, WelcomeActivity.class)); mActivity.finish(); return; } } new AlertDialog.Builder(mActivity).setTitle(R.string.error).setMessage(error.toString()) .setPositiveButton(android.R.string.ok, null).show(); }
From source file:com.mlohr.hvvgti.ApiClient.java
private BaseResponse executeApiRequest(BaseRequest apiRequest) throws ApiException { HttpPost httpRequest = new HttpPost(getBaseUri() + apiRequest.getUriPart()); httpRequest.setHeader(new BasicHeader("Content-Type", "application/json")); httpRequest.setHeader(new BasicHeader("Accept", "application/json")); // TODO configure user agent httpRequest.setHeader(new BasicHeader("geofox-auth-type", getSignatureAlgorithm().getAlgorithmString())); httpRequest.setHeader(new BasicHeader("geofox-auth-user", authUser)); httpRequest.setHeader(new BasicHeader("geofox-auth-signature", generateSignature(apiRequest.getBody()))); httpRequest.setEntity(new ByteArrayEntity(apiRequest.getBody().toString().getBytes())); try {//from www.ja v a 2 s . c om HttpResponse httpResponse = httpClient.execute(httpRequest); BasicResponseHandler responseHandler = new BasicResponseHandler(); String responseBody = responseHandler.handleResponse(httpResponse); return new BaseResponse(responseBody); } catch (HttpResponseException e) { throw new ApiException("Error sending HTTP request", e.getStatusCode(), e); } catch (ClientProtocolException e) { throw new ApiException("Error sending HTTP request", e); } catch (JSONException e) { throw new ApiException("Error parsing JSON response", e); } catch (IOException e) { throw new ApiException(e); } }
From source file:org.opentestsystem.shared.permissions.rest.APIHandler.java
@SuppressWarnings("rawtypes") @ExceptionHandler(HttpResponseException.class) @ResponseBody/*w ww . ja v a 2s. c o m*/ public ReturnStatus handleException(HttpResponseException e, HttpServletResponse response) { response.setStatus(e.getStatusCode()); return new ReturnStatus(StatusEnum.FAILURE, e.getMessage()); }
From source file:com.github.horrorho.liquiddonkey.cloud.engine.Donkey.java
Map<ICloud.MBSFile, Outcome> process(ChunkServer.StorageHostChunkList chunkList) throws InterruptedException, IOException { logger.trace("<< process() < chunk list: {}", chunkList.getHostInfo().getUri()); request.set(chunksClient.get(chunkList)); int count = 0; while (true) { Map<ByteString, DataWriter> writers; if (request.get() == null || Thread.currentThread().isInterrupted()) { throw new InterruptedException("Interrupted"); }/*w w w . j a v a 2s . c o m*/ try { byte[] data = agent .execute(client -> client.execute(request.get(), chunksClient.responseHandler())); writers = storeManager.put(chunkList.getChunkInfoList(), data); } catch (HttpResponseException ex) { if (ex.getStatusCode() == 401) { fail(ex, chunkList); throw ex; } if (++count >= retryCount) { // TODO consider aggression option return fail(ex, chunkList); } logger.warn("-- process() > count: {} exception: {}", count, ex); continue; } catch (BadDataException ex) { if (++count >= retryCount) { return fail(ex, chunkList); } logger.warn("-- process() > count: {} exception: {}", count, ex); continue; } Map<ICloud.MBSFile, Outcome> outcomes; outcomes = write(chunkList, writers); logger.trace(">> process() > outcomes: {}", outcomes.size()); return outcomes; } }
From source file:com.github.rnewson.couchdb.lucene.couchdb.Database.java
public UUID getUuid() throws IOException, JSONException { try {//from www .ja v a 2s. c om final CouchDocument local = getDocument("_local/lucene"); return UUID.fromString(local.asJson().getString("uuid")); } catch (final HttpResponseException e) { switch (e.getStatusCode()) { case HttpStatus.SC_NOT_FOUND: return null; default: throw e; } } }