List of usage examples for org.apache.commons.lang StringUtils removeEnd
public static String removeEnd(String str, String remove)
Removes a substring only if it is at the end of a source string, otherwise returns the source string.
From source file:org.apache.stratos.messaging.test.AmqpSubscriberTest.java
private static String getResourcesFolderPath() { String path = AmqpSubscriberTest.class.getResource("/").getPath(); return StringUtils.removeEnd(path, File.separator); }
From source file:org.apache.stratos.python.cartridge.agent.test.PythonCartridgeAgentTest.java
/** * Get resources folder path//from w w w .j a v a2s .c om * @return */ private static String getResourcesFolderPath() { String path = PythonCartridgeAgentTest.class.getResource("/").getPath(); return StringUtils.removeEnd(path, File.separator); }
From source file:org.apache.usergrid.rest.ApiResponse.java
public static String exceptionToErrorCode(Throwable e) { if (e == null) { return "service_error"; }// w ww . ja v a 2 s. c o m String s = ClassUtils.getShortClassName(e.getClass()); s = StringUtils.removeEnd(s, "Exception"); s = InflectionUtils.underscore(s).toLowerCase(); return s; }
From source file:org.archive.modules.forms.ExtractorHTMLForms.java
protected String findAttributeValueGroup(String pattern, int groupNumber, CharSequence cs) { Matcher m = TextUtils.getMatcher(pattern, cs); try {/*from w w w. ja v a 2s .c o m*/ if (m.find()) { String value = m.group(groupNumber); /* * In a case like this <input name="foo"/> the group here will * be "foo"/ ... it's difficult to adjust the regex to avoid * slurping that trailing slash, so handle it here */ value = StringUtils.removeEnd(value, "'/"); value = StringUtils.removeEnd(value, "\"/"); value = StringUtils.strip(value, "\'\""); // strip quotes if present return value; } else { return null; } } finally { TextUtils.recycleMatcher(m); } }
From source file:org.artifactory.repo.remote.browse.S3RepositoryBrowser.java
/** * Detects the bucket url (i.e., root url). The given url is assumed to either point to the root or to "directory" * under the root. The most reliable way to get the root is to request non-existing resource and analyze the response. * * @param url URL to S3 repository/*from w w w . jav a 2 s . com*/ * @return The root url of the repository (the bucket) */ String detectRootUrl(String url) throws IOException { //noinspection RedundantStringConstructorCall String copyUrl = new String(url); //defense // force non-directory copyUrl. S3 returns 200 for directory paths url = url.endsWith("/") ? StringUtils.removeEnd(url, "/") : url; // generate a random string to force 404 String randomString = RandomStringUtils.randomAlphanumeric(16); url = url + "/" + randomString; HttpGet method = new HttpGet(url); try (CloseableHttpResponse response = client.executeMethod(method)) { // most likely to get 404 if the repository exists assertSizeLimit(url, response); String responseString = IOUtils.toString(HttpUtils.getResponseBody(response), Charsets.UTF_8.name()); log.debug("Detect S3 root url got response code {} with content: {}", response.getStatusLine().getStatusCode(), responseString); Document doc = XmlUtils.parse(responseString); Element root = doc.getRootElement(); String errorCode = root.getChildText("Code", root.getNamespace()); if (ERROR_CODE_NOSUCHKEY.equals(errorCode)) { String relativePath = root.getChildText("Key", root.getNamespace()); rootUrl = StringUtils.removeEnd(url, relativePath); } else if (INVALID_ARGUMENT.equals(errorCode)) { if (isPro()) { String message = root.getChildText("Message"); if (UNSUPPORTED_AUTHORIZATION_TYPE.equals(message)) { rootUrl = detectRootUrlSecured(copyUrl); } } else { log.warn("Browsing secured S3 requires Artifactory Pro"); //TODO [mamo] should inform otherwise? } } else { throw new IOException("Couldn't detect S3 root URL. Unknown error code: " + errorCode); } } log.debug("Detected S3 root URL: {}", rootUrl); return rootUrl; }
From source file:org.artifactory.repo.remote.browse.S3RepositoryBrowser.java
private String detectRootUrlSecured(String url) throws IOException { String securedUrl = buildSecuredS3RequestUrl(url, httpRepo, "") + "&prefix=" + getPrefix(url) + "&delimiter=/&max-keys=1"; HttpGet method = new HttpGet(securedUrl); try (CloseableHttpResponse response = client.executeMethod(method)) { if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { String rootUrl = StringUtils.removeEnd(httpRepo.getUrl(), getPrefix(httpRepo.getUrl())); if (!rootUrl.endsWith("/")) { rootUrl += "/"; }//ww w . j a v a2 s . c o m secured = true; return rootUrl; } } return null; }
From source file:org.artifactory.webapp.wicket.page.config.advanced.SystemInfoPage.java
/** * Return a formatted string of the system info to display * * @return/* ww w . ja v a 2 s.c om*/ */ private String collectSystemInfo() { StringBuilder infoBuilder = new StringBuilder(); StorageProperties storageProperties = ContextHelper.get().beanForType(StorageProperties.class); infoBuilder.append("Storage Info:").append("\n"); addInfo(infoBuilder, "Database Type", storageProperties.getDbType().toString()); BinaryProviderType binariesStorageType = storageProperties.getBinariesStorageType(); addInfo(infoBuilder, "Storage Type", binariesStorageType.toString()); if (BinaryProviderType.S3 == binariesStorageType) { // S3 properties addInfo(infoBuilder, "s3.bucket.name", storageProperties.getS3BucketName()); addInfo(infoBuilder, "s3.bucket.path", storageProperties.getS3BucketPath()); addInfo(infoBuilder, "s3.endpoint", storageProperties.getS3Entpoint()); // Retry properties addInfo(infoBuilder, "retry.max.retries.number", Integer.toString(storageProperties.getMaxRetriesNumber())); addInfo(infoBuilder, "retry.delay.between.retries", Integer.toString(storageProperties.getDelayBetweenRetries())); // Eventually persisted properties addInfo(infoBuilder, "eventually.persisted.max.number.of.threads", Integer.toString(storageProperties.getEventuallyPersistedMaxNumberOfThread())); addInfo(infoBuilder, "eventually.persisted.timeout", Integer.toString(storageProperties.getEventuallyPersistedTimeOut())); addInfo(infoBuilder, "eventually.dispatcher.sleep.time", Long.toString(storageProperties.getEventuallyPersistedDispatcherSleepTime())); } infoBuilder.append("\n").append("System Properties:").append("\n"); Properties properties = System.getProperties(); //// add Artifactory version to the properties, will be alphabetically sorted later. properties.setProperty(ConstantValues.artifactoryVersion.getPropertyName(), ConstantValues.artifactoryVersion.getString()); AddonsManager addonsManager = ContextHelper.get().beanForType(AddonsManager.class); addInfo(infoBuilder, "artifactory.running.mode", addonsManager.getArtifactoryRunningMode().name()); addInfo(infoBuilder, "artifactory.running.state", ContextHelper.get().isOffline() ? "Offline" : "Online"); addFromProperties(infoBuilder, properties); addHaProperties(infoBuilder); infoBuilder.append("\n").append("General JVM Info:").append("\n"); OperatingSystemMXBean systemBean = ManagementFactory.getOperatingSystemMXBean(); addInfo(infoBuilder, "Available Processors", Integer.toString(systemBean.getAvailableProcessors())); MemoryMXBean memoryBean = ManagementFactory.getMemoryMXBean(); MemoryUsage heapMemoryUsage = memoryBean.getHeapMemoryUsage(); addInfo(infoBuilder, "Heap Memory Usage-Committed", Long.toString(heapMemoryUsage.getCommitted())); addInfo(infoBuilder, "Heap Memory Usage-Init", Long.toString(heapMemoryUsage.getInit())); addInfo(infoBuilder, "Heap Memory Usage-Max", Long.toString(heapMemoryUsage.getMax())); addInfo(infoBuilder, "Heap Memory Usage-Used", Long.toString(heapMemoryUsage.getUsed())); MemoryUsage nonHeapMemoryUsage = memoryBean.getNonHeapMemoryUsage(); addInfo(infoBuilder, "Non-Heap Memory Usage-Committed", Long.toString(nonHeapMemoryUsage.getCommitted())); addInfo(infoBuilder, "Non-Heap Memory Usage-Init", Long.toString(nonHeapMemoryUsage.getInit())); addInfo(infoBuilder, "Non-Heap Memory Usage-Max", Long.toString(nonHeapMemoryUsage.getMax())); addInfo(infoBuilder, "Non-Heap Memory Usage-Used", Long.toString(nonHeapMemoryUsage.getUsed())); RuntimeMXBean RuntimemxBean = ManagementFactory.getRuntimeMXBean(); StringBuilder vmArgumentBuilder = new StringBuilder(); List<String> vmArguments = RuntimemxBean.getInputArguments(); if (vmArguments != null) { for (String vmArgument : vmArguments) { if (InfoWriter.shouldMaskValue(vmArgument)) { vmArgument = Strings.maskKeyValue(vmArgument); } vmArgumentBuilder.append(vmArgument); if (vmArguments.indexOf(vmArgument) != (vmArguments.size() - 1)) { vmArgumentBuilder.append("\n"); } } } infoBuilder.append("\nJVM Arguments:\n").append(vmArgumentBuilder.toString()); return StringUtils.removeEnd(infoBuilder.toString(), "\n"); }
From source file:org.artifactory.webapp.wicket.page.home.settings.BaseSettingsPage.java
/** * Add the settings panel or a place holder if no virtual repos are available *//*from w ww . j a va2 s . co m*/ private void addSettingsPanel() { //Add a markup container, in case we don't need to add the panel WebMarkupContainer markupContainer = new WebMarkupContainer("settingsPanel"); add(markupContainer); if (virtualRepoDescriptors.isEmpty()) { markupContainer.replaceWith(new Label("settingsPanel", "Settings Generator is disabled: Unable to find readable virtual repositories.")); } else { //Get context URL String contextUrl = getContextUrl(); if (contextUrl.endsWith("/")) { contextUrl = StringUtils.removeEnd(contextUrl, "/"); } markupContainer.replaceWith(getSettingsPanel("settingsPanel", contextUrl)); } }
From source file:org.b3log.solo.event.ping.AddArticleGoogleBlogSearchPinger.java
@Override public void action(final Event<JSONObject> event) throws EventException { final JSONObject eventData = event.getData(); String articleTitle = null;//from ww w.ja v a 2 s .co m try { final JSONObject article = eventData.getJSONObject(Article.ARTICLE); articleTitle = article.getString(Article.ARTICLE_TITLE); final JSONObject preference = PreferenceQueryService.getInstance().getPreference(); final String blogTitle = preference.getString(Preference.BLOG_TITLE); String blogHost = preference.getString(Preference.BLOG_HOST).toLowerCase().trim(); if ("localhost".equals(blogHost.split(":")[0].trim())) { LOGGER.log(Level.INFO, "Blog Solo runs on local server, so should not ping " + "Google Blog Search Service for the article[title={0}]", new Object[] { article.getString(Article.ARTICLE_TITLE) }); return; } blogHost = StringUtils.removeEnd("http://" + blogHost, "/"); final String articlePermalink = blogHost + article.getString(Article.ARTICLE_PERMALINK); final String spec = "http://blogsearch.google.com/ping?name=" + URLEncoder.encode(blogTitle, "UTF-8") + "&url=" + URLEncoder.encode(blogHost, "UTF-8") + "&changesURL=" + URLEncoder.encode(articlePermalink, "UTF-8"); LOGGER.log(Level.FINER, "Request Google Blog Search Service API[{0}] while adding an " + "article[title=" + articleTitle + "]", spec); final HTTPRequest request = new HTTPRequest(); request.setURL(new URL(spec)); URL_FETCH_SERVICE.fetchAsync(request); } catch (final Exception e) { LOGGER.log(Level.SEVERE, "Ping Google Blog Search Service fail while adding an article[title=" + articleTitle + "]", e); } }
From source file:org.b3log.solo.event.ping.UpdateArticleGoogleBlogSearchPinger.java
@Override public void action(final Event<JSONObject> event) throws EventException { final JSONObject eventData = event.getData(); String articleTitle = null;//from w ww. j a v a 2 s . c o m try { final JSONObject article = eventData.getJSONObject(Article.ARTICLE); articleTitle = article.getString(Article.ARTICLE_TITLE); final JSONObject preference = PreferenceQueryService.getInstance().getPreference(); final String blogTitle = preference.getString(Preference.BLOG_TITLE); String blogHost = preference.getString(Preference.BLOG_HOST).toLowerCase().trim(); if ("localhost".equals(blogHost.split(":")[0].trim())) { LOGGER.log(Level.INFO, "Blog Solo runs on local server, so should not ping " + "Google Blog Search Service for the article[title={0}]", new Object[] { article.getString(Article.ARTICLE_TITLE) }); return; } blogHost = StringUtils.removeEnd("http://" + blogHost, "/"); final String articlePermalink = blogHost + article.getString(Article.ARTICLE_PERMALINK); final String spec = "http://blogsearch.google.com/ping?name=" + URLEncoder.encode(blogTitle, "UTF-8") + "&url=" + URLEncoder.encode(blogHost, "UTF-8") + "&changesURL=" + URLEncoder.encode(articlePermalink, "UTF-8"); LOGGER.log(Level.FINER, "Request Google Blog Search Service API[{0}] while updateing " + "an article[title=" + articleTitle + "]", spec); final HTTPRequest request = new HTTPRequest(); request.setURL(new URL(spec)); URL_FETCH_SERVICE.fetchAsync(request); } catch (final Exception e) { LOGGER.log(Level.SEVERE, "Ping Google Blog Search Service fail while updating an " + "article[title=" + articleTitle + "]", e); } }