From 93309901bad9a6d2377d742bfd6317a6b665029e Mon Sep 17 00:00:00 2001 From: Mark Payne Date: Wed, 7 Jan 2015 09:01:42 -0500 Subject: [PATCH] NIFI-225: Change Locale to always be EN-US --- .../language/evaluation/cast/DateCastEvaluator.java | 5 +++-- .../language/evaluation/functions/FormatEvaluator.java | 3 ++- .../evaluation/functions/StringToDateEvaluator.java | 3 ++- .../nifi/attribute/expression/language/TestQuery.java | 6 +++--- .../src/main/java/org/apache/nifi/util/FormatUtils.java | 5 +++-- .../apache/nifi/web/api/dto/util/DateTimeAdapter.java | 6 ++++-- .../org/apache/nifi/web/api/dto/util/TimeAdapter.java | 6 ++++-- .../apache/nifi/web/api/dto/util/TimestampAdapter.java | 6 ++++-- .../apache/nifi/cluster/client/MulticastTestClient.java | 4 +++- .../nifi/cluster/manager/impl/TestWebClusterManager.java | 4 +++- .../java/org/apache/nifi/controller/StandardFunnel.java | 2 +- .../main/java/org/apache/nifi/logging/LogMessage.java | 3 ++- .../main/java/org/apache/nifi/connectable/LocalPort.java | 2 +- .../java/org/apache/nifi/controller/FlowController.java | 6 +++--- .../org/apache/nifi/remote/StandardRootGroupPort.java | 2 +- .../apache/nifi/web/api/request/DateTimeParameter.java | 5 +++-- .../org/apache/nifi/processors/standard/GetFile.java | 3 ++- .../apache/nifi/processors/standard/GetFileTransfer.java | 3 ++- .../org/apache/nifi/processors/standard/GetHTTP.java | 4 ++-- .../org/apache/nifi/processors/standard/PutFile.java | 3 ++- .../nifi/processors/standard/util/FTPTransfer.java | 6 +++--- .../nifi/processors/standard/util/SFTPTransfer.java | 4 ++-- .../processors/standard/RESTServiceContentModified.java | 3 ++- .../org/apache/nifi/processors/standard/TestGetFile.java | 9 +++++---- .../apache/nifi/processors/standard/TestInvokeHTTP.java | 5 +++-- 25 files changed, 65 insertions(+), 43 deletions(-) diff --git a/commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/evaluation/cast/DateCastEvaluator.java b/commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/evaluation/cast/DateCastEvaluator.java index 2a182403d9..96e74ef598 100644 --- a/commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/evaluation/cast/DateCastEvaluator.java +++ b/commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/evaluation/cast/DateCastEvaluator.java @@ -19,6 +19,7 @@ package org.apache.nifi.attribute.expression.language.evaluation.cast; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.Locale; import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -66,7 +67,7 @@ public class DateCastEvaluator extends DateEvaluator { case STRING: final String value = ((StringQueryResult) result).getValue().trim(); if (DATE_TO_STRING_PATTERN.matcher(value).matches()) { - final SimpleDateFormat sdf = new SimpleDateFormat(DATE_TO_STRING_FORMAT); + final SimpleDateFormat sdf = new SimpleDateFormat(DATE_TO_STRING_FORMAT, Locale.US); try { final Date date = sdf.parse(value); @@ -89,7 +90,7 @@ public class DateCastEvaluator extends DateEvaluator { format = ALTERNATE_FORMAT_WITH_MILLIS; } - final SimpleDateFormat sdf = new SimpleDateFormat(format); + final SimpleDateFormat sdf = new SimpleDateFormat(format, Locale.US); try { final Date date = sdf.parse(value); diff --git a/commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/evaluation/functions/FormatEvaluator.java b/commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/evaluation/functions/FormatEvaluator.java index ccb1a89d9e..132b9e7d1c 100644 --- a/commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/evaluation/functions/FormatEvaluator.java +++ b/commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/evaluation/functions/FormatEvaluator.java @@ -18,6 +18,7 @@ package org.apache.nifi.attribute.expression.language.evaluation.functions; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.Locale; import java.util.Map; import org.apache.nifi.attribute.expression.language.evaluation.DateEvaluator; @@ -49,7 +50,7 @@ public class FormatEvaluator extends StringEvaluator { return null; } - return new StringQueryResult(new SimpleDateFormat(format).format(subjectValue)); + return new StringQueryResult(new SimpleDateFormat(format, Locale.US).format(subjectValue)); } @Override diff --git a/commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/evaluation/functions/StringToDateEvaluator.java b/commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/evaluation/functions/StringToDateEvaluator.java index a4e21a44a7..1575d75377 100644 --- a/commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/evaluation/functions/StringToDateEvaluator.java +++ b/commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/evaluation/functions/StringToDateEvaluator.java @@ -19,6 +19,7 @@ package org.apache.nifi.attribute.expression.language.evaluation.functions; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.Locale; import java.util.Map; import org.apache.nifi.attribute.expression.language.evaluation.DateEvaluator; @@ -47,7 +48,7 @@ public class StringToDateEvaluator extends DateEvaluator { } try { - return new DateQueryResult(new SimpleDateFormat(formatValue).parse(subjectValue)); + return new DateQueryResult(new SimpleDateFormat(formatValue, Locale.US).parse(subjectValue)); } catch (final ParseException e) { throw new IllegalAttributeException("Cannot parse attribute value as a date; date format: " + formatValue + "; attribute value: " + subjectValue); diff --git a/commons/nifi-expression-language/src/test/java/org/apache/nifi/attribute/expression/language/TestQuery.java b/commons/nifi-expression-language/src/test/java/org/apache/nifi/attribute/expression/language/TestQuery.java index dd7a7fe36c..76e043afc5 100644 --- a/commons/nifi-expression-language/src/test/java/org/apache/nifi/attribute/expression/language/TestQuery.java +++ b/commons/nifi-expression-language/src/test/java/org/apache/nifi/attribute/expression/language/TestQuery.java @@ -25,6 +25,7 @@ import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Locale; import java.util.Map; import org.apache.nifi.attribute.expression.language.Query.Range; @@ -32,7 +33,6 @@ import org.apache.nifi.attribute.expression.language.evaluation.QueryResult; import org.apache.nifi.attribute.expression.language.exception.AttributeExpressionLanguageParsingException; import org.apache.nifi.expression.AttributeExpression.ResultType; import org.apache.nifi.flowfile.FlowFile; - import org.antlr.runtime.tree.Tree; import org.junit.Assert; import org.junit.Ignore; @@ -203,7 +203,7 @@ public class TestQuery { // the date.toString() above will end up truncating the milliseconds. So remove millis from the Date before // formatting it - final SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss.SSS"); + final SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss.SSS", Locale.US); final long millis = date.getTime() % 1000L; final Date roundedToNearestSecond = new Date(date.getTime() - millis); final String formatted = sdf.format(roundedToNearestSecond); @@ -458,7 +458,7 @@ public class TestQuery { final String query = "startDateTime=\"${date:toNumber():toDate():format(\"" + format + "\")}\""; final String result = Query.evaluateExpressions(query, attributes, null); - final String expectedTime = new SimpleDateFormat(format).format(timestamp); + final String expectedTime = new SimpleDateFormat(format, Locale.US).format(timestamp); assertEquals("startDateTime=\"" + expectedTime + "\"", result); final List ranges = Query.extractExpressionRanges(query); diff --git a/commons/nifi-utils/src/main/java/org/apache/nifi/util/FormatUtils.java b/commons/nifi-utils/src/main/java/org/apache/nifi/util/FormatUtils.java index 9954bfb09f..805223f3b7 100644 --- a/commons/nifi-utils/src/main/java/org/apache/nifi/util/FormatUtils.java +++ b/commons/nifi-utils/src/main/java/org/apache/nifi/util/FormatUtils.java @@ -19,6 +19,7 @@ package org.apache.nifi.util; import java.text.NumberFormat; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.Locale; import java.util.concurrent.TimeUnit; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -64,7 +65,7 @@ public class FormatUtils { */ public static String formatMinutesSeconds(final long sourceDuration, final TimeUnit sourceUnit) { final long millis = TimeUnit.MILLISECONDS.convert(sourceDuration, sourceUnit); - final SimpleDateFormat formatter = new SimpleDateFormat("mm:ss.SSS"); + final SimpleDateFormat formatter = new SimpleDateFormat("mm:ss.SSS", Locale.US); return formatter.format(new Date(millis)); } @@ -81,7 +82,7 @@ public class FormatUtils { final int hours = (int) (millis / millisInHour); final long whatsLeft = millis - hours * millisInHour; - return pad(hours) + ":" + new SimpleDateFormat("mm:ss.SSS").format(new Date(whatsLeft)); + return pad(hours) + ":" + new SimpleDateFormat("mm:ss.SSS", Locale.US).format(new Date(whatsLeft)); } private static String pad(final int val) { diff --git a/nar-bundles/framework-bundle/framework/client-dto/src/main/java/org/apache/nifi/web/api/dto/util/DateTimeAdapter.java b/nar-bundles/framework-bundle/framework/client-dto/src/main/java/org/apache/nifi/web/api/dto/util/DateTimeAdapter.java index f860b305e7..46ba674f6e 100644 --- a/nar-bundles/framework-bundle/framework/client-dto/src/main/java/org/apache/nifi/web/api/dto/util/DateTimeAdapter.java +++ b/nar-bundles/framework-bundle/framework/client-dto/src/main/java/org/apache/nifi/web/api/dto/util/DateTimeAdapter.java @@ -18,7 +18,9 @@ package org.apache.nifi.web.api.dto.util; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.Locale; import java.util.TimeZone; + import javax.xml.bind.annotation.adapters.XmlAdapter; /** @@ -30,14 +32,14 @@ public class DateTimeAdapter extends XmlAdapter { @Override public String marshal(Date date) throws Exception { - final SimpleDateFormat formatter = new SimpleDateFormat(DEFAULT_DATE_TIME_FORMAT); + final SimpleDateFormat formatter = new SimpleDateFormat(DEFAULT_DATE_TIME_FORMAT, Locale.US); formatter.setTimeZone(TimeZone.getDefault()); return formatter.format(date); } @Override public Date unmarshal(String date) throws Exception { - final SimpleDateFormat parser = new SimpleDateFormat(DEFAULT_DATE_TIME_FORMAT); + final SimpleDateFormat parser = new SimpleDateFormat(DEFAULT_DATE_TIME_FORMAT, Locale.US); parser.setTimeZone(TimeZone.getDefault()); return parser.parse(date); } diff --git a/nar-bundles/framework-bundle/framework/client-dto/src/main/java/org/apache/nifi/web/api/dto/util/TimeAdapter.java b/nar-bundles/framework-bundle/framework/client-dto/src/main/java/org/apache/nifi/web/api/dto/util/TimeAdapter.java index ab77370803..100d6c1745 100644 --- a/nar-bundles/framework-bundle/framework/client-dto/src/main/java/org/apache/nifi/web/api/dto/util/TimeAdapter.java +++ b/nar-bundles/framework-bundle/framework/client-dto/src/main/java/org/apache/nifi/web/api/dto/util/TimeAdapter.java @@ -18,7 +18,9 @@ package org.apache.nifi.web.api.dto.util; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.Locale; import java.util.TimeZone; + import javax.xml.bind.annotation.adapters.XmlAdapter; /** @@ -30,14 +32,14 @@ public class TimeAdapter extends XmlAdapter { @Override public String marshal(Date date) throws Exception { - final SimpleDateFormat formatter = new SimpleDateFormat(DEFAULT_TIME_FORMAT); + final SimpleDateFormat formatter = new SimpleDateFormat(DEFAULT_TIME_FORMAT, Locale.US); formatter.setTimeZone(TimeZone.getDefault()); return formatter.format(date); } @Override public Date unmarshal(String date) throws Exception { - final SimpleDateFormat parser = new SimpleDateFormat(DEFAULT_TIME_FORMAT); + final SimpleDateFormat parser = new SimpleDateFormat(DEFAULT_TIME_FORMAT, Locale.US); parser.setTimeZone(TimeZone.getDefault()); return parser.parse(date); } diff --git a/nar-bundles/framework-bundle/framework/client-dto/src/main/java/org/apache/nifi/web/api/dto/util/TimestampAdapter.java b/nar-bundles/framework-bundle/framework/client-dto/src/main/java/org/apache/nifi/web/api/dto/util/TimestampAdapter.java index 49b90a2a13..d182cf3bc9 100644 --- a/nar-bundles/framework-bundle/framework/client-dto/src/main/java/org/apache/nifi/web/api/dto/util/TimestampAdapter.java +++ b/nar-bundles/framework-bundle/framework/client-dto/src/main/java/org/apache/nifi/web/api/dto/util/TimestampAdapter.java @@ -18,7 +18,9 @@ package org.apache.nifi.web.api.dto.util; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.Locale; import java.util.TimeZone; + import javax.xml.bind.annotation.adapters.XmlAdapter; /** @@ -30,14 +32,14 @@ public class TimestampAdapter extends XmlAdapter { @Override public String marshal(Date date) throws Exception { - final SimpleDateFormat formatter = new SimpleDateFormat(DEFAULT_DATE_TIME_FORMAT); + final SimpleDateFormat formatter = new SimpleDateFormat(DEFAULT_DATE_TIME_FORMAT, Locale.US); formatter.setTimeZone(TimeZone.getDefault()); return formatter.format(date); } @Override public Date unmarshal(String date) throws Exception { - final SimpleDateFormat parser = new SimpleDateFormat(DEFAULT_DATE_TIME_FORMAT); + final SimpleDateFormat parser = new SimpleDateFormat(DEFAULT_DATE_TIME_FORMAT, Locale.US); parser.setTimeZone(TimeZone.getDefault()); return parser.parse(date); } diff --git a/nar-bundles/framework-bundle/framework/cluster/src/main/java/org/apache/nifi/cluster/client/MulticastTestClient.java b/nar-bundles/framework-bundle/framework/cluster/src/main/java/org/apache/nifi/cluster/client/MulticastTestClient.java index 183c7ca9b5..0b70c61c9a 100644 --- a/nar-bundles/framework-bundle/framework/cluster/src/main/java/org/apache/nifi/cluster/client/MulticastTestClient.java +++ b/nar-bundles/framework-bundle/framework/cluster/src/main/java/org/apache/nifi/cluster/client/MulticastTestClient.java @@ -23,8 +23,10 @@ import java.net.InetSocketAddress; import java.net.MulticastSocket; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.Locale; import java.util.Timer; import java.util.TimerTask; + import org.apache.nifi.cluster.protocol.ProtocolContext; import org.apache.nifi.cluster.protocol.ProtocolException; import org.apache.nifi.cluster.protocol.ProtocolHandler; @@ -85,7 +87,7 @@ public class MulticastTestClient { @Override public ProtocolMessage handle(ProtocolMessage msg) throws ProtocolException { final PingMessage pingMsg = (PingMessage) msg; - final SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss"); + final SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss", Locale.US); logger.info("Pinged at: " + sdf.format(pingMsg.getDate())); return null; } diff --git a/nar-bundles/framework-bundle/framework/cluster/src/test/java/org/apache/nifi/cluster/manager/impl/TestWebClusterManager.java b/nar-bundles/framework-bundle/framework/cluster/src/test/java/org/apache/nifi/cluster/manager/impl/TestWebClusterManager.java index 7347a94958..13a192fdd4 100644 --- a/nar-bundles/framework-bundle/framework/cluster/src/test/java/org/apache/nifi/cluster/manager/impl/TestWebClusterManager.java +++ b/nar-bundles/framework-bundle/framework/cluster/src/test/java/org/apache/nifi/cluster/manager/impl/TestWebClusterManager.java @@ -17,12 +17,14 @@ package org.apache.nifi.cluster.manager.impl; import org.apache.nifi.cluster.manager.impl.WebClusterManager; + import static org.junit.Assert.assertEquals; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.Locale; import org.junit.Test; @@ -30,7 +32,7 @@ public class TestWebClusterManager { @Test public void testNormalizedStatusSnapshotDate() throws ParseException { - final DateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm:SS.SSS"); + final DateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm:SS.SSS", Locale.US); final Date date1 = df.parse("2014/01/01 00:00:00.000"); final Date date2 = df.parse("2014/01/01 00:04:59.999"); final Date date3 = df.parse("2014/01/01 00:05:00.000"); diff --git a/nar-bundles/framework-bundle/framework/core-api/src/main/java/org/apache/nifi/controller/StandardFunnel.java b/nar-bundles/framework-bundle/framework/core-api/src/main/java/org/apache/nifi/controller/StandardFunnel.java index 52a4e40d21..e516f209f8 100644 --- a/nar-bundles/framework-bundle/framework/core-api/src/main/java/org/apache/nifi/controller/StandardFunnel.java +++ b/nar-bundles/framework-bundle/framework/core-api/src/main/java/org/apache/nifi/controller/StandardFunnel.java @@ -536,6 +536,6 @@ public class StandardFunnel implements Funnel { @Override public SchedulingStrategy getSchedulingStrategy() { - return SchedulingStrategy.EVENT_DRIVEN; + return SchedulingStrategy.TIMER_DRIVEN; } } diff --git a/nar-bundles/framework-bundle/framework/core-api/src/main/java/org/apache/nifi/logging/LogMessage.java b/nar-bundles/framework-bundle/framework/core-api/src/main/java/org/apache/nifi/logging/LogMessage.java index 27cc6c54c8..2ac89deaaf 100644 --- a/nar-bundles/framework-bundle/framework/core-api/src/main/java/org/apache/nifi/logging/LogMessage.java +++ b/nar-bundles/framework-bundle/framework/core-api/src/main/java/org/apache/nifi/logging/LogMessage.java @@ -21,6 +21,7 @@ import java.io.StringWriter; import java.sql.Date; import java.text.DateFormat; import java.text.SimpleDateFormat; +import java.util.Locale; public class LogMessage { @@ -57,7 +58,7 @@ public class LogMessage { @Override public String toString() { - final DateFormat dateFormat = new SimpleDateFormat(DATE_TIME_FORMAT); + final DateFormat dateFormat = new SimpleDateFormat(DATE_TIME_FORMAT, Locale.US); final String formattedTime = dateFormat.format(new Date(time)); String formattedMsg = String.format(TO_STRING_FORMAT, formattedTime, level.toString(), message); diff --git a/nar-bundles/framework-bundle/framework/core/src/main/java/org/apache/nifi/connectable/LocalPort.java b/nar-bundles/framework-bundle/framework/core/src/main/java/org/apache/nifi/connectable/LocalPort.java index 1efa0cd130..f0739c2291 100644 --- a/nar-bundles/framework-bundle/framework/core/src/main/java/org/apache/nifi/connectable/LocalPort.java +++ b/nar-bundles/framework-bundle/framework/core/src/main/java/org/apache/nifi/connectable/LocalPort.java @@ -162,7 +162,7 @@ public class LocalPort extends AbstractPort { @Override public SchedulingStrategy getSchedulingStrategy() { - return SchedulingStrategy.EVENT_DRIVEN; + return SchedulingStrategy.TIMER_DRIVEN; } @Override diff --git a/nar-bundles/framework-bundle/framework/core/src/main/java/org/apache/nifi/controller/FlowController.java b/nar-bundles/framework-bundle/framework/core/src/main/java/org/apache/nifi/controller/FlowController.java index bb98418fac..99d8d6e28a 100644 --- a/nar-bundles/framework-bundle/framework/core/src/main/java/org/apache/nifi/controller/FlowController.java +++ b/nar-bundles/framework-bundle/framework/core/src/main/java/org/apache/nifi/controller/FlowController.java @@ -31,6 +31,7 @@ import java.util.Date; import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Set; import java.util.UUID; @@ -181,7 +182,6 @@ import org.apache.nifi.web.api.dto.RemoteProcessGroupDTO; import org.apache.nifi.web.api.dto.RemoteProcessGroupPortDTO; import org.apache.nifi.web.api.dto.TemplateDTO; import org.apache.nifi.web.api.dto.status.StatusHistoryDTO; - import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -3209,7 +3209,7 @@ public class FlowController implements EventAccess, ControllerServiceProvider, H private class BulletinsTask implements Runnable { private final NodeProtocolSender protocolSender; - private final DateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss,SSS"); + private final DateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss,SSS", Locale.US); public BulletinsTask(NodeProtocolSender protocolSender) { if (protocolSender == null) { @@ -3315,7 +3315,7 @@ public class FlowController implements EventAccess, ControllerServiceProvider, H private class HeartbeatSendTask implements Runnable { private final NodeProtocolSender protocolSender; - private final DateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss,SSS"); + private final DateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss,SSS", Locale.US); public HeartbeatSendTask(final NodeProtocolSender protocolSender) { if (protocolSender == null) { diff --git a/nar-bundles/framework-bundle/framework/site-to-site/src/main/java/org/apache/nifi/remote/StandardRootGroupPort.java b/nar-bundles/framework-bundle/framework/site-to-site/src/main/java/org/apache/nifi/remote/StandardRootGroupPort.java index 8196d7399b..5fbd92fd6b 100644 --- a/nar-bundles/framework-bundle/framework/site-to-site/src/main/java/org/apache/nifi/remote/StandardRootGroupPort.java +++ b/nar-bundles/framework-bundle/framework/site-to-site/src/main/java/org/apache/nifi/remote/StandardRootGroupPort.java @@ -619,7 +619,7 @@ public class StandardRootGroupPort extends AbstractPort implements RootGroupPort @Override public SchedulingStrategy getSchedulingStrategy() { - return SchedulingStrategy.EVENT_DRIVEN; + return SchedulingStrategy.TIMER_DRIVEN; } @Override diff --git a/nar-bundles/framework-bundle/framework/web/nifi-web-api/src/main/java/org/apache/nifi/web/api/request/DateTimeParameter.java b/nar-bundles/framework-bundle/framework/web/nifi-web-api/src/main/java/org/apache/nifi/web/api/request/DateTimeParameter.java index 5fd7de8214..726f031f14 100644 --- a/nar-bundles/framework-bundle/framework/web/nifi-web-api/src/main/java/org/apache/nifi/web/api/request/DateTimeParameter.java +++ b/nar-bundles/framework-bundle/framework/web/nifi-web-api/src/main/java/org/apache/nifi/web/api/request/DateTimeParameter.java @@ -19,6 +19,7 @@ package org.apache.nifi.web.api.request; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.Locale; /** * Class for parsing integer parameters and providing a user friendly error @@ -45,7 +46,7 @@ public class DateTimeParameter { } public static String format(final Date date) { - SimpleDateFormat parser = new SimpleDateFormat(DATE_TIME_FORMAT); + SimpleDateFormat parser = new SimpleDateFormat(DATE_TIME_FORMAT, Locale.US); parser.setLenient(false); return parser.format(date); } @@ -55,7 +56,7 @@ public class DateTimeParameter { } public static Date parse(final String str) throws ParseException { - SimpleDateFormat parser = new SimpleDateFormat(DATE_TIME_FORMAT); + SimpleDateFormat parser = new SimpleDateFormat(DATE_TIME_FORMAT, Locale.US); parser.setLenient(false); return parser.parse(str); } diff --git a/nar-bundles/standard-bundle/standard-processors/src/main/java/org/apache/nifi/processors/standard/GetFile.java b/nar-bundles/standard-bundle/standard-processors/src/main/java/org/apache/nifi/processors/standard/GetFile.java index bf4de58cfb..2152d2ec6b 100644 --- a/nar-bundles/standard-bundle/standard-processors/src/main/java/org/apache/nifi/processors/standard/GetFile.java +++ b/nar-bundles/standard-bundle/standard-processors/src/main/java/org/apache/nifi/processors/standard/GetFile.java @@ -37,6 +37,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.ListIterator; +import java.util.Locale; import java.util.Map; import java.util.Set; import java.util.concurrent.BlockingQueue; @@ -304,7 +305,7 @@ public class GetFile extends AbstractProcessor { FileStore store = Files.getFileStore(file); if (store.supportsFileAttributeView("basic")) { try { - final DateFormat formatter = new SimpleDateFormat(FILE_MODIFY_DATE_ATTR_FORMAT); + final DateFormat formatter = new SimpleDateFormat(FILE_MODIFY_DATE_ATTR_FORMAT, Locale.US); BasicFileAttributeView view = Files.getFileAttributeView(file, BasicFileAttributeView.class); BasicFileAttributes attrs = view.readAttributes(); attributes.put(FILE_LAST_MODIFY_TIME_ATTRIBUTE, formatter.format(new Date(attrs.lastModifiedTime().toMillis()))); diff --git a/nar-bundles/standard-bundle/standard-processors/src/main/java/org/apache/nifi/processors/standard/GetFileTransfer.java b/nar-bundles/standard-bundle/standard-processors/src/main/java/org/apache/nifi/processors/standard/GetFileTransfer.java index 7eff28c115..3edebe832e 100644 --- a/nar-bundles/standard-bundle/standard-processors/src/main/java/org/apache/nifi/processors/standard/GetFileTransfer.java +++ b/nar-bundles/standard-bundle/standard-processors/src/main/java/org/apache/nifi/processors/standard/GetFileTransfer.java @@ -27,6 +27,7 @@ import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Set; import java.util.concurrent.BlockingQueue; @@ -257,7 +258,7 @@ public abstract class GetFileTransfer extends AbstractProcessor { protected Map getAttributesFromFile(FileInfo info) { Map attributes = new HashMap<>(); if (info != null) { - final DateFormat formatter = new SimpleDateFormat(FILE_MODIFY_DATE_ATTR_FORMAT); + final DateFormat formatter = new SimpleDateFormat(FILE_MODIFY_DATE_ATTR_FORMAT, Locale.US); attributes.put(FILE_LAST_MODIFY_TIME_ATTRIBUTE, formatter.format(new Date(info.getLastModifiedTime()))); attributes.put(FILE_PERMISSIONS_ATTRIBUTE, info.getPermissions()); attributes.put(FILE_OWNER_ATTRIBUTE, info.getOwner()); diff --git a/nar-bundles/standard-bundle/standard-processors/src/main/java/org/apache/nifi/processors/standard/GetHTTP.java b/nar-bundles/standard-bundle/standard-processors/src/main/java/org/apache/nifi/processors/standard/GetHTTP.java index 321f2c3408..85fc1ac0f3 100644 --- a/nar-bundles/standard-bundle/standard-processors/src/main/java/org/apache/nifi/processors/standard/GetHTTP.java +++ b/nar-bundles/standard-bundle/standard-processors/src/main/java/org/apache/nifi/processors/standard/GetHTTP.java @@ -29,6 +29,7 @@ import java.util.Collections; import java.util.Date; import java.util.HashSet; import java.util.List; +import java.util.Locale; import java.util.Properties; import java.util.Set; import java.util.TimeZone; @@ -61,7 +62,6 @@ import org.apache.nifi.processor.util.StandardValidators; import org.apache.nifi.ssl.SSLContextService; import org.apache.nifi.ssl.SSLContextService.ClientAuth; import org.apache.nifi.util.StopWatch; - import org.apache.http.Header; import org.apache.http.HttpResponse; import org.apache.http.auth.AuthScope; @@ -173,7 +173,7 @@ public class GetHTTP extends AbstractSessionFactoryProcessor { static final String LAST_MODIFIED = "LastModified"; static { - SimpleDateFormat sdf = new SimpleDateFormat(LAST_MODIFIED_DATE_PATTERN_RFC1123); + SimpleDateFormat sdf = new SimpleDateFormat(LAST_MODIFIED_DATE_PATTERN_RFC1123, Locale.US); sdf.setTimeZone(TimeZone.getTimeZone("GMT")); UNINITIALIZED_LAST_MODIFIED_VALUE = sdf.format(new Date(1L)); } diff --git a/nar-bundles/standard-bundle/standard-processors/src/main/java/org/apache/nifi/processors/standard/PutFile.java b/nar-bundles/standard-bundle/standard-processors/src/main/java/org/apache/nifi/processors/standard/PutFile.java index c6e4854cef..6db275796d 100644 --- a/nar-bundles/standard-bundle/standard-processors/src/main/java/org/apache/nifi/processors/standard/PutFile.java +++ b/nar-bundles/standard-bundle/standard-processors/src/main/java/org/apache/nifi/processors/standard/PutFile.java @@ -29,6 +29,7 @@ import java.util.Collections; import java.util.Date; import java.util.HashSet; import java.util.List; +import java.util.Locale; import java.util.Set; import java.util.concurrent.TimeUnit; import java.util.regex.Pattern; @@ -226,7 +227,7 @@ public class PutFile extends AbstractProcessor { final String lastModifiedTime = context.getProperty(CHANGE_LAST_MODIFIED_TIME).evaluateAttributeExpressions(flowFile).getValue(); if (lastModifiedTime != null && !lastModifiedTime.trim().isEmpty()) { try { - final DateFormat formatter = new SimpleDateFormat(FILE_MODIFY_DATE_ATTR_FORMAT); + final DateFormat formatter = new SimpleDateFormat(FILE_MODIFY_DATE_ATTR_FORMAT, Locale.US); final Date fileModifyTime = formatter.parse(lastModifiedTime); dotCopyFile.toFile().setLastModified(fileModifyTime.getTime()); } catch (Exception e) { diff --git a/nar-bundles/standard-bundle/standard-processors/src/main/java/org/apache/nifi/processors/standard/util/FTPTransfer.java b/nar-bundles/standard-bundle/standard-processors/src/main/java/org/apache/nifi/processors/standard/util/FTPTransfer.java index 3a7dff77fa..04a9a0f90f 100644 --- a/nar-bundles/standard-bundle/standard-processors/src/main/java/org/apache/nifi/processors/standard/util/FTPTransfer.java +++ b/nar-bundles/standard-bundle/standard-processors/src/main/java/org/apache/nifi/processors/standard/util/FTPTransfer.java @@ -28,6 +28,7 @@ import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.Locale; import java.util.concurrent.TimeUnit; import java.util.regex.Pattern; @@ -37,7 +38,6 @@ import org.apache.nifi.logging.ProcessorLog; import org.apache.nifi.processor.ProcessContext; import org.apache.nifi.processor.exception.ProcessException; import org.apache.nifi.processor.util.StandardValidators; - import org.apache.commons.net.ftp.FTPClient; import org.apache.commons.net.ftp.FTPFile; import org.apache.commons.net.ftp.FTPReply; @@ -346,9 +346,9 @@ public class FTPTransfer implements FileTransfer { final String lastModifiedTime = ctx.getProperty(LAST_MODIFIED_TIME).evaluateAttributeExpressions(flowFile).getValue(); if (lastModifiedTime != null && !lastModifiedTime.trim().isEmpty()) { try { - final DateFormat informat = new SimpleDateFormat(FILE_MODIFY_DATE_ATTR_FORMAT); + final DateFormat informat = new SimpleDateFormat(FILE_MODIFY_DATE_ATTR_FORMAT, Locale.US); final Date fileModifyTime = informat.parse(lastModifiedTime); - final DateFormat outformat = new SimpleDateFormat(FTP_TIMEVAL_FORMAT); + final DateFormat outformat = new SimpleDateFormat(FTP_TIMEVAL_FORMAT, Locale.US); final String time = outformat.format(fileModifyTime); if (!client.setModificationTime(tempFilename, time)) { // FTP server probably doesn't support MFMT command diff --git a/nar-bundles/standard-bundle/standard-processors/src/main/java/org/apache/nifi/processors/standard/util/SFTPTransfer.java b/nar-bundles/standard-bundle/standard-processors/src/main/java/org/apache/nifi/processors/standard/util/SFTPTransfer.java index 5e53d954dd..a294aa406a 100644 --- a/nar-bundles/standard-bundle/standard-processors/src/main/java/org/apache/nifi/processors/standard/util/SFTPTransfer.java +++ b/nar-bundles/standard-bundle/standard-processors/src/main/java/org/apache/nifi/processors/standard/util/SFTPTransfer.java @@ -26,6 +26,7 @@ import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.Locale; import java.util.Properties; import java.util.Vector; import java.util.concurrent.TimeUnit; @@ -37,7 +38,6 @@ import org.apache.nifi.flowfile.FlowFile; import org.apache.nifi.logging.ProcessorLog; import org.apache.nifi.processor.ProcessContext; import org.apache.nifi.processor.util.StandardValidators; - import org.slf4j.LoggerFactory; import com.jcraft.jsch.ChannelSftp; @@ -524,7 +524,7 @@ public class SFTPTransfer implements FileTransfer { final String lastModifiedTime = ctx.getProperty(LAST_MODIFIED_TIME).evaluateAttributeExpressions(flowFile).getValue(); if (lastModifiedTime != null && !lastModifiedTime.trim().isEmpty()) { try { - final DateFormat formatter = new SimpleDateFormat(FILE_MODIFY_DATE_ATTR_FORMAT); + final DateFormat formatter = new SimpleDateFormat(FILE_MODIFY_DATE_ATTR_FORMAT, Locale.US); final Date fileModifyTime = formatter.parse(lastModifiedTime); int time = (int) (fileModifyTime.getTime() / 1000L); sftp.setMtime(tempPath, time); diff --git a/nar-bundles/standard-bundle/standard-processors/src/test/java/org/apache/nifi/processors/standard/RESTServiceContentModified.java b/nar-bundles/standard-bundle/standard-processors/src/test/java/org/apache/nifi/processors/standard/RESTServiceContentModified.java index 3aa6384112..8548c46256 100644 --- a/nar-bundles/standard-bundle/standard-processors/src/test/java/org/apache/nifi/processors/standard/RESTServiceContentModified.java +++ b/nar-bundles/standard-bundle/standard-processors/src/test/java/org/apache/nifi/processors/standard/RESTServiceContentModified.java @@ -18,6 +18,7 @@ package org.apache.nifi.processors.standard; import java.io.IOException; import java.text.SimpleDateFormat; +import java.util.Locale; import java.util.TimeZone; import javax.servlet.http.HttpServlet; @@ -42,7 +43,7 @@ public class RESTServiceContentModified extends HttpServlet { String ifModifiedSince = request.getHeader("If-Modified-Since"); String ifNoneMatch = request.getHeader("If-None-Match"); - final SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz"); + final SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US); dateFormat.setTimeZone(TimeZone.getTimeZone("GMT")); response.setContentType("application/json"); diff --git a/nar-bundles/standard-bundle/standard-processors/src/test/java/org/apache/nifi/processors/standard/TestGetFile.java b/nar-bundles/standard-bundle/standard-processors/src/test/java/org/apache/nifi/processors/standard/TestGetFile.java index a2b36eb531..018cbdc330 100644 --- a/nar-bundles/standard-bundle/standard-processors/src/test/java/org/apache/nifi/processors/standard/TestGetFile.java +++ b/nar-bundles/standard-bundle/standard-processors/src/test/java/org/apache/nifi/processors/standard/TestGetFile.java @@ -17,6 +17,7 @@ package org.apache.nifi.processors.standard; import org.apache.nifi.processors.standard.GetFile; + import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -31,12 +32,12 @@ import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; +import java.util.Locale; import org.apache.nifi.flowfile.attributes.CoreAttributes; import org.apache.nifi.util.MockFlowFile; import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; - import org.junit.Test; public class TestGetFile { @@ -83,7 +84,7 @@ public class TestGetFile { @Test public void testTodaysFilesPickedUp() throws IOException { - final SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd"); + final SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd", Locale.US); final String dirStruc = sdf.format(new Date()); final File directory = new File("target/test/data/in/" + dirStruc); @@ -107,7 +108,7 @@ public class TestGetFile { @Test public void testPath() throws IOException { - final SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd/"); + final SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd/", Locale.US); final String dirStruc = sdf.format(new Date()); final File directory = new File("target/test/data/in/" + dirStruc); @@ -171,7 +172,7 @@ public class TestGetFile { if (verifyLastModified) { try { - final DateFormat formatter = new SimpleDateFormat(GetFile.FILE_MODIFY_DATE_ATTR_FORMAT); + final DateFormat formatter = new SimpleDateFormat(GetFile.FILE_MODIFY_DATE_ATTR_FORMAT, Locale.US); final Date fileModifyTime = formatter.parse(successFiles.get(0).getAttribute("file.lastModifiedTime")); assertEquals(new Date(1000000000), fileModifyTime); } catch (ParseException e) { diff --git a/nar-bundles/standard-bundle/standard-processors/src/test/java/org/apache/nifi/processors/standard/TestInvokeHTTP.java b/nar-bundles/standard-bundle/standard-processors/src/test/java/org/apache/nifi/processors/standard/TestInvokeHTTP.java index 85cd8364a5..85cd3db318 100644 --- a/nar-bundles/standard-bundle/standard-processors/src/test/java/org/apache/nifi/processors/standard/TestInvokeHTTP.java +++ b/nar-bundles/standard-bundle/standard-processors/src/test/java/org/apache/nifi/processors/standard/TestInvokeHTTP.java @@ -17,6 +17,7 @@ package org.apache.nifi.processors.standard; import org.apache.nifi.processors.standard.InvokeHTTP; + import static org.junit.Assert.*; import java.io.IOException; @@ -26,6 +27,7 @@ import java.nio.charset.StandardCharsets; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; +import java.util.Locale; import java.util.Map; import javax.servlet.ServletException; @@ -38,7 +40,6 @@ import org.apache.nifi.ssl.StandardSSLContextService; import org.apache.nifi.util.MockFlowFile; import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; - import org.eclipse.jetty.server.Handler; import org.eclipse.jetty.server.Request; import org.eclipse.jetty.server.Server; @@ -123,7 +124,7 @@ public class TestInvokeHTTP { // extract the date string sent to the server // and store it as a java.util.Date - SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z"); + SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US); Date date = sdf.parse(dh.dateString); // calculate the difference between the date string sent by the client and