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.
Related
I want to programmatically set the paths on a rest service. I have this bean method which has all the paths.
public List<String> getSubscribeChannelsForRest() { .. }
This is the rest service
#RestController
public class RestMessageController {
#PostMapping(
path = { "#{somebean.getSubscribeChannelsForRest()[0]}",
"#{somebean.getSubscribeChannelsForRest()[1]}",
"#{somebean.getSubscribeChannelsForRest()[2]}"
})
public String processMessage(#RequestBody String messageBody, HttpServletRequest request) { .. }
The above code works but I want to avoid hard coding the array numbers. There is what I tried.
#PostMapping(
path = { "#{somebean.getSubscribeChannelsForRest()}",
This doesn't work because the spring method RequestMappingHandlerMapping.resolveEmbeddedValuesInPatterns(String[] patterns) takes the above SpEL as a single element array. I've checked the trace logs and all the element in the given list get concatenated .
I have a very simple camel ssh route setup with Java DSL with only one pollCommand: date +%s%3N which should output the current timestamp. But the result is empty. However if the command is just date it works as expected. I am pretty sure that the problem is in + or % characters but URL encoding didn't help:
date%20%2B%25s%253N
date %2B%25s%253N
date +%25s%253N
date %2B%s%3N
nothing from above worked.
Below is the code snippet which I am using:
public static void main(String[] args) throws Exception {
DefaultCamelContext camelContext = new DefaultCamelContext();
camelContext.addRoutes(new RouteBuilder(){
#Override
public void configure() throws Exception {
from("ssh://root:pswrd#192.168.12.12:22?delay=1000&pollCommand=date +s3N%0A")
.convertBodyTo(String.class, "UTF-8")
.log(LoggingLevel.INFO, "${body}");
}
});
camelContext.start();
}
The version of Camel is 2.19.2.
So how should I encode/escape the special characters from the parameter part (+%s%3N) of my command?
Found one more solution in addition to #Claus Ibsen's
date RAW(+%s%3N)
As I thought the problem was in + sign. So I just need to do not use it in pollCommand which could be done by following command:
date $(printf "\x2b")%s%3N
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
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())));
}
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.