Сообщения

Сообщения за июнь, 2017

Spring Boot, JUnit and org.json collision

org.json:json package provides a neat set of fuctions, including XML to JSON conversion. While you can use the library in production code of a project based on Spring Boot. It works fine in Spring Boot based production code, but when it comes to the tests you should expect to see  java.lang.NoSuchMethodError: org.json.JSONObject.stringToValue(Ljava/lang/String;)Ljava/lang/Object; Sping Boot starting from 1.5.4 detects this collision and shows the following message on startup: Found multiple occurrences of org.json.JSONObject on the class path: jar:file:/home/ilya/.m2/repository/com/vaadin/external/google/android-json/0.0.20131108.vaadin1/android-json-0.0.20131108.vaadin1.jar!/org/json/JSONObject.class jar:file:/home/ilya/.m2/repository/org/json/json/20170516/json-20170516.jar!/org/json/JSONObject.class You may wish to exclude one of them to ensure predictable runtime behaviour. As you can see another library comes to play when we have dependency on spring-boot-st...

Mime type issue with Geoserver and Spring

Trying to code a simple client for OGC WFS implemented with GeoServer I got the exception: Invalid mime type "text/xml; subtype=gml/2.1.2": Invalid token character '/' in token "gml/2.1.2" The source of the problem is Content-Type header value - " text/xml; subtype=gml/2.1.2 ", which makes Spring insane when getContentType() is executed. How to deal with that? Create the following custom RestTemplate  that replaces  "text/xml; subtype=gml/2.1.2" with "text/xml" : class WfsRestTemplate extends RestTemplate {     @Override     protected <T> T doExecute(URI url, HttpMethod method, RequestCallback callback,  final ResponseExtractor<T> responseExtractor) throws RestClientException {         return super.doExecute(url, method, callback, response -> {              response.getHeaders().setContentType(MediaType.TEXT_XML);             return resp...