Boiling frogs 2017 inspirations: teach (1)

It is longer than three weeks since I was attending that software craftsmanship conference in Wrocław. The seven-hour train journey was exhausting, but worth that amazing experience of meeting a lot of great people and learning something new about my job. Here I just want to share some thoughts with hope, that someone gets inspired.

Moore’s law of our times – Tomasz Kaczmarzyk (opening speak)

    • “The software craftsmanship manifest” was reminded. I think that every programmer aspiring to be a professional should recall it more often than on the conference. I would say at least once a month! The thing is to keep the focusing on “raising the bar”.
    • The next fun thing was a prediction of Uncle Bob, that “every 5 years the number of programmers doubles”. And here is my tweet about it:

    • There was nice explanation what “10x programmer” really means in the context of software craftsmanship: maybe 1 senior programmer cannot be as much productive as 10 junior programmers, but he can improve them by teaching and helping. So senior guys step up and don’t hesitate to be mentors! I believe that teaching is a natural way to become an expert.

Thanks for reading!

Cheers, Rafał 🙂

[IntelliJ] Auto-filling Java call arguments like Eclipse did

After changing my IDE from Eclipse to IntelliJ, I suffered from lack of really helpful functionality of auto-completing method call arguments (topic on Stackoverflow).

The standard auto-completition wasn’t enough and “Ctrl+P” shortcut doesn’t satisfy me either.

Hopefully I found this issue: IDEABKL-5496 – Auto-filling the actual Java call arguments, where the last comment written just couple days ago has a great news for me!

Making long story short: some German developer made pretty cool plugin, that fix this problem!

Usage is very simple – you don’t need to know new shortcut, just press “Alt+Enter” and select “Fill …” from suggestions menu. It rocks!

[Guava] Preconditions

Preconditions should be ideal for situations, where there is no specific business exceptions for checking arguments and performance is not an issue.



    * Returns the positive square root of the given value.
    * @throws IllegalArgumentException if the value is negative
   public static double sqrt(double value) {
     Preconditions.checkArgument(value >= 0.0, "negative value: %s", value);
     // calculate the square root


Here is more about checking conditions:

Using Spock for testing code – getting started with syntax (1)

Getting started guide:

Interesting things:

  • cool way to verify throwing exceptions:
    EmptyStackException e = thrown() e.cause == null
  • instead of writing, “when-then”, just use “except”:
    Math.max(1, 2) == 2
  • to parameterize test with different data, use “where” syntax:
    def "computing the maximum of two numbers"() {
    Math.max(a, b) == c
    a << [5, 3]
    b << [1, 9]
    c << [5, 9]
  • in helper method use “assert” keyword:
    assert pc.vendor == "Sunny"

Spring security handle AJAX XHR request for logout users and response 401 instead of 302

I found this article with filter implementation:

Spring Security part VI : Session Timeout handling for Ajax calls

However in comment someone point that we can simply extend “LoginUrlAuthenticationEntryPoint”.

My solution sets only status 401 and doesn’t write anything to response body:

	static class AjaxAwareLoginUrlAuthenticationEntryPoint
			extends LoginUrlAuthenticationEntryPoint {

		public AjaxAwareLoginUrlAuthenticationEntryPoint(String loginFormUrl) {

		public void commence(HttpServletRequest request, HttpServletResponse response,
				AuthenticationException authException) throws IOException, ServletException {

			if (isAjaxRequest(request) && authException != null) {
			super.commence(request, response, authException);

		private static boolean isAjaxRequest(HttpServletRequest request) {
			return "XMLHttpRequest".equalsIgnoreCase(request.getHeader("X-Requested-With"));

Workaround for “X-Forwarded” headers in Spring UriComponentsBuilder

When our application server user proxy, that doesn’t set “X-Forwarded” headers with original request port, then we can use some hack in our application. Just ignore port when it is equal 80 or 443, cause it is default. For example instead of "http://localhost:80/app", we will get "http://localhost/app". And "https://localhost:443/app" will output "https://localhost/app".

UriComponentsBuilder currentUrl = ServletUriComponentsBuilder
int port =;
currentUrl.port(port != 80 && port != 443 ? port : -1);
String currentUrlString = currentUrl.toUriString();

Inspired by Mat Banik strackoverflow answer –