List of usage examples for org.joda.time DateTime toString
@ToString
public String toString()
From source file:com.claresco.tinman.servlet.XapiServletSimpleErrorLogger.java
License:Open Source License
protected long log(Exception theException, int errorNumber, String errorMessage, HttpServletRequest req) { DateTime theDate = DateTime.now(); long theReturnedValue = logID; //String fileName = theDate.year().getAsShortText() + "-" + theDate.monthOfYear() // .getAsString() + "-" +theDate.dayOfMonth().getAsShortText() + ".txt"; String fileName = myFileName; File theLogFile = new File(myPath + fileName); try {/*from www .j a va 2 s .co m*/ if (!theLogFile.exists()) { theLogFile.createNewFile(); } PrintWriter theWriter = new PrintWriter(new BufferedWriter(new FileWriter(myPath + fileName, true))); theWriter.println("==============================================================="); theWriter.println(logID); theWriter.println(theDate.toString()); logID++; theException.printStackTrace(theWriter); theWriter.println(errorNumber + " : " + errorMessage); theWriter.println(); theWriter.println("request.getRequstURI() gives :"); theWriter.println(req.getRequestURI()); theWriter.println("request.getQueryString() gives :"); theWriter.println(req.getQueryString()); theWriter.println("iterating through parameter names gives :"); Enumeration<String> e = req.getParameterNames(); while (e.hasMoreElements()) { String paramName = e.nextElement(); theWriter.println(paramName + " : " + req.getParameter(paramName)); } theWriter.println("\nthe header names :\n"); e = req.getHeaderNames(); while (e.hasMoreElements()) { String headerName = e.nextElement(); theWriter.println(headerName + " : " + req.getHeader(headerName) + "\n"); } theWriter.println(req.getMethod()); theWriter.println("Path info : " + req.getPathInfo()); theWriter.println("Reading from the request's reader gives :"); theWriter.println(XapiServletUtility.getStringFromReader(req.getReader())); theWriter.println("===============================================================\n\n\n"); theWriter.close(); return theReturnedValue; } catch (Exception e) { e.printStackTrace(); } return -1; }
From source file:com.collective.celos.trigger.DelayTrigger.java
License:Apache License
private String humanReadableDescription(boolean ready, DateTime waitUntilDT) { if (ready) {// w w w . j a v a 2s.c om return "Ready since " + waitUntilDT.toString(); } else { return "Delayed until " + waitUntilDT.toString(); } }
From source file:com.datascience.gal.service.Service.java
License:Open Source License
/** * a simple method to see if the service is awake * //from w ww. ja v a 2s. c o m * @return a string with the current time */ @GET @Path("ping") @Produces(MediaType.APPLICATION_JSON) public Response test() { try { setup(context); } catch (IOException e) { logger.error("ioexception: " + e.getLocalizedMessage()); } catch (ClassNotFoundException e) { logger.error("class not found exception: " + e.getLocalizedMessage()); } catch (SQLException e) { logger.error("sql exception: " + e.getLocalizedMessage()); } DateTime datetime = new DateTime(); String cargo = "processing request at: " + datetime.toString(); logger.info(cargo); return Response.ok(JSONUtils.gson.toJson(cargo)).build(); }
From source file:com.example.appengine.logs.LogsServlet.java
License:Open Source License
@Override public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { resp.setContentType("text/html"); PrintWriter writer = resp.getWriter(); writer.println("<!DOCTYPE html>"); writer.println("<meta charset=\"utf-8\">"); writer.println("<title>App Engine Logs Sample</title>"); // We use this to break out of our iteration loop, limiting record // display to 5 request logs at a time. int limit = 5; // This retrieves the offset from the Next link upon user click. String offset = req.getParameter("offset"); // We want the App logs for each request log LogQuery query = LogQuery.Builder.withDefaults(); query.includeAppLogs(true);// w ww .j av a 2 s . co m // Set the offset value retrieved from the Next link click. if (offset != null) { query.offset(offset); } // This gets filled from the last request log in the iteration String lastOffset = null; int count = 0; // Display a few properties of each request log. for (RequestLogs record : LogServiceFactory.getLogService().fetch(query)) { writer.println("<br>REQUEST LOG <br>"); DateTime reqTime = new DateTime(record.getStartTimeUsec() / 1000); writer.println("IP: " + record.getIp() + "<br>"); writer.println("Method: " + record.getMethod() + "<br>"); writer.println("Resource " + record.getResource() + "<br>"); writer.println(String.format("<br>Date: %s", reqTime.toString())); lastOffset = record.getOffset(); // Display all the app logs for each request log. for (AppLogLine appLog : record.getAppLogLines()) { writer.println("<br>" + "APPLICATION LOG" + "<br>"); DateTime appTime = new DateTime(appLog.getTimeUsec() / 1000); writer.println(String.format("<br>Date: %s", appTime.toString())); writer.println("<br>Level: " + appLog.getLogLevel() + "<br>"); writer.println("Message: " + appLog.getLogMessage() + "<br> <br>"); } if (++count >= limit) { break; } } // When the user clicks this link, the offset is processed in the // GET handler and used to cycle through to the next 5 request logs. writer.println(String.format("<br><a href=\"/?offset=%s\">Next</a>", lastOffset)); }
From source file:com.expedia.edw.datapeek.dataProcessors.scomDataProcessor.service.ScomWebService.java
License:Open Source License
/** * Creates a new Search.//from www. j a va 2 s . c om * * @param searchQuery * The search query string. * @param earliest * The start time for the search. * @param latest * The end time for the search. * @return The response, containing the new Search Id (if it exists) and any messages. */ @Override public PostSearchResponse postSearch(final String searchQuery, final DateTime earliest, final DateTime latest) { final Stopwatcher localStopwatch = this.stopwatch.child(); localStopwatch.startMeasuring(Stopwatcher.METRIC_HTTP); final WebResource request = this.defaultWebResource.path("search/jobs"); final MultivaluedMap<String, String> formData = new MultivaluedMapImpl(); formData.add("search", "search " + searchQuery); formData.add("earliest_time", earliest.toString()); formData.add("latest_time", latest.toString()); final ClientResponse response = request.type(MediaType.APPLICATION_FORM_URLENCODED) .post(ClientResponse.class, formData); localStopwatch.stopMeasuring(Stopwatcher.METRIC_HTTP, "httpPostSearch"); localStopwatch.incrementParentMetric("scomHttpOps", true); localStopwatch.finish(ImmutableMap.of("verb", "POST", "requestHost", request.getURI().getHost(), "operation", "/search/jobs", "statusCode", response.getStatus())); return response.getEntity(PostSearchResponse.class); }
From source file:com.fujitsu.dc.common.auth.token.TransCellAccessToken.java
License:Apache License
/** * ?SAML????./*from ww w .j a va 2 s . c o m*/ * @return SAML */ public String toSamlString() { /* * Creation of SAML2.0 Document * http://docs.oasis-open.org/security/saml/v2.0/saml-core-2.0-os.pdf */ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); DocumentBuilder builder = null; try { builder = dbf.newDocumentBuilder(); } catch (ParserConfigurationException e) { // ???????????? throw new RuntimeException(e); } Document doc = builder.newDocument(); Element assertion = doc.createElementNS(URN_OASIS_NAMES_TC_SAML_2_0_ASSERTION, "Assertion"); doc.appendChild(assertion); assertion.setAttribute("ID", this.id); assertion.setAttribute("Version", "2.0"); // Dummy Date DateTime dateTime = new DateTime(this.issuedAt); assertion.setAttribute("IssueInstant", dateTime.toString()); // Issuer Element issuer = doc.createElement("Issuer"); issuer.setTextContent(this.issuer); assertion.appendChild(issuer); // Subject Element subject = doc.createElement("Subject"); Element nameId = doc.createElement("NameID"); nameId.setTextContent(this.subject); Element subjectConfirmation = doc.createElement("SubjectConfirmation"); subject.appendChild(nameId); subject.appendChild(subjectConfirmation); assertion.appendChild(subject); // Conditions Element conditions = doc.createElement("Conditions"); Element audienceRestriction = doc.createElement("AudienceRestriction"); for (String aud : new String[] { this.target, this.schema }) { Element audience = doc.createElement("Audience"); audience.setTextContent(aud); audienceRestriction.appendChild(audience); } conditions.appendChild(audienceRestriction); assertion.appendChild(conditions); // AuthnStatement Element authnStmt = doc.createElement("AuthnStatement"); authnStmt.setAttribute("AuthnInstant", dateTime.toString()); Element authnCtxt = doc.createElement("AuthnContext"); Element authnCtxtCr = doc.createElement("AuthnContextClassRef"); authnCtxtCr.setTextContent("urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport"); authnCtxt.appendChild(authnCtxtCr); authnStmt.appendChild(authnCtxt); assertion.appendChild(authnStmt); // AttributeStatement Element attrStmt = doc.createElement("AttributeStatement"); Element attribute = doc.createElement("Attribute"); for (Role role : this.roleList) { Element attrValue = doc.createElement("AttributeValue"); Attr attr = doc.createAttributeNS("http://www.w3.org/2001/XMLSchema-instance", "type"); attr.setPrefix("xsi"); attr.setValue("string"); attrValue.setAttributeNodeNS(attr); attrValue.setTextContent(role.schemeCreateUrlForTranceCellToken(this.issuer)); attribute.appendChild(attrValue); } attrStmt.appendChild(attribute); assertion.appendChild(attrStmt); // Normalization doc.normalizeDocument(); // Dsig?? // Create a DOMSignContext and specify the RSA PrivateKey and // location of the resulting XMLSignature's parent element. DOMSignContext dsc = new DOMSignContext(privKey, doc.getDocumentElement()); // Create the XMLSignature, but don't sign it yet. XMLSignature signature = xmlSignatureFactory.newXMLSignature(signedInfo, keyInfo); // Marshal, generate, and sign the enveloped signature. try { signature.sign(dsc); // ? return DcCoreUtils.nodeToString(doc.getDocumentElement()); } catch (MarshalException e1) { // DOM??????? throw new RuntimeException(e1); } catch (XMLSignatureException e1) { // ?????????? throw new RuntimeException(e1); } /* * ------------------------------------------------------------ * http://tools.ietf.org/html/draft-ietf-oauth-saml2-bearer-10 * ------------------------------------------------------------ 2.1. Using SAML Assertions as Authorization * Grants To use a SAML Bearer Assertion as an authorization grant, use the following parameter values and * encodings. The value of "grant_type" parameter MUST be "urn:ietf:params:oauth:grant-type:saml2-bearer" The * value of the "assertion" parameter MUST contain a single SAML 2.0 Assertion. The SAML Assertion XML data MUST * be encoded using base64url, where the encoding adheres to the definition in Section 5 of RFC4648 [RFC4648] * and where the padding bits are set to zero. To avoid the need for subsequent encoding steps (by "application/ * x-www-form-urlencoded" [W3C.REC-html401-19991224], for example), the base64url encoded data SHOULD NOT be * line wrapped and pad characters ("=") SHOULD NOT be included. */ }
From source file:com.github.markserrano.jsonquery.jpa.util.DateTimeUtil.java
License:Apache License
public static DateTime normalize(DateTime dateTime) { if (dateTime.toString().matches(".+(\\+)[0-9][0-9]:[0-9][0-9]")) { dateTime = dateTime.minusHours(dateTime.getHourOfDay()); } else if (dateTime.toString().matches(".+(\\-)[0-9][0-9]:[0-9][0-9]")) { dateTime = dateTime.plusHours(24 - dateTime.getHourOfDay()); }/*w w w .java2 s . c om*/ return dateTime; }
From source file:com.github.markserrano.jsonquery.jpa.util.DateTimeUtil.java
License:Apache License
public static String toDateRangeQuery(String filter, String datefield) { DateTime from = DateTimeUtil.getDateTime(filter, datefield); DateTime to = from.plusHours(23).plusMinutes(59).plusSeconds(59); // Replace operator from "eq" to "ge" filter = filter.replace("\"field\":\"" + datefield + "\",\"op\":\"eq\"", "\"field\":\"" + datefield + "\",\"op\":\"ge\""); filter = QueryUtil.addAnd(filter, datefield, OperatorEnum.LESSER_EQUAL, to.toString()); return filter; }
From source file:com.google.android.apps.paco.AlarmCreator2.java
License:Open Source License
void createAlarm(DateTime alarmTime, Experiment experiment) { Log.i(PacoConstants.TAG,//w ww. ja v a 2s . c om "Creating alarm: " + alarmTime.toString() + " for experiment: " + experiment.getTitle()); PendingIntent intent = createAlarmReceiverIntentForExperiment(alarmTime); alarmManager.cancel(intent); alarmManager.set(AlarmManager.RTC_WAKEUP, alarmTime.getMillis(), intent); }
From source file:com.google.android.apps.paco.NotificationCreator.java
License:Open Source License
private void createAllNotificationsForLastMinute(long alarmTime) { DateTime alarmAsDateTime = new DateTime(alarmTime); Log.i(PacoConstants.TAG, "Creating All notifications for last minute from signaled alarmTime: " + alarmAsDateTime.toString()); List<TimeExperiment> times = ExperimentAlarms.getAllAlarmsWithinOneMinuteofNow( alarmAsDateTime.minusSeconds(59), experimentProviderUtil.getJoinedExperiments(), context); for (TimeExperiment timeExperiment : times) { timeoutNotifications(experimentProviderUtil.getNotificationsFor(timeExperiment.experiment.getId())); createNewNotificationForExperiment(context, timeExperiment, false); }/* ww w . j a v a 2 s . c o m*/ }