Example usage for java.time Instant parse

List of usage examples for java.time Instant parse

Introduction

In this page you can find the example usage for java.time Instant parse.

Prototype

public static Instant parse(final CharSequence text) 

Source Link

Document

Obtains an instance of Instant from a text string such as 2007-12-03T10:15:30.00Z .

Usage

From source file:jp.classmethod.aws.brian.BrianClient.java

@Override
public CreateTriggerResult createTrigger(BrianTrigger trigger)
        throws BrianClientException, BrianServerException {
    logger.debug("create trigger: {}/{}", trigger.getGroup(), trigger.getName());
    HttpResponse httpResponse = null;/*from   w w w . j  a v a  2  s .  c om*/
    try {
        BrianTriggerRequest request = trigger.toBrianTriggerRequest();
        String requestBody = mapper.writeValueAsString(request);
        logger.trace("create: requestBody = {}", requestBody);
        HttpEntity entity = new StringEntity(requestBody);

        String path = String.format("/triggers/%s", trigger.getGroup());
        URI uri = new URI(scheme, null, hostname, port, path, null, null);
        HttpUriRequest httpRequest = RequestBuilder.post().setUri(uri).setEntity(entity).build();
        httpResponse = httpClientExecute(httpRequest);
        int statusCode = httpResponse.getStatusLine().getStatusCode();
        logger.debug("statusCode: {}", statusCode);
        JsonNode tree = mapper.readTree(httpResponse.getEntity().getContent());
        if (statusCode == HttpStatus.SC_CREATED) {
            String nextFireTime = tree.path("content").path("nextFireTime").asText();
            logger.info("trigger created: nextFireTime = {}", nextFireTime);
            return new CreateTriggerResult(Instant.parse(nextFireTime));
        } else if (statusCode >= 500) {
            throw new BrianServerException(String.format("status = %d; message = %s",
                    new Object[] { statusCode, tree.get("message").textValue() }));
        } else if (statusCode == HttpStatus.SC_CONFLICT) {
            throw new BrianClientException(String.format("triggerKey (%s/%s) is already exist",
                    new Object[] { trigger.getGroup(), trigger.getName() }));
        } else if (statusCode >= 400) {
            throw new BrianClientException(String.format("status = %d; message = %s",
                    new Object[] { statusCode, tree.get("message").textValue() }));
        } else {
            throw new Error(String.format("status = %d; message = %s",
                    new Object[] { statusCode, tree.get("message").textValue() }));
        }
    } catch (JsonProcessingException e) {
        throw new BrianServerException(e);
    } catch (URISyntaxException e) {
        throw new IllegalStateException(e);
    } catch (IOException e) {
        throw new BrianServerException(e);
    } catch (IllegalStateException e) {
        throw new Error(e);
    } finally {
        if (httpResponse != null) {
            EntityUtils.consumeQuietly(httpResponse.getEntity());
        }
    }
}

From source file:com.orange.ngsi2.utility.Utils.java

static public List<Subscription> createListSubscriptionsReference() throws MalformedURLException {

    SubjectEntity subjectEntity = new SubjectEntity();
    subjectEntity.setId(Optional.of("Bcn_Welt"));
    subjectEntity.setType(Optional.of("Room"));
    Condition condition = new Condition();
    condition.setAttributes(Collections.singletonList("temperature"));
    condition.setExpression("q", "temperature>40");
    SubjectSubscription subjectSubscription = new SubjectSubscription(Collections.singletonList(subjectEntity),
            condition);//from www.ja  v a  2 s  .c  o m
    List<String> attributes = new ArrayList<>();
    attributes.add("temperature");
    attributes.add("humidity");
    Notification notification = new Notification(attributes, new URL("http://localhost:1234"));
    notification.setHeader("X-MyHeader", "foo");
    notification.setQuery("authToken", "bar");
    notification.setAttrsFormat(Optional.of(Notification.Format.keyValues));
    notification.setThrottling(Optional.of(new Long(5)));
    notification.setTimesSent(12);
    notification.setLastNotification(Instant.parse("2015-10-05T16:00:00.10Z"));
    Subscription subscription = new Subscription("abcdefg", subjectSubscription, notification,
            Instant.parse("2016-04-05T14:00:00.20Z"), Subscription.Status.active);
    return Collections.singletonList(subscription);
}

From source file:org.apache.james.transport.mailets.DSNBounceTest.java

@Test
public void serviceShouldUpdateTheMailStateWhenNoSenderAndPassThroughIsFalse() throws Exception {
    FakeMailetConfig mailetConfig = FakeMailetConfig.builder().mailetName(MAILET_NAME)
            .mailetContext(fakeMailContext).setProperty("passThrough", "false").build();
    dsnBounce.init(mailetConfig);//from   www .  j  a v a  2 s.c  o m

    FakeMail mail = FakeMail.builder().attribute("delivery-error", "Delivery error")
            .mimeMessage(MimeMessageBuilder.mimeMessageBuilder().setText("My content")).name(MAILET_NAME)
            .recipient("recipient@domain.com").lastUpdated(Date.from(Instant.parse("2016-09-08T14:25:52.000Z")))
            .remoteAddr("remoteHost").build();

    dsnBounce.service(mail);

    assertThat(mail.getState()).isEqualTo(Mail.GHOST);
}

From source file:com.linecorp.bot.model.event.CallbackRequestTest.java

