Example usage for org.apache.commons.lang StringUtils stripEnd

List of usage examples for org.apache.commons.lang StringUtils stripEnd

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils stripEnd.

Prototype

public static String stripEnd(String str, String stripChars) 

Source Link

Document

Strips any of a set of characters from the end of a String.

Usage

From source file:org.jboss.as.test.integration.security.common.Utils.java

/**
 * Creates request against SPNEGO protected web-app with FORM fallback. It doesn't try to login using SPNEGO - it uses FORM
 * authn directly.//from  w w w.j  a v  a  2s.co  m
 *
 * @param contextUrl
 * @param page
 * @param user
 * @param pass
 * @param expectedStatusCode
 * @return
 * @throws IOException
 * @throws URISyntaxException
 * @throws PrivilegedActionException
 * @throws LoginException
 */
public static String makeHttpCallWoSPNEGO(final String contextUrl, final String page, final String user,
        final String pass, final int expectedStatusCode)
        throws IOException, URISyntaxException, PrivilegedActionException, LoginException {
    final String strippedContextUrl = StringUtils.stripEnd(contextUrl, "/");
    final String url = strippedContextUrl + page;
    LOGGER.trace("Requesting URL: " + url);

    String unauthorizedPageBody = null;
    try (final CloseableHttpClient httpClient = HttpClientBuilder.create()
            .setRedirectStrategy(REDIRECT_STRATEGY).build()) {
        final HttpGet httpGet = new HttpGet(url);
        HttpResponse response = httpClient.execute(httpGet);
        int statusCode = response.getStatusLine().getStatusCode();
        if (HttpServletResponse.SC_UNAUTHORIZED != statusCode || StringUtils.isEmpty(user)) {
            assertEquals("Unexpected HTTP response status code.", expectedStatusCode, statusCode);
            return EntityUtils.toString(response.getEntity());
        }
        final Header[] authnHeaders = response.getHeaders("WWW-Authenticate");
        assertTrue("WWW-Authenticate header is present", authnHeaders != null && authnHeaders.length > 0);
        final Set<String> authnHeaderValues = new HashSet<String>();
        for (final Header header : authnHeaders) {
            authnHeaderValues.add(header.getValue());
        }
        assertTrue("WWW-Authenticate: Negotiate header is missing", authnHeaderValues.contains("Negotiate"));

        LOGGER.debug("HTTP response was SC_UNAUTHORIZED, let's authenticate the user " + user);
        unauthorizedPageBody = EntityUtils.toString(response.getEntity());

        assertNotNull(unauthorizedPageBody);
        LOGGER.trace(unauthorizedPageBody);
        assertTrue(unauthorizedPageBody.contains("j_security_check"));

        HttpPost httpPost = new HttpPost(strippedContextUrl + "/j_security_check");
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
        nameValuePairs.add(new BasicNameValuePair("j_username", user));
        nameValuePairs.add(new BasicNameValuePair("j_password", pass));
        httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        response = httpClient.execute(httpPost);
        statusCode = response.getStatusLine().getStatusCode();
        assertEquals("Unexpected status code returned after the authentication.", expectedStatusCode,
                statusCode);
        return EntityUtils.toString(response.getEntity());
    }
}

From source file:org.jboss.pnc.coordinator.maintenance.IndyFactory.java

@Inject
public IndyFactory(IndyRepoDriverModuleConfig config) {
    this.defaultRequestTimeout = config.getDefaultRequestTimeout();

    String baseUrl = StringUtils.stripEnd(config.getBaseUrl(), "/");
    if (!baseUrl.endsWith("/api")) {
        baseUrl += "/api";
    }//from   w  w  w  .  ja va  2s.c o  m
    this.baseUrl = baseUrl;
}

From source file:org.jboss.pnc.indyrepositorymanager.RepositoryManagerDriver.java

@Inject
public RepositoryManagerDriver(Configuration configuration) {
    IndyRepoDriverModuleConfig config;/*from  w  w w .j ava2 s.  com*/
    try {
        config = configuration.getModuleConfig(new PncConfigProvider<>(IndyRepoDriverModuleConfig.class));
    } catch (ConfigurationParseException e) {
        throw new IllegalStateException("Cannot read configuration for " + DRIVER_ID + ".", e);
    }
    this.DEFAULT_REQUEST_TIMEOUT = config.getDefaultRequestTimeout();
    this.BUILD_PROMOTION_TARGET = config.getBuildPromotionTarget();
    this.TEMP_BUILD_PROMOTION_GROUP = config.getTempBuildPromotionGroup();

    baseUrl = StringUtils.stripEnd(config.getBaseUrl(), "/");
    if (!baseUrl.endsWith("/api")) {
        baseUrl += "/api";
    }

    List<String> constInternalRepoPatterns = new ArrayList<>();
    constInternalRepoPatterns.add(IndyRepositoryConstants.SHARED_IMPORTS_ID);
    internalRepoPatterns = new InternalRepoPatterns();
    internalRepoPatterns.setMaven(constInternalRepoPatterns);
    internalRepoPatterns.setNpm(new ArrayList<>(constInternalRepoPatterns));

    InternalRepoPatterns extraInternalRepoPatterns = config.getInternalRepoPatterns();
    if (extraInternalRepoPatterns != null) {
        internalRepoPatterns.addMaven(extraInternalRepoPatterns.getMaven());
        internalRepoPatterns.addNpm(extraInternalRepoPatterns.getNpm());
    }

    IgnoredPathSuffixes ignoredPathSuffixes = config.getIgnoredPathSuffixes();
    if (ignoredPathSuffixes == null) {
        this.ignoredPathSuffixes = new IgnoredPathSuffixes();
    } else {
        this.ignoredPathSuffixes = ignoredPathSuffixes; // TODO do we need a copy?
    }
}

