axis2 xsd:date format issue - axis2

Merged with axis2 xsd:date format issue.
In WSDL I have the following format:
USER_ACT_STRDT is a date.
When I generate the STUB (using Axis2 1.5.3), the generated stub (ADB Data Binding) has the following source code :
public void setUSER_ACT_STRDT_TypeDef(Date param) {
if (ConverterUtil.convertToString(param).matches("\d{4}-\d{2}-\d{2}")) {
this.localUSER_ACT_STRDT_TypeDef=param; } else { throw new java.lang.RuntimeException();
} }
This method always throws RuntimeException because the ConverterUtil.convertToString() method returns a String in a different format than "yyyy-mm-dd". It returns the date by appending +5.30 as 2011-03-21+05:30.
I tried passing the date in different formats but same result for all.
Can any one suggest how to resolve this issue.

Related

Error try to access profile through .net code on sabre ProfileReadRQ

When we try to access profile through code we are getting message as below, please advice
The error is:
There was an error in serializing one of the headers in message
EPS_ProfileReadRQRequest: 'Unable to generate a temporary class (result=1).
error CS0030: Cannot convert type 'CRM.ProfileReadRQ.BusinessSystemIdentityInfoSynchronizationCriterionTypeExcludeCombination' to 'CRM.ProfileReadRQ.BusinessSystemIdentityInfoSynchronizationCriterionTypeIncludeCombination'
error CS0029: Cannot implicitly convert type 'CRM.ProfileReadRQ.BusinessSystemIdentityInfoSynchronizationCriterionTypeIncludeCombination' to 'CRM.ProfileReadRQ.BusinessSystemIdentityInfoSynchronizationCriterionTypeExcludeCombination'
This happens because the serializer doesn't know what type to cast to since the types that throw the error can be of more than one type. I think that simplifies the XML but it makes the WSDL/.NET stuff more complicated. I'm probably not saying that perfectly accurately but that's the gist of it, at least as I understand it.
You can go into your reference.cs file and remove the serialization for those offending fields and try again. I've done this in the past with some success. If/when you update the API version with a new WSDL file you'll have to remember to do it again, though, so it's not a perfect solution. I've got a sample of what I removed from my reference.cs file to get one of the profile APIs below, hopefully it's helpful.
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.7.3056.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://www.sabre.com/eps/schemas")]
public partial class BusinessSystemIdentityInfoSynchronizationCriterionType {
private BusinessSystemIdentityInfoSynchronizationCriterionTypeExcludeCombination[] itemsField;
private ItemsChoiceType1[] itemsElementNameField;
//remarked this out 12/24/18 - these include/exclude combinations do not serialize correctly for some reason
/// <remarks/>
//[System.Xml.Serialization.XmlElementAttribute("ExcludeCombination", typeof(BusinessSystemIdentityInfoSynchronizationCriterionTypeExcludeCombination))]
//[System.Xml.Serialization.XmlElementAttribute("IncludeCombination", typeof(BusinessSystemIdentityInfoSynchronizationCriterionTypeIncludeCombination))]
//[System.Xml.Serialization.XmlChoiceIdentifierAttribute("ItemsElementName")]
//public BusinessSystemIdentityInfoSynchronizationCriterionTypeExcludeCombination[] Items {
// get {
// return this.itemsField;
// }
// set {
// this.itemsField = value;
// }
//}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("ItemsElementName")]
[System.Xml.Serialization.XmlIgnoreAttribute()]
public ItemsChoiceType1[] ItemsElementName {
get {
return this.itemsElementNameField;
}
set {
this.itemsElementNameField = value;
}
}
}

SpringFox Date format to milliseconds

I'm using SpringFox (Swagger) to document my REST APIs. One of the nice features in Swagger is to show example model and the data type format.
Now, I configured my APIs to produce and consume dates in milliseconds but when I'm looking at the sample JSON model the date format is following: "2015-09-21T00:51:32.617Z". See screenshot below. Is it possible to tell SpringFox (Swagger) how to format the date properly?
You could try:
Docket docket = new Docket(DocumentationType.SWAGGER_2)
.apiInfo(getApiInfo())
.directModelSubstitute(YourDateTimeClass.class, Integer.class);
Basically you are telling Swagger to replace the date class with an Integer which could represent the milliseconds.
This is related to the underlying Jackson serialiser. You have to set the correct date format for it otherwise by default it's using timestamps.
Here is an example configuration
#Configuration
public class WebConfiguration extends WebMvcConfigurerAdapter {
#Override
public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
for (HttpMessageConverter<?> converter : converters) {
if (converter instanceof MappingJackson2HttpMessageConverter) {
MappingJackson2HttpMessageConverter jsonMessageConverter = (MappingJackson2HttpMessageConverter) converter;
ObjectMapper objectMapper = jsonMessageConverter.getObjectMapper();
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
break;
}
}
}
}
This way it will use an ISO-8601 date-time format. Here is another blog post that explains how to set your own preferred date format: http://yysource.com/2016/06/change-default-date-for-jackson-in-spring-boot-application/
I got a similar problem as yours, and I resolved it by adding the following config in my Spring Boot's application.properties file:
spring.jackson.date-format=com.fasterxml.jackson.databind.util.ISO8601DateFormat

