org.apache.commons.lang3.time.DateParser Java Examples
The following examples show how to use
org.apache.commons.lang3.time.DateParser.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JwtCreatorCallout.java From iloveapis2015-jwt-jwe-jws with Apache License 2.0 | 5 votes |
private static Date parseDate(String dateString) { if (dateString == null) return null; Matcher m = secondsSinceEpochPattern.matcher(dateString); if (m.matches()) { return new Date(Long.parseLong(dateString) * 1000); } for (DateParser format : allowableInputFormats){ try { return format.parse(dateString); } catch (ParseException ex) { } } return null; }
Example #2
Source File: TestJwtCreation.java From iloveapis2015-jwt-jwe-jws with Apache License 2.0 | 5 votes |
@Test public void CreateJwt_ExplicitNotBeforeTime() throws Exception { String notBeforeString = "2017-08-14T11:00:21.269-0700"; Map properties = new HashMap(); properties.put("algorithm", "RS256"); properties.put("debug", "true"); properties.put("not-before", notBeforeString); properties.put("private-key", privateKeyMap.get("rsa-private-3")); properties.put("expiresIn", "300"); // seconds properties.put("claim_testname", "CreateJwt_ExplicitNotBeforeTime"); properties.put("claim_jti", java.util.UUID.randomUUID().toString()); JwtCreatorCallout callout = new JwtCreatorCallout(properties); ExecutionResult result = callout.execute(msgCtxt, exeCtxt); // check result and output Assert.assertEquals(result, ExecutionResult.SUCCESS); // retrieve and check output String jwt = msgCtxt.getVariable("jwt_jwt"); System.out.println("jwt: " + jwt); String jwtClaims = msgCtxt.getVariable("jwt_claims"); Assert.assertNotNull(jwtClaims, "jwt_claims"); System.out.println("claims: " + jwtClaims); JsonNode claimsNode = om.readTree(jwtClaims); String nbfAsText = claimsNode.get("nbf").asText(); Assert.assertNotNull(nbfAsText, "nbf"); DateParser dp = FastDateFormat.getInstance("yyyy-MM-dd'T'HH:mm:ss.SSSZ", TimeZone.getTimeZone("UTC")); Date notBefore = dp.parse(notBeforeString); int secondsNbfExpected = (int) (notBefore.getTime()/1000); int secondsNbfActual = Integer.parseInt(nbfAsText); Assert.assertEquals( secondsNbfActual, secondsNbfExpected, "nbf"); }