I'm trying to consume a SOAP service with Java. I need to set a date/time element properly.
<element maxOccurs="1" minOccurs="0" name="startDate" nillable="true" type="xsd:dateTime"/>
I generated a client jar with Axis 1.4 wsdl2java
I need to send a Calendar type object.
java.util.Calendar startDate
In SOAPUI, it accepts the format below.
<startDate>22/05/2022 14:27:00.000</startDate>
In code, I tried formatting the date but didn't work. I get the same error every time while getting response.
AxisFault java.lang.NumberFormatException Invalid date/time
Any ideas?
xsd:dateTime expects a value in the ISO 8601 format e.g. 2022-05-22T14:27:00.000 which is in the pattern yyyy-MM-dd'T'HH:mm:ss.SSS. Learn more about it from this tutorial.
Note: The java.time API has a constant, DateTimeFormatter.ISO_LOCAL_DATE_TIME as a pre-defined pattern.
Related
I have a request body have date field and I want to validate the input of the date and return error code 400 BadRequest if the format is wrong.
If I use the JsonFormat then it throws error 500:
#JsonFormat(shape=JsonFormat.Shape.STRING, pattern="yyyy-MM-dd")
private Date dateAt;
So I changed the field to String and then parse and throw BadRequest format everywhere using the getDate()
I am not really satisfied with this approach. Is there any other elegant way to achieve this validation?
I think I will accept error 500 from JSON formatter and skip my custom exception.
Since Java 8, you should avoid using Date. Java 8 brought an entirely new date and time API.
According to your question, a suitable replacement for Date would be LocalDate, which is expected to be in the format yyyy-MM-dd.
Jackson has a module supporting the new date and time API and an exception will be thrown if the date is not in the correct format. When serializing, you want to make sure the WRITE_DATES_AS_TIMESTAMPS feature is disabled, so the values will be written according to the ISO 8601 format.
My goal
I want to post my json file for indexing. When I specify the field as string, post and index success, but if I do it as tdates, tdate or date, it fail.
I will use date value for faceting.
Environment
CentOS 7, Solr 5.4
What I did
Prepare the managed-schema. The portion of code is the following:
<field name="name" type="string" indexed="true" stored="true" docValues="false" />
<field name="record_date" type="xxxx" indexed="false" stored="false" docValues="true" />
When xxxx is string, indexing success and tdates, tdate or date failed.
(Ofcourse tdates, tdate and date are defined in managed-schema.
e.g. <fieldType name="tdate" class="solr.TrieDateField" precisionStep="6" positionIncrementGap="0" />)
And the portion of posting json is the following:
{"name":"Calendar", "record_date":"2015-11-30T00:00:00Z"},
{"name":"Clock", "record_date":"2015-12-01T11:05:00Z"}
I execute the command like the following(in the solr root dir): bin/post -c mycorename ~/myfile.json
After that, I got the error like the following:
SimplePostTool: WARNING: Solr returned an error #400 (Bad Request) for url: http://xxxx:8983/solr/mycorename/update/json/docs
SimplePostTool: WARNING: Response: {"responseHeader":{"status":400, "QTime":7},"error":{"msg":"Invalid Date String:'Mon Nov 30 00:00:00 UTC 2015'","code":400}}
SimplePostToll: WARNING: IOException while reading response: java.io.IOException: Server returned HTTP response code: 400 for URL: http://xxxx:8983/solr/mycorename/update/json/docs
1 files indexed.
COOMITing Solr index changes to http://xxxx:8983/solr/mycorename/update...
Time spent: 0:00:00.102
Refs and comments
I checked this document Working with Dates and so I update my JSON date value yyyy-MM-ddThh:mm:ssZ style, but it is not working.
I also tried to post json appended escape-sequence ver like the following:
{"name":"Calendar", "record_date":"2015-11-30T00\:00\:00Z"},
{"name":"Clock", "record_date":"2015-12-01T11\:05\:00Z"}
But the error message is completely same before.
I found one thing on the error message. It says "Invalid Date String:'Mon Nov 30 00:00:00 UTC 2015'" and this date value is not the same format with my json value.
I guess Solr couverts the date value before indexing and as a result indexed value is string value, NOT date value, so I get this message.
What was wrong with me? How can I fix it... any ideas?
I'm using swagger-ui and a stub server in Java Spring-MVC generated using swagger-codegen. I have a date format somewhere and if I enter some date, it always returns me the UNIX Date Time format. I would like to have the RFC-3339 format for the date and date-time. Does anyone knows how to do this?
I found the answer..
I had to overwrite the JsonFormat since I'm returning a JSON object..
Therefore, if you have the same problem as me, use:
#JsonFormat(pattern="...")
Date foo;
Do not forget to use import com.fasterxml.jackson.annotation.JsonFormat;
I am having a hard time trying to make a web service client work. It is a XML RPC specification. I am using Apache WS XML-RPC library, which I find full of holes that causes problem due to Serialization. I have to send a Date parameter for the library to add the tags , however the web service expects it with the TZ, that means adding -0500 at the end of the Date object. If I dont send it as Date Object, it wont add the tags and it will fail. And when trying to do this:
DateFormat df = new SimpleDateFormat("yyyyMMdd'T'HH:mm:ssZ");
String fecha = df.format(new Date());
Date date = new SimpleDateFormat("yyyyMMdd'T'HH:mm:ssZ").parse(fecha);
And using parameter date, and it always sends it as
<dateTime.iso8601>20130517T20:30:33</dateTime.iso8601>
Can't find a way for it to send it as Date object in the format above but with the -0500 at the end. Any help would be appreciated.
I would like to know how could I remove the timezone automatically shown in my service output.
Let me explain:
My webservice's output contains a field derived from this Simple Type:
<xs:simpleType name="tsMyDateTime">
<xs:restriction base="xs:dateTime">
<xs:pattern value="[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}" />
</xs:restriction>
</xs:simpleType>
I would expect the following tsMyDateTime output format (for instance):
2026-02-25T00:00:00
But the output looks like:
2026-02-25T00:00:00.835-03:00
The original date object has the correct date and time, but I need to use Calendar (for xs:dateTime), but the timezone always appears.
I set the Calendar object by this way:
java.util.Date dateObject = (...)
calendar.setTime(dateObject);
Can someone give me suggestions?