Search in sources :

Example 1 with Property

use of org.apache.logging.log4j.core.config.Property in project logging-log4j2 by apache.

the class FlumeEmbeddedManager method getManager.

/**
     * Returns a FlumeEmbeddedManager.
     * @param name The name of the manager.
     * @param agents The agents to use.
     * @param properties Properties for the embedded manager.
     * @param batchSize The number of events to include in a batch.
     * @param dataDir The directory where the Flume FileChannel should write to.
     * @return A FlumeAvroManager.
     */
public static FlumeEmbeddedManager getManager(final String name, final Agent[] agents, final Property[] properties, int batchSize, final String dataDir) {
    if (batchSize <= 0) {
        batchSize = 1;
    }
    if ((agents == null || agents.length == 0) && (properties == null || properties.length == 0)) {
        throw new IllegalArgumentException("Either an Agent or properties are required");
    } else if (agents != null && agents.length > 0 && properties != null && properties.length > 0) {
        throw new IllegalArgumentException("Cannot configure both Agents and Properties.");
    }
    final StringBuilder sb = new StringBuilder();
    boolean first = true;
    if (agents != null && agents.length > 0) {
        sb.append(name).append('[');
        for (final Agent agent : agents) {
            if (!first) {
                sb.append('_');
            }
            sb.append(agent.getHost()).append('-').append(agent.getPort());
            first = false;
        }
        sb.append(']');
    } else {
        String sep = Strings.EMPTY;
        sb.append(name).append('-');
        final StringBuilder props = new StringBuilder();
        for (final Property prop : properties) {
            props.append(sep);
            props.append(prop.getName()).append('=').append(prop.getValue());
            sep = "_";
        }
        sb.append(NameUtil.md5(props.toString()));
    }
    return getManager(sb.toString(), factory, new FactoryData(name, agents, properties, batchSize, dataDir));
}
Also used : EmbeddedAgent(org.apache.flume.agent.embedded.EmbeddedAgent) Property(org.apache.logging.log4j.core.config.Property)

Example 2 with Property

use of org.apache.logging.log4j.core.config.Property in project logging-log4j2 by apache.

the class DriverManagerH2ConnectionSourceTest method testH2Properties.

@Test
public void testH2Properties() throws SQLException {
    final Property[] properties = new Property[] { // @formatter:off
    Property.createProperty("username", JdbcH2TestHelper.USER_NAME), Property.createProperty("password", JdbcH2TestHelper.PASSWORD) // @formatter:on
    };
    // @formatter:off
    final DriverManagerConnectionSource source = DriverManagerConnectionSource.newBuilder().setConnectionString(JdbcH2TestHelper.CONNECTION_STRING_IN_MEMORY).setProperties(properties).build();
    // @formatter:on
    try (Connection conn = source.getConnection()) {
        Assert.assertFalse(conn.isClosed());
    }
}
Also used : Connection(java.sql.Connection) Property(org.apache.logging.log4j.core.config.Property) Test(org.junit.Test)

Example 3 with Property

use of org.apache.logging.log4j.core.config.Property in project logging-log4j2 by apache.

the class KafkaManager method getManager.

public static KafkaManager getManager(final LoggerContext loggerContext, final String name, final String topic, final boolean syncSend, final boolean sendTimestamp, final Property[] properties, final String key, final String retryCount) {
    StringBuilder sb = new StringBuilder(name);
    sb.append(" ").append(topic).append(" ").append(syncSend + "");
    for (Property prop : properties) {
        sb.append(" ").append(prop.getName()).append("=").append(prop.getValue());
    }
    return getManager(sb.toString(), factory, new FactoryData(loggerContext, topic, syncSend, sendTimestamp, properties, key, retryCount));
}
Also used : Property(org.apache.logging.log4j.core.config.Property)

Example 4 with Property

use of org.apache.logging.log4j.core.config.Property in project logging-log4j2 by apache.

the class HttpURLConnectionManager method send.

