Example usage for org.apache.commons.lang3 StringUtils substringAfter

List of usage examples for org.apache.commons.lang3 StringUtils substringAfter

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils substringAfter.

Prototype

public static String substringAfter(final String str, final String separator) 

Source Link

Document

Gets the substring after the first occurrence of a separator.

Usage

From source file:org.kawanfw.sql.tomcat.TomcatConnectorsUpdater.java

/**
 * If there are some Connector properties, set them on Tomcat instance
 *//*from  w w  w  .  j a  v  a 2 s.  co m*/
public void setConnectorValues() {

    // Do we have to set special values to the Connector?
    Enumeration<?> enumeration = properties.propertyNames();

    if (enumeration.hasMoreElements()) {
        System.out.println(SqlTag.SQL_PRODUCT_START + " Setting Default Connector attribute values:");
    }

    while (enumeration.hasMoreElements()) {
        String property = (String) enumeration.nextElement();

        if (property.startsWith("connector.")) {

            String theValue = properties.getProperty(property);
            String tomcatProperty = StringUtils.substringAfter(property, "connector.");

            if (theValue != null && !theValue.isEmpty()) {

                theValue = theValue.trim();

                System.out.println(SqlTag.SQL_PRODUCT_START + "  -> " + tomcatProperty + " = " + theValue);

                tomcat.getConnector().setProperty(tomcatProperty, theValue);
            }
        }
    }
}

From source file:org.kawanfw.sql.tomcat.TomcatConnectorsUpdater.java

/**
 * If there are some SSL Connector properties, set them on Tomcat instance
 * /*from  w  w  w. ja  v  a 2s  . com*/
 * @return the setted Connector
 */
public Connector setSslConnectorValues() throws SqlConfigurationException, ConnectException {

    String sslConnectorSSLEnabled = properties.getProperty("sslConnector.SSLEnabled");

    if (sslConnectorSSLEnabled != null) {
        sslConnectorSSLEnabled = sslConnectorSSLEnabled.trim();
    }

    Connector sslConnector = null;

    // Do we have to add an SSL Connector?
    if (sslConnectorSSLEnabled == null || !sslConnectorSSLEnabled.trim().equals("true")) {
        return sslConnector;
    }

    // Ok, set the connector properties
    sslConnector = new Connector();

    // Scheme is mandatory
    String scheme = getMandatoryPropertyValue("sslConnector.scheme");
    if (!scheme.equals("https")) {
        throw new SqlConfigurationException(
                "The property sslConnector.https value must be \"https\" in properties file. "
                        + SqlTag.PLEASE_CORRECT);
    }

    String portStr = getMandatoryPropertyValue("sslConnector.port");

    int port = -1;
    try {
        port = Integer.parseInt(portStr);
    } catch (NumberFormatException e) {
        throw new SqlConfigurationException(
                "The property sslConnector.port is not numeric: " + portStr + " in properties file.");
    }

    if (!TomcatStarterUtil.available(port)) {
        throw new ConnectException("The port for SSL " + port + " is not available for starting Web server. "
                + SqlTag.PLEASE_CORRECT);
    }

    // Testing the keystore file
    String keyStoreFileStr = getMandatoryPropertyValue("sslConnector.keystoreFile");

    File keystoreFile = new File(keyStoreFileStr);
    if (!keystoreFile.exists()) {
        throw new SqlConfigurationException(
                "The file specified by sslConnector.keystoreFile property does not exists: " + keystoreFile
                        + ". " + SqlTag.PLEASE_CORRECT);
    }

    // Testing taht keystore & keyPass password are set
    @SuppressWarnings("unused")
    String keystorePass = getMandatoryPropertyValue("sslConnector.keystorePass");
    @SuppressWarnings("unused")
    String keyPass = getMandatoryPropertyValue("sslConnector.keyPass");

    sslConnector.setScheme(scheme);
    sslConnector.setPort(port);
    sslConnector.setSecure(true);

    // Set the SSL connector
    Enumeration<?> enumeration = properties.propertyNames();

    if (enumeration.hasMoreElements()) {
        System.out.println(SqlTag.SQL_PRODUCT_START + " Setting SSL Connector attribute values:");
    }

    while (enumeration.hasMoreElements()) {
        String property = (String) enumeration.nextElement();

        if (property.startsWith("sslConnector.") && !property.equals("sslConnector.scheme")
                && !property.equals("sslConnector.port")) {

            String theValue = properties.getProperty(property);
            String tomcatProperty = StringUtils.substringAfter(property, "sslConnector.");

            if (theValue != null && !theValue.isEmpty()) {

                theValue = theValue.trim();
                sslConnector.setProperty(tomcatProperty, theValue);

                if (property.equals("sslConnector.keyPass") || property.equals("sslConnector.keystorePass")) {
                    theValue = TomcatStarter.MASKED_PASSWORD;
                }

                System.out.println(SqlTag.SQL_PRODUCT_START + "  -> " + tomcatProperty + " = " + theValue);

            }
        }
    }

    Service service = tomcat.getService();
    service.addConnector(sslConnector); // Add the connector

    return sslConnector;

}

