cannot get a mesage on the service bus queue - azure

I've a small java web app in which I send messages on a service bus queue when a user click on a button. I want to display the messages on my jsp page. But when I make the call
resultQM = service.receiveQueueMessage(queueName, opts);
I get the following exception. Thanks in advance for your help.
java.lang.IllegalArgumentException: org.codehaus.jackson.map.JsonMappingException: Can not construct instance of java.util.Date from String value 'Sun, 03 Jun 2012 13:54:40 GMT': not a valid representation (error: Can not parse date "Sun, 03 Jun 2012 13:54:40 GMT": not compatible with any of standard forms ("yyyy-MM-dd'T'HH:mm:ss.SSSZ", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", "EEE, dd MMM yyyy HH:mm:ss zzz", "yyyy-MM-dd"))
at [Source: [B#8719e; line: 1, column: 70] (through reference chain: com.microsoft.windowsazure.services.serviceBus.implementation.BrokerProperties["LockedUntilUtc"])
com.microsoft.windowsazure.services.serviceBus.implementation.BrokerPropertiesMapper.fromString(BrokerPropertiesMapper.java:41)
com.microsoft.windowsazure.services.serviceBus.implementation.ServiceBusRestProxy.receiveMessage(ServiceBusRestProxy.java:187)
com.microsoft.windowsazure.services.serviceBus.implementation.ServiceBusRestProxy.receiveQueueMessage(ServiceBusRestProxy.java:151)
com.microsoft.windowsazure.services.serviceBus.implementation.ServiceBusExceptionProcessor.receiveQueueMessage(ServiceBusExceptionProcessor.java:108)
messaging.QueueListener.getMessage(QueueListener.java:22)
org.apache.jsp.index_jsp._jspService(index_jsp.java:116)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

I think the exception is clear enough? There is a message that holds a string containing a date, and the library can't parse the string to a valid date.
"Sun, 03 Jun 2012 13:54:40 GMT": not compatible with any of standard forms ("yyyy-MM-dd'T'HH:mm:ss.SSSZ", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", "EEE, dd MMM yyyy HH:mm:ss zzz", "yyyy-MM-dd")

I suggest you to check if your local machine's clock is correct. Also try to create a SimpleDateFormat, as described on Jersey + Jackson deserialization failure with date object (a similar exception).

Set the default system locale to US before calling receiveQueueMessage:
Locale.setDefault(Locale.US);
Cause:
The Windows Azure SDK for Java uses Jackson, which uses the default system locale when creating SimpleDateFormat objects for parsing dates. Windows Azure Service Bus returns dates formatted to string using RFC-1123 and ENGLISH locale. RFC-1123 date format contains day of the week and the parser fails when your default locale is not ENGLISH and has different day of week names.
Source: Alexander Racheev's answer in the MSDN Forum.

In the latest version of Windows Azure SDK for Java, Version 0.4.2. This should have been fixed, let us know if anyone can still repro this.

Related

Convert String to Date format in andorid

I am getting the strings like 1604341549 and want to convert them to normal date format like
12 feb 2012 4:00. Here is my implementation
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
try {
Date d = sdf.parse(date);
sdf.applyPattern("dd MMM yyyy hh:mm");
holder.v.setText(sdf.format(d));
} catch (ParseException ex) {
Log.e("Exception", ex.getLocalizedMessage());
}
I have checked the logs and it is showing the dates as String before the try block but it is not implementing in the try block instead it is giving an error " Unparseable date: "1604341549" ".
Looks like your date is a long that encodes timestamp in seconds so you don't need to parse a String, instead you should simply build a Date object using Date(long date) constructor. don't forget to convert seconds to milliseconds by multiplying it by 1000
java.time through desugaring
Consider using java.time, the modern Java date and time API, for your date and time work. Let’s first declare two formatters, one for your input and one for your desired output.
/** For parsing seconds since the epoch */
private static final DateTimeFormatter unixTimestampFormatter
= new DateTimeFormatterBuilder()
.appendValue(ChronoField.INSTANT_SECONDS)
.toFormatter();
/** For formatting into normal date and time */
private static final DateTimeFormatter normalFormatter
= DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM)
.withLocale(Locale.UK);
Now the conversion goes like this:
String inputStr = "1604341549";
Instant inst = unixTimestampFormatter.parse(inputStr, Instant.FROM);
String normalDateTimeStr = inst.atZone(ZoneId.systemDefault())
.format(normalFormatter);
System.out.println(normalDateTimeStr);
Output is:
02-Nov-2020 19:25:49
I am convinced that Shamm is correct in the other answer: your input strings contain so-called Unix timestamps, that is, counts of seconds since the Unix epoch on Jan 1, 1970 at 00:00 UTC. With java.time we can build a formatter that parses such.
For giving “normal” output I am using Java’s built-in date and time format. In this case for UK locale, but you should use your users’ locale for most content users.
What went wrong in your code?
First, you were trying to parse the input string as containing year, month, date, hour, etc., which it didn’t. So you were lucky to get an exception so you got aware that it’s wrong (SimpleDateFormat very often does not give that, leaving you believing that everything is fine when it isn’t).
SimpleDateFormat parsed 1604 as year, 34 as month, 15 as day of month and 49 as hour of day. It then objected because there weren’t any digits left for the minutes (and seconds).
Question: Doesn’t java.time require Android API level 26?
java.time works nicely on both older and newer Android devices. It just requires at least Java 6.
In Java 8 and later and on newer Android devices (from API level 26) the modern API comes built-in.
In non-Android Java 6 and 7 get the ThreeTen Backport, the backport of the modern classes (ThreeTen for JSR 310; see the links at the bottom).
On older Android either use desugaring or the Android edition of ThreeTen Backport. It’s called ThreeTenABP. In the latter case make sure you import the date and time classes from org.threeten.bp with subpackages.
Links
Oracle tutorial: Date Time explaining how to use java.time.
Unix time
Java Specification Request (JSR) 310, where java.time was first described.
ThreeTen Backport project, the backport of java.time to Java 6 and 7 (ThreeTen for JSR-310).
Java 8+ APIs available through desugaring
ThreeTenABP, Android edition of ThreeTen Backport
Question: How to use ThreeTenABP in Android Project, with a very thorough explanation.

Understanding GTFS service times

I have a problem with the understanding of the gtfs file format. Or maybe there is an error in that data. There is a gtfs file from a public transportation agency called "Verkehrsverbund Mittelthüringen" (VMT). This data is accessible at https://transitfeeds.com/p/verkehrsverbund-mittelth-ringen/1080/latest/routes.
For example: I have taken the trip with the ID 9782458 (trips.txt).
2841_0,45,9782458,"Erfurt, Thüringenhalle","",0,,,,
This has the service ID 45 with the specification
45,0,0,0,0,0,0,0,20191101,20200229
Additionally here are the entries for the celendar_dates.txt
45,20191104,1
45,20191111,1
45,20191118,1
45,20191125,1
45,20191202,1
45,20191209,1
45,20191216,1
45,20191105,1
45,20191112,1
45,20191119,1
45,20191126,1
45,20191203,1
45,20191210,1
45,20191217,1
45,20191106,1
45,20191113,1
45,20191120,1
45,20191127,1
45,20191204,1
45,20191211,1
45,20191218,1
45,20191107,1
45,20191114,1
45,20191121,1
45,20191128,1
45,20191205,1
45,20191212,1
45,20191219,1
45,20191101,1
45,20191108,1
45,20191115,1
45,20191122,1
45,20191129,1
45,20191206,1
45,20191213,1
45,20191220,1
Does this mean, that the service is available all times, except from the 1st November 2019 to the 29th February 2020? My Problem now is the output of the search engine tansitfeeds.com. It says the trip with the ID 9782458 is available at the 14th November 2019. Which is contary to my understanding of the data: the trip won't be available in November. Where is the clue I missed? Or is there an error in the data?
The line you pasted indicates that service ID 45 runs on zero days of the week (that's what all those zeros mean), so the start and end dates in the same line don't really mean anything.
If this service actually does run on Nov. 14, this could be represented in the calendar_dates.txt file, which is usually used to represent service changes for special dates.
EDIT: the data you added from calendar_dates.txt does indeed show that service 45 has been added for date 20191114.

the time that now() function returns is different from system time

I get result as follow when I execute a sql which includes now()function in VoltDB
select * from test2;
C1
---------------------------
2019-06-29 07:13:38.050000
But,I get another time when I execute a shell command 'date'
[root#localhost config]# date
Sat Jun 29 03:30:09 EDT 2019
How can I make them same?
VoltDB stores time in the UTC timezone. If you want to change this to EDT or any other timezone, you should be able to do it using a variety of methods and languages.
For example, in java you might use VoltTableRow.getTimestampAsSqlTimestamp(0) to get the value of a timestamp row. You could then use DateFormat to convert this to a particular timezone.
You can read more about the "getTimestampAsSqlTimestamp" method here: https://docs.voltdb.com/javadoc/java-client-api/org/voltdb/VoltTableRow.html
Full Disclosure: I work at VoltDB.

How to set date time format in Logic App

I have created an API which creates an excel having Date columns too. When I execute the code from local it works well and displays the date as expected.
When I try executing API via Logic App, it changes the date format of that field. How can I set date time in Logic App?
When you have a fixed DateTime-Format you can use the Logic App function "formatDateTime" as follow:
formatDateTime(triggerBody()?['myDate'], 'yyyy-MM-dd')
You can find it under Expressions - Date and Time - "See more" - formatDateTime
I found some useful documentation on Microsoft's site here:
https://learn.microsoft.com/en-us/azure/kusto/query/format-datetimefunction
Here it is .. in action:
Try this to get the current date in GMT format:
The problem is your local machine is running a different Locale than the machine running your code when it is deployed.
You could either set the CultureInfo.CurrentCulture to make sure the right CultureInfo is used.
CultureInfo...
Provides information about a specific culture (called a locale for unmanaged code development). The information includes the names for the culture, the writing system, the calendar used, the sort order of strings, and formatting for dates and numbers.
You could also use the appropriate DateTimeFormatInfo, when writing the date to Excel, it
Provides culture-specific information about the format of date and time values.
Logic apps time zone base on UTC. So, it needs conversion between UTC to your local time.
In my case, 'SE Asia Standard Time', (UTC+07:00); Bangkok, Hanoi, Jakarta. So, you need to convert it as your local time. Here's in my case:
Date convertTimeZone(utcNow(), 'UTC', 'SE Asia Standard Time', 'MMMM dd, yyyy');
Time convertTimeZone(utcNow(), 'UTC', 'SE Asia Standard Time','hh:mm:ss.ff tt')

Convert string to date to string in Talend Open Studio

I am trying to covert a date from one string format ("M/d/yyyy H:mm:ss") to another ("yyyy-MM-ddTHH:mm:ss") in Talend Open Studio. I've been reading through forum posts, blogs, and the help documentation, and all of the solutions I've found ultimately result in error. I think it's because most solutions are actually attempting to convert a date to a string or vice versa, but none of them are attempting, as I am, to convert a string to a date and then back again. (And I'm willing to be told that's the wrong way to approach this, but it seems like the natural way to do the conversion since, presumably, Talend knows how to convert all the parts of the Date type.)
My current iteration looks like this:
row2._ACTIVITY_DUE_DATE_==""?"":TalendDate.formatDate("yyyy-MM-dd HH:mm:ss", TalendDate.parseDate("M/d/yyyy H:mm:ss", row2._ACTIVITY_DUE_DATE_))
So if I feed in 5/18/2012 1:00:00 PM, I would want to get back 2012-05-18 13:00:00. I'm getting an unparsable date error, which I've included below. I don't understand why this is happening. The expression above should only be trying to parse the date if it's not equal to "", but apparently that's the value it can't parse:
Exception in component tMap_1
java.lang.RuntimeException: java.text.ParseException: Unparseable date: ""
at routines.TalendDate.parseDate(TalendDate.java:864)
at routines.TalendDate.parseDate(TalendDate.java:808)
at msm_extras.msm_activities_i360_tasks_0_1.MSM_Activities_i360_Tasks.tFileInputDelimited_1Process(MSM_Activities_i360_Tasks.java:2854)
at msm_extras.msm_activities_i360_tasks_0_1.MSM_Activities_i360_Tasks.runJobInTOS(MSM_Activities_i360_Tasks.java:3690)
at msm_extras.msm_activities_i360_tasks_0_1.MSM_Activities_i360_Tasks.main(MSM_Activities_i360_Tasks.java:3549)
Caused by: java.text.ParseException: Unparseable date: ""
at java.text.DateFormat.parse(Unknown Source)
at routines.TalendDate.parseDate(TalendDate.java:850)
... 4 more
When comparing strings in Java you should use .equals. So in your case you should use "".equals(row2._ACTIVITY_DUE_DATE) ? "" : ....
Everything else about your date format conversion looks fine.

Resources