日期格式 - momentjs - 使用区域设置语言分别提取日期和时间(Date format - momentjs - extract date and time separately using locale language)
我正在使用moment.js库我有这种格式的日期:
2014-08-07T10:00:00+02:00
我想要两个单独的值:
- Thursday, August 7 2014 - 10 am
但我也希望他们使用当地语言。 例如,如果是moment.lang(“fr”),则输出应为
- Jeudi 7 Août 2014 - 10h
我以正确的方式设置了moment.js lang。 我设法删除小时,分钟和秒(以提取第一个值):
new Date(moment.utc(date).format('LL')) //Outputs Thu Aug 07 2014 00:00:00 GMT+0200 (Paris, Madrid)
但我不知道如何提取小时和分钟 (第二个值)以及如何使用当前语言显示日期。
I am using moment.js library I have a date in this format :
2014-08-07T10:00:00+02:00
I want to have two separate values :
- Thursday, August 7 2014 - 10 am
But I also want them to be using the local language. For example, if moment.lang("fr"), the output should be
- Jeudi 7 Août 2014 - 10h
I set the moment.js lang in the correct way. I managed to remove hour,minutes and seconds (to extract the first value) :
new Date(moment.utc(date).format('LL')) //Outputs Thu Aug 07 2014 00:00:00 GMT+0200 (Paris, Madrid)
But I don't know how to extract the hour and minutes (for the second value) and how to show the date using the current language.
原文:https://stackoverflow.com/questions/25179377
最满意答案
我真的不明白为什么你需要使用2个不同的密钥库,因为密钥库配置提供了使用多个证书的可能性。
从文档引用:
要使JMeter使用多个证书,您需要确保:
https.use.cached.ssl.context=false
在jmeter.properties或user.properties中设置您对HTTP请求使用HTTPClient 4(ADVISED)或HTTPClient 3.1(DEPRECATED SINCE 3.0)实现
如果出于任何原因,您仍然需要使用2个密钥库 ,而不是来自一个密钥库的2个证书,遗憾的是,在密钥库配置初始化之前无法执行Beanshell测试元素(或任何内容)。
但是,您应该能够强制从Beanshell脚本重新初始化。
示例代码:
import org.apache.jmeter.config.KeystoreConfig; import org.apache.jmeter.engine.StandardJMeterEngine; import org.apache.jmeter.testelement.TestPlan; import org.apache.jorphan.collections.HashTree; import org.apache.jorphan.collections.SearchByClass; import java.lang.reflect.Field; import java.util.Collection; StandardJMeterEngine engine = ctx.getEngine(); Field test = engine.getClass().getDeclaredField("test"); test.setAccessible(true); HashTree testPlanTree = (HashTree) test.get(engine); SearchByClass keyStoreConfigs = new SearchByClass(KeystoreConfig.class); testPlanTree.traverse(keyStoreConfigs); Collection keystoreConfigResults = keyStoreConfigs.getSearchResults(); KeystoreConfig keystoreConfig = (KeystoreConfig)keystoreConfigResults.toArray()[0]; keystoreConfig.testStarted();
请参阅如何使用BeanShell:JMeter最喜欢的内置组件文章,以获取有关JMeter中Beanshell脚本的高级信息。
I am able to solve this issue with the below steps:
- Get all the certs(pfx) for the application environments
- Optional: Change the extension of the files to p12
Set a meaningful alias names to these certs with the below command:
keytool -changealias -alias "ExistingAliasName" -destalias "AppName_Environment" -keystore "C:\JKS\AppName_environment.p12" -storepass "StorePassword"
Notes for step 3:
a. It might ask to enter keypass and we can enter the store pass
b. Even we provide upper case in alias name, the text will be converted to lower case and will be set as alias name
c. Here I followed this alias naming convention: application name_environment name as mentioned in JMeter
Import the certs into a JKS file and we can set any password to JKS and need not be same as cert. See the below command:
keytool -importkeystore -srckeystore "C:\ JKS\ AppName _ Environment.p12" -srcstoretype pkcs12 -srcstorepass "SourceStorePasword” -destkeystore "C:\HomesiteJKS\BungalowFinal.jks" -deststoretype JKS -storepass "JKSPassword"
- Repeat the above step for all the remaining certs by changing the required parameter values
Once we have the final JKS, we can start changing password for each of the cert in JKS and make it same as JKS(keystore) password. See the below command:
keytool -keypasswd -alias " AppName_Environment" -keystore “C:\JKS\Final.jks"
Note for step 6: It will ask you to enter keystore password, existing cert password, new password and repeat new password
- Repeat this step for all the cert entries of JKS file to have JKS password for all the certs
Now we can use this file and add below entries in system.properties of JMeter:
javax.net.ssl.keyStore=C:/JKS/Final.jks
javax.net.ssl.keyStorePassword=JKSPassword
Add the below entry either in user.properties or jmeter.properties of JMeter, which will allow us to use multiple certs from JKS file:
https.use.cached.ssl.context=false
- Change Http Request implementation to
HttpClient4
Add Keystore configuration element to JMeter test with the below values:
a. Preload: True
b. Variable name holding certificate alias: CertAlias
c. Alias Start index: 0
d. Alias End index: 10000
- JMeter user defined variables must have CertAlias with the required alias name
- All set and we should be able to run the script on different application environments by loading particular cert with alias name
相关问答
更多-
如何使用jarx中的文件作为javax.net.ssl.keystore?(How to use a file in a jar as javax.net.ssl.keystore?)[2024-04-03]
仍然在实现,但我相信可以通过InputStream从jar中加载密钥库,并以编程方式显式设置TrustStore(vs设置系统属性)。 请参阅文章: 在同一个JVM上设置多个信任库 得到它的工作! InputStream keystoreInput = Thread.currentThread().getContextClassLoader() .getResourceAsStream(/client.ks"); InputStream truststoreInput = ... -
如果在这种情况下使用系统属性设置了代理,则所有后续的Https调用都将使用该代理,即使您没有在程序中进行设置,java也会在内部执行此操作。 在我们的例子中,我们想要访问没有代理的服务器1,对于服务器2,我们想要代理。 因此,当我们第一次尝试访问Server2时,我们使用系统属性设置Proxy,之后当我们尝试连接到服务器1时,它失败了因为https请求通过代理并且在我们的代理服务器上没有策略集对于服务器1 解决方案:1)Donot在系统级别设置代理,在连接级别添加2)在服务器1的代理服务器中添加规则,因此服 ...
-
您可以创建自己的RMIConnectorServer ,并有条件地为SSL启用它。 构造服务器实例时,可以使用定义的RMIClientSocketFactory和RMIServerSocketFactory实例加载环境映射。 要启用SSL,可以将这些工厂设置为已配置的SslRMIClientSocketFactory和SslRMIServerSocketFactory实例,并且您将重新创建系统道具配置的连接器服务器的等效项。 我没有用SSL做过这个,但它似乎记录得很清楚。 You can create yo ...
-
javax.net.ssl.SSLException:SSLSocketFactory为null(javax.net.ssl.SSLException: SSLSocketFactory is null)[2023-03-25]
即使在Windows上,您也可以尝试使用正斜杠: System.setProperty("javax.net.ssl.keyStoreType", "pkcs12"); System.setProperty("javax.net.ssl.trustStoreType", "jks"); System.setProperty("javax.net.ssl.keyStore","C:/ClientKeyStore/ClientKeyStore.p12"); System.setProperty("javax.n ... -
对不起..我没有检查正确..方法3工作.. Sorry..I did not check properly.. Approach 3 worked..
-
所以经过一些挖掘和评论中的想法,它归结为Tomcat配置。 Tomcat配置只允许RC4-SHA ,这是不安全的,并且不再受Java 8支持,每个RFC7465 (感谢Robert的参考)。 通过更新服务器SSL配置并删除RC4-SHA仅限于密码)并允许所有默认密码套件,例如从server.xml Tomcat配置文件中删除SSLCipherSuite="RC4-SHA" ,我得到了JMeter在Java8上的工作。 增加更强大的安全加密( JCE Unlimited Strength Policy ),将 ...
-
我真的不明白为什么你需要使用2个不同的密钥库,因为密钥库配置提供了使用多个证书的可能性。 从文档引用: 要使JMeter使用多个证书,您需要确保: https.use.cached.ssl.context=false在jmeter.properties或user.properties中设置 您对HTTP请求使用HTTPClient 4(ADVISED)或HTTPClient 3.1(DEPRECATED SINCE 3.0)实现 如果出于任何原因,您仍然需要使用2个密钥库 ,而不是来自一个密钥库的2个证书, ...
-
您的javax.net.ssl.trustStore设置仅实现了默认设置。 删除它们。 密钥库不是信任库。 除非您通过向其添加自己的私钥和证书来使Java信任库发声,否则您指定的密钥库应该与信任库不同。 除非您要连接的服务器需要客户端证书,否则根本不需要密钥库。 所以修复或删除它。 您需要将确切的异常和堆栈跟踪粘贴到您的问题中,以获得进一步的帮助。 Thanks to some questions here I could find out that the enabled protocols on my ...
-
不起作用的原因是这些系统属性期望在实际文件系统上存在文件,而不是在存档内。 使用这些密钥库和信任流创建自己的SSLContext会更好: KeyStore keyStore = KeyStore.getInstance("jks"); keyStore.load(TestFramework.class.getResourceAsStream("/security/keystore.jks"), password.toCharArray()); KeyManagerFactory keyManagerFact ...
-
在您上一次评论之后,我设法重现了与您的主机不匹配的证书与您的主机匹配的问题。 看来你正面临着Java 6中的一个错误。事实上,我重现了JDK6的问题,但没有使用JMeter 2.7重现JDK7。 要记录这个,我在这里打开了错误: https://issues.apache.org/bugzilla/show_bug.cgi?id=53922 在这里,Oleg给了我关于JDK7的提示: https://issues.apache.org/jira/browse/HTTPCLIENT-1234 进一步分析您的配 ...