From source file:org.kawanfw.sql.transport.TransportConverter.java

/**
 * Transform a byte [] transported in hex prefixed by "**!kawanfw_bytes!**"
 * to it's orginal byte []//w  w  w.  jav a 2s. com
 * 
 * @param string
 *            the string that contains the bytes prefixed by
 *            "**!kawanfw_bytes!**"
 * @return the bytes
 */
public static byte[] fromTransportFormatToBytes(String string) {
    String encodedString = StringUtils.substringAfter(string, KAWANFW_BYTES);

    if (encodedString.equals("null")) {
        return null;
    }

    try {
        byte[] bytes = Base64.base64ToByteArray(encodedString);
        return bytes;
    } catch (Exception e) {
        throw new IllegalArgumentException(
                Tag.PRODUCT_PRODUCT_FAIL + "String is not in BASE64 format: " + encodedString, e);
    }

}

From source file:org.kawanfw.sql.transport.UrlTransporter.java

/**
 * Transforms a serialized Base 64 String to an URL .
 * /*from w  ww  .j a v a2s  . c om*/
 * @param s
 *            a serialized URL in Base64 format
 * @return the rebuilt URL
 * @throws IOException
 * @throws ClassNotFoundException
 */
public URL fromBase64(String s) throws IOException, ClassNotFoundException {

    s = StringUtils.substringAfter(s, URL_HEADER);

    byte[] byteArray = Base64.base64ToByteArray(s);
    ByteArrayInputStream bis = new ByteArrayInputStream(byteArray);

    ObjectInputStream ois = new ObjectInputStream(bis);

    URL url = null;
    try {
        url = (URL) ois.readObject();
        return url;
    } finally {
        if (ois != null) {
            ois.close();
        }
    }
}

From source file:org.kawanfw.sql.util.crypto.CallableStatementHolderCrypto.java

/**
 * Encrypt the CallableStatementHolder/*from  w w w  . j av  a 2 s . c o  m*/
 * 
 * @param mode
 * @throws Exception
 */
private void cipher(int mode) throws Exception {
    if (mode != Cipher.ENCRYPT_MODE && mode != Cipher.DECRYPT_MODE) {
        throw new IllegalArgumentException("Invalid Cipher Mode: " + mode);
    }

    String sqlOrder = this.callableStatementHolder.getSqlOrder();

    // do nothing on empty sql order
    if (sqlOrder == null || sqlOrder.isEmpty()) {
        return;
    }

    Pbe pbe = new Pbe();
    if (mode == Cipher.ENCRYPT_MODE) {
        // Need to re-Html Convert sqlOrder
        sqlOrder = HtmlConverter.toHtml(sqlOrder);
        sqlOrder = pbe.encryptToHexa(sqlOrder, password);
        this.callableStatementHolder.setSqlOrder(Pbe.KAWANFW_ENCRYPTED + sqlOrder);

    } else {

        if (sqlOrder.startsWith(Pbe.KAWANFW_ENCRYPTED)) {
            sqlOrder = StringUtils.substringAfter(sqlOrder, Pbe.KAWANFW_ENCRYPTED);
            sqlOrder = pbe.decryptFromHexa(sqlOrder, password);
            this.callableStatementHolder.setSqlOrder(sqlOrder);
        } else {
            return; // do nothing if it was not encrypted at start
        }
    }

    if (callableStatementHolder.isParamatersEncrypted()) {
        Map<Integer, String> parmValues = this.callableStatementHolder.getParameterStringValues();

        Set<Integer> keys = parmValues.keySet();

        for (Iterator<Integer> iterator = keys.iterator(); iterator.hasNext();) {
            Integer key = iterator.next();
            String value = parmValues.get(key);

            if (value != null) {

                if (mode == Cipher.ENCRYPT_MODE) {
                    value = pbe.encryptToHexa(value, password);
                } else {
                    value = pbe.decryptFromHexa(value, password);
                }

                // This will automatically refresh the inside value
                parmValues.put(key, value);
            }

        }
    }

}

