Example usage for java.util SimpleTimeZone UTC_TIME

List of usage examples for java.util SimpleTimeZone UTC_TIME

Introduction

In this page you can find the example usage for java.util SimpleTimeZone UTC_TIME.

Prototype

int UTC_TIME

To view the source code for java.util SimpleTimeZone UTC_TIME.

Click Source Link

Document

Constant for a mode of start or end time specified as UTC.

Usage

From source file:com.ibm.dgaasx.utils.JSONUtils.java

public static SimpleDateFormat getSDFISO8601() {
    SimpleDateFormat sdf = new ISO8601DateTimeFormat();
    sdf.setTimeZone(new SimpleTimeZone(SimpleTimeZone.UTC_TIME, "UTC")); //$NON-NLS-1$
    return sdf;/*  w w w  .j ava2  s  .  co m*/
}

From source file:com.devicehive.service.time.LocalTimestampService.java

@Override
public String getDateAsString() {
    DATE_FORMAT.setTimeZone(new SimpleTimeZone(SimpleTimeZone.UTC_TIME, "UTC"));
    return DATE_FORMAT.format(getDate());
}

From source file:wsattacker.sso.openid.attacker.evaluation.attack.ReplayAttack.java

@Attack(number = 0)
private AttackResult performSameResponseNonceAttack() {
    OpenIdServerConfiguration.getAttackerInstance().setPerformAttack(true);

    String description = "The same timestamp and nonce in two consecutive " + "Authentication Responses.";

    // current time in utc
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
    dateFormat.setTimeZone(new SimpleTimeZone(SimpleTimeZone.UTC_TIME, "UTC"));
    String timestamp = dateFormat.format(new Date()) + RandomStringUtils.random(8, true, true);
    ;/*from w  w  w. j a va  2 s . c o m*/

    // set response_nonce
    AttackParameter responseNonceParameter = keeper.getParameter("openid.response_nonce");
    responseNonceParameter.setAttackValueUsedForSignatureComputation(true);
    responseNonceParameter.setValidMethod(HttpMethod.DO_NOT_SEND);
    responseNonceParameter.setAttackMethod(HttpMethod.GET);
    responseNonceParameter.setAttackValue(timestamp);

    // include modified response_nonce in signature
    AttackParameter sigParameter = keeper.getParameter("openid.sig");
    sigParameter.setValidMethod(HttpMethod.DO_NOT_SEND);
    sigParameter.setAttackMethod(HttpMethod.GET);

    // two logins
    LoginResult loginResult = serviceProvider.login(User.ATTACKER);
    LoginResult loginResult2 = serviceProvider.loginAndDetermineAuthenticatedUser(User.ATTACKER);

    boolean success = loginResult2.getAuthenticatedUser() == User.ATTACKER;
    Result result = success ? Result.SUCCESS : Result.FAILURE;
    Interpretation interpretation = success ? Interpretation.CRITICAL : Interpretation.PREVENTED;

    if (loginResult2.hasDirectVerification() && success) {
        result = Result.NOT_PERFORMABLE;
        interpretation = Interpretation.NEUTRAL;
    }

    assert isSignatureValid(loginResult2) : "Signature is not valid!";

    loginResult2.addLogEntriesAtStart(loginResult.getLogEntries());

    return new AttackResult(description, loginResult2, result, interpretation);
}

From source file:wsattacker.sso.openid.attacker.evaluation.attack.ReplayAttack.java

private String generateResponseNonceOfCurrentDateMinus(int years, int days, int hours) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(new Date());
    calendar.add(Calendar.HOUR_OF_DAY, (0 - hours));
    calendar.add(Calendar.DAY_OF_YEAR, (0 - days));
    calendar.add(Calendar.YEAR, (0 - years));

    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
    dateFormat.setTimeZone(new SimpleTimeZone(SimpleTimeZone.UTC_TIME, "UTC"));
    String timestamp = dateFormat.format(calendar.getTime());

    String randomString = RandomStringUtils.random(8, true, true);
    return timestamp + randomString;
}

From source file:org.wso2.ei.analytics.elk.publisher.ElasticStatisticsPublisher.java

/**
 * Takes time in milliseconds and returns the formatted date and time according to Elasticsearch
 *
 * @param time long time in millis//  w ww  .j  a v a  2s  . c o  m
 * @return timeStamp formatted according to the Elasticsearch
 */
