Open BenDol opened 4 years ago
Manually overriding the Content-Type
header in the settings resolves this issue:
@Bean
@ConditionalOnMissingBean
public GoodDataSettings goodDataSettings() {
GoodDataSettings settings = new GoodDataSettings();
settings.setPresetHeader("Content-Type", ContentType.APPLICATION_JSON.toString());
return settings;
}
but now I'm getting:
Caused by: com.gooddata.GoodDataRestException: 400: [request_id=wYTzCwTOrOcdjiOw] Malformed request: [Parsing error: Unexpected character ('<' (code 60)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')
at [Source: (<hidden>ResetableServletInputStream); line: 1, column: 2]]
Okay so the reason the XML content type is added is because the RestTemplate
adds a the MappingJackson2XmlHttpMessageConverter
message converter that processes the request. So removing this from the RestTemplate
message converters resolves the issue. Might need to explicitly define what message converter is used.
@BenDol thanks for reporting the issue - just to clarify:
FYI: ad 1) no, logs say that "GoodData-Java-SDK/2.34.0+api1" version was used
I changed to use the latest version 3.0.0-RC.3+api3
while trying to resolve it, but @liry is correct I initially was using 2.34.0+api1
. The issue occurs in either.
GoodData: 3.0.0-RC.3+api3 Spring: 5.1.5.RELEASE
The reason I'm experiencing this is that the RestTemplate detects what libraries you have in your classpath and add the message converters to the list and for what ever reason the MappingJackson2XmlHttpMessageConverter
is being used (likely its just the first in the list before JSON). We need to make sure the RestTemplate
favors the MappingJackson2HttpMessageConverter
.
RestTemplate:
...
jackson2XmlPresent = ClassUtils.isPresent("com.fasterxml.jackson.dataformat.xml.XmlMapper", classLoader);
...
if (jackson2XmlPresent) {
this.messageConverters.add(new MappingJackson2XmlHttpMessageConverter());
}
If you want to reproduce the issue just add Maven: com.fasterxml.jackson.dataformat:jackson-dataformat-xml
to your project.
@BenDol thanks for investigation and sorry for inactivity due to vacancies. We will try to find the way for ensuring the correct set of converters when GoodData is created.
At the same time I suppose you resolved the situation by excluding dataformat-xml from classpath?
Having trouble getting the Afm execution working.
Caused by: com.gooddata.GoodDataRestException: 415: [request_id=tzRYVbhAWy3Z8aTS] Content type 'application/xml;charset=UTF-8' not supported
Results in:
I wasn't able to find any resource on this particular issue. Any help is appreciated.