http://git-wip-us.apache.org/repos/asf/nifi/blob/3a7ddc6a/nifi-bootstrap/src/main/java/org/apache/nifi/bootstrap/notification/email/EmailNotificationService.java ---------------------------------------------------------------------- diff --git a/nifi-bootstrap/src/main/java/org/apache/nifi/bootstrap/notification/email/EmailNotificationService.java b/nifi-bootstrap/src/main/java/org/apache/nifi/bootstrap/notification/email/EmailNotificationService.java index ce8bc0e..d6d876e 100644 --- a/nifi-bootstrap/src/main/java/org/apache/nifi/bootstrap/notification/email/EmailNotificationService.java +++ b/nifi-bootstrap/src/main/java/org/apache/nifi/bootstrap/notification/email/EmailNotificationService.java @@ -1,289 +1,289 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.nifi.bootstrap.notification.email; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.Map.Entry; - -import javax.mail.Authenticator; -import javax.mail.Message; -import javax.mail.MessagingException; -import javax.mail.PasswordAuthentication; -import javax.mail.Session; -import javax.mail.Transport; -import javax.mail.Message.RecipientType; -import javax.mail.internet.AddressException; -import javax.mail.internet.InternetAddress; -import javax.mail.internet.MimeMessage; -import org.apache.nifi.bootstrap.notification.AbstractNotificationService; -import org.apache.nifi.bootstrap.notification.NotificationContext; -import org.apache.nifi.bootstrap.notification.NotificationFailedException; -import org.apache.nifi.components.PropertyDescriptor; -import org.apache.nifi.components.ValidationContext; -import org.apache.nifi.components.ValidationResult; -import org.apache.nifi.processor.exception.ProcessException; -import org.apache.nifi.processor.util.StandardValidators; - -public class EmailNotificationService extends AbstractNotificationService { - - public static final PropertyDescriptor SMTP_HOSTNAME = new PropertyDescriptor.Builder() - .name("SMTP Hostname") - .description("The hostname of the SMTP Server that is used to send Email Notifications") - .addValidator(StandardValidators.NON_EMPTY_VALIDATOR) - .required(true) - .build(); - public static final PropertyDescriptor SMTP_PORT = new PropertyDescriptor.Builder() - .name("SMTP Port") - .description("The Port used for SMTP communications") - .required(true) - .defaultValue("25") - .expressionLanguageSupported(true) - .addValidator(StandardValidators.PORT_VALIDATOR) - .build(); - public static final PropertyDescriptor SMTP_USERNAME = new PropertyDescriptor.Builder() - .name("SMTP Username") - .description("Username for the SMTP account") - .expressionLanguageSupported(true) - .addValidator(StandardValidators.NON_EMPTY_VALIDATOR) - .required(false) - .build(); - public static final PropertyDescriptor SMTP_PASSWORD = new PropertyDescriptor.Builder() - .name("SMTP Password") - .description("Password for the SMTP account") - .expressionLanguageSupported(true) - .addValidator(StandardValidators.NON_EMPTY_VALIDATOR) - .required(false) - .sensitive(true) - .build(); - public static final PropertyDescriptor SMTP_AUTH = new PropertyDescriptor.Builder() - .name("SMTP Auth") - .description("Flag indicating whether authentication should be used") - .required(true) - .expressionLanguageSupported(true) - .addValidator(StandardValidators.BOOLEAN_VALIDATOR) - .defaultValue("true") - .build(); - public static final PropertyDescriptor SMTP_TLS = new PropertyDescriptor.Builder() - .name("SMTP TLS") - .description("Flag indicating whether TLS should be enabled") - .required(true) - .expressionLanguageSupported(true) - .addValidator(StandardValidators.BOOLEAN_VALIDATOR) - .defaultValue("false") - .build(); - public static final PropertyDescriptor SMTP_SOCKET_FACTORY = new PropertyDescriptor.Builder() - .name("SMTP Socket Factory") - .description("Socket Factory to use for SMTP Connection") - .required(true) - .expressionLanguageSupported(true) - .addValidator(StandardValidators.NON_EMPTY_VALIDATOR) - .defaultValue("javax.net.ssl.SSLSocketFactory") - .build(); - public static final PropertyDescriptor HEADER_XMAILER = new PropertyDescriptor.Builder() - .name("SMTP X-Mailer Header") - .description("X-Mailer used in the header of the outgoing email") - .required(true) - .expressionLanguageSupported(true) - .addValidator(StandardValidators.NON_EMPTY_VALIDATOR) - .defaultValue("NiFi") - .build(); - public static final PropertyDescriptor CONTENT_TYPE = new PropertyDescriptor.Builder() - .name("Content Type") - .description("Mime Type used to interpret the contents of the email, such as text/plain or text/html") - .required(true) - .expressionLanguageSupported(true) - .addValidator(StandardValidators.NON_EMPTY_VALIDATOR) - .defaultValue("text/plain") - .build(); - public static final PropertyDescriptor FROM = new PropertyDescriptor.Builder() - .name("From") - .description("Specifies the Email address to use as the sender") - .required(true) - .expressionLanguageSupported(true) - .addValidator(StandardValidators.NON_EMPTY_VALIDATOR) - .build(); - public static final PropertyDescriptor TO = new PropertyDescriptor.Builder() - .name("To") - .description("The recipients to include in the To-Line of the email") - .required(false) - .expressionLanguageSupported(true) - .addValidator(StandardValidators.NON_EMPTY_VALIDATOR) - .build(); - public static final PropertyDescriptor CC = new PropertyDescriptor.Builder() - .name("CC") - .description("The recipients to include in the CC-Line of the email") - .required(false) - .expressionLanguageSupported(true) - .addValidator(StandardValidators.NON_EMPTY_VALIDATOR) - .build(); - public static final PropertyDescriptor BCC = new PropertyDescriptor.Builder() - .name("BCC") - .description("The recipients to include in the BCC-Line of the email") - .required(false) - .expressionLanguageSupported(true) - .addValidator(StandardValidators.NON_EMPTY_VALIDATOR) - .build(); - - /** - * Mapping of the mail properties to the NiFi PropertyDescriptors that will be evaluated at runtime - */ - private static final Map<String, PropertyDescriptor> propertyToContext = new HashMap<>(); - - static { - propertyToContext.put("mail.smtp.host", SMTP_HOSTNAME); - propertyToContext.put("mail.smtp.port", SMTP_PORT); - propertyToContext.put("mail.smtp.socketFactory.port", SMTP_PORT); - propertyToContext.put("mail.smtp.socketFactory.class", SMTP_SOCKET_FACTORY); - propertyToContext.put("mail.smtp.auth", SMTP_AUTH); - propertyToContext.put("mail.smtp.starttls.enable", SMTP_TLS); - propertyToContext.put("mail.smtp.user", SMTP_USERNAME); - propertyToContext.put("mail.smtp.password", SMTP_PASSWORD); - } - - @Override - protected List<PropertyDescriptor> getSupportedPropertyDescriptors() { - final List<PropertyDescriptor> properties = new ArrayList<>(); - properties.add(SMTP_HOSTNAME); - properties.add(SMTP_PORT); - properties.add(SMTP_USERNAME); - properties.add(SMTP_PASSWORD); - properties.add(SMTP_AUTH); - properties.add(SMTP_TLS); - properties.add(SMTP_SOCKET_FACTORY); - properties.add(HEADER_XMAILER); - properties.add(CONTENT_TYPE); - properties.add(FROM); - properties.add(TO); - properties.add(CC); - properties.add(BCC); - return properties; - } - - @Override - protected Collection<ValidationResult> customValidate(final ValidationContext context) { - final List<ValidationResult> errors = new ArrayList<>(super.customValidate(context)); - - final String to = context.getProperty(TO).getValue(); - final String cc = context.getProperty(CC).getValue(); - final String bcc = context.getProperty(BCC).getValue(); - - if (to == null && cc == null && bcc == null) { - errors.add(new ValidationResult.Builder().subject("To, CC, BCC").valid(false).explanation("Must specify at least one To/CC/BCC address").build()); - } - - return errors; - } - - @Override - public void notify(final NotificationContext context, final String subject, final String messageText) throws NotificationFailedException { - final Properties properties = getMailProperties(context); - final Session mailSession = createMailSession(properties); - final Message message = new MimeMessage(mailSession); - - try { - message.setFrom(InternetAddress.parse(context.getProperty(FROM).evaluateAttributeExpressions().getValue())[0]); - - final InternetAddress[] toAddresses = toInetAddresses(context.getProperty(TO).evaluateAttributeExpressions().getValue()); - message.setRecipients(RecipientType.TO, toAddresses); - - final InternetAddress[] ccAddresses = toInetAddresses(context.getProperty(CC).evaluateAttributeExpressions().getValue()); - message.setRecipients(RecipientType.CC, ccAddresses); - - final InternetAddress[] bccAddresses = toInetAddresses(context.getProperty(BCC).evaluateAttributeExpressions().getValue()); - message.setRecipients(RecipientType.BCC, bccAddresses); - - message.setHeader("X-Mailer", context.getProperty(HEADER_XMAILER).evaluateAttributeExpressions().getValue()); - message.setSubject(subject); - - final String contentType = context.getProperty(CONTENT_TYPE).evaluateAttributeExpressions().getValue(); - message.setContent(messageText, contentType); - message.setSentDate(new Date()); - - Transport.send(message); - } catch (final ProcessException | MessagingException e) { - throw new NotificationFailedException("Failed to send E-mail Notification", e); - } - } - - /** - * Creates an array of 0 or more InternetAddresses for the given String - * - * @param val the String to parse for InternetAddresses - * @return an array of 0 or more InetAddresses - * @throws AddressException if val contains an invalid address - */ - private static InternetAddress[] toInetAddresses(final String val) throws AddressException { - if (val == null) { - return new InternetAddress[0]; - } - return InternetAddress.parse(val); - } - - /** - * Uses the mapping of javax.mail properties to NiFi PropertyDescriptors to build the required Properties object to be used for sending this email - * - * @param context context - * @return mail properties - */ - private Properties getMailProperties(final NotificationContext context) { - final Properties properties = new Properties(); - - for (Entry<String, PropertyDescriptor> entry : propertyToContext.entrySet()) { - // Evaluate the property descriptor against the flow file - String property = entry.getKey(); - String propValue = context.getProperty(entry.getValue()).evaluateAttributeExpressions().getValue(); - - // Nullable values are not allowed, so filter out - if (null != propValue) { - properties.setProperty(property, propValue); - } - } - - return properties; - } - - /** - * Based on the input properties, determine whether an authenticate or unauthenticated session should be used. If authenticated, creates a Password Authenticator for use in sending the email. - * - * @param properties mail properties - * @return session - */ - private Session createMailSession(final Properties properties) { - String authValue = properties.getProperty("mail.smtp.auth"); - Boolean auth = Boolean.valueOf(authValue); - - /* - * Conditionally create a password authenticator if the 'auth' parameter is set. - */ - final Session mailSession = auth ? Session.getInstance(properties, new Authenticator() { - @Override - public PasswordAuthentication getPasswordAuthentication() { - String username = properties.getProperty("mail.smtp.user"), password = properties.getProperty("mail.smtp.password"); - return new PasswordAuthentication(username, password); - } - }) : Session.getInstance(properties); // without auth - - return mailSession; - } - -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.nifi.bootstrap.notification.email; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.Map.Entry; + +import javax.mail.Authenticator; +import javax.mail.Message; +import javax.mail.MessagingException; +import javax.mail.PasswordAuthentication; +import javax.mail.Session; +import javax.mail.Transport; +import javax.mail.Message.RecipientType; +import javax.mail.internet.AddressException; +import javax.mail.internet.InternetAddress; +import javax.mail.internet.MimeMessage; +import org.apache.nifi.bootstrap.notification.AbstractNotificationService; +import org.apache.nifi.bootstrap.notification.NotificationContext; +import org.apache.nifi.bootstrap.notification.NotificationFailedException; +import org.apache.nifi.components.PropertyDescriptor; +import org.apache.nifi.components.ValidationContext; +import org.apache.nifi.components.ValidationResult; +import org.apache.nifi.processor.exception.ProcessException; +import org.apache.nifi.processor.util.StandardValidators; + +public class EmailNotificationService extends AbstractNotificationService { + + public static final PropertyDescriptor SMTP_HOSTNAME = new PropertyDescriptor.Builder() + .name("SMTP Hostname") + .description("The hostname of the SMTP Server that is used to send Email Notifications") + .addValidator(StandardValidators.NON_EMPTY_VALIDATOR) + .required(true) + .build(); + public static final PropertyDescriptor SMTP_PORT = new PropertyDescriptor.Builder() + .name("SMTP Port") + .description("The Port used for SMTP communications") + .required(true) + .defaultValue("25") + .expressionLanguageSupported(true) + .addValidator(StandardValidators.PORT_VALIDATOR) + .build(); + public static final PropertyDescriptor SMTP_USERNAME = new PropertyDescriptor.Builder() + .name("SMTP Username") + .description("Username for the SMTP account") + .expressionLanguageSupported(true) + .addValidator(StandardValidators.NON_EMPTY_VALIDATOR) + .required(false) + .build(); + public static final PropertyDescriptor SMTP_PASSWORD = new PropertyDescriptor.Builder() + .name("SMTP Password") + .description("Password for the SMTP account") + .expressionLanguageSupported(true) + .addValidator(StandardValidators.NON_EMPTY_VALIDATOR) + .required(false) + .sensitive(true) + .build(); + public static final PropertyDescriptor SMTP_AUTH = new PropertyDescriptor.Builder() + .name("SMTP Auth") + .description("Flag indicating whether authentication should be used") + .required(true) + .expressionLanguageSupported(true) + .addValidator(StandardValidators.BOOLEAN_VALIDATOR) + .defaultValue("true") + .build(); + public static final PropertyDescriptor SMTP_TLS = new PropertyDescriptor.Builder() + .name("SMTP TLS") + .description("Flag indicating whether TLS should be enabled") + .required(true) + .expressionLanguageSupported(true) + .addValidator(StandardValidators.BOOLEAN_VALIDATOR) + .defaultValue("false") + .build(); + public static final PropertyDescriptor SMTP_SOCKET_FACTORY = new PropertyDescriptor.Builder() + .name("SMTP Socket Factory") + .description("Socket Factory to use for SMTP Connection") + .required(true) + .expressionLanguageSupported(true) + .addValidator(StandardValidators.NON_EMPTY_VALIDATOR) + .defaultValue("javax.net.ssl.SSLSocketFactory") + .build(); + public static final PropertyDescriptor HEADER_XMAILER = new PropertyDescriptor.Builder() + .name("SMTP X-Mailer Header") + .description("X-Mailer used in the header of the outgoing email") + .required(true) + .expressionLanguageSupported(true) + .addValidator(StandardValidators.NON_EMPTY_VALIDATOR) + .defaultValue("NiFi") + .build(); + public static final PropertyDescriptor CONTENT_TYPE = new PropertyDescriptor.Builder() + .name("Content Type") + .description("Mime Type used to interpret the contents of the email, such as text/plain or text/html") + .required(true) + .expressionLanguageSupported(true) + .addValidator(StandardValidators.NON_EMPTY_VALIDATOR) + .defaultValue("text/plain") + .build(); + public static final PropertyDescriptor FROM = new PropertyDescriptor.Builder() + .name("From") + .description("Specifies the Email address to use as the sender") + .required(true) + .expressionLanguageSupported(true) + .addValidator(StandardValidators.NON_EMPTY_VALIDATOR) + .build(); + public static final PropertyDescriptor TO = new PropertyDescriptor.Builder() + .name("To") + .description("The recipients to include in the To-Line of the email") + .required(false) + .expressionLanguageSupported(true) + .addValidator(StandardValidators.NON_EMPTY_VALIDATOR) + .build(); + public static final PropertyDescriptor CC = new PropertyDescriptor.Builder() + .name("CC") + .description("The recipients to include in the CC-Line of the email") + .required(false) + .expressionLanguageSupported(true) + .addValidator(StandardValidators.NON_EMPTY_VALIDATOR) + .build(); + public static final PropertyDescriptor BCC = new PropertyDescriptor.Builder() + .name("BCC") + .description("The recipients to include in the BCC-Line of the email") + .required(false) + .expressionLanguageSupported(true) + .addValidator(StandardValidators.NON_EMPTY_VALIDATOR) + .build(); + + /** + * Mapping of the mail properties to the NiFi PropertyDescriptors that will be evaluated at runtime + */ + private static final Map<String, PropertyDescriptor> propertyToContext = new HashMap<>(); + + static { + propertyToContext.put("mail.smtp.host", SMTP_HOSTNAME); + propertyToContext.put("mail.smtp.port", SMTP_PORT); + propertyToContext.put("mail.smtp.socketFactory.port", SMTP_PORT); + propertyToContext.put("mail.smtp.socketFactory.class", SMTP_SOCKET_FACTORY); + propertyToContext.put("mail.smtp.auth", SMTP_AUTH); + propertyToContext.put("mail.smtp.starttls.enable", SMTP_TLS); + propertyToContext.put("mail.smtp.user", SMTP_USERNAME); + propertyToContext.put("mail.smtp.password", SMTP_PASSWORD); + } + + @Override + protected List<PropertyDescriptor> getSupportedPropertyDescriptors() { + final List<PropertyDescriptor> properties = new ArrayList<>(); + properties.add(SMTP_HOSTNAME); + properties.add(SMTP_PORT); + properties.add(SMTP_USERNAME); + properties.add(SMTP_PASSWORD); + properties.add(SMTP_AUTH); + properties.add(SMTP_TLS); + properties.add(SMTP_SOCKET_FACTORY); + properties.add(HEADER_XMAILER); + properties.add(CONTENT_TYPE); + properties.add(FROM); + properties.add(TO); + properties.add(CC); + properties.add(BCC); + return properties; + } + + @Override + protected Collection<ValidationResult> customValidate(final ValidationContext context) { + final List<ValidationResult> errors = new ArrayList<>(super.customValidate(context)); + + final String to = context.getProperty(TO).getValue(); + final String cc = context.getProperty(CC).getValue(); + final String bcc = context.getProperty(BCC).getValue(); + + if (to == null && cc == null && bcc == null) { + errors.add(new ValidationResult.Builder().subject("To, CC, BCC").valid(false).explanation("Must specify at least one To/CC/BCC address").build()); + } + + return errors; + } + + @Override + public void notify(final NotificationContext context, final String subject, final String messageText) throws NotificationFailedException { + final Properties properties = getMailProperties(context); + final Session mailSession = createMailSession(properties); + final Message message = new MimeMessage(mailSession); + + try { + message.setFrom(InternetAddress.parse(context.getProperty(FROM).evaluateAttributeExpressions().getValue())[0]); + + final InternetAddress[] toAddresses = toInetAddresses(context.getProperty(TO).evaluateAttributeExpressions().getValue()); + message.setRecipients(RecipientType.TO, toAddresses); + + final InternetAddress[] ccAddresses = toInetAddresses(context.getProperty(CC).evaluateAttributeExpressions().getValue()); + message.setRecipients(RecipientType.CC, ccAddresses); + + final InternetAddress[] bccAddresses = toInetAddresses(context.getProperty(BCC).evaluateAttributeExpressions().getValue()); + message.setRecipients(RecipientType.BCC, bccAddresses); + + message.setHeader("X-Mailer", context.getProperty(HEADER_XMAILER).evaluateAttributeExpressions().getValue()); + message.setSubject(subject); + + final String contentType = context.getProperty(CONTENT_TYPE).evaluateAttributeExpressions().getValue(); + message.setContent(messageText, contentType); + message.setSentDate(new Date()); + + Transport.send(message); + } catch (final ProcessException | MessagingException e) { + throw new NotificationFailedException("Failed to send E-mail Notification", e); + } + } + + /** + * Creates an array of 0 or more InternetAddresses for the given String + * + * @param val the String to parse for InternetAddresses + * @return an array of 0 or more InetAddresses + * @throws AddressException if val contains an invalid address + */ + private static InternetAddress[] toInetAddresses(final String val) throws AddressException { + if (val == null) { + return new InternetAddress[0]; + } + return InternetAddress.parse(val); + } + + /** + * Uses the mapping of javax.mail properties to NiFi PropertyDescriptors to build the required Properties object to be used for sending this email + * + * @param context context + * @return mail properties + */ + private Properties getMailProperties(final NotificationContext context) { + final Properties properties = new Properties(); + + for (Entry<String, PropertyDescriptor> entry : propertyToContext.entrySet()) { + // Evaluate the property descriptor against the flow file + String property = entry.getKey(); + String propValue = context.getProperty(entry.getValue()).evaluateAttributeExpressions().getValue(); + + // Nullable values are not allowed, so filter out + if (null != propValue) { + properties.setProperty(property, propValue); + } + } + + return properties; + } + + /** + * Based on the input properties, determine whether an authenticate or unauthenticated session should be used. If authenticated, creates a Password Authenticator for use in sending the email. + * + * @param properties mail properties + * @return session + */ + private Session createMailSession(final Properties properties) { + String authValue = properties.getProperty("mail.smtp.auth"); + Boolean auth = Boolean.valueOf(authValue); + + /* + * Conditionally create a password authenticator if the 'auth' parameter is set. + */ + final Session mailSession = auth ? Session.getInstance(properties, new Authenticator() { + @Override + public PasswordAuthentication getPasswordAuthentication() { + String username = properties.getProperty("mail.smtp.user"), password = properties.getProperty("mail.smtp.password"); + return new PasswordAuthentication(username, password); + } + }) : Session.getInstance(properties); // without auth + + return mailSession; + } + +}
http://git-wip-us.apache.org/repos/asf/nifi/blob/3a7ddc6a/nifi-commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/evaluation/literals/ToLiteralEvaluator.java ---------------------------------------------------------------------- diff --git a/nifi-commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/evaluation/literals/ToLiteralEvaluator.java b/nifi-commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/evaluation/literals/ToLiteralEvaluator.java index e297eea..ea683ad 100644 --- a/nifi-commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/evaluation/literals/ToLiteralEvaluator.java +++ b/nifi-commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/evaluation/literals/ToLiteralEvaluator.java @@ -1,43 +1,43 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.nifi.attribute.expression.language.evaluation.literals; - -import java.util.Map; - -import org.apache.nifi.attribute.expression.language.evaluation.Evaluator; -import org.apache.nifi.attribute.expression.language.evaluation.QueryResult; -import org.apache.nifi.attribute.expression.language.evaluation.StringEvaluator; -import org.apache.nifi.attribute.expression.language.evaluation.StringQueryResult; - -public class ToLiteralEvaluator extends StringEvaluator { - private final Evaluator<?> argEvaluator; - - public ToLiteralEvaluator(final Evaluator<?> argEvaluator) { - this.argEvaluator = argEvaluator; - } - - @Override - public QueryResult<String> evaluate(final Map<String, String> attributes) { - final Object result = argEvaluator.evaluate(attributes); - return new StringQueryResult(result == null ? null : result.toString()); - } - - @Override - public Evaluator<?> getSubjectEvaluator() { - return null; - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.nifi.attribute.expression.language.evaluation.literals; + +import java.util.Map; + +import org.apache.nifi.attribute.expression.language.evaluation.Evaluator; +import org.apache.nifi.attribute.expression.language.evaluation.QueryResult; +import org.apache.nifi.attribute.expression.language.evaluation.StringEvaluator; +import org.apache.nifi.attribute.expression.language.evaluation.StringQueryResult; + +public class ToLiteralEvaluator extends StringEvaluator { + private final Evaluator<?> argEvaluator; + + public ToLiteralEvaluator(final Evaluator<?> argEvaluator) { + this.argEvaluator = argEvaluator; + } + + @Override + public QueryResult<String> evaluate(final Map<String, String> attributes) { + final Object result = argEvaluator.evaluate(attributes); + return new StringQueryResult(result == null ? null : result.toString()); + } + + @Override + public Evaluator<?> getSubjectEvaluator() { + return null; + } +} http://git-wip-us.apache.org/repos/asf/nifi/blob/3a7ddc6a/nifi-commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/evaluation/selection/IteratingEvaluator.java ---------------------------------------------------------------------- diff --git a/nifi-commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/evaluation/selection/IteratingEvaluator.java b/nifi-commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/evaluation/selection/IteratingEvaluator.java index 5156345..f2e738a 100644 --- a/nifi-commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/evaluation/selection/IteratingEvaluator.java +++ b/nifi-commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/evaluation/selection/IteratingEvaluator.java @@ -1,33 +1,33 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.nifi.attribute.expression.language.evaluation.selection; - -import org.apache.nifi.attribute.expression.language.evaluation.Evaluator; - -/** - * Interface for an Evaluator that should be evaluated multiple times - * - * @param <T> return type of evaluator - */ -public interface IteratingEvaluator<T> extends Evaluator<T> { - - /** - * @return the evaluator that evaluates some sort of logic against its subject - */ - Evaluator<?> getLogicEvaluator(); - -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.nifi.attribute.expression.language.evaluation.selection; + +import org.apache.nifi.attribute.expression.language.evaluation.Evaluator; + +/** + * Interface for an Evaluator that should be evaluated multiple times + * + * @param <T> return type of evaluator + */ +public interface IteratingEvaluator<T> extends Evaluator<T> { + + /** + * @return the evaluator that evaluates some sort of logic against its subject + */ + Evaluator<?> getLogicEvaluator(); + +} http://git-wip-us.apache.org/repos/asf/nifi/blob/3a7ddc6a/nifi-commons/nifi-properties/src/test/java/org/apache/nifi/util/NiFiPropertiesTest.java ---------------------------------------------------------------------- diff --git a/nifi-commons/nifi-properties/src/test/java/org/apache/nifi/util/NiFiPropertiesTest.java b/nifi-commons/nifi-properties/src/test/java/org/apache/nifi/util/NiFiPropertiesTest.java index 9c1c8d7..96a618e 100644 --- a/nifi-commons/nifi-properties/src/test/java/org/apache/nifi/util/NiFiPropertiesTest.java +++ b/nifi-commons/nifi-properties/src/test/java/org/apache/nifi/util/NiFiPropertiesTest.java @@ -1,127 +1,127 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.nifi.util; - -import org.junit.Assert; -import org.junit.Test; - -import java.io.BufferedInputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.InputStream; -import java.net.URISyntaxException; -import java.nio.file.Path; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import static org.junit.Assert.assertEquals; - -public class NiFiPropertiesTest { - - @Test - public void testProperties() { - - NiFiProperties properties = loadSpecifiedProperties("/NiFiProperties/conf/nifi.properties"); - - assertEquals("UI Banner Text", properties.getBannerText()); - - Set<File> expectedDirectories = new HashSet<>(); - expectedDirectories.add(new File("./target/resources/NiFiProperties/lib/")); - expectedDirectories.add(new File("./target/resources/NiFiProperties/lib2/")); - - Set<String> directories = new HashSet<>(); - for (Path narLibDir : properties.getNarLibraryDirectories()) { - directories.add(narLibDir.toString()); - } - - Assert.assertEquals("Did not have the anticipated number of directories", expectedDirectories.size(), directories.size()); - for (File expectedDirectory : expectedDirectories) { - Assert.assertTrue("Listed directories did not contain expected directory", directories.contains(expectedDirectory.getPath())); - } - } - - @Test - public void testMissingProperties() { - - NiFiProperties properties = loadSpecifiedProperties("/NiFiProperties/conf/nifi.missing.properties"); - - List<Path> directories = properties.getNarLibraryDirectories(); - - assertEquals(1, directories.size()); - - assertEquals(new File(NiFiProperties.DEFAULT_NAR_LIBRARY_DIR).getPath(), directories.get(0) - .toString()); - - } - - @Test - public void testBlankProperties() { - - NiFiProperties properties = loadSpecifiedProperties("/NiFiProperties/conf/nifi.blank.properties"); - - List<Path> directories = properties.getNarLibraryDirectories(); - - assertEquals(1, directories.size()); - - assertEquals(new File(NiFiProperties.DEFAULT_NAR_LIBRARY_DIR).getPath(), directories.get(0) - .toString()); - - } - - private NiFiProperties loadSpecifiedProperties(String propertiesFile) { - - String filePath; - try { - filePath = NiFiPropertiesTest.class.getResource(propertiesFile).toURI().getPath(); - } catch (URISyntaxException ex) { - throw new RuntimeException("Cannot load properties file due to " - + ex.getLocalizedMessage(), ex); - } - - System.setProperty(NiFiProperties.PROPERTIES_FILE_PATH, filePath); - - NiFiProperties properties = NiFiProperties.getInstance(); - - // clear out existing properties - for (String prop : properties.stringPropertyNames()) { - properties.remove(prop); - } - - InputStream inStream = null; - try { - inStream = new BufferedInputStream(new FileInputStream(filePath)); - properties.load(inStream); - } catch (final Exception ex) { - throw new RuntimeException("Cannot load properties file due to " - + ex.getLocalizedMessage(), ex); - } finally { - if (null != inStream) { - try { - inStream.close(); - } catch (final Exception ex) { - /** - * do nothing * - */ - } - } - } - - return properties; - } - -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.nifi.util; + +import org.junit.Assert; +import org.junit.Test; + +import java.io.BufferedInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; +import java.net.URISyntaxException; +import java.nio.file.Path; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import static org.junit.Assert.assertEquals; + +public class NiFiPropertiesTest { + + @Test + public void testProperties() { + + NiFiProperties properties = loadSpecifiedProperties("/NiFiProperties/conf/nifi.properties"); + + assertEquals("UI Banner Text", properties.getBannerText()); + + Set<File> expectedDirectories = new HashSet<>(); + expectedDirectories.add(new File("./target/resources/NiFiProperties/lib/")); + expectedDirectories.add(new File("./target/resources/NiFiProperties/lib2/")); + + Set<String> directories = new HashSet<>(); + for (Path narLibDir : properties.getNarLibraryDirectories()) { + directories.add(narLibDir.toString()); + } + + Assert.assertEquals("Did not have the anticipated number of directories", expectedDirectories.size(), directories.size()); + for (File expectedDirectory : expectedDirectories) { + Assert.assertTrue("Listed directories did not contain expected directory", directories.contains(expectedDirectory.getPath())); + } + } + + @Test + public void testMissingProperties() { + + NiFiProperties properties = loadSpecifiedProperties("/NiFiProperties/conf/nifi.missing.properties"); + + List<Path> directories = properties.getNarLibraryDirectories(); + + assertEquals(1, directories.size()); + + assertEquals(new File(NiFiProperties.DEFAULT_NAR_LIBRARY_DIR).getPath(), directories.get(0) + .toString()); + + } + + @Test + public void testBlankProperties() { + + NiFiProperties properties = loadSpecifiedProperties("/NiFiProperties/conf/nifi.blank.properties"); + + List<Path> directories = properties.getNarLibraryDirectories(); + + assertEquals(1, directories.size()); + + assertEquals(new File(NiFiProperties.DEFAULT_NAR_LIBRARY_DIR).getPath(), directories.get(0) + .toString()); + + } + + private NiFiProperties loadSpecifiedProperties(String propertiesFile) { + + String filePath; + try { + filePath = NiFiPropertiesTest.class.getResource(propertiesFile).toURI().getPath(); + } catch (URISyntaxException ex) { + throw new RuntimeException("Cannot load properties file due to " + + ex.getLocalizedMessage(), ex); + } + + System.setProperty(NiFiProperties.PROPERTIES_FILE_PATH, filePath); + + NiFiProperties properties = NiFiProperties.getInstance(); + + // clear out existing properties + for (String prop : properties.stringPropertyNames()) { + properties.remove(prop); + } + + InputStream inStream = null; + try { + inStream = new BufferedInputStream(new FileInputStream(filePath)); + properties.load(inStream); + } catch (final Exception ex) { + throw new RuntimeException("Cannot load properties file due to " + + ex.getLocalizedMessage(), ex); + } finally { + if (null != inStream) { + try { + inStream.close(); + } catch (final Exception ex) { + /** + * do nothing * + */ + } + } + } + + return properties; + } + +} http://git-wip-us.apache.org/repos/asf/nifi/blob/3a7ddc6a/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/Communicant.java ---------------------------------------------------------------------- diff --git a/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/Communicant.java b/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/Communicant.java index 17b990e..6245a53 100644 --- a/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/Communicant.java +++ b/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/Communicant.java @@ -1,46 +1,46 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.nifi.remote; - -/** - * Represents the remote entity that the client is communicating with - */ -public interface Communicant { - - /** - * @return the NiFi site-to-site URL for the remote NiFi instance - */ - String getUrl(); - - /** - * @return The Host of the remote NiFi instance - */ - String getHost(); - - /** - * @return The Port that the remote NiFi instance is listening on for - * site-to-site communications - */ - int getPort(); - - /** - * @return The distinguished name that the remote NiFi instance has provided - * in its certificate if using secure communications, or <code>null</code> - * if the Distinguished Name is unknown - */ - String getDistinguishedName(); -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.nifi.remote; + +/** + * Represents the remote entity that the client is communicating with + */ +public interface Communicant { + + /** + * @return the NiFi site-to-site URL for the remote NiFi instance + */ + String getUrl(); + + /** + * @return The Host of the remote NiFi instance + */ + String getHost(); + + /** + * @return The Port that the remote NiFi instance is listening on for + * site-to-site communications + */ + int getPort(); + + /** + * @return The distinguished name that the remote NiFi instance has provided + * in its certificate if using secure communications, or <code>null</code> + * if the Distinguished Name is unknown + */ + String getDistinguishedName(); +} http://git-wip-us.apache.org/repos/asf/nifi/blob/3a7ddc6a/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/PeerDescription.java ---------------------------------------------------------------------- diff --git a/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/PeerDescription.java b/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/PeerDescription.java index 6fc90e4..f34c31d 100644 --- a/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/PeerDescription.java +++ b/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/PeerDescription.java @@ -1,80 +1,80 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.nifi.remote; - -public class PeerDescription { - - private final String hostname; - private final int port; - private final boolean secure; - - public PeerDescription(final String hostname, final int port, final boolean secure) { - this.hostname = hostname; - this.port = port; - this.secure = secure; - } - - public String getHostname() { - return hostname; - } - - public int getPort() { - return port; - } - - public boolean isSecure() { - return secure; - } - - @Override - public String toString() { - return "PeerDescription[hostname=" + hostname + ", port=" + port + ", secure=" + secure + "]"; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((hostname == null) ? 0 : hostname.hashCode()); - result = prime * result + port; - return result; - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - - final PeerDescription other = (PeerDescription) obj; - if (hostname == null) { - if (other.hostname != null) { - return false; - } - } else if (!hostname.equals(other.hostname)) { - return false; - } - - return port == other.port; - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.nifi.remote; + +public class PeerDescription { + + private final String hostname; + private final int port; + private final boolean secure; + + public PeerDescription(final String hostname, final int port, final boolean secure) { + this.hostname = hostname; + this.port = port; + this.secure = secure; + } + + public String getHostname() { + return hostname; + } + + public int getPort() { + return port; + } + + public boolean isSecure() { + return secure; + } + + @Override + public String toString() { + return "PeerDescription[hostname=" + hostname + ", port=" + port + ", secure=" + secure + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((hostname == null) ? 0 : hostname.hashCode()); + result = prime * result + port; + return result; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + + final PeerDescription other = (PeerDescription) obj; + if (hostname == null) { + if (other.hostname != null) { + return false; + } + } else if (!hostname.equals(other.hostname)) { + return false; + } + + return port == other.port; + } +} http://git-wip-us.apache.org/repos/asf/nifi/blob/3a7ddc6a/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/TransactionCompletion.java ---------------------------------------------------------------------- diff --git a/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/TransactionCompletion.java b/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/TransactionCompletion.java index 1587e87..aae94af 100644 --- a/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/TransactionCompletion.java +++ b/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/TransactionCompletion.java @@ -1,64 +1,64 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.nifi.remote; - -import java.io.InputStream; -import java.util.concurrent.TimeUnit; - -import org.apache.nifi.remote.protocol.DataPacket; - -/** - * A TransactionCompletion provides information about a {@link Transaction} that - * has completed successfully. - */ -public interface TransactionCompletion { - - /** - * When a sending to a NiFi instance, the server may accept the content sent - * to it but indicate that its queues are full and that the client should - * backoff sending data for a bit. - * - * @return <code>true</code> if the server did in fact request that, - * <code>false</code> otherwise - */ - boolean isBackoff(); - - /** - * @return the number of Data Packets that were sent to or received from the - * remote NiFi instance in the Transaction - */ - int getDataPacketsTransferred(); - - /** - * @return the number of bytes of DataPacket content that were sent to or - * received from the remote NiFI instance in the Transaction. Note that this - * is different than the number of bytes actually transferred between the - * client and server, as it does not take into account the attributes or - * protocol-specific information that is exchanged but rather takes into - * account only the data in the {@link InputStream} of the - * {@link DataPacket} - */ - long getBytesTransferred(); - - /** - * @param timeUnit unit of time for which to report the duration - * @return the amount of time that the Transaction took, from the time that - * the Transaction was created to the time that the Transaction was - * completed - */ - long getDuration(TimeUnit timeUnit); -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.nifi.remote; + +import java.io.InputStream; +import java.util.concurrent.TimeUnit; + +import org.apache.nifi.remote.protocol.DataPacket; + +/** + * A TransactionCompletion provides information about a {@link Transaction} that + * has completed successfully. + */ +public interface TransactionCompletion { + + /** + * When a sending to a NiFi instance, the server may accept the content sent + * to it but indicate that its queues are full and that the client should + * backoff sending data for a bit. + * + * @return <code>true</code> if the server did in fact request that, + * <code>false</code> otherwise + */ + boolean isBackoff(); + + /** + * @return the number of Data Packets that were sent to or received from the + * remote NiFi instance in the Transaction + */ + int getDataPacketsTransferred(); + + /** + * @return the number of bytes of DataPacket content that were sent to or + * received from the remote NiFI instance in the Transaction. Note that this + * is different than the number of bytes actually transferred between the + * client and server, as it does not take into account the attributes or + * protocol-specific information that is exchanged but rather takes into + * account only the data in the {@link InputStream} of the + * {@link DataPacket} + */ + long getBytesTransferred(); + + /** + * @param timeUnit unit of time for which to report the duration + * @return the amount of time that the Transaction took, from the time that + * the Transaction was created to the time that the Transaction was + * completed + */ + long getDuration(TimeUnit timeUnit); +} http://git-wip-us.apache.org/repos/asf/nifi/blob/3a7ddc6a/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/client/KeystoreType.java ---------------------------------------------------------------------- diff --git a/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/client/KeystoreType.java b/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/client/KeystoreType.java index 63c3d63..657fcb9 100644 --- a/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/client/KeystoreType.java +++ b/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/client/KeystoreType.java @@ -1,24 +1,24 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.nifi.remote.client; - -import java.io.Serializable; - -public enum KeystoreType implements Serializable { - PKCS12, - JKS; -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.nifi.remote.client; + +import java.io.Serializable; + +public enum KeystoreType implements Serializable { + PKCS12, + JKS; +} http://git-wip-us.apache.org/repos/asf/nifi/blob/3a7ddc6a/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/client/SiteToSiteClientConfig.java ---------------------------------------------------------------------- diff --git a/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/client/SiteToSiteClientConfig.java b/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/client/SiteToSiteClientConfig.java index 50a0d3c..8962c71 100644 --- a/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/client/SiteToSiteClientConfig.java +++ b/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/client/SiteToSiteClientConfig.java @@ -1,148 +1,148 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.nifi.remote.client; - -import java.io.File; -import java.io.Serializable; -import java.util.concurrent.TimeUnit; - -import javax.net.ssl.SSLContext; - -import org.apache.nifi.events.EventReporter; -import org.apache.nifi.remote.protocol.DataPacket; - -public interface SiteToSiteClientConfig extends Serializable { - - /** - * @return the configured URL for the remote NiFi instance - */ - String getUrl(); - - /** - * @param timeUnit unit over which to report the timeout - * @return the communications timeout in given unit - */ - long getTimeout(final TimeUnit timeUnit); - - /** - * @param timeUnit the unit for which to report the time - * @return the amount of time that a connection can remain idle before it is - * "expired" and shut down - */ - long getIdleConnectionExpiration(TimeUnit timeUnit); - - /** - * @param timeUnit unit over which to report the time - * @return the amount of time that a particular node will be ignored after a - * communications error with that node occurs - */ - long getPenalizationPeriod(TimeUnit timeUnit); - - /** - * @return the SSL Context that is configured for this builder - */ - SSLContext getSslContext(); - - /** - * @return the filename to use for the keystore, or <code>null</code> if none is configured - */ - String getKeystoreFilename(); - - /** - * @return the password to use for the keystore, or <code>null</code> if none is configured - */ - String getKeystorePassword(); - - /** - * @return the Type of the keystore, or <code>null</code> if none is configured - */ - KeystoreType getKeystoreType(); - - /** - * @return the filename to use for the truststore, or <code>null</code> if none is configured - */ - String getTruststoreFilename(); - - /** - * @return the password to use for the truststore, or <code>null</code> if none is configured - */ - String getTruststorePassword(); - - /** - * @return the type of the truststore, or <code>null</code> if none is configured - */ - KeystoreType getTruststoreType(); - - /** - * @return the file that is to be used for persisting the nodes of a remote - * cluster, if any - */ - File getPeerPersistenceFile(); - - /** - * @return a boolean indicating whether or not compression will be used to - * transfer data to and from the remote instance - */ - boolean isUseCompression(); - - /** - * @return the name of the port that the client is to communicate with - */ - String getPortName(); - - /** - * @return the identifier of the port that the client is to communicate with - */ - String getPortIdentifier(); - - /** - * When pulling data from a NiFi instance, the sender chooses how large a - * Transaction is. However, the client has the ability to request a - * particular batch size/duration. - * - * @param timeUnit unit of time over which to report the duration - * @return the maximum amount of time that we will request a NiFi instance - * to send data to us in a Transaction - */ - long getPreferredBatchDuration(TimeUnit timeUnit); - - /** - * When pulling data from a NiFi instance, the sender chooses how large a - * Transaction is. However, the client has the ability to request a - * particular batch size/duration. - * - * @return returns the maximum number of bytes that we will request a NiFi - * instance to send data to us in a Transaction - */ - long getPreferredBatchSize(); - - /** - * When pulling data from a NiFi instance, the sender chooses how large a - * Transaction is. However, the client has the ability to request a - * particular batch size/duration. - * - * @return the maximum number of {@link DataPacket}s that we will request a - * NiFi instance to send data to us in a Transaction - */ - int getPreferredBatchCount(); - - /** - * @return the EventReporter that is to be used by clients to report events - */ - EventReporter getEventReporter(); - -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.nifi.remote.client; + +import java.io.File; +import java.io.Serializable; +import java.util.concurrent.TimeUnit; + +import javax.net.ssl.SSLContext; + +import org.apache.nifi.events.EventReporter; +import org.apache.nifi.remote.protocol.DataPacket; + +public interface SiteToSiteClientConfig extends Serializable { + + /** + * @return the configured URL for the remote NiFi instance + */ + String getUrl(); + + /** + * @param timeUnit unit over which to report the timeout + * @return the communications timeout in given unit + */ + long getTimeout(final TimeUnit timeUnit); + + /** + * @param timeUnit the unit for which to report the time + * @return the amount of time that a connection can remain idle before it is + * "expired" and shut down + */ + long getIdleConnectionExpiration(TimeUnit timeUnit); + + /** + * @param timeUnit unit over which to report the time + * @return the amount of time that a particular node will be ignored after a + * communications error with that node occurs + */ + long getPenalizationPeriod(TimeUnit timeUnit); + + /** + * @return the SSL Context that is configured for this builder + */ + SSLContext getSslContext(); + + /** + * @return the filename to use for the keystore, or <code>null</code> if none is configured + */ + String getKeystoreFilename(); + + /** + * @return the password to use for the keystore, or <code>null</code> if none is configured + */ + String getKeystorePassword(); + + /** + * @return the Type of the keystore, or <code>null</code> if none is configured + */ + KeystoreType getKeystoreType(); + + /** + * @return the filename to use for the truststore, or <code>null</code> if none is configured + */ + String getTruststoreFilename(); + + /** + * @return the password to use for the truststore, or <code>null</code> if none is configured + */ + String getTruststorePassword(); + + /** + * @return the type of the truststore, or <code>null</code> if none is configured + */ + KeystoreType getTruststoreType(); + + /** + * @return the file that is to be used for persisting the nodes of a remote + * cluster, if any + */ + File getPeerPersistenceFile(); + + /** + * @return a boolean indicating whether or not compression will be used to + * transfer data to and from the remote instance + */ + boolean isUseCompression(); + + /** + * @return the name of the port that the client is to communicate with + */ + String getPortName(); + + /** + * @return the identifier of the port that the client is to communicate with + */ + String getPortIdentifier(); + + /** + * When pulling data from a NiFi instance, the sender chooses how large a + * Transaction is. However, the client has the ability to request a + * particular batch size/duration. + * + * @param timeUnit unit of time over which to report the duration + * @return the maximum amount of time that we will request a NiFi instance + * to send data to us in a Transaction + */ + long getPreferredBatchDuration(TimeUnit timeUnit); + + /** + * When pulling data from a NiFi instance, the sender chooses how large a + * Transaction is. However, the client has the ability to request a + * particular batch size/duration. + * + * @return returns the maximum number of bytes that we will request a NiFi + * instance to send data to us in a Transaction + */ + long getPreferredBatchSize(); + + /** + * When pulling data from a NiFi instance, the sender chooses how large a + * Transaction is. However, the client has the ability to request a + * particular batch size/duration. + * + * @return the maximum number of {@link DataPacket}s that we will request a + * NiFi instance to send data to us in a Transaction + */ + int getPreferredBatchCount(); + + /** + * @return the EventReporter that is to be used by clients to report events + */ + EventReporter getEventReporter(); + +} http://git-wip-us.apache.org/repos/asf/nifi/blob/3a7ddc6a/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/protocol/socket/SocketClientTransactionCompletion.java ---------------------------------------------------------------------- diff --git a/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/protocol/socket/SocketClientTransactionCompletion.java b/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/protocol/socket/SocketClientTransactionCompletion.java index bd95013..136fe8d 100644 --- a/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/protocol/socket/SocketClientTransactionCompletion.java +++ b/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/protocol/socket/SocketClientTransactionCompletion.java @@ -1,57 +1,57 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.nifi.remote.protocol.socket; - -import java.util.concurrent.TimeUnit; - -import org.apache.nifi.remote.TransactionCompletion; - -public class SocketClientTransactionCompletion implements TransactionCompletion { - - private final boolean backoff; - private final int dataPacketsTransferred; - private final long bytesTransferred; - private final long durationNanos; - - public SocketClientTransactionCompletion(final boolean backoff, final int dataPacketsTransferred, final long bytesTransferred, final long durationNanos) { - this.backoff = backoff; - this.dataPacketsTransferred = dataPacketsTransferred; - this.bytesTransferred = bytesTransferred; - this.durationNanos = durationNanos; - } - - @Override - public boolean isBackoff() { - return backoff; - } - - @Override - public int getDataPacketsTransferred() { - return dataPacketsTransferred; - } - - @Override - public long getBytesTransferred() { - return bytesTransferred; - } - - @Override - public long getDuration(final TimeUnit timeUnit) { - return timeUnit.convert(durationNanos, TimeUnit.NANOSECONDS); - } - -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.nifi.remote.protocol.socket; + +import java.util.concurrent.TimeUnit; + +import org.apache.nifi.remote.TransactionCompletion; + +public class SocketClientTransactionCompletion implements TransactionCompletion { + + private final boolean backoff; + private final int dataPacketsTransferred; + private final long bytesTransferred; + private final long durationNanos; + + public SocketClientTransactionCompletion(final boolean backoff, final int dataPacketsTransferred, final long bytesTransferred, final long durationNanos) { + this.backoff = backoff; + this.dataPacketsTransferred = dataPacketsTransferred; + this.bytesTransferred = bytesTransferred; + this.durationNanos = durationNanos; + } + + @Override + public boolean isBackoff() { + return backoff; + } + + @Override + public int getDataPacketsTransferred() { + return dataPacketsTransferred; + } + + @Override + public long getBytesTransferred() { + return bytesTransferred; + } + + @Override + public long getDuration(final TimeUnit timeUnit) { + return timeUnit.convert(durationNanos, TimeUnit.NANOSECONDS); + } + +} http://git-wip-us.apache.org/repos/asf/nifi/blob/3a7ddc6a/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/util/NiFiRestApiUtil.java ---------------------------------------------------------------------- diff --git a/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/util/NiFiRestApiUtil.java b/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/util/NiFiRestApiUtil.java index d746abf..92d3408 100644 --- a/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/util/NiFiRestApiUtil.java +++ b/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/util/NiFiRestApiUtil.java @@ -1,100 +1,100 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.nifi.remote.util; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.net.HttpURLConnection; -import java.net.URL; - -import javax.net.ssl.HostnameVerifier; -import javax.net.ssl.HttpsURLConnection; -import javax.net.ssl.SSLContext; -import javax.net.ssl.SSLSession; - -import org.apache.nifi.stream.io.StreamUtils; -import org.apache.nifi.web.api.dto.ControllerDTO; -import org.codehaus.jackson.JsonNode; -import org.codehaus.jackson.map.ObjectMapper; - -public class NiFiRestApiUtil { - - public static final int RESPONSE_CODE_OK = 200; - - private final SSLContext sslContext; - - public NiFiRestApiUtil(final SSLContext sslContext) { - this.sslContext = sslContext; - } - - private HttpURLConnection getConnection(final String connUrl, final int timeoutMillis) throws IOException { - final URL url = new URL(connUrl); - final HttpURLConnection connection = (HttpURLConnection) url.openConnection(); - connection.setConnectTimeout(timeoutMillis); - connection.setReadTimeout(timeoutMillis); - - // special handling for https - if (sslContext != null && connection instanceof HttpsURLConnection) { - HttpsURLConnection secureConnection = (HttpsURLConnection) connection; - secureConnection.setSSLSocketFactory(sslContext.getSocketFactory()); - - // check the trusted hostname property and override the HostnameVerifier - secureConnection.setHostnameVerifier(new OverrideHostnameVerifier(url.getHost(), - secureConnection.getHostnameVerifier())); - } - - return connection; - } - - public ControllerDTO getController(final String url, final int timeoutMillis) throws IOException { - final HttpURLConnection connection = getConnection(url, timeoutMillis); - connection.setRequestMethod("GET"); - final int responseCode = connection.getResponseCode(); - - final ByteArrayOutputStream baos = new ByteArrayOutputStream(); - StreamUtils.copy(connection.getInputStream(), baos); - final String responseMessage = baos.toString(); - - if (responseCode == RESPONSE_CODE_OK) { - final ObjectMapper mapper = new ObjectMapper(); - final JsonNode jsonNode = mapper.readTree(responseMessage); - final JsonNode controllerNode = jsonNode.get("controller"); - return mapper.readValue(controllerNode, ControllerDTO.class); - } else { - throw new IOException("Got HTTP response Code " + responseCode + ": " + connection.getResponseMessage() + " with explanation: " + responseMessage); - } - } - - private static class OverrideHostnameVerifier implements HostnameVerifier { - - private final String trustedHostname; - private final HostnameVerifier delegate; - - private OverrideHostnameVerifier(String trustedHostname, HostnameVerifier delegate) { - this.trustedHostname = trustedHostname; - this.delegate = delegate; - } - - @Override - public boolean verify(String hostname, SSLSession session) { - if (trustedHostname.equalsIgnoreCase(hostname)) { - return true; - } - return delegate.verify(hostname, session); - } - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.nifi.remote.util; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.net.HttpURLConnection; +import java.net.URL; + +import javax.net.ssl.HostnameVerifier; +import javax.net.ssl.HttpsURLConnection; +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLSession; + +import org.apache.nifi.stream.io.StreamUtils; +import org.apache.nifi.web.api.dto.ControllerDTO; +import org.codehaus.jackson.JsonNode; +import org.codehaus.jackson.map.ObjectMapper; + +public class NiFiRestApiUtil { + + public static final int RESPONSE_CODE_OK = 200; + + private final SSLContext sslContext; + + public NiFiRestApiUtil(final SSLContext sslContext) { + this.sslContext = sslContext; + } + + private HttpURLConnection getConnection(final String connUrl, final int timeoutMillis) throws IOException { + final URL url = new URL(connUrl); + final HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setConnectTimeout(timeoutMillis); + connection.setReadTimeout(timeoutMillis); + + // special handling for https + if (sslContext != null && connection instanceof HttpsURLConnection) { + HttpsURLConnection secureConnection = (HttpsURLConnection) connection; + secureConnection.setSSLSocketFactory(sslContext.getSocketFactory()); + + // check the trusted hostname property and override the HostnameVerifier + secureConnection.setHostnameVerifier(new OverrideHostnameVerifier(url.getHost(), + secureConnection.getHostnameVerifier())); + } + + return connection; + } + + public ControllerDTO getController(final String url, final int timeoutMillis) throws IOException { + final HttpURLConnection connection = getConnection(url, timeoutMillis); + connection.setRequestMethod("GET"); + final int responseCode = connection.getResponseCode(); + + final ByteArrayOutputStream baos = new ByteArrayOutputStream(); + StreamUtils.copy(connection.getInputStream(), baos); + final String responseMessage = baos.toString(); + + if (responseCode == RESPONSE_CODE_OK) { + final ObjectMapper mapper = new ObjectMapper(); + final JsonNode jsonNode = mapper.readTree(responseMessage); + final JsonNode controllerNode = jsonNode.get("controller"); + return mapper.readValue(controllerNode, ControllerDTO.class); + } else { + throw new IOException("Got HTTP response Code " + responseCode + ": " + connection.getResponseMessage() + " with explanation: " + responseMessage); + } + } + + private static class OverrideHostnameVerifier implements HostnameVerifier { + + private final String trustedHostname; + private final HostnameVerifier delegate; + + private OverrideHostnameVerifier(String trustedHostname, HostnameVerifier delegate) { + this.trustedHostname = trustedHostname; + this.delegate = delegate; + } + + @Override + public boolean verify(String hostname, SSLSession session) { + if (trustedHostname.equalsIgnoreCase(hostname)) { + return true; + } + return delegate.verify(hostname, session); + } + } +}