From source file:org.jboss.pnc.mavenrepositorymanager.RepositoryManagerDriver.java

@Inject
public RepositoryManagerDriver(Configuration configuration) {
    MavenRepoDriverModuleConfig config;//  ww  w  .j ava  2 s . c om
    try {
        config = configuration.getModuleConfig(new PncConfigProvider<>(MavenRepoDriverModuleConfig.class));
    } catch (ConfigurationParseException e) {
        throw new IllegalStateException("Cannot read configuration for " + DRIVER_ID + ".", e);
    }
    this.DEFAULT_REQUEST_TIMEOUT = config.getDefaultRequestTimeout();
    this.BUILD_REPOSITORY_ALLOW_SNAPSHOTS = config.getBuildRepositoryAllowSnapshots();
    this.BUILD_PROMOTION_GROUP = config.getBuildPromotionGroup();

    baseUrl = StringUtils.stripEnd(config.getBaseUrl(), "/");
    if (!baseUrl.endsWith("/api")) {
        baseUrl += "/api";
    }

    internalRepoPatterns = new ArrayList<>();
    internalRepoPatterns.add(MavenRepositoryConstants.SHARED_IMPORTS_ID);

    List<String> extraInternalRepoPatterns = config.getInternalRepoPatterns();
    if (extraInternalRepoPatterns != null) {
        internalRepoPatterns.addAll(extraInternalRepoPatterns);
    }

    List<String> ignoredPathSuffixes = config.getIgnoredPathSuffixes();
    if (ignoredPathSuffixes == null) {
        this.ignoredPathSuffixes = Collections.emptySet();
    } else {
        this.ignoredPathSuffixes = new HashSet<>(ignoredPathSuffixes);
    }
}

From source file:org.jfrog.bamboo.builder.BuilderDependencyHelper.java

public String downloadDependenciesAndGetPath(File rootDir, AbstractBuildContext context, String dependencyKey)
        throws IOException {
    String pluginKey = PluginProperties.getPluginKey();
    String pluginDescriptorKey = PluginProperties.getPluginDescriptorKey();

    if (rootDir == null) {
        return null;
    }/*from   w  ww  .j ava2 s  .c o m*/
    File rootDirParent = rootDir.getParentFile();

    //Search for older plugin dirs and remove if any exist
    for (File buildDirChild : rootDirParent.listFiles()) {
        String buildDirChildName = buildDirChild.getName();
        if (buildDirChildName.startsWith(pluginDescriptorKey)
                && (!buildDirChildName.equals(pluginKey) || buildDirChildName.endsWith("-SNAPSHOT"))) {
            FileUtils.deleteQuietly(buildDirChild);
            buildDirChild.delete();
        }
    }

    File pluginDir = new File(rootDirParent, pluginKey);
    File builderDependencyDir = new File(pluginDir, builderKey);
    if (builderDependencyDir.isDirectory()) {
        if (builderDependencyDir.list().length != 0) {
            return builderDependencyDir.getCanonicalPath();
        }
    } else {
        builderDependencyDir.mkdirs();
    }

    String bambooBaseUrl = getBambooBaseUrl(context);
    bambooBaseUrl = StringUtils.stripEnd(bambooBaseUrl, "/");
    if (StringUtils.isNotBlank(bambooBaseUrl)) {
        StringBuilder builder = new StringBuilder(bambooBaseUrl);
        if (!bambooBaseUrl.endsWith("/")) {
            builder.append("/");
        }
        String dependencyBaseUrl = builder.append("download/resources/").append(pluginDescriptorKey)
                .append("/builder/dependencies/").toString();
        try {
            downloadDependencies(dependencyBaseUrl, builderDependencyDir, dependencyKey);
            return builderDependencyDir.getCanonicalPath();
        } catch (IOException ioe) {
            FileUtils.deleteDirectory(builderDependencyDir);
            throw ioe;
        }
    }

    return null;
}

From source file:org.jfrog.build.client.ArtifactoryBuildInfoClient.java

