List of usage examples for java.time Instant now
public static Instant now()
From source file:com.joyent.manta.client.MantaClientSigningIT.java
@Test public final void testCanCreateSignedHEADUriFromPath() throws IOException { if (config.isClientEncryptionEnabled()) { throw new SkipException("Signed URLs are not decrypted by the client"); }//from w w w .j a va2 s .c o m final String name = UUID.randomUUID().toString(); final String path = testPathPrefix + name; mantaClient.put(path, TEST_DATA); // This will throw an error if the newly inserted object isn't present mantaClient.head(path); Instant expires = Instant.now().plus(1, ChronoUnit.HOURS); URI uri = mantaClient.getAsSignedURI(path, "HEAD", expires); HttpURLConnection connection = (HttpURLConnection) uri.toURL().openConnection(); try { connection.setReadTimeout(3000); connection.setRequestMethod("HEAD"); connection.connect(); Map<String, List<String>> headers = connection.getHeaderFields(); if (connection.getResponseCode() != 200) { Assert.fail(IOUtils.toString(connection.getErrorStream(), Charset.defaultCharset())); } Assert.assertNotNull(headers); Assert.assertEquals(TEST_DATA.length(), connection.getContentLength()); } finally { connection.disconnect(); } }
From source file:cn.edu.zjnu.acm.judge.config.SecurityConfiguration.java
private void saveLoginLog(HttpServletRequest request, boolean success) { String userId = Optional.ofNullable(request.getParameter("user_id1")).orElse(""); String password = Optional.ofNullable(request.getParameter("password1")).orElse(""); loginlogService.save(LoginLog.builder().user(userId).password(passwordConfuser.confuse(password)) .ip(request.getRemoteAddr()).success(success).build()); if (success) { Optional.ofNullable(userMapper.findOne(userId)).ifPresent(user -> { userMapper.update(user.toBuilder().accesstime(Instant.now()).ip(request.getRemoteAddr()).build()); });/*from www .j a v a2 s . com*/ } }
From source file:no.ssb.jsonstat.v2.DatasetTest.java
@Test public void testBuilder() throws Exception { DatasetBuilder builder = Dataset.create().withLabel(""); builder.withSource(""); builder.updatedAt(Instant.now()); Dimension.Builder dimension = Dimension.create("year").withRole(Dimension.Roles.TIME) .withCategories(ImmutableSet.of("2003", "2004", "2005")); DatasetValueBuilder valueBuilder = builder.withDimensions(dimension, Dimension.create("month").withRole(Dimension.Roles.TIME) .withCategories(ImmutableSet.of("may", "june", "july")), Dimension.create("week").withTimeRole().withLabels(ImmutableList.of("30", "31", "32")), Dimension.create("population").withIndexedLabels( ImmutableMap.of("A", "active population", "E", "employment", "U", "unemployment", "I", "inactive population", "T", "population 15 years old and over")), Dimension.create("arrival").withMetricRole(), Dimension.create("departure").withRole(Dimension.Roles.METRIC)); builder.withExtension(ImmutableMap.<String, String>of("arbitrary_field", "arbitrary_value")); // TODO: addDimension("name") returning Dimension.Builder? Super fluent? // TODO: How to ensure valid data with the geo builder? Add the type first and extend builders? // TODO: express hierarchy with the builder? Check how ES did that with the query builders. // example: builder.withDimension(Dimension.create("location") // .withGeoRole()); //Dataset build = valueBuilder.build(); //assertThat(build).isNotNull(); }
From source file:nl.ctrlaltdev.harbinger.evidence.EvidenceCollectorTest.java
@Test public void shouldClean() { evidence = new Evidence(new Evidence(evidence, request), response); collector.store(evidence);// ww w . j a va 2 s. co m collector.store(evidence); collector.store(evidence); assertEquals(3, collector.findByIp(evidence).getNumberOfRequests()); assertEquals(3, collector.findBySession(evidence).getNumberOfRequests()); collector.clean(Instant.now().plusMillis(1)); // cleans anything before this time. assertEquals(1, collector.findByIp(evidence).getNumberOfRequests()); assertEquals(1, collector.findBySession(evidence).getNumberOfRequests()); }
From source file:com.coinblesk.server.service.KeyService.java
@Transactional public Pair<Boolean, Keys> storeKeysAndAddress(@NonNull final byte[] clientPublicKey, @NonNull final byte[] serverPublicKey, @NonNull final byte[] serverPrivateKey) { // need to check if it exists here, as not all DBs do that for us final Keys keys = keyRepository.findByClientPublicKey(clientPublicKey); if (keys != null) { return new Pair<>(false, keys); }/* w w w . j a va 2s . c o m*/ final Keys clientKey = new Keys().clientPublicKey(clientPublicKey).serverPrivateKey(serverPrivateKey) .serverPublicKey(serverPublicKey).timeCreated(Instant.now().getEpochSecond()); final Keys storedKeys = keyRepository.save(clientKey); return new Pair<>(true, storedKeys); }
From source file:net.jmhertlein.mcanalytics.api.auth.SSLUtil.java
/** * Creates a new self-signed X509 certificate * * @param pair the public/private keypair- the pubkey will be added to the cert and the private * key will be used to sign the certificate * @param subject the distinguished name of the subject * @param isAuthority true to make the cert a CA cert, false otherwise * @return/*w w w .jav a 2 s . c om*/ */ public static X509Certificate newSelfSignedCertificate(KeyPair pair, X500Name subject, boolean isAuthority) { X509v3CertificateBuilder b = new JcaX509v3CertificateBuilder(subject, BigInteger.probablePrime(128, new SecureRandom()), Date.from(Instant.now().minusSeconds(1)), Date.from(LocalDateTime.now().plusYears(3).toInstant(ZoneOffset.UTC)), subject, pair.getPublic()); try { b.addExtension(Extension.basicConstraints, true, new BasicConstraints(isAuthority)); } catch (CertIOException ex) { Logger.getLogger(SSLUtil.class.getName()).log(Level.SEVERE, null, ex); } try { X509CertificateHolder bcCert = b.build( new JcaContentSignerBuilder(SIGNING_ALGORITHM).setProvider("BC").build(pair.getPrivate())); return new JcaX509CertificateConverter().setProvider("BC").getCertificate(bcCert); } catch (CertificateException | OperatorCreationException ex) { Logger.getLogger(SSLUtil.class.getName()).log(Level.SEVERE, null, ex); return null; } }
From source file:com.perry.infrastructure.call.CallDaoServiceImpl.java
@Override public Call create(Call call) { String sql = "INSERT INTO calls(\r\n" + // " customer_first_name, customer_last_name, pick_up_location, \r\n" + // " drop_off_location, customer_vehicle_year, customer_vehicle_make, \r\n" + // " customer_vehicle_model, customer_vehicle_color, customer_vehicle_license_plate_number, \r\n" + ////ww w .j ava2 s . c om " customer_phone_number, customer_vehicle_key_location, customer_call_type, \r\n" + // " customer_payment_information, insert_by, update_by, truck_id, \r\n" + // " insert_time, update_time)\r\n" + // " VALUES (:customerFirstName, :customerLastName, :pickUpLocation, \r\n" + // " :dropOffLocation, :customerVehicleYear, :customerVehicleMake, \r\n" + // " :customerVehicleModel, :customerVehicleColor, :customerVehicleLiscensePlateNumber, \r\n" + // " :customerPhoneNumber, :customerVehicleKeyLocation, :customerCallType, \r\n" + // " :customerPaymentInformation , :insertBy, :updateBy, :truckId, \r\n" + // " :insertTime, :updateTime)"; MapSqlParameterSource params = new MapSqlParameterSource(); params.addValue("customerFirstName", call.getCustomer().getFirstName()); params.addValue("customerLastName", call.getCustomer().getLastName()); params.addValue("pickUpLocation", call.getPickUpLocation()); params.addValue("dropOffLocation", call.getDropOffLocation()); params.addValue("customerVehicleYear", call.getCustomer().getVehicle().getYear()); params.addValue("customerVehicleMake", call.getCustomer().getVehicle().getMake()); params.addValue("customerVehicleModel", call.getCustomer().getVehicle().getMake()); params.addValue("customerVehicleColor", call.getCustomer().getVehicle().getColor()); params.addValue("customerVehicleLiscensePlateNumber", call.getCustomer().getVehicle().getLicensePlateNumber()); params.addValue("customerPhoneNumber", call.getCustomer().getPhoneNumber()); params.addValue("customerVehicleKeyLocation", call.getCustomer().getVehicle().getKeyLocationType().getValue()); params.addValue("customerCallType", call.getCallType().getValue()); params.addValue("customerPaymentInformation", call.getCustomer().getVehicle().getMake()); params.addValue("insertBy", 1); params.addValue("updateBy", 1); params.addValue("truckId", 0); params.addValue("insertTime", Instant.now().getEpochSecond()); params.addValue("updateTime", Instant.now().getEpochSecond()); GeneratedKeyHolder keyHolder = new GeneratedKeyHolder(); namedParameterJdbcTemplate.update(sql, params, keyHolder); // update call with primary key returned from DB call.setId((Long) keyHolder.getKeys().get("call_id")); return call; }
From source file:com.buffalokiwi.api.APIDate.java
/** * Attempt to take some value and turn it into a valid APIDate. * If it isn't valid, then this returns null. * // w w w .ja v a 2 s . c om * @param value Jet value * @return date or null */ public static APIDate fromStringOrNull(String value) { if (value == null || value.isEmpty()) return null; for (final DateTimeFormatter fmt : FORMATS) { try { final TemporalAccessor t = fmt.parse(value); try { return new APIDate(ZonedDateTime.from(t)); } catch (DateTimeException e) { APILog.warn(LOG, e, "Failed to determine timezone. Defaulting to local offset"); final LocalDateTime local = LocalDateTime.from(t); final ZoneOffset offset = ZoneId.systemDefault().getRules().getOffset(Instant.now()); return new APIDate(ZonedDateTime.of(local, offset)); } } catch (DateTimeParseException e) { //..do nothing, yet. } } //..Not found. Log it and return null APILog.error(LOG, "Failed to parse date string:", value); return null; }
From source file:org.ng200.openolympus.services.ContestService.java
public Contest getRunningContest() { return this.intersects(Date.from(Instant.now()), Date.from(Instant.now())); }
From source file:eu.hansolo.tilesfx.tools.Location.java
public Location(final double LATITUDE, final double LONGITUDE, final double ALTITUDE, final String NAME) { this(LATITUDE, LONGITUDE, ALTITUDE, Instant.now(), NAME, "", TileColor.BLUE); }