List of usage examples for org.apache.http.client HttpResponseException getStatusCode
public int getStatusCode()
From source file:com.puppetlabs.geppetto.forge.v2.service.TagService.java
/** * Returns a list of all known Tags./*from w w w . j a v a 2s . co m*/ * * @param listPreferences * Pagination preferences or <code>null</code> to get all in no particular order. * @return A list of all Tags. * @throws IOException */ public List<Tag> getAll(ListPreferences listPreferences) throws IOException { List<Tag> tags = null; try { tags = getClient(false).get(Constants.COMMAND_GROUP_TAGS, toQueryMap(listPreferences), Constants.LIST_TAG); } catch (HttpResponseException e) { if (e.getStatusCode() != HttpStatus.SC_NOT_FOUND) throw e; } if (tags == null) tags = Collections.emptyList(); return tags; }
From source file:com.puppetlabs.geppetto.forge.v2.service.TagService.java
/** * @param name/*from w w w . j a v a 2 s.co m*/ * The name of the Tag. * @param listPreferences * @return Modules for a particular tag * @throws IOException */ public List<Module> getModules(String name, ListPreferences listPreferences) throws IOException { List<Module> modules = null; try { modules = getClient(false).get(getTagPath(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:ch.cyberduck.core.dav.DAVExceptionMappingService.java
@Override public BackgroundException map(final HttpResponseException failure) { final StringBuilder buffer = new StringBuilder(); final int statusCode = failure.getStatusCode(); if (statusCode == HttpStatus.SC_OK || statusCode == HttpStatus.SC_MULTI_STATUS) { // HTTP method status this.append(buffer, failure.getMessage()); // Failure unmarshalling XML response return new InteroperabilityException(buffer.toString(), failure); }// www .j av a 2s . c om return super.map(failure); }
From source file:com.github.horrorho.liquiddonkey.cloud.HttpAgent.java
public <T> T execute(IOBiFunction<HttpClient, String, T> function) throws IOException { return execute(c -> { while (true) { Authenticator.Token token = authenticator.get(); try { return function.apply(c, token.auth().mmeAuthToken()); } catch (HttpResponseException ex) { if (ex.getStatusCode() == 401) { logger.warn("-- execute() > exception: ", ex); execute(cc -> authenticator.reauthenticate(cc, token)); } else { throw ex; }//from w w w . j ava2 s . c o m } } }); }
From source file:com.puppetlabs.geppetto.forge.v2.service.ReleaseService.java
/** * Returns a list of all known releases. * // w w w.ja v a 2 s. c om * @param listPreferences * Pagination preferences or <code>null</code> to get all in no particular order. * @return A list of all Releases. * @throws IOException */ public List<Release> list(ListPreferences listPreferences) throws IOException { List<Release> releases = null; try { releases = getClient(false).get(Constants.COMMAND_GROUP_RELEASES, null, 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:me.vertretungsplan.parser.IndiwareStundenplan24Parser.java
@Override public SubstitutionSchedule getSubstitutionSchedule() throws IOException, JSONException, CredentialInvalidException { String baseurl;// w w w . j a va 2 s . co m if (data.has("schoolNumber")) { baseurl = "http://www.stundenplan24.de/" + data.getString("schoolNumber") + "/vplan/"; if (credential == null || !(credential instanceof UserPasswordCredential)) { throw new IOException("no login"); } String login = ((UserPasswordCredential) credential).getUsername(); String password = ((UserPasswordCredential) credential).getPassword(); executor.auth(login, password); } else { baseurl = data.getString("baseurl") + "/"; new LoginHandler(scheduleData, credential, cookieProvider).handleLogin(executor, cookieStore); } List<Document> docs = new ArrayList<>(); for (int i = 0; i < MAX_DAYS; i++) { LocalDate date = LocalDate.now().plusDays(i); String dateStr = DateTimeFormat.forPattern("yyyyMMdd").print(date); String url = baseurl + "vdaten/VplanKl" + dateStr + ".xml?_=" + System.currentTimeMillis(); try { String xml = httpGet(url, ENCODING); Document doc = Jsoup.parse(xml, url, Parser.xmlParser()); if (doc.select("kopf datei").text().equals("VplanKl" + dateStr + ".xml")) { docs.add(doc); } } catch (HttpResponseException e) { if (e.getStatusCode() != 404 && e.getStatusCode() != 300) throw e; } } SubstitutionSchedule v = SubstitutionSchedule.fromData(scheduleData); for (Document doc : docs) { v.addDay(parseIndiwareDay(doc, false)); } v.setWebsite(baseurl); v.setClasses(getAllClasses()); v.setTeachers(getAllTeachers()); return v; }
From source file:de.mpg.imeji.presentation.servlet.ExportServlet.java
/** * {@inheritDoc}//from ww w. ja v a 2s . c o m */ @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { SessionBean session = getSessionBean(req, resp); String instanceName = session.getInstanceName(); User user = session.getUser(); try { ExportManager exportManager = new ExportManager(resp.getOutputStream(), user, req.getParameterMap()); String exportName = instanceName + "_"; exportName += new Date().toString().replace(" ", "_").replace(":", "-"); if (exportManager.getContentType().equalsIgnoreCase("application/xml")) { exportName += ".xml"; } if (exportManager.getContentType().equalsIgnoreCase("application/zip")) { exportName += ".zip"; } resp.setHeader("Connection", "close"); resp.setHeader("Content-Type", exportManager.getContentType()); resp.setHeader("Content-disposition", "filename=" + exportName); resp.setStatus(HttpServletResponse.SC_OK); SearchResult result = exportManager.search(); exportManager.export(result); resp.getOutputStream().flush(); } catch (HttpResponseException he) { resp.sendError(he.getStatusCode(), he.getMessage()); } catch (Exception e) { resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage()); } }
From source file:aiai.ai.station.actors.DownloadResourceActor.java
public void fixedDelay() { if (globals.isUnitTesting) { return;/* w w w . j a v a 2s . c o m*/ } if (!globals.isStationEnabled) { return; } DownloadResourceTask task; while ((task = poll()) != null) { // if (Boolean.TRUE.equals(preparedMap.get(task.getId()))) { // continue; // } AssetFile assetFile = StationResourceUtils.prepareResourceFile(task.targetDir, task.binaryDataType, task.id, null); if (assetFile.isError) { log.warn("Resource can't be downloaded. Asset file initialization was failed, {}", assetFile); continue; } if (assetFile.isContent) { log.info("Resource was already downloaded. Asset file: {}", assetFile.file.getPath()); // preparedMap.put(task.getId(), true); continue; } try { Request request = Request.Get(targetUrl + '/' + task.getBinaryDataType() + '/' + task.getId()) .connectTimeout(5000).socketTimeout(5000); Response response; if (globals.isSecureRestUrl) { response = executor.executor.execute(request); } else { response = request.execute(); } response.saveContent(assetFile.file); // preparedMap.put(task.getId(), true); log.info("Resource #{} was loaded", task.getId()); } catch (HttpResponseException e) { if (e.getStatusCode() == HttpServletResponse.SC_GONE) { log.warn("Resource with id {} wasn't found", task.getId()); } else if (e.getStatusCode() == HttpServletResponse.SC_CONFLICT) { log.warn("Resource with id {} is broken and need to be recreated", task.getId()); } else { log.error("HttpResponseException.getStatusCode(): {}", e.getStatusCode()); log.error("HttpResponseException", e); } } catch (SocketTimeoutException e) { log.error("SocketTimeoutException", e); } catch (IOException e) { log.error("IOException", e); } } }
From source file:au.csiro.casda.sodalint.ValidateAsync.java
private String getAsyncContent(final Reporter reporter, URL address) { try {// w ww . ja va 2 s. co m String content = getXmlContentFromUrl(address.toString()); if (content == null) { reporter.report(SodaCode.E_ASCO, "Async response contains no content"); } return content; } catch (HttpResponseException e) { reporter.report(SodaCode.E_ASCO, "Unexpected http response: " + e.getStatusCode() + " Reason: " + e.getMessage()); } catch (UnsupportedEncodingException e) { reporter.report(SodaCode.E_ASCO, "Async response has an unexpected content type:" + e.getMessage()); } catch (IOException e) { reporter.report(SodaCode.E_ASCO, "Unable to read async response: " + e.getMessage()); } return null; }
From source file:com.puppetlabs.geppetto.forge.v2.service.ModuleService.java
/** * @param owner/* w w w . ja v a 2s . 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 The tags attached to the module identified by <code>owner</code> and <code>name</code>. * @throws IOException */ public List<Tag> getTags(String owner, String name, ListPreferences listPreferences) throws IOException { List<Tag> tags = null; try { tags = getClient(false).get(getModulePath(owner, name) + "/tags", toQueryMap(listPreferences), Constants.LIST_TAG); } catch (HttpResponseException e) { if (e.getStatusCode() != HttpStatus.SC_NOT_FOUND) throw e; } if (tags == null) tags = Collections.emptyList(); return tags; }