/**
 * Creates a new client for the given Artifactory url.
 *
 * @param artifactoryUrl Artifactory url in the form of: protocol://host[:port]/contextPath
 * @param username       Authentication username
 * @param password       Authentication password
 *//*from   ww w  . ja  v  a2s .c  o m*/
public ArtifactoryBuildInfoClient(String artifactoryUrl, String username, String password, Log log) {
    this.artifactoryUrl = StringUtils.stripEnd(artifactoryUrl, "/");
    httpClient = new ArtifactoryHttpClient(this.artifactoryUrl, username, password, log);
    this.log = log;
}

From source file:org.jfrog.build.client.ArtifactoryDependenciesClient.java

public ArtifactoryDependenciesClient(String artifactoryUrl, String username, String password, Log logger) {
    this.artifactoryUrl = StringUtils.stripEnd(artifactoryUrl, "/");
    httpClient = new ArtifactoryHttpClient(this.artifactoryUrl, username, password, logger);
}

From source file:org.jfrog.build.client.ArtifactoryHttpClient.java

public ArtifactoryHttpClient(String artifactoryUrl, String username, String password, Log log) {
    this.artifactoryUrl = StringUtils.stripEnd(artifactoryUrl, "/");
    this.username = username;
    this.password = password;
    this.log = log;
}

From source file:org.jfrog.build.extractor.gradle.BuildInfoRecorderTask.java

/**
 * Returns the artifacts which will be uploaded.
 *
 * @param gbie Tomer will document later.
 * @throws java.io.IOException Tomer will document later.
 *///from w  ww .ja v a2 s. co m

private void closeAndDeploy(GradleBuildInfoExtractor gbie) throws IOException {
    String uploadArtifactsProperty = getProperty(ClientProperties.PROP_PUBLISH_ARTIFACT, getRootProject());
    String fileExportPath = getProperty(PROP_EXPORT_FILE_PATH, getRootProject());
    if (Boolean.parseBoolean(uploadArtifactsProperty)) {
        /**
         * if the {@link org.jfrog.build.client.ClientProperties#PROP_PUBLISH_ARTIFACT} is set the true,
         * The uploadArchives task will be triggered ONLY at the end, ensuring that the artifacts will be published
         * only after a successful build. This is done before the build-info is sent.
         */
        for (Project uploadingProject : getRootProject().getAllprojects()) {
            Set<Task> uploadTask = uploadingProject.getTasksByName("uploadArchives", false);
            if (uploadTask != null) {
                for (Task task : uploadTask) {
                    try {
                        log.debug("Uploading project {}", uploadingProject);
                        ((Upload) task).execute();
                    } catch (Exception e) {
                        throw new GradleException("Unable to upload project: " + uploadingProject, e);
                    }

                }
            }
        }
    }
    String publishBuildInfo = getProperty(ClientProperties.PROP_PUBLISH_BUILD_INFO, getRootProject());
    boolean isPublishBuildInfo = Boolean.parseBoolean(publishBuildInfo);
    if (isPublishBuildInfo) {
        /**
         * After all the artifacts were uploaded successfully the next task is to send the build-info
         * object.
         */
        String buildInfoUploadUrl = getProperty(ClientProperties.PROP_CONTEXT_URL, getRootProject());
        buildInfoUploadUrl = StringUtils.stripEnd(buildInfoUploadUrl, "/");
        Build build = gbie.extract(this, new BuildInfoExtractorSpec());
        if (fileExportPath != null) {
            // If export property set always save the file before sending it to artifactory
            exportBuildInfo(build, new File(fileExportPath));
        }
        String username = getProperty(ClientProperties.PROP_PUBLISH_USERNAME, getRootProject());
        if (StringUtils.isBlank(username)) {
            username = "";
        }
        String password = getProperty(ClientProperties.PROP_PUBLISH_PASSWORD, getRootProject());
        if (StringUtils.isBlank(password)) {
            password = "";
        }
        ArtifactoryBuildInfoClient artifactoryBuildInfoClient = new ArtifactoryBuildInfoClient(
                buildInfoUploadUrl, username, password);
        artifactoryBuildInfoClient.sendBuildInfo(build);
    } else {
        /**
         * If we do not deploy any artifacts or build-info, the build-info will be written to a file in its
         * JSON form.
         */
        File savedFile;
        if (fileExportPath == null) {
            savedFile = new File(getProject().getBuildDir(), "build-info.json");
        } else {
            savedFile = new File(fileExportPath);
        }
        Build build = gbie.extract(this, new BuildInfoExtractorSpec());
        exportBuildInfo(build, savedFile);
    }
}

From source file:org.kuali.kfs.sys.batch.AbstractRegexSpecificationBase.java

/**
 * Trims the trailing space only from the given line, though only if trimLineBeforeMatch is true
 * @param line the line to perhaps trim trailing spaces from
 * @return the maybe trimmed line// ww  w  .j  a v a2 s. c om
 */
protected String trimLine(String line) {
    if (isTrimLineBeforeMatch()) {
        return StringUtils.stripEnd(line, " \t\n\f\r");
    }
    return line;
}