ec-jrc / re3gistry

Re3gistry is a reusable open source solution for managing and sharing ‘reference codes’, ensuring semantic interoperability across organisations.
European Union Public License 1.2
29 stars 21 forks source link

Issue with date conversion #88

Closed heidivanparys closed 2 years ago

heidivanparys commented 2 years ago

When using the REST API to get register items in different format, I get the following error:

23-Nov-2021 13:54:47.195 SEVERE [http-nio-8088-exec-4] eu.europa.ec.re3gistry2.restapi.util.DateUtil.convertDate null
    java.text.ParseException: Unparseable date: "Thu Nov 11 13:51:33 CET 2021"
        at java.text.DateFormat.parse(DateFormat.java:366)
        at eu.europa.ec.re3gistry2.restapi.util.DateUtil.convertDate(DateUtil.java:27)
        at eu.europa.ec.re3gistry2.restapi.format.JSONFormatter.writeDate(JSONFormatter.java:210)
        at eu.europa.ec.re3gistry2.restapi.format.JSONFormatter.writeItem(JSONFormatter.java:161)
        at eu.europa.ec.re3gistry2.restapi.format.JSONFormatter.write(JSONFormatter.java:74)
        at eu.europa.ec.re3gistry2.restapi.util.ResponseUtil.ok(ResponseUtil.java:48)
        at eu.europa.ec.re3gistry2.restapi.ItemsServlet.doGet(ItemsServlet.java:209)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:655)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:764)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:196)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:544)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
        at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:698)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:364)
        at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:624)
        at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
        at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:831)
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1650)
        at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
        at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
        at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        at java.lang.Thread.run(Thread.java:748)

This probably has to do with the locale on the system the application is running on (I get this error on my local machine, with the locale set to Danish).

https://github.com/ec-jrc/re3gistry/blob/ba3be0ef5a286b193c8050618b90c2815ddcface/sources/Re3gistry2RestAPI/src/main/java/eu/europa/ec/re3gistry2/restapi/util/DateUtil.java#L24-L35

emanuelaepure10 commented 2 years ago

Dear @heidivanparys

I see that in our local we are not calling anomore that method, I'm formating the date using

DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm a z"); df.format(regItem.getInsertdate());

It will be commited soon. In meanwhile try using the code above. Best regards

heidivanparys commented 2 years ago

DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm a z");

I am not sure that that will give a correct date according to e.g. XML? See https://www.w3.org/TR/xmlschema-2/#dateTime