Optional or orElse

What’s more elegant

Optional<Header> resultcode = Arrays.stream(response.getAllHeaders())
        .filter(h -> "X-Header-Result".equals(h.getName()))
        .findFirst();

return resultcode.isPresent() ? resultcode.get().getValue() : "";

Or

String resultcode = Arrays.stream(response.getAllHeaders())
        .filter(h -> "X-Header-Result".equals(h.getName()))
        .findFirst().map(NameValuePair::getValue)
        .orElse("");

return resultcode;

Inspect unknown Java objects at runtime

// debug purposes: to inspect unknown objects at runtime
static void inspect(Object obj) {
try {
for (Field f : obj.getClass().getDeclaredFields()) {
f.setAccessible(true);
System.out.printf("%s %s %s %s%n",
Modifier.toString(f.getModifiers()),
f.getType().getSimpleName(),
f.getName(),
f.get(obj)
);
if ("Object[]".equals(f.getType().getSimpleName())) {
LOG.warn("further inspect object " + f.get(obj));
}
if ("int".equals(f.getType().getSimpleName())) {
LOG.warn("expected size " + f.get(obj));
}
if ("List".equals(f.getType().getSimpleName())) {
List<Object> objects = (List<Object>)(List<?>) f.get(obj);
for (Object o : objects) {
inspect(o);
}
}
}
} catch (IllegalAccessException iae) {
System.out.println("IllegalAccessException : " + iae.getMessage());
}
}

remove last git push

Show last commit comment first:
git log –name-status HEAD^..HEAD

Then, remove the last commit and push:
git reset –hard HEAD~1

See also: https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History

ActiveMQ Illegal character +0x16

ActiveMQ Illegal character +0x16 HttpChannelOverHttp {\x16<<<\x03\x01\x00\xD6\x01\x00\x00\xD2\x03\x03\xDd#\x13\xBb\xA3…\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00}

Reason is, you’re listening HTTP on an HTTPS port. Unfortunately restarting the ActiveMQ won’t help.

For me, what helped was:

  1. stop the ActiveMQ
  2. clear the maps in the map “..\activemq\data\tmp”
  3. clear the files in the map “..\activemq\data\kahadb”