@Override
public void send(final Layout<?> layout, final LogEvent event) throws IOException {
    final HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
    urlConnection.setAllowUserInteraction(false);
    urlConnection.setDoOutput(true);
    urlConnection.setDoInput(true);
    urlConnection.setRequestMethod(method);
    if (connectTimeoutMillis > 0) {
        urlConnection.setConnectTimeout(connectTimeoutMillis);
    }
    if (readTimeoutMillis > 0) {
        urlConnection.setReadTimeout(readTimeoutMillis);
    }
    if (layout.getContentType() != null) {
        urlConnection.setRequestProperty("Content-Type", layout.getContentType());
    }
    for (final Property header : headers) {
        urlConnection.setRequestProperty(header.getName(), header.isValueNeedsLookup() ? getConfiguration().getStrSubstitutor().replace(event, header.getValue()) : header.getValue());
    }
    if (sslConfiguration != null) {
        ((HttpsURLConnection) urlConnection).setSSLSocketFactory(sslConfiguration.getSslSocketFactory());
    }
    if (isHttps && !verifyHostname) {
        ((HttpsURLConnection) urlConnection).setHostnameVerifier(LaxHostnameVerifier.INSTANCE);
    }
    final byte[] msg = layout.toByteArray(event);
    urlConnection.setFixedLengthStreamingMode(msg.length);
    urlConnection.connect();
    try (final OutputStream os = urlConnection.getOutputStream()) {
        os.write(msg);
    }
    final byte[] buffer = new byte[1024];
    try (final InputStream is = urlConnection.getInputStream()) {
        while (IOUtils.EOF != is.read(buffer)) {
        // empty
        }
    } catch (final IOException e) {
        final StringBuilder errorMessage = new StringBuilder();
        try (final InputStream es = urlConnection.getErrorStream()) {
            errorMessage.append(urlConnection.getResponseCode());
            if (urlConnection.getResponseMessage() != null) {
                errorMessage.append(' ').append(urlConnection.getResponseMessage());
            }
            if (es != null) {
                errorMessage.append(" - ");
                int n;
                while (IOUtils.EOF != (n = es.read(buffer))) {
                    errorMessage.append(new String(buffer, 0, n, CHARSET));
                }
            }
        }
        if (urlConnection.getResponseCode() > -1) {
            throw new IOException(errorMessage.toString());
        } else {
            throw e;
        }
    }
}
Also used : HttpURLConnection(java.net.HttpURLConnection) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) IOException(java.io.IOException) Property(org.apache.logging.log4j.core.config.Property) HttpsURLConnection(javax.net.ssl.HttpsURLConnection)

Example 5 with Property

use of org.apache.logging.log4j.core.config.Property in project logging-log4j2 by apache.

the class FlumeEmbeddedManager method createManagerName.

private static String createManagerName(final String name, final Agent[] agents, final Property[] properties) {
    final StringBuilder sb = new StringBuilder();
    boolean first = true;
    if (agents != null && agents.length > 0) {
        sb.append(name).append('[');
        for (final Agent agent : agents) {
            if (!first) {
                sb.append('_');
            }
            sb.append(agent.getHost()).append('-').append(agent.getPort());
            first = false;
        }
        sb.append(']');
    } else {
        String sep = Strings.EMPTY;
        sb.append(name).append('-');
        final StringBuilder props = new StringBuilder();
        for (final Property prop : properties) {
            props.append(sep);
            props.append(prop.getName()).append('=').append(prop.getValue());
            sep = "_";
        }
        sb.append(NameUtil.md5(props.toString()));
    }
    return sb.toString();
}
Also used : EmbeddedAgent(org.apache.flume.agent.embedded.EmbeddedAgent) Property(org.apache.logging.log4j.core.config.Property)

Aggregations

Property (org.apache.logging.log4j.core.config.Property)18 HashMap (java.util.HashMap)3 LoggerConfig (org.apache.logging.log4j.core.config.LoggerConfig)3 StringMap (org.apache.logging.log4j.util.StringMap)3 Map (java.util.Map)2 EmbeddedAgent (org.apache.flume.agent.embedded.EmbeddedAgent)2 LoggerContext (org.apache.logging.log4j.core.LoggerContext)2 AppenderRef (org.apache.logging.log4j.core.config.AppenderRef)2 Configuration (org.apache.logging.log4j.core.config.Configuration)2 Test (org.junit.Test)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 HttpURLConnection (java.net.HttpURLConnection)1 URL (java.net.URL)1 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 HttpsURLConnection (javax.net.ssl.HttpsURLConnection)1 ConnectionFactory (org.apache.commons.dbcp2.ConnectionFactory)1