private static String getFormattedDate(long time) {
    Date date = new Date(time);

    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    String formattedDate = dateFormat.format(date);

    DateFormat timeFormat = new SimpleDateFormat("HH:mm:ss.SSS");
    timeFormat.setTimeZone(new SimpleTimeZone(SimpleTimeZone.UTC_TIME, "UTC"));
    String formattedTime = timeFormat.format(date);

    return formattedDate + "T" + formattedTime + "Z";
}

From source file:ti.mobileapptracker.MobileapptrackerModule.java

@Kroll.method
public void setEventDate1(String dateString) {

    SimpleDateFormat sdf = new SimpleDateFormat(MAT_DATE_TIME_FORMAT, Locale.ENGLISH);
    sdf.setTimeZone(new SimpleTimeZone(SimpleTimeZone.UTC_TIME, "UTC"));

    Date date;/* ww w. ja v a  2 s  .c om*/

    try {
        date = sdf.parse(dateString);

        mat.setEventDate1(date);
    } catch (ParseException e) {
        e.printStackTrace();
    }
}

From source file:ti.mobileapptracker.MobileapptrackerModule.java

@Kroll.method
public void setEventDate2(String dateString) {

    SimpleDateFormat sdf = new SimpleDateFormat(MAT_DATE_TIME_FORMAT, Locale.ENGLISH);
    sdf.setTimeZone(new SimpleTimeZone(SimpleTimeZone.UTC_TIME, "UTC"));

    Date date;/*  w  w  w. jav a 2 s  . c  o  m*/

    try {
        date = sdf.parse(dateString);

        mat.setEventDate2(date);
    } catch (ParseException e) {
        e.printStackTrace();
    }
}

From source file:xc.mst.manager.record.DefaultRecordService.java

