List of usage examples for java.lang Exception getLocalizedMessage
public String getLocalizedMessage()
From source file:org.eurekapp.pageturner.catalog.LoadOPDSTask.java
@Override public Option<Feed> doInBackground(String... params) { String baseUrl = params[0];/* w w w .ja va 2 s.c om*/ // if (baseUrl == null || baseUrl.trim().length() == 0) { // Feed feed = new Feed(); // addCustomSitesEntry(feed); // return some(feed); // } //todo de aca para abajo queda sin usar boolean isBaseFeed = baseUrl.equals(config.getBaseOPDSFeed()); baseUrl = baseUrl.trim(); try { HttpGet currentRequest = new HttpGet(baseUrl); currentRequest.setHeader("User-Agent", config.getUserAgent()); currentRequest.setHeader("Accept-Language", config.getLocale().getLanguage()); HttpResponse response = httpClient.execute(currentRequest); LOG.debug("Starting download of " + baseUrl); if (response.getStatusLine().getStatusCode() != 200) { this.errorMessage = "HTTP " + response.getStatusLine().getStatusCode() + ": " + response.getStatusLine().getReasonPhrase(); return none(); } InputStream stream = response.getEntity().getContent(); Feed feed = Nucular.readAtomFeedFromStream(stream); feed.setURL(baseUrl); feed.setDetailFeed(asDetailsFeed); feed.setSearchFeed(asSearchFeed); for (Entry entry : feed.getEntries()) { entry.setBaseURL(baseUrl); } if (isBaseFeed) { //addCustomSitesEntry(feed); } if (isCancelled()) { return none(); } Option<Link> searchLinkOption = feed.findByRel(AtomConstants.REL_SEARCH); if (!isEmpty(searchLinkOption)) { Link searchLink = searchLinkOption.unsafeGet(); URL mBaseUrl = new URL(baseUrl); URL mSearchUrl = new URL(mBaseUrl, searchLink.getHref()); searchLink.setHref(mSearchUrl.toString()); LOG.debug("Got searchLink of type " + searchLink.getType() + " with href=" + searchLink.getHref()); /* Some sites report the search as OpenSearch, but still have the searchTerms in the URL. If the URL already contains searchTerms, we ignore the reported type and treat it as Atom */ if (searchLink.getHref().contains(AtomConstants.SEARCH_TERMS)) { searchLink.setType(AtomConstants.TYPE_ATOM); } if (AtomConstants.TYPE_OPENSEARCH.equals(searchLink.getType())) { String searchURL = searchLink.getHref(); LOG.debug("Attempting to download OpenSearch description from " + searchURL); try { currentRequest = new HttpGet(searchURL); InputStream searchStream = httpClient.execute(currentRequest).getEntity().getContent(); SearchDescription desc = Nucular.readOpenSearchFromStream(searchStream); desc.getSearchLink().forEach(l -> searchLink.setHref(l.getHref())); searchLink.setType(AtomConstants.TYPE_ATOM); } catch (Exception searchIO) { LOG.error("Could not get search info", searchIO); } } LOG.debug("Using searchURL " + searchLink.getHref()); } return some(feed); } catch (Exception e) { this.errorMessage = e.getLocalizedMessage(); LOG.error("Download failed for url: " + baseUrl, e); return none(); } }
From source file:com.amalto.workbench.actions.XSDEditXPathAction.java
public IStatus doAction() { try {//from w ww. j a v a 2 s . c om IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection(); XSDXPathDefinition xpath = (XSDXPathDefinition) selection.getFirstElement(); icd = (XSDIdentityConstraintDefinition) xpath.getContainer(); // InputDialog id = new InputDialog( // page.getSite().getShell(), // "Edit XPath", // "Enter a new XPath for the "+((xpath.getVariety().equals(XSDXPathVariety.FIELD_LITERAL))?"field":"selector"), // xpath.getValue(), // new IInputValidator() { // public String isValid(String newText) { // if ((newText==null) || "".equals(newText)) return "The XPath cannot be empty"; // return null; // }; // } // ); // List<String> childNames = Util.getChildElementNames("", (XSDElementDeclaration) icd.getContainer()); List<String> childNames = new ArrayList<String>(); childNames.add("."); //$NON-NLS-1$ SelectFieldDialog id = new SelectFieldDialog(page.getSite().getShell(), Messages.XSDEditXPathAction_DialogTitle, childNames, xpath.getValue()); id.create(); id.setBlockOnOpen(true); int ret = id.open(); if (ret == Window.CANCEL) { return Status.CANCEL_STATUS; } String field = id.getField(); if (field.length() == 0) return Status.CANCEL_STATUS; XSDXPathDefinition newXpath = XSDSchemaBuildingTools.getXSDFactory().createXSDXPathDefinition(); newXpath.setValue(field); if (xpath.getVariety().equals(XSDXPathVariety.FIELD_LITERAL)) { int index = icd.getFields().indexOf(xpath); newXpath.setVariety(XSDXPathVariety.FIELD_LITERAL); icd.getFields().set(index, newXpath); } else { newXpath.setVariety(XSDXPathVariety.SELECTOR_LITERAL); icd.setSelector(newXpath); } icd.updateElement(); page.refresh(); page.getTreeViewer().setSelection(new StructuredSelection(newXpath), true); page.markDirty(); } catch (Exception e) { log.error(e.getMessage(), e); MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDEditXPathAction_ErrorMsg, e.getLocalizedMessage())); return Status.CANCEL_STATUS; } return Status.OK_STATUS; }
From source file:com.swordlord.jalapeno.DBConnection.java
public boolean persistObjectContext(ObjectContext oc) { try {//from w w w . j ava 2 s . c o m oc.commitChanges(); } catch (ValidationException vex) { String strMessage = ""; ValidationResult vr = vex.getValidationResult(); if (vr.hasFailures()) { List<ValidationFailure> failures = vr.getFailures(); if (failures.size() > 0) { Iterator<ValidationFailure> it = failures.iterator(); while (it.hasNext()) { Object info = it.next(); if (info != null) { LOG.info(info); } if (info instanceof BeanValidationFailure) { BeanValidationFailure bvf = (BeanValidationFailure) info; strMessage += "- " + bvf.getDescription() + ".\n\r"; System.out.println(bvf.getSource()); } } } } String strError = "Persist crashed: " + vex.getLocalizedMessage() + ": " + vex.getCause() + "\n\r" + strMessage; LOG.info(strError); // ErrorDialog.reportError("validation: " + strMessage); return false; } catch (DeleteDenyException dde) { String strError = "Persist crashed: " + dde.getLocalizedMessage() + ": " + dde.getCause(); LOG.info(strError); // ErrorDialog.reportError(dde.getCause().getMessage()); return false; } catch (FaultFailureException ffe) { String strError = "Persist crashed: " + ffe.getLocalizedMessage() + ": " + ffe.getCause(); LOG.info(strError); // ErrorDialog.reportError(ffe.getCause().getMessage()); return false; } catch (CayenneRuntimeException cex) { String strError = "Persist crashed: " + cex.getLocalizedMessage() + ": " + cex.getCause(); LOG.info(strError); // ErrorDialog.reportError(cex.getCause().getMessage()); return false; } catch (Exception e) { String strError = "Persist crashed: " + e.getLocalizedMessage() + ": " + e.getCause(); LOG.info(strError); // ErrorDialog.reportError(e.getCause().getMessage()); return false; } return true; }
From source file:com.tarsoft.openlibra.OpenLibraClient.java
public List<Book> getBooks(Criteria criteria) throws JSONException, MalformedURLException, IOException { this.criteria = criteria; HttpClient httpClient = new DefaultHttpClient(); String getURL = getURLOpenLibra(); Log.v(TAG, "URL: " + getURL); URI uri;//from w w w . j av a 2s .c o m String data = null; try { uri = new URI(getURL); HttpGet method = new HttpGet(uri); HttpResponse response = httpClient.execute(method); HttpEntity resEntity = response.getEntity(); //if exists, get it if (resEntity != null) { data = EntityUtils.toString(resEntity, HTTP.UTF_8); } } catch (Exception e) { e.printStackTrace(); Log.v(TAG, "Error: " + e.getMessage() + " - " + e.getLocalizedMessage()); } if (data != null) { //Delete initial "(" and final ");" data = data.substring(1, data.length() - 2); return parseData(data); } else { return null; } }
From source file:com.ewcms.plugin.crawler.generate.EwcmsContentCrawler.java
/** * ?page??//from w ww . j a v a2s. c o m */ @Override public void visit(Page page) { try { String url = page.getWebURL().getURL(); page.setContentType("text/html; charset=" + gather.getEncoding()); Document doc = Jsoup.connect(url).timeout(gather.getTimeOutWait().intValue() * 1000).get(); String title = doc.title(); if (gather.getTitleExternal() && gather.getTitleRegex() != null && gather.getTitleRegex().length() > 0) { Elements titleEles = doc.select(gather.getTitleRegex()); if (!titleEles.isEmpty()) { String tempTitle = titleEles.text(); if (tempTitle != null && tempTitle.length() > 0) { title = tempTitle; } } } if (title != null && title.trim().length() > 0) { Elements elements = doc.select(matchRegex); if (filterRegex != null && filterRegex.trim().length() > 0) { elements = elements.not(filterRegex); } if (!elements.isEmpty()) { String subHtml = elements.html(); Document blockDoc = Jsoup.parse(subHtml); String contentText = blockDoc.html(); if (gather.getRemoveHref()) { Document moveDoc = Jsoup.parse(contentText); Elements moveEles = moveDoc.select("*").not("a"); contentText = moveEles.html(); } if (gather.getRemoveHtmlTag()) contentText = doc.text(); if (isLocal) { contentText = doc.text(); Boolean isMatcher = true; for (int i = 0; i < keys.length; i++) { Boolean result = Pattern.compile(keys[i].trim()).matcher(contentText).find(); if (!result) { isMatcher = false; break; } } if (isMatcher) { Storage storage = new Storage(); storage.setGatherId(gather.getId()); storage.setGatherName(gather.getName()); storage.setTitle(title); storage.setUrl(url); try { gatherService.addStorage(storage); } catch (Exception e) { logger.error("save storage error : {}", e.getLocalizedMessage()); } finally { storage = null; } } } else { Content content = new Content(); content.setDetail(contentText); content.setPage(1); List<Content> contents = new ArrayList<Content>(); contents.add(content); Article article = new Article(); article.setTitle(title); article.setContents(contents); articleMainService.addArticleMainByCrawler(article, gather.getChannelId(), CrawlerUtil.USER_NAME); } } } } catch (IOException e) { logger.warn(e.getLocalizedMessage()); } }
From source file:com.amalto.workbench.actions.XSDDeleteAttributeAction.java
@Override protected IStatus doAction() { try {//w ww . ja va 2 s .c o m XSDAttributeUse attriUse = attributeUse; XSDAttributeDeclaration attriDec = attributeDeclaration; if (attriUse == null || attriDec == null) { ISelection selection = page.getTreeViewer().getSelection(); Object firstElement = ((IStructuredSelection) selection).getFirstElement(); if (firstElement instanceof XSDAttributeUse) { attriUse = (XSDAttributeUse) firstElement; } else if (firstElement instanceof XSDAttributeDeclaration) { attriDec = (XSDAttributeDeclaration) firstElement; } } if (attriUse != null) { if (attriUse.getContainer() == null) { return Status.CANCEL_STATUS; } XSDConcreteComponent container = attriUse.getContainer(); if (container instanceof XSDComplexTypeDefinition) { XSDComplexTypeDefinition cType = (XSDComplexTypeDefinition) container; cType.getAttributeUses().remove(attriUse); cType.getAttributeContents().remove(attriUse); cType.updateElement(); } } else if (attriDec != null) { if (attriDec.getContainer() == null) { return Status.CANCEL_STATUS; } XSDConcreteComponent container = attriDec.getContainer(); if (container instanceof XSDSchema) { XSDSchema xsdschema = (XSDSchema) container; xsdschema.getContents().remove(attriDec); } } schema.update(); attributeUse = null; attributeDeclaration = null; page.refresh(); page.markDirtyWithoutCommit(); } catch (Exception e) { log.error(e.getMessage(), e); MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDDeleteElementAction_ErrorMsg, e.getLocalizedMessage())); return Status.CANCEL_STATUS; } return Status.OK_STATUS; }
From source file:com.impetus.ankush.common.utils.AnkushRestClient.java
/** * Method sendNodeInfo./* www . j a va2 s .co m*/ * * @param urlPath * String * @param input * String * @return String * @throws IOException */ public HttpResult sendRequest(String urlPath, String input, String method, String accept, String contentType) { HttpURLConnection conn = null; String output = ""; OutputStream os = null; // Http Response object. HttpResult result = new HttpResult(); boolean status = true; try { URL url = new URL(urlPath); logger.info("Executing request : " + urlPath); conn = (HttpURLConnection) url.openConnection(); conn.setDoOutput(true); conn.setRequestMethod(method); conn.setRequestProperty("Accept", accept); conn.setRequestProperty("Content-type", contentType); if (input != null && !input.isEmpty()) { os = conn.getOutputStream(); os.write(input.getBytes()); os.flush(); } String buffer = ""; BufferedReader br; if (conn.getResponseCode() != HttpURLConnection.HTTP_OK) { status = false; String error = ""; // get ErrorStream br = new BufferedReader(new InputStreamReader((conn.getErrorStream()))); while ((buffer = br.readLine()) != null) { error += buffer; } result.setError(error); } br = new BufferedReader(new InputStreamReader((conn.getInputStream()))); while ((buffer = br.readLine()) != null) { output += buffer; } } catch (Exception e) { logger.debug(e.getMessage()); logger.error("Exception in executing request : " + urlPath, e); result.setError(e.getLocalizedMessage()); status = false; } finally { if (conn != null) { conn.disconnect(); } if (os != null) { IOUtils.closeQuietly(os); } } result.setStatus(status); result.setOutput(output); return result; }
From source file:com.wonders.bud.freshmommy.web.asq.controller.AsqResultController.java
@RequestMapping(method = RequestMethod.GET) @ResponseBody/*from w w w . ja va2s .c om*/ public RestMsg<PageVO<AsqResultVO>> findByPage(HttpServletRequest request) { RestMsg<PageVO<AsqResultVO>> rm = new RestMsg<PageVO<AsqResultVO>>(); String qType = request.getParameter("qType"); String month = request.getParameter("month"); String rDesc = request.getParameter("rDesc"); String row = request.getParameter("row"); String start = request.getParameter("start"); String sortorder = request.getParameter("sord"); String sortfield = request.getParameter("sidx"); try { Map<String, Object> eq = new HashMap<String, Object>(); Map<String, Object> like = new HashMap<String, Object>(); if (StringUtils.isNotBlank(qType)) { eq.put("qType", Integer.valueOf(qType)); } if (StringUtils.isNotBlank(month)) { eq.put("month", Integer.valueOf(month)); } if (StringUtils.isNotBlank(rDesc)) { like.put("rDesc", rDesc); } QueryParam param = new QueryParam(); param.setEq(eq); param.setLike(like); Page<AsqResultPO> page = new Page<AsqResultPO>(); page.setParam(param); PageUtil.pageSplit(page, start, row, sortorder, sortfield, null); page = asqResultService.findByPage(page); PageVO<AsqResultVO> pageVO = new PageVO<AsqResultVO>(); List<AsqResultVO> data = new ArrayList<AsqResultVO>(); List<AsqResultPO> list = page.getResult(); if (null != list && list.size() > 0) { for (AsqResultPO po : list) { AsqResultVO vo = new AsqResultVO(); BeanUtils.copyProperties(vo, po); data.add(vo); } } pageVO.setData(data); PageUtil.pageVOSplit(page, pageVO); rm.setResult(pageVO); rm.successMsg(); } catch (Exception e) { rm.errorMsg("?"); log.error(e.getLocalizedMessage()); } return rm; }