List of usage examples for java.net MalformedURLException getMessage
public String getMessage()
From source file:de.codecentric.jira.jenkins.plugin.servlet.OverviewServlet.java
/** * Creates a Jenkins Job List if authorization is required * @return Jenkins Job List//from www. jav a 2s.c o m */ @SuppressWarnings("unchecked") private List<JenkinsJob> getJobListByServerAuth(String urlJenkinsServer, String view, I18nHelper i18nHelper) throws MalformedURLException, DocumentException { List<JenkinsJob> jobList = new ArrayList<JenkinsJob>(); String jobListUrl = urlJenkinsServer + (StringUtils.isNotEmpty(view) ? "view/" + view : "") + "/api/xml?depth=1"; PostMethod post = new PostMethod(jobListUrl); post.setDoAuthentication(true); Document jobsDocument = null; try { client.executeMethod(post); jobsDocument = new SAXReader().read(post.getResponseBodyAsStream()); } catch (MalformedURLException e) { e.printStackTrace(); } catch (SSLException e) { if (e.getMessage().equals("Unrecognized SSL message, plaintext connection?")) { urlJenkinsServer = urlJenkinsServer.replaceFirst("s", ""); this.getJobListByServerAuth(urlJenkinsServer, view, i18nHelper); return jobList; } else { e.printStackTrace(); } } catch (IOException e) { e.printStackTrace(); } finally { post.releaseConnection(); } // if jenkinsUrl is invalid if (jobsDocument == null) { return jobList; } // get all jobs from xml and add them to list for (Element job : (List<Element>) jobsDocument.getRootElement().elements("job")) { // create a new job and set all params from xml JenkinsJob hJob = new JenkinsJob(); String jobName = job.elementText("name"); hJob.setName(jobName); hJob.setUrl(job.elementText("url")); hJob.setBuildTrigger(hJob.getUrl() + "/build"); hJob.setColor(job.elementText("color")); hJob.setLastSuccBuild(createBuildAuth(urlJenkinsServer, jobName, BuildType.LAST_SUCCESS, i18nHelper)); hJob.setLastFailBuild(createBuildAuth(urlJenkinsServer, jobName, BuildType.LAST_FAIL, i18nHelper)); jobList.add(hJob); } return jobList; }
From source file:com.gargoylesoftware.htmlunit.javascript.host.html.HTMLImageElement.java
/** * Returns the value of the {@code src} attribute. * @return the value of the {@code src} attribute *///from www . j a v a 2 s . co m @JsxGetter public String getSrc() { final HtmlImage img = (HtmlImage) getDomNodeOrDie(); final String src = img.getSrcAttribute(); if ("".equals(src)) { return src; } try { final HtmlPage page = (HtmlPage) img.getPage(); return page.getFullyQualifiedUrl(src).toExternalForm(); } catch (final MalformedURLException e) { final String msg = "Unable to create fully qualified URL for src attribute of image " + e.getMessage(); throw Context.reportRuntimeError(msg); } }
From source file:org.esupportail.portlet.filemanager.services.cifs.CifsAccessImpl.java
/** * @param path/*from ww w. j a v a 2s . com*/ * @return */ @Override public List<JsTreeFile> getChildren(String path, SharedUserPortletParameters userParameters) { List<JsTreeFile> files = new ArrayList<JsTreeFile>(); try { String ppath = path; this.open(userParameters); if (!ppath.endsWith("/")) ppath = ppath.concat("/"); SmbFile resource = new SmbFile(this.getUri() + ppath, userAuthenticator); if (resource.canRead()) { for (SmbFile child : resource.listFiles()) { try { if (!child.isHidden() || userParameters.isShowHiddenFiles()) { files.add(resourceAsJsTreeFile(child, userParameters, false, true)); } } catch (SmbException se) { log.warn("The resource isn't accessible and so will be ignored", se); } } } else { log.warn("The resource can't be read " + resource.toString()); } return files; } catch (SmbAuthException sae) { log.error(sae.getMessage()); throw new EsupStockPermissionDeniedException(sae); } catch (SmbException se) { log.error(se.getMessage()); throw new EsupStockException(se); } catch (MalformedURLException me) { log.error(me.getMessage()); throw new EsupStockException(me); } }
From source file:com.redhat.red.build.koji.it.AbstractIT.java
protected synchronized String formatUrl(String... path) { String baseUrl = getBaseUrl(); try {/* w w w .jav a2s.c om*/ return UrlUtils.buildUrl(baseUrl, path); } catch (MalformedURLException e) { e.printStackTrace(); Assert.fail(String.format("Failed to format URL from parts: [%s]. Reason: %s", StringUtils.join(path, ", "), e.getMessage())); } return null; }
From source file:hydrograph.ui.dataviewer.filemanager.DataViewerFileManager.java
/** * /*from w w w .j av a 2 s . co m*/ * Download debug file in data viewer workspace * @param filterApplied * @param filterConditions * * @return error code */ public StatusMessage downloadDataViewerFiles(boolean filterApplied, FilterConditions filterConditions, boolean isOverWritten) { // Get csv debug file name and location String csvDebugFileAbsolutePath = null; String csvDebugFileName = null; try { if (filterConditions != null) { if (!filterConditions.getRetainRemote()) { if (!filterApplied) { csvDebugFileAbsolutePath = getDebugFileAbsolutePath(); } else { csvDebugFileAbsolutePath = getDebugFileAbsolutePath(); csvDebugFileName = getFileName(csvDebugFileAbsolutePath); csvDebugFileAbsolutePath = getFilterFileAbsolutePath(filterConditions, csvDebugFileName); } } else { csvDebugFileAbsolutePath = getDebugFileAbsolutePath(); csvDebugFileName = getFileName(csvDebugFileAbsolutePath); csvDebugFileAbsolutePath = getFilterFileAbsolutePath(filterConditions, csvDebugFileName); } } else { csvDebugFileAbsolutePath = getDebugFileAbsolutePath(); } } catch (MalformedURLException malformedURLException) { Status status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, malformedURLException.getMessage(), malformedURLException); StatusMessage statusMessage = new StatusMessage.Builder(StatusConstants.ERROR, Messages.UNABLE_TO_FETCH_DEBUG_FILE + ": either no legal protocol could be found in a specification string or the path could not be parsed.") .errorStatus(status).build(); logger.error("Unable to fetch viewData file", malformedURLException); return statusMessage; } catch (HttpException httpException) { Status status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, httpException.getMessage(), httpException); StatusMessage statusMessage = new StatusMessage.Builder(StatusConstants.ERROR, Messages.UNABLE_TO_FETCH_DEBUG_FILE + ": error from Http client").errorStatus(status).build(); logger.error("Unable to fetch viewData file", httpException); return statusMessage; } catch (NumberFormatException numberFormateException) { Status status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, numberFormateException.getMessage(), numberFormateException); StatusMessage statusMessage = new StatusMessage.Builder(StatusConstants.ERROR, Messages.UNABLE_TO_FETCH_DEBUG_FILE + ": please check if port number is defined correctly") .errorStatus(status).build(); logger.error("Unable to fetch viewData file", numberFormateException); return statusMessage; } catch (IOException ioException) { Status status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, ioException.getMessage(), ioException); StatusMessage statusMessage = new StatusMessage.Builder(StatusConstants.ERROR, Messages.UNABLE_TO_FETCH_DEBUG_FILE + ": please check if service is running") .errorStatus(status).build(); logger.error("Unable to fetch viewData file", ioException); return statusMessage; } if (csvDebugFileAbsolutePath != null) { csvDebugFileName = csvDebugFileAbsolutePath .substring(csvDebugFileAbsolutePath.lastIndexOf("/") + 1, csvDebugFileAbsolutePath.length()) .replace(DEBUG_DATA_FILE_EXTENTION, "").trim(); } //Copy csv debug file to Data viewers temporary file location if (StringUtils.isNotBlank(csvDebugFileName)) { String dataViewerDebugFile = getDataViewerDebugFile(csvDebugFileName); try { if (!filterApplied) { copyCSVDebugFileToDataViewerStagingArea(jobDetails, csvDebugFileAbsolutePath, dataViewerDebugFile, isOverWritten); } else { copyFilteredFileToDataViewerStagingArea(jobDetails, csvDebugFileAbsolutePath, dataViewerDebugFile); } } catch (IOException | JSchException e1) { logger.error("Unable to fetch viewData file", e1); return new StatusMessage(StatusConstants.ERROR, Messages.UNABLE_TO_FETCH_DEBUG_FILE + ": unable to copy the files from temporary location"); } File debugFile = new File(dataViewerDebugFile); double debugFileSizeInByte = (double) debugFile.length(); double debugFileSizeKB = (debugFileSizeInByte / 1024); debugFileSizeInKB = new BigDecimal(debugFileSizeKB).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); // Delete csv debug file after copy deleteFileOnRemote(jobDetails, csvDebugFileName); // Check for empty csv debug file if (isEmptyDebugCSVFile(dataViewerFilePath, dataViewerFileName)) { logger.error("Empty viewData file"); return new StatusMessage(StatusConstants.ERROR, Messages.EMPTY_DEBUG_FILE); } } return new StatusMessage(StatusConstants.SUCCESS); }
From source file:uk.ac.ebi.metabolights.referencelayer.importer.ChebiMetaboliteScanner.java
public ChebiWebServiceClient getChebiWS() { if (chebiWS == null) try {//from w w w .j a va 2 s . co m LOGGER.info("Starting a new instance of the ChEBI ChebiWebServiceClient"); chebiWS = new ChebiWebServiceClient(new URL(chebiWSUrl), new QName("http://www.ebi.ac.uk/webservices/chebi", "ChebiWebServiceService")); } catch (MalformedURLException e) { LOGGER.error("Error instanciating a new ChebiWebServiceClient " + e.getMessage()); } return chebiWS; }
From source file:com.amalto.workbench.dialogs.SelectImportedModulesDialog.java
public URL getSourceURL(String path) { Matcher match = urlPattern.matcher(path); if (match.matches()) { try {/*from ww w. j av a 2 s . c o m*/ return new URL(path); } catch (MalformedURLException e) { log.error(e.getMessage()); } } return null; }
From source file:com.andrada.sitracker.reader.Samlib.java
@Override public boolean updateAuthor(@NotNull Author author) throws SQLException { boolean authorUpdated = false; HttpRequest request;//from w w w. j a v a2 s . co m AuthorPageReader reader; try { URL authorURL = new URL(author.getUrl()); request = HttpRequest.get(authorURL); if (request.code() == 404) { //skip this author //Not available atm return false; } if (!authorURL.getHost().equals(request.url().getHost())) { //We are being redirected hell knows where. //Skip return false; } //TODO OutOfMemory thrown here reader = new SamlibAuthorPageReader(request.body()); //We go a blank response but no exception, skip author if (reader.isPageBlank()) { return false; } } catch (MalformedURLException e) { //Just swallow exception, as this is unlikely to happen //Skip author trackException(e.getMessage()); return false; } catch (HttpRequest.HttpRequestException e) { //Author currently inaccessible or no internet //Skip author trackException(e.getMessage()); return false; } AuthorDao authorDao = null; PublicationDao publicationsDao = null; try { publicationsDao = helper.getDao(Publication.class); } catch (SQLException e) { Log.e("Samlib", "Could not create DAO publicationsDao", e); } try { authorDao = helper.getDao(Author.class); } catch (SQLException e) { Log.e("Samlib", "Could not create DAO authorDao", e); } assert authorDao != null; assert publicationsDao != null; String authImgUrl = reader.getAuthorImageUrl(author.getUrl()); String authDescription = reader.getAuthorDescription(); if (authImgUrl != null) { author.setAuthorImageUrl(authImgUrl); } if (authDescription != null) { author.setAuthorDescription(authDescription); } authorDao.update(author); ForeignCollection<Publication> oldItems = author.getPublications(); List<Publication> newItems = reader.getPublications(author); HashMap<String, Publication> oldItemsMap = new HashMap<String, Publication>(); for (Publication oldPub : oldItems) { oldItemsMap.put(oldPub.getUrl(), oldPub); } if (newItems.size() == 0 && oldItemsMap.size() > 1) { LogUtils.LOGW(Constants.APP_TAG, "Something went wrong. No publications found for author that already exists"); //Just skip for now to be on the safe side. return false; } for (Publication pub : newItems) { //Find pub in oldItems if (oldItemsMap.containsKey(pub.getUrl())) { Publication old = oldItemsMap.get(pub.getUrl()); if (old.getUpdatesIgnored()) { //Do not check anything continue; } //Check size/name/description if (pub.getSize() != old.getSize() || !pub.getName().equals(old.getName())) { //if something differs //Store the old size if (old.getOldSize() != 0) { pub.setOldSize(old.getOldSize()); } else { pub.setOldSize(old.getSize()); } //Swap the ids, do an update in DB pub.setId(old.getId()); //Copy over custom properties that do not relate to samlib pub.setMyVote(old.getMyVote()); pub.setVoteCookie(old.getVoteCookie()); pub.setVoteDate(old.getVoteDate()); pub.setUpdatesIgnored(old.getUpdatesIgnored()); pub.setNew(true); authorUpdated = true; publicationsDao.update(pub); //Mark author new, update in DB author.setUpdateDate(new Date()); author.setNew(true); authorDao.update(author); } else if (!StringUtils.equalsIgnoreCase(old.getImagePageUrl(), pub.getImagePageUrl())) { pub.setId(old.getId()); //Update silently publicationsDao.update(pub); } } else { //Mark author new, update in DB author.setUpdateDate(new Date()); author.setNew(true); authorDao.update(author); //Mark publication new, create in DB pub.setNew(true); authorUpdated = true; publicationsDao.create(pub); } } return authorUpdated; }
From source file:com.sun.portal.rssportlet.RssPortlet.java
private void processEditAddAction(ActionRequest request, ActionResponse response, AlertHandler alertHandler, Resources resources, SettingsBean readBean, SettingsBean writeBean) { String url = request.getParameter(INPUT_ADD_FEED); try {/* w w w . jav a 2 s . co m*/ // see if the url exists // if there's no exception, then the feed exists and is valid FeedHelper.getInstance().getFeed(readBean, url); //add to the existing values LinkedList feeds = readBean.getFeeds(); feeds.add(url); writeBean.setFeeds(feeds); // // set newly added feed as selected feed // writeBean.setSelectedFeed(url); // we stay in edit mode here } catch (MalformedURLException mue) { alertHandler.setError(resources.get("invalid_url"), mue.getMessage()); log.info("MalformedURLException: " + mue.getMessage()); getPortletConfig().getPortletContext().log("could not add feed", mue); } catch (UnknownHostException uhe) { alertHandler.setError(resources.get("invalid_url"), uhe.getMessage()); log.info("UnknownHostException: " + uhe.getMessage()); } catch (FileNotFoundException fnfe) { alertHandler.setError(resources.get("invalid_url"), fnfe.getMessage()); log.info("FileNotFoundException: " + fnfe.getMessage()); getPortletConfig().getPortletContext().log("could not add feed", fnfe); } catch (IllegalArgumentException iae) { alertHandler.setError(resources.get("invalid_url"), iae.getMessage()); log.info("IllegalArgumentException: " + iae.getMessage()); getPortletConfig().getPortletContext().log("could not add feed", iae); } catch (FeedException fe) { alertHandler.setError(resources.get("invalid_url"), fe.getMessage()); log.info("FeedException: " + fe.getMessage()); getPortletConfig().getPortletContext().log("could not add feed", fe); } catch (IOException ioe) { alertHandler.setError(resources.get("invalid_url"), ioe.getMessage()); log.info("IOException: " + ioe.getMessage()); getPortletConfig().getPortletContext().log("could not add feed", ioe); } catch (Exception ex) { alertHandler.setError(resources.get("invalid_url"), ex.getMessage()); log.info("Exception: " + ex.getMessage()); getPortletConfig().getPortletContext().log("could not add feed", ex); } }
From source file:org.commonjava.indy.koji.ftest.AbstractKojiIT.java
protected synchronized String formatSSLUrl(String... path) { String baseUrl = getSSLBaseUrl(); try {//from w w w . j a v a2 s . c o m return UrlUtils.buildUrl(baseUrl, path); } catch (MalformedURLException e) { e.printStackTrace(); fail(String.format("Failed to format URL from parts: [%s]. Reason: %s", StringUtils.join(path, ", "), e.getMessage())); } return null; }