@Test
public void testUnknown() throws IOException {
    parse("callback/unknown.json", callbackRequest -> {
        assertThat(callbackRequest.getEvents()).hasSize(2);

        Event event1 = callbackRequest.getEvents().get(0);
        assertThat(event1).isInstanceOf(UnknownEvent.class);
        assertThat(event1.getSource()).isInstanceOf(UserSource.class);
        assertThat(event1.getSource().getUserId()).isEqualTo("U012345678901234567890123456789ab");
        assertThat(event1.getTimestamp()).isEqualTo(Instant.parse("2016-05-07T13:57:59.859Z"));
        assertThat(((UnknownEvent) event1).getType()).isEqualTo("greatNewFeature");

        Event event2 = callbackRequest.getEvents().get(1);
        assertThat(event2).isInstanceOf(MessageEvent.class);
        assertThat(event2.getSource()).isInstanceOf(UnknownSource.class);
        MessageEvent messageEvent = (MessageEvent) event2;
        assertThat(messageEvent.getMessage()).isInstanceOf(UnknownMessageContent.class);
    });/*from   w ww .  java 2 s.c  o m*/
}

From source file:org.openhab.binding.chromecast.internal.ChromecastStatusUpdater.java

private Object getValue(String channelId, Map<String, Object> metadata) {
    if (metadata == null) {
        return null;
    }/*from ww  w .j av  a 2s  . c  om*/

    if (channelId.equals(ChromecastBindingConstants.CHANNEL_BROADCAST_DATE)
            || channelId.equals(ChromecastBindingConstants.CHANNEL_RELEASE_DATE)
            || channelId.equals(ChromecastBindingConstants.CHANNEL_CREATION_DATE)) {
        String dateString = (String) metadata.get(channelId);
        if (dateString == null) {
            return null;
        }

        Instant instant = Instant.parse(dateString);
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(Date.from(instant));

        return calendar;
    }

    return metadata.get(channelId);
}

From source file:org.apache.james.transport.mailets.DSNBounceTest.java

@Test
public void serviceShouldNotUpdateTheMailStateWhenNoSenderPassThroughHasDefaultValue() throws Exception {
    FakeMailetConfig mailetConfig = FakeMailetConfig.builder().mailetName(MAILET_NAME)
            .mailetContext(fakeMailContext).build();
    dsnBounce.init(mailetConfig);//from  ww  w  . j av a  2  s . com

    FakeMail mail = FakeMail.builder().attribute("delivery-error", "Delivery error")
            .mimeMessage(MimeMessageBuilder.mimeMessageBuilder().setText("My content")).name(MAILET_NAME)
            .recipient("recipient@domain.com").lastUpdated(Date.from(Instant.parse("2016-09-08T14:25:52.000Z")))
            .remoteAddr("remoteHost").build();

    dsnBounce.service(mail);

    assertThat(mail.getState()).isNull();
}

From source file:com.orange.ngsi2.utility.Utils.java

static public Subscription createSubscriptionReference() throws MalformedURLException {
    SubjectEntity subjectEntity = new SubjectEntity();
    subjectEntity.setType(Optional.of("Room"));
    Condition condition = new Condition();
    condition.setAttributes(Collections.singletonList("temperature"));
    condition.setExpression("q", "temperature>40");
    SubjectSubscription subjectSubscription = new SubjectSubscription(Collections.singletonList(subjectEntity),
            condition);//ww  w . j a va2 s  .c om
    List<String> attributes = new ArrayList<>();
    attributes.add("temperature");
    attributes.add("humidity");
    Notification notification = new Notification(attributes, new URL("http://localhost:1234"));
    notification.setThrottling(Optional.of(new Long(5)));
    Subscription subscription = new Subscription();
    subscription.setSubject(subjectSubscription);
    subscription.setNotification(notification);
    subscription.setExpires(Instant.parse("2016-04-05T14:00:00.20Z"));
    return subscription;
}

From source file:org.apache.james.transport.mailets.DSNBounceTest.java

@Test
public void serviceShouldNotUpdateTheMailStateWhenNoSenderPassThroughIsTrue() throws Exception {
    FakeMailetConfig mailetConfig = FakeMailetConfig.builder().mailetName(MAILET_NAME)
            .mailetContext(fakeMailContext).setProperty("passThrough", "true").build();
    dsnBounce.init(mailetConfig);/*w w w  .  java  2  s .  c  o m*/

    FakeMail mail = FakeMail.builder().attribute("delivery-error", "Delivery error")
            .mimeMessage(MimeMessageBuilder.mimeMessageBuilder().setText("My content")).name(MAILET_NAME)
            .recipient("recipient@domain.com").lastUpdated(Date.from(Instant.parse("2016-09-08T14:25:52.000Z")))
            .remoteAddr("remoteHost").build();

    dsnBounce.service(mail);

    assertThat(mail.getState()).isNull();
}

From source file:com.orange.ngsi2.utility.Utils.java

static public Subscription createSubscriptionReferenceWithBadSyntax() throws MalformedURLException {
    SubjectEntity subjectEntity = new SubjectEntity();
    subjectEntity.setType(Optional.of("Room"));
    Condition condition = new Condition();
    condition.setAttributes(Collections.singletonList("temperature"));
    condition.setExpression("q", "temperature>40");
    SubjectSubscription subjectSubscription = new SubjectSubscription(Collections.singletonList(subjectEntity),
            condition);//  w w w . j  av  a2 s .  co  m
    List<String> attributes = new ArrayList<>();
    attributes.add("temperature");
    attributes.add("humidity#");
    Notification notification = new Notification(attributes, new URL("http://localhost:1234"));
    notification.setThrottling(Optional.of(new Long(5)));
    Subscription subscription = new Subscription();
    subscription.setSubject(subjectSubscription);
    subscription.setNotification(notification);
    subscription.setExpires(Instant.parse("2016-04-05T14:00:00.20Z"));
    return subscription;
}