From source file:org.kawanfw.sql.util.crypto.StatementHolderCrypto.java

/**
 * Encrypt the StatementHolder//from   ww  w  . j av  a 2  s.  c om
 * 
 * @param mode
 * @throws Exception
 */
private void cipher(int mode) throws Exception {
    if (mode != Cipher.ENCRYPT_MODE && mode != Cipher.DECRYPT_MODE) {
        throw new IllegalArgumentException("Invalid Cipher Mode: " + mode);
    }

    String sqlOrder = this.statementHolder.getSqlOrder();

    // do nothing on empty sql order
    if (sqlOrder == null || sqlOrder.isEmpty()) {
        return;
    }

    Pbe pbe = new Pbe();
    if (mode == Cipher.ENCRYPT_MODE) {
        // Need to re-Html Convert sqlOrder
        sqlOrder = HtmlConverter.toHtml(sqlOrder);
        sqlOrder = pbe.encryptToHexa(sqlOrder, password);
        this.statementHolder.setSqlOrder(Pbe.KAWANFW_ENCRYPTED + sqlOrder);

    } else {

        if (sqlOrder.startsWith(Pbe.KAWANFW_ENCRYPTED)) {
            sqlOrder = StringUtils.substringAfter(sqlOrder, Pbe.KAWANFW_ENCRYPTED);
            sqlOrder = pbe.decryptFromHexa(sqlOrder, password);
            this.statementHolder.setSqlOrder(sqlOrder);
        } else {
            return; // do nothing if it was not encrypted at start
        }
    }

    if (statementHolder.isParamatersEncrypted()) {
        Map<Integer, String> parmValues = this.statementHolder.getParameterStringValues();

        Set<Integer> keys = parmValues.keySet();

        for (Iterator<Integer> iterator = keys.iterator(); iterator.hasNext();) {
            Integer key = iterator.next();
            String value = parmValues.get(key);

            if (value != null) {

                if (mode == Cipher.ENCRYPT_MODE) {
                    value = pbe.encryptToHexa(value, password);
                } else {
                    value = pbe.decryptFromHexa(value, password);
                }

                // This will automatically refresh the inside value
                parmValues.put(key, value);
            }

        }
    }

}

From source file:org.kawanfw.sql.util.FileNameFromBlobBuilder.java

/**
 * Returns the table name in use type from a DML SQL order.
 * //from w w w.j  ava 2  s .c om
 * @param statementType
 *            the statement type (INSERT, ...)
 * @param sql
 *            the sql order
 * 
 * @return the table name in use (the first one in a <code>SELECT</code>
 *         statement) for a DML statement. Returns null if statement is not
 *         DML.
 */
private String getTableNameFromDmlStatement(String statementType, String sql) throws IllegalArgumentException {
    // Extract the first order
    String statementTypeUpper = statementType.toUpperCase();

    String sqlUpper = sql.toUpperCase();

    // Extract the table depending on the ordOer
    sqlUpper = StringUtils.substringAfter(sqlUpper, statementTypeUpper);
    sqlUpper = sqlUpper.trim();

    String table = null;

    if (statementTypeUpper.equals(INSERT)) {
        sqlUpper = StringUtils.substringAfter(sqlUpper, "INTO ");
        sqlUpper = sqlUpper.trim();
        table = StringUtils.substringBefore(sqlUpper, " ");
    } else if (statementTypeUpper.equals(SELECT) || statementTypeUpper.equals(DELETE)) {
        sqlUpper = StringUtils.substringAfter(sqlUpper, "FROM ");
        sqlUpper = sqlUpper.trim();
        // Remove commas in the statement and replace with blanks in case we
        // have
        // a join: "TABLE," ==> "TABLE "
        sqlUpper = sqlUpper.replaceAll(",", " ");
        table = StringUtils.substringBefore(sqlUpper, BLANK);
    } else if (statementTypeUpper.equals(UPDATE)) {
        // debug("sqlLocal :" + sqlUpper + ":");
        table = StringUtils.substringBefore(sqlUpper, BLANK);
    } else {
        return null; // No table
    }

    if (table != null) {
        table = table.trim();
    }

    // Return the part after last dot
    if (table.contains(".")) {
        table = StringUtils.substringAfterLast(table, ".");
    }

    table = table.replace("\'", "");
    table = table.replace("\"", "");

    return table;
}

