A REST and websocket programmers daily log

We want to share issues and annoyances that made our trip slower.

ThreadLocalRandom

Good to remember that it exists.

JSON Parsing

It is possible to use Jackson with no JAXB as for these examples
https://github.com/jersey/jersey/tree/2.17/examples/json-jackson
and this specification
https://jersey.java.net/nonav/documentation/latest/media.html#json.jackson

MessageBodyProviderNotFoundException

The MessageBodyProviderNotFoundException has to do with JSON deserialization.
It is the sympton and happens when Jersey client deserializea a map or collections when readEntity fails
http://stackoverflow.com/questions/26818492/serialization-and-deserialization-of-map-with-jersey-and-jackson

Test With ObjectMapper

@Test
public void testGetIt() throws Exception {
String responseMsg = target.path(“apipath”).request().get(String.class);
ObjectMapper mapper = new ObjectMapper();
MyList books = mapper.readValue(
responseMsg, MyListAnswer.class);
System.out.println(books);
}

SERVLET, JERSEY and TOMCAT

Jersey version 2 servlet

If you want to use jersey version 2 you need to replace the servlet definition with the following:

<servlet>
<servlet-name>Jersey-Servlet</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.memorynotfound.rs</param-value>
</init-param>
</servlet>
===============
<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-value>true</param-value>
</init-param>

Cannot call sendError() after the response has been committed

Solution: return after sendError() to avoid chain.doFilter(request, response); to be called

How throttle servlet requests-Solution

Use a  web filter.

ClassNotFoundException: org.glassfish.jersey.servlet.ServletContainer

Solution: .war file is incomplete. Make it again and check that it contains all libraries.

Setting property ‘source’ to ‘org.eclipse.jst.jee.server:appname’ did not find a matching property

You can change the eclipse tomcat server configuration. Open the server view, double click on you server to open server configuration. Then click to activate “Publish module contents to separate XML files”. Finally, restart your server, the message must disappear.

At least one JAR was scanned for TLDs yet contained no TLDs

Set catalina.properties
tomcat.util.scan.StandardJarScanFilter.jarsToSkip=*.jar

Charting, Rickshaw, JavaScript, Servlet, JSON

set “Keep-alive” to … with JAX-RS Response.header() .

IMPLEMENT PUSH WITH WEBSOCKETS IN JAVA

Client javascript parsing of Json

Use JSON.parse in onMessage(), or everything will be caos 🙂

function onMessage(event) {
  var json = JSON.parse(event.data);

Some help

http://stackoverflow.com/questions/25947790/real-time-updates-from-database-using-jsf-java-ee/

MAVEN

Update repository , and mirrors
https://maven.apache.org/guides/mini/guide-configuring-maven.html

Install custom jars
https://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html

GIT

Setting up kdiff3 as the Default Merge Tool for git on Windows

Edit .gitconfig , it is usually in your user directory. There may exist other .gitconfig files, pay attention please!

[merge]
tool = kdiff3
[mergetool “kdiff3”]
path = “D:/Progra~1″/KDiff3/kdiff3.exe
cmd = “D:\\Progra~1\\KDiff3\\kdiff3.exe” $BASE $LOCAL $REMOTE -o $MERGED
cmdOK = “D:/Progra~1″/KDiff3/kdiff3.exe
keepBackup = false
trustExitCode = false