List of usage examples for java.util Properties put
@Override public synchronized Object put(Object key, Object value)
From source file:io.amient.examples.wikipedia.WikipediaStreamDemo.java
private static KafkaStreams createWikipediaStreamsInstance(String bootstrapServers) { final Serializer<JsonNode> jsonSerializer = new JsonSerializer(); final Deserializer<JsonNode> jsonDeserializer = new JsonDeserializer(); final Serde<JsonNode> jsonSerde = Serdes.serdeFrom(jsonSerializer, jsonDeserializer); KStreamBuilder builder = new KStreamBuilder(); Properties props = new Properties(); props.put(StreamsConfig.APPLICATION_ID_CONFIG, "wikipedia-streams"); props.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers); KStream<JsonNode, JsonNode> wikipediaRaw = builder.stream(jsonSerde, jsonSerde, "wikipedia-raw"); KStream<String, WikipediaMessage> wikipediaParsed = wikipediaRaw.map(WikipediaMessage::parceIRC) .filter(WikipediaMessage::filterNonNull) .through(Serdes.String(), new JsonPOJOSerde<>(WikipediaMessage.class), "wikipedia-parsed"); KTable<String, Long> totalEditsByUser = wikipediaParsed .filter((key, value) -> value.type == WikipediaMessage.Type.EDIT) .countByKey(Serdes.String(), "wikipedia-edits-by-user"); //some print/* w w w . jav a 2 s .co m*/ totalEditsByUser.toStream().process(() -> new AbstractProcessor<String, Long>() { @Override public void process(String user, Long numEdits) { System.out.println("USER: " + user + " num.edits: " + numEdits); } }); return new KafkaStreams(builder, props); }
From source file:Main.java
static Properties convertResourceBundleToProperties(ResourceBundle resource) { Properties properties = new Properties(); Enumeration<String> keys = resource.getKeys(); while (keys.hasMoreElements()) { String key = keys.nextElement(); properties.put(key, resource.getString(key)); }//w w w . java2 s . c om return properties; }
From source file:com.ieprofile.helper.gmail.OAuth2Authenticator.java
/** * Connects and authenticates to an SMTP server with OAuth2. You must have * called {@code initialize}./* ww w . j a va 2 s .c o m*/ * * @param host Hostname of the smtp server, for example {@code * smtp.googlemail.com}. * @param port Port of the smtp server, for example 587. * @param userEmail Email address of the user to authenticate, for example * {@code oauth@gmail.com}. * @param oauthToken The user's OAuth token. * @param debug Whether to enable debug logging on the connection. * * @return An authenticated SMTPTransport that can be used for SMTP * operations. */ public static SMTPTransport connectToSmtp(String host, int port, String userEmail, String oauthToken, boolean debug) throws Exception { Properties props = new Properties(); props.put("mail.smtp.starttls.enable", "true"); props.put("mail.smtp.starttls.required", "true"); props.put("mail.smtp.sasl.enable", "true"); props.put("mail.smtp.sasl.mechanisms", "XOAUTH2"); props.put(OAuth2SaslClientFactory.OAUTH_TOKEN_PROP, oauthToken); Session session = Session.getInstance(props); session.setDebug(debug); final URLName unusedUrlName = null; SMTPTransport transport = new SMTPTransport(session, unusedUrlName); // If the password is non-null, SMTP tries to do AUTH LOGIN. final String emptyPassword = ""; transport.connect(host, port, userEmail, emptyPassword); return transport; }
From source file:com.rdonasco.security.utils.EncryptionUtil.java
private static void generateEncryptedPassword(String propsFile, String outFile) throws Exception { FileInputStream fis = null;/*from w ww . j av a2 s . com*/ FileOutputStream fos = null; try { fis = new FileInputStream(new File(propsFile)); Properties props = new Properties(); props.load(fis); String stringToEncrypt = props.getProperty("password"); String passphrase = props.getProperty("passphrase"); System.out.println("passphrase:<" + passphrase + ">"); System.out.println("encrypting " + stringToEncrypt); String encrypted = EncryptionUtil.encryptWithPassword(stringToEncrypt, passphrase); System.out.println("encrypted:" + encrypted); String decrypted = EncryptionUtil.decryptWithPassword(encrypted, passphrase); System.out.println("decrypted:" + decrypted); if (!stringToEncrypt.equals(decrypted)) { throw new Exception( "password cannot be decrypted properly, please choose another password or change passphrase."); } Properties keyProperties = new Properties(); keyProperties.put("encrypted", encrypted); fos = new FileOutputStream(new File(outFile)); keyProperties.store(fos, "last updated " + new SimpleDateFormat("dd/MMM/yyyy HH:mm:ss").format(new Date())); } finally { if (null != fis) { try { fis.close(); } catch (IOException ex) { LOG.log(Level.SEVERE, ex.getMessage(), ex); } } if (null != fos) { try { fos.close(); } catch (IOException ex) { LOG.log(Level.SEVERE, ex.getMessage(), ex); } } } }
From source file:Main.java
/** * Returns properties for non XA datasource * * @param jndiName/*from ww w. ja va 2 s . c o m*/ */ public static Properties nonXaDsProperties(String jndiName, boolean userName) { Properties params = commonDsProperties(jndiName, userName); //attributes params.put("jta", "false"); //common params.put("driver-class", "org.hsqldb.jdbcDriver"); params.put("datasource-class", "org.jboss.as.connector.subsystems.datasources.ModifiableDataSource"); params.put("connection-url", "jdbc:h2:mem:test;DB_CLOSE_DELAY=-1"); return params; }
From source file:Main.java
public static String map2Xml(Map<String, String> content, String root_elem_id, String item_elem_id) throws Exception { DocumentBuilder b = documentBuilder(); Document doc = b.newDocument(); String str = null;/* ww w.j a va 2s.c o m*/ SAXTransformerFactory tf = (SAXTransformerFactory) SAXTransformerFactory.newInstance(); ByteArrayOutputStream out = new ByteArrayOutputStream(); Element root = doc.createElement(root_elem_id); doc.appendChild(root); // Now, add all the children for (Entry<String, String> e : content.entrySet()) { Element item = doc.createElement(item_elem_id); item.setAttribute("id", e.getKey()); CDATASection data = doc.createCDATASection(e.getValue()); item.appendChild(data); root.appendChild(item); } try { DOMSource ds = new DOMSource(doc); StreamResult sr = new StreamResult(out); TransformerHandler th = tf.newTransformerHandler(); th.getTransformer().setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); Properties format = new Properties(); format.put(OutputKeys.METHOD, "xml"); // format.put("{http://xml. customer .org/xslt}indent-amount", "4"); // format.put("indent-amount", "4"); // format.put(OutputKeys.DOCTYPE_SYSTEM, "myfile.dtd"); format.put(OutputKeys.ENCODING, "UTF-8"); format.put(OutputKeys.INDENT, "yes"); th.getTransformer().setOutputProperties(format); th.setResult(sr); th.getTransformer().transform(ds, sr); str = out.toString(); } catch (Exception e) { e.printStackTrace(); } return str; }
From source file:io.amient.examples.TwitterStreamDemo.java
private static ConnectEmbedded createTwitterSourceConnectInstance(String bootstrapServers) throws Exception { Properties workerProps = new Properties(); workerProps.put(DistributedConfig.GROUP_ID_CONFIG, "twitter-connect"); workerProps.put(DistributedConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers); workerProps.put(DistributedConfig.OFFSET_STORAGE_TOPIC_CONFIG, "connect-offsets"); workerProps.put(DistributedConfig.CONFIG_TOPIC_CONFIG, "connect-configs"); workerProps.put(DistributedConfig.STATUS_STORAGE_TOPIC_CONFIG, "connect-status"); workerProps.put(DistributedConfig.KEY_CONVERTER_CLASS_CONFIG, "org.apache.kafka.connect.json.JsonConverter"); workerProps.put("key.converter.schemas.enable", "false"); workerProps.put(DistributedConfig.VALUE_CONVERTER_CLASS_CONFIG, "org.apache.kafka.connect.json.JsonConverter"); workerProps.put("value.converter.schemas.enable", "false"); workerProps.put(DistributedConfig.OFFSET_COMMIT_INTERVAL_MS_CONFIG, "30000"); workerProps.put(DistributedConfig.INTERNAL_KEY_CONVERTER_CLASS_CONFIG, "org.apache.kafka.connect.json.JsonConverter"); workerProps.put("internal.key.converter.schemas.enable", "false"); workerProps.put(DistributedConfig.INTERNAL_VALUE_CONVERTER_CLASS_CONFIG, "org.apache.kafka.connect.json.JsonConverter"); workerProps.put("internal.value.converter.schemas.enable", "false"); Properties connectorProps = new Properties(); connectorProps.put(ConnectorConfig.NAME_CONFIG, "twitter-source"); connectorProps.put(ConnectorConfig.CONNECTOR_CLASS_CONFIG, "example.TwitterSourceConnector"); connectorProps.put(ConnectorConfig.TASKS_MAX_CONFIG, "1"); connectorProps.put(TwitterSourceConfig.CONSUMER_KEY_CONFIG(), "*****"); connectorProps.put(TwitterSourceConfig.CONSUMER_SECRET_CONFIG(), "*****"); connectorProps.put(TwitterSourceConfig.TOKEN_CONFIG(), "*****"); connectorProps.put(TwitterSourceConfig.SECRET_CONFIG(), "*****"); connectorProps.put(TwitterSourceConfig.TOPIC_CONFIG(), "twitter"); return new ConnectEmbedded(workerProps, connectorProps); }
From source file:org.eclipse.dirigible.cli.utils.Utils.java
public static Properties loadCLIProperties(String[] args) { Properties propeties = new Properties(); for (String next : args) { String[] properties = next.split(SPLITTER); propeties.put(properties[0], properties[1]); }//from w w w . j av a 2 s .c om return propeties; }
From source file:com.linkedin.kafka.clients.utils.tests.KafkaTestUtils.java
public static KafkaConsumer<String, String> vanillaConsumerFor(EmbeddedBroker broker) { String bootstrap = broker.getPlaintextAddr(); if (bootstrap == null) { bootstrap = broker.getSslAddr(); }//from w ww .j a va 2 s. c om Properties props = new Properties(); props.put("bootstrap.servers", bootstrap); props.put("group.id", "test"); props.put("auto.offset.reset", "earliest"); props.put("enable.auto.commit", "false"); props.put("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer"); props.put("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer"); KafkaConsumer<String, String> consumer = new KafkaConsumer<>(props); return consumer; }
From source file:io.amient.examples.wikipedia.WikipediaStreamDemo.java
private static ConnectEmbedded createWikipediaFeedConnectInstance(String bootstrapServers) throws Exception { Properties workerProps = new Properties(); workerProps.put(DistributedConfig.GROUP_ID_CONFIG, "wikipedia-connect"); workerProps.put(DistributedConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers); workerProps.put(DistributedConfig.OFFSET_STORAGE_TOPIC_CONFIG, "connect-offsets"); workerProps.put(DistributedConfig.CONFIG_TOPIC_CONFIG, "connect-configs"); workerProps.put(DistributedConfig.STATUS_STORAGE_TOPIC_CONFIG, "connect-status"); workerProps.put(DistributedConfig.KEY_CONVERTER_CLASS_CONFIG, "org.apache.kafka.connect.json.JsonConverter"); workerProps.put("key.converter.schemas.enable", "false"); workerProps.put(DistributedConfig.VALUE_CONVERTER_CLASS_CONFIG, "org.apache.kafka.connect.json.JsonConverter"); workerProps.put("value.converter.schemas.enable", "false"); workerProps.put(DistributedConfig.OFFSET_COMMIT_INTERVAL_MS_CONFIG, "30000"); workerProps.put(DistributedConfig.INTERNAL_KEY_CONVERTER_CLASS_CONFIG, "org.apache.kafka.connect.json.JsonConverter"); workerProps.put("internal.key.converter.schemas.enable", "false"); workerProps.put(DistributedConfig.INTERNAL_VALUE_CONVERTER_CLASS_CONFIG, "org.apache.kafka.connect.json.JsonConverter"); workerProps.put("internal.value.converter.schemas.enable", "false"); Properties connectorProps = new Properties(); connectorProps.put(ConnectorConfig.NAME_CONFIG, "wikipedia-irc-source"); connectorProps.put(ConnectorConfig.CONNECTOR_CLASS_CONFIG, "io.amient.kafka.connect.irc.IRCFeedConnector"); connectorProps.put(ConnectorConfig.TASKS_MAX_CONFIG, "10"); connectorProps.put(IRCFeedConnector.IRC_HOST_CONFIG, "irc.wikimedia.org"); connectorProps.put(IRCFeedConnector.IRC_PORT_CONFIG, "6667"); connectorProps.put(IRCFeedConnector.IRC_CHANNELS_CONFIG, "#en.wikipedia,#en.wiktionary,#en.wikinews"); connectorProps.put(IRCFeedConnector.TOPIC_CONFIG, "wikipedia-raw"); return new ConnectEmbedded(workerProps, connectorProps); }