From source file:org.kawanfw.sql.util.JdbcUrlHeader.java

/**
 * Returns the HTTP URL/*from   ww  w . ja v  a 2s  . c  o  m*/
 * 
 * @param url
 *            the JDBC URL with maybe "jdbc:aceql:" header
 * @return the pure HTTP URL
 */
public static String getUrlHttpOnly(String url) {

    if (url == null) {
        throw new IllegalArgumentException("url is null!");
    }

    String urlHttpOnly = url;
    if (url.startsWith(JDBC_URL_HEADER)) {
        urlHttpOnly = StringUtils.substringAfter(url, JDBC_URL_HEADER);
    }
    return urlHttpOnly;
}

From source file:org.kawanfw.test.api.client.CallTest.java

public void test(Connection connection) throws Exception {

    MessageDisplayer.initClassDisplay(this.getClass().getSimpleName());

    if (!(connection instanceof RemoteConnection)) {
        MessageDisplayer.display("CallTest not called because Connection is local.");
        return;/*from   w  ww .  j a v  a2s  .  c o m*/
    }

    // Don't do it with default configurators of AceQL Web Server
    String url = ((RemoteConnection) connection).getUrl();
    if (url.contains(":9090")) {
        MessageDisplayer.display("Test not done with AceQL Web Server.");
        return;
    }

    RemoteConnection remoteConnection = (RemoteConnection) connection;
    RemoteSession remoteSession = remoteConnection.getRemoteSession();

    int a = 33;
    int b = 44;

    String resultStr = remoteSession.call("org.kawanfw.test.api.server.CalculatorNotAuthenticated.add", a, b);
    int result = Integer.parseInt(resultStr);

    MessageDisplayer.display("CalculatorNotAuthenticated Result: " + result);

    Assert.assertEquals(a + b, result);

    SessionParameters sessionParameters = new SessionParameters();
    sessionParameters.setAcceptAllSslCertificates(true);

    String callUrl = SqlTestParms.ACEQL_URL;
    callUrl = StringUtils.substringAfter(callUrl, JdbcUrlHeader.JDBC_URL_HEADER);

    remoteSession = new RemoteSession(callUrl, SqlTestParms.REMOTE_USER,
            SqlTestParms.REMOTE_PASSWORD.toCharArray(), null, null, sessionParameters);

    resultStr = remoteSession.call("org.kawanfw.test.api.server.Calculator.add", a, b);
    result = Integer.parseInt(resultStr);

    MessageDisplayer.display("Calculator Result: " + result);

    Assert.assertEquals(a + b, result);

}

From source file:org.kawanfw.test.parms.ProxyLoader.java

public Proxy getProxy() throws IOException, URISyntaxException {
    if (FrameworkSystemUtil.isAndroid()) {
        return null;
    }/*from w  ww.j  av a  2 s .  co m*/

    System.setProperty("java.net.useSystemProxies", "true");
    List<Proxy> proxies = ProxySelector.getDefault().select(new URI("http://www.google.com/"));

    if (proxies != null && proxies.size() >= 1) {
        System.out.println("Loading proxy file info...");

        if (proxies.get(0).type().equals(Proxy.Type.DIRECT)) {
            return null;
        }

        File file = new File(NEOTUNNEL_TXT);
        if (file.exists()) {
            String proxyValues = FileUtils.readFileToString(file);
            String username = StringUtils.substringBefore(proxyValues, " ");
            String password = StringUtils.substringAfter(proxyValues, " ");

            username = username.trim();
            password = password.trim();

            proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("localhost", 8080));

            passwordAuthentication = new PasswordAuthentication(username, password.toCharArray());

            System.out.println("USING PROXY WITH AUTHENTICATION: " + proxy + " / " + username + " " + password);
        } else {
            throw new FileNotFoundException("proxy values not found. No file " + file);
        }
    }

    return proxy;
}