Сообщения

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...

Getting rid of boilerplate code for ReentrantReadWriteLock

Got tired of the idioms alike? rwl.readLock(); try {     // thread     // unsafe     // code } finally {     rwl.readLock().unlock(); } It is 2017 and Java 8 have been released in 2014! Using lamdas makes the code keen and clean. Here what you get: // You can assign the result to a variable of the type you need: String s = callReadLocked(() -> {         // thread         // unsafe         // code         return someString;     }); } // If nothing needs to be returned, just return anything: callReadLocked(() -> {         // thread          // unsafe         // code            return null;     }); } For the magic to work you need to define a couple of methods and a functional interface: private <T, E extends Throwab...

Changing channel colors at Saleae Logic

Изображение
Saleae Logic is a simple but handy  logic analyzer , which enables you to debug your MCU -based circuits by capturing actual voltage levels present on certain wires of your circuit. Like that: Availability of cheap clones made this tool (along with based on the same chip unbelievably popular among hobbyists. Sometimes these clones are bit glitchy, but they are indeed a good start if you are not familiar with the logic analyzers. Original software works with them likewise good. The serious only problem you may encounter is... colors of wires. Original device and the software has channels colored black , brown , red , orange , etc. Clone uses the same sequence, but starting with brown . Black is used for ground in clone, which does make sence. Surely, to avoid mistakes you may want to make the two sets match. The problem is the channel colors in the app are fixed.You can edit labels but not colors - at least in version 1.1.15 for Linux. As the result possible solutions ...