@Override
protected SolrInputDocument setFieldsOnDocument(Record record, SolrInputDocument doc, boolean generateNewId)
        throws DatabaseConfigException {
    if (log.isDebugEnabled())
        log.debug("Set Field on Document");

    boolean throttleSolr = false;

    // If we need to generate an ID, set the record's ID to the next available record ID
    if (generateNewId) {
        record.setId(getXcIdentifierForFrbrElementDAO()
                .getNextXcIdForFrbrElement(XcIdentifierForFrbrElementDAO.ELEMENT_ID_RECORD));
    }//from   w w w. ja va 2s. c  o m

    // If the oaiDatestamp is null, set it to the current time
    if (record.getOaiDatestamp() == null)
        record.setOaiDatestamp(generateNewId ? record.getCreatedAt() : record.getUpdatedAt());

    // If the header is null, set it based on the identifier, datestamp, and sets
    if (record.getOaiHeader() == null || record.getOaiHeader().length() <= 0) {
        StringBuilder header = new StringBuilder();
        header.append("<header>\n");
        header.append("\t<identifier>").append(record.getOaiIdentifier()).append("</identifier>\n");

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
        sdf.setTimeZone(new SimpleTimeZone(SimpleTimeZone.UTC_TIME, "UTC"));

        header.append("\t<datestamp>").append(sdf.format(record.getOaiDatestamp())).append("</datestamp>\n");

        // Get each set from the list of set IDs this record belongs to. If the set is
        // not null, add its setSpec to the header.
        for (Set set : record.getSets())
            if (set != null)
                header.append("\t<setSpec>").append(set.getSetSpec()).append("</setSpec>\n");

        header.append("</header>");

        record.setOaiHeader(header.toString());
    } // end if(header needs to be set)

    // TimingLogger.turnOff();

    // Set the appropriate fields on it.
    doc.addField(FIELD_RECORD_ID, Long.toString(record.getId()));
    /*
    if (record.getType() != null) {
    doc.addField(FIELD_RECORD_TYPE, record.getType());
    TimingLogger.add("SOLR-"+FIELD_RECORD_TYPE, record.getType().length());
    }
            
    doc.addField(FIELD_FRBR_LEVEL_ID, Long.toString(record.getFrbrLevelId()));
    TimingLogger.add("SOLR-"+FIELD_FRBR_LEVEL_ID, Long.toString(record.getFrbrLevelId()).length());
    */

    if (record.getCreatedAt() != null) {
        doc.addField(FIELD_CREATED_AT, record.getCreatedAt());
        TimingLogger.add("SOLR-" + FIELD_CREATED_AT, 10);
    }

    doc.addField(FIELD_DELETED, Boolean.toString(record.getDeleted()));
    TimingLogger.add("SOLR-" + FIELD_DELETED, Boolean.toString(record.getDeleted()).length());

    doc.addField(FIELD_FORMAT_ID, Integer.toString(record.getFormat().getId()));
    TimingLogger.add("SOLR-" + FIELD_FORMAT_ID, Integer.toString(record.getFormat().getId()).length());
    doc.addField(FIELD_FORMAT_NAME, record.getFormat().getName());
    TimingLogger.add("SOLR-" + FIELD_FORMAT_NAME, record.getFormat().getName().length());

    doc.addField(FIELD_PROVIDER_ID,
            (record.getProvider() == null ? "0" : Integer.toString(record.getProvider().getId())));
    TimingLogger.add("SOLR-" + FIELD_PROVIDER_ID,
            (record.getProvider() == null ? "0" : Integer.toString(record.getProvider().getId())).length());
    if (record.getProvider() != null) {
        if (!throttleSolr) {
            doc.addField(FIELD_PROVIDER_NAME,
                    (record.getProvider().getName() == null ? "" : record.getProvider().getName()));
            TimingLogger.add("SOLR-" + FIELD_PROVIDER_NAME,
                    (record.getProvider().getName() == null ? "" : record.getProvider().getName()).length());
            doc.addField(FIELD_PROVIDER_URL, (record.getProvider().getOaiProviderUrl() == null ? ""
                    : record.getProvider().getOaiProviderUrl()));
            TimingLogger.add("SOLR-" + FIELD_PROVIDER_URL,
                    (record.getProvider().getOaiProviderUrl() == null ? ""
                            : record.getProvider().getOaiProviderUrl()).length());
        }
    }

    doc.addField(FIELD_HARVEST_ID,
            (record.getHarvest() == null ? "0" : Integer.toString(record.getHarvest().getId())));
    TimingLogger.add("SOLR-" + FIELD_HARVEST_ID,
            (record.getHarvest() == null ? "0" : Integer.toString(record.getHarvest().getId())).length());

    if (record.getHarvest() != null) {
        HarvestSchedule schedule = record.getHarvest().getHarvestSchedule();
        if (schedule != null) {
            doc.addField(FIELD_HARVEST_SCHEDULE_NAME, schedule.getScheduleName());
            TimingLogger.add("SOLR-" + FIELD_HARVEST_SCHEDULE_NAME, schedule.getScheduleName().length());
        }
    }

    if (record.getHarvest() != null && record.getProvider() != null) {
        doc.addField(FIELD_HARVEST_START_TIME, record.getProvider().getName() + " "
                + new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(record.getHarvest().getStartTime()));
        TimingLogger.add("SOLR-" + FIELD_HARVEST_START_TIME, record.getProvider().getName().length() + 10);
    }

    doc.addField(FIELD_SERVICE_ID,
            (record.getService() == null ? "0" : Integer.toString(record.getService().getId())));
    TimingLogger.add("SOLR-" + FIELD_SERVICE_ID,
            (record.getService() == null ? "0" : Integer.toString(record.getService().getId())).length());

    if (record.getService() != null) {
        doc.addField(FIELD_SERVICE_NAME, record.getService().getName());
        TimingLogger.add("SOLR-" + FIELD_SERVICE_NAME, record.getService().getName().length());
    }

    doc.addField(FIELD_OAI_IDENTIFIER, record.getOaiIdentifier());
    TimingLogger.add("SOLR-" + FIELD_OAI_IDENTIFIER, record.getOaiIdentifier().length());

    if (record.getOaiDatestamp() != null) {
        // If the record is output of a harvest then the OAI date stamp is already in UTC format
        if (record.getProvider() != null) {
            doc.addField(FIELD_OAI_DATESTAMP,
                    new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").format(record.getOaiDatestamp()));
            TimingLogger.add("SOLR-" + FIELD_OAI_DATESTAMP, 10);
        } else {
            doc.addField(FIELD_OAI_DATESTAMP, record.getOaiDatestamp());
            TimingLogger.add("SOLR-" + FIELD_OAI_DATESTAMP, 10);
        }
    }

    if (!throttleSolr) {
        doc.addField(FIELD_OAI_HEADER, record.getOaiHeader());
        TimingLogger.add("SOLR-" + FIELD_OAI_HEADER, record.getOaiHeader().length());

        doc.addField(FIELD_OAI_XML, record.getOaiXml());
        TimingLogger.add("SOLR-" + FIELD_OAI_XML, record.getOaiXml().length());
        // System.out.println(record.getOaiXml());
    }

    if (record.getUpdatedAt() != null) {
        doc.addField(FIELD_UPDATED_AT, record.getUpdatedAt());
        TimingLogger.add("SOLR-" + FIELD_UPDATED_AT, 10);
    }

    for (String upLink : record.getUpLinks()) {
        doc.addField(FIELD_UP_LINK, upLink);
        TimingLogger.add("SOLR-" + FIELD_UP_LINK, upLink.length());
    }

    for (Set set : record.getSets()) {
        doc.addField(FIELD_SET_SPEC, set.getSetSpec());
        TimingLogger.add("SOLR-" + FIELD_SET_SPEC, set.getSetSpec().length());
        doc.addField(FIELD_SET_NAME, set.getDisplayName());
        TimingLogger.add("SOLR-" + FIELD_SET_NAME, set.getDisplayName().length());
    } // end loop over sets

    for (Record processedFrom : record.getProcessedFrom()) {
        doc.addField(FIELD_PROCESSED_FROM, Long.toString(processedFrom.getId()));
        TimingLogger.add("SOLR-" + FIELD_PROCESSED_FROM, Long.toString(processedFrom.getId()).length());
    }

    for (RecordIfc successor : record.getSuccessors()) {
        doc.addField(FIELD_SUCCESSOR, Long.toString(successor.getId()));
        TimingLogger.add("SOLR-" + FIELD_SUCCESSOR, Long.toString(successor.getId()).length());
    }

    for (Service inputForService : record.getInputForServices()) {
        doc.addField(FIELD_INPUT_FOR_SERVICE_ID, Long.toString(inputForService.getId()));
        TimingLogger.add("SOLR-" + FIELD_INPUT_FOR_SERVICE_ID, Long.toString(inputForService.getId()).length());
    }

    for (Service processedByService : record.getProcessedByServices()) {
        doc.addField(FIELD_PROCESSED_BY_SERVICE_ID, Long.toString(processedByService.getId()));
        TimingLogger.add("SOLR-" + FIELD_PROCESSED_BY_SERVICE_ID,
                Long.toString(processedByService.getId()).length());
    }

    for (String trait : record.getTraits()) {
        doc.addField(FIELD_TRAIT, trait.replaceAll(" ", "_"));
        TimingLogger.add("SOLR-" + FIELD_TRAIT, trait.length());
    }

    /*
    for(RecordMessage error : record.getMessages()) {
    String message = error.getServiceId() + "-" + error.getMessageCode() + ":" + error.getMessage();
    doc.addField(FIELD_ERROR, message);
    TimingLogger.add("SOLR-"+FIELD_ERROR, message.length());
    }
    */

    StringBuffer all = new StringBuffer();
    if (record.getFormat() != null) {
        all.append(record.getFormat().getName());
        all.append(" ");
    }
    if (record.getProvider() != null) {
        all.append(record.getProvider().getName());
        all.append(" ");
    }

    for (Set set : record.getSets()) {
        all.append(set.getSetSpec());
        all.append(" ");
        all.append(set.getDisplayName());
        all.append(" ");
    }

    if (record.getService() != null) {
        all.append(record.getService().getName());
        all.append(" ");
    }

    for (RecordMessage error : record.getMessages()) {
        // all.append(error.getServiceId() + "-" + error.getMessageCode() + ":" + error.getMessage());
        all.append(" ");
    }

    if (record.getHarvest() != null) {
        all.append(record.getHarvest().getStartTime());
    }

    all.append(record.getOaiIdentifier());

    if (!throttleSolr) {
        doc.addField(FIELD_ALL, all.toString());
        TimingLogger.add("SOLR-" + FIELD_ALL, all.length());
    }

    TimingLogger.turnOn();

    return doc;
}

From source file:xc.mst.oai.Facade.java

private String getHeader(Record record) {

    StringBuilder header = new StringBuilder();
    header.append("<header>\n");

    // Inject service to get OAI identifier
    record.setService(service);/*from  ww w. j ava  2  s .  co  m*/

    header.append("\t<identifier>").append(record.getOaiIdentifier()).append("</identifier>\n");

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
    sdf.setTimeZone(new SimpleTimeZone(SimpleTimeZone.UTC_TIME, "UTC"));

    header.append("\t<datestamp>").append(sdf.format(record.getUpdatedAt())).append("</datestamp>\n");

    // Get each set from the list of set IDs this record belongs to. If the set is
    // not null, add its setSpec to the header.
    SortedSet<String> setSpecs = new TreeSet<String>();

    for (Set s : record.getSets())
        if (s != null)
            setSpecs.add(s.getSetSpec());

    for (String setSpec : setSpecs) {
        header.append("\t<setSpec>").append(setSpec).append("</setSpec>\n");
    }

    header.append("</header>");

    return header.toString();

}