Spring Data Rest Content Type

I am writing unit tests for my application with Spring Data Rest MongoDB. Based on Josh's "Building REST services with Spring" get start guide, I have the following test code:
#Test
public void readSingleAccount() throws Exception {
mockMvc.perform(get("/accounts/"
+ this.account.getId()))
.andExpect(status().isOk())
.andExpect(content().contentType(contentType))
.andExpect(jsonPath("$.id", is(this.account.getId())))
.andExpect(jsonPath("$.email", is(this.account.getEmail())))
.andExpect(jsonPath("$.password", is(this.account.getPassword())));
}
And this test fails on the content type.
Content type expected:<application/json;charset=UTF-8> but was: <application/hal+json>
Expected :application/json;charset=UTF-8
Actual :application/hal+json
I don't see MediaType come with HAL. Is the content type defined in another class?
Had the same Problem when not using tomcat (which is configured to return utf-8 using Spring Boot). The solution is to set the accept header in your GET request so the response gets the correct content type:
private MediaType contentType = new MediaType("application", "hal+json", Charset.forName("UTF-8"));
and in your request, do
#Test
public void readSingleAccount() throws Exception {
mockMvc.perform(get("/accounts/"
+ this.account.getId()).**accept(contentType)**)
.andExpect(status().isOk())
.andExpect(content().contentType(contentType))
.andExpect(jsonPath("$.id", is(this.account.getId())))
.andExpect(jsonPath("$.email", is(this.account.getEmail())))
.andExpect(jsonPath("$.password", is(this.account.getPassword())));
}

FileHelper library - custom error messages

I am use the FileHelper to parse CSV files. Error messages encountered when parsing the file are displayed to the end user. The end user may not be able to make sense of the technical error message. Not too many clerks know what an Int32 is or Class: UploadFooDto.
I would like to customize the error messages so they are more user friendly. Something like:
Line 1. Column 2. A string (a) was entered instead of a number
Line 2. Column 3. '13-14-15' is not a valid date
I cannot find anything in the API that would allow me to customize the error messages. The most I have so far are some extension methods to clean up the errors:
public static class FileHelperExceptionExtensions
{
public static string BuildMessage(this ErrorInfo error)
{
if (error.ExceptionInfo is ConvertException)
{
return ((ConvertException)error.ExceptionInfo).BuildMessage();
}
if (error.ExceptionInfo is BadUsageException)
{
var message = error.ExceptionInfo.Message;
var readTo = message.IndexOf("Class:");
return message.Substring(0, readTo);
}
return string.Format("Line: {0}. An unspecific error occured.", error.LineNumber);
}
public static string BuildMessage(this ConvertException exception)
{
return string.Format("Line: {0}. Column: {1}. Field: {2}. Cannot convert '{3}' to type: '{4}'", exception.LineNumber, exception.ColumnNumber, exception.FieldName, exception.FieldStringValue, exception.FieldType.Name);
}
}
but these extensions still leave a lot to be desired. Is it possible to customize the error messages?
It's hard to improve on your extension methods without it being more hassle than it's worth.
You cannot subclass the default converters (e.g., FileHelpers.ConvertHelpers.Int32Converter since they are internal and sealed). You could create your own custom converter for each type (and base it on the corresponding source code from FileHelpers, e.g., Int32Converter). Then you can raise an alternative to ConvertException (also sealed so you cannot subclass) which would format the message differently.

AXIS 1.5.3 Date Formatting Issue

Merged with axis2 xsd:date format issue.
In WSDL I have the following format:
When I generate the STUB (using Axis2 1.5.3), the generated stub (ADB
Data Binding) has the following source code :
public void setUSER_ACT_STRDT_TypeDef(Date param)
{
if (ConverterUtil.convertToString(param).matches("\d{4}-\d{2}-\d{2}"))
{
this.localUSER_ACT_STRDT_TypeDef=param;
}
else
{
throw new java.lang.RuntimeException();
}
}
This method always throws RuntimeException because the
ConverterUtil.convertToString() method returns a String in a different
format than "yyyy-mm-dd".
It returns the date by appending +5.30 as 2011-03-21+05:30.