Current request is not of type HttpServletRequest

Ran into this error this week

There was an unexpected error (type=Internal Server Error, status=500). Current request is not of type [org.apache.catalina.servlet4preview.http.HttpServletRequest]: ServletWebRequest: uri=/my/url/

Make sure you imported the correct HttpServletRequest import. I wanted import javax.servlet.http.HttpServletRequest;

read more

Filtering FiveThirtyEight's NFL Forecasting Leaderboard

A group of friends and I have a contest going on FiveThirtyEight’s NFL Forecasting Game Leaderboard and they don’t allow group functionality, so at the end of each week I Ctrl + F on the page to find each of our name’s and update a spreadsheet. Instead of spending 3 minutes once a week I decided to spend 15 minutes and write something that will do it for me.

Just replace the names array with a list of the names in your group

const table = document.getElementById('leaderboard-table-wrap').getElementsByTagName('tr');
Array.from(table).forEach(function(item) {
  const names = ['Matt Busche', 'Random Dude'];
  if (names.indexOf(item.getElementsByClassName('name')[0].textContent) === -1) {
    item.closest('tr').remove();
  }
});

As always you can use a Bookmarklet Creator to add this as a “bookmark” on your address bar to make filtering super easy.

Note: If you can’t find a person, each person needs to acknowledge that they want to publically post their score by visiting the leaderboard page and clicking a link.

read more

Finding md5 hash of file

Fun tip I learned today. If you need to find the md5 hash of a file you can simply user the following command.

certutil -hashfile {path+filename} md5 

certutil is included in windows by default, so you aren’t required to have anything additional installed.

read more

Angular Loading JavaScript file in different environments

If you ever need to load two different files in production vs test, you can add some code to your main.ts file in your Angular project. The existing code includes the if statement and enableProdMode(), but you can easily add in the else to conditionally load a different file. In my case I don’t want google analytics posting to my production account.

import { environment } from './environments/environment';

//create a new element
const script = document.createElement('script');
if (environment.production) {
    enableProdMode();
    script.src = 'analytics.js';
} else {
    script.src = 'test-analytics.js';
}
//append that element into the dom
document.head.appendChild(script);

read more

Java setting tracking mode for session

If you avoid using xml for you configuration files like I do, but don’t want to pass the jsessionid around through the URL you can create a @Bean and use a lambda to set the tracking mode as follows

public class AuthProvidersSecurityConfig extends WebSecurityConfigurerAdapter {

    @Bean
    public ServletContextInitializer servletContextInitializer() {
      return servletContext -> {
        servletContext.setSessionTrackingModes(EnumSet.of(SessionTrackingMode.COOKIE));
      };
    }
}

read more

Java settting domain on a session cookie

If you need to override the domain on a session cookie you can add the following method to your AuthProvidersSecurityConfig class to do so. It’s not common you’d need to do this, but our domain wasn’t setting correctly in our cookie and this cleared the issue up.

public class AuthProvidersSecurityConfig extends WebSecurityConfigurerAdapter {

  @Bean
  public ServletContextInitializer servletContextInitializer() {
    return servletContext -> {
      servletContext.getSessionCookieConfig().setDomain("mrbusche.com");
    };
  }
}

read more

I'm speaking at Iowa Technology Summit

I’m proud to announce I’ll be speaking at Iowa Technology Summit on October 2nd! The conference will be held at the Community Choice Credit Union Convention Center in down Des Moines.

I’ll be speaking on Secure by Design and how you can ensure security throughout development of your application. I’ll cover some of the OWASP top 10, best practices, and things I’ve implemented at work. I gave a similar talk at DevOpsDays Des Moines, but I have a lot of takeaways from that talk and my team at work has made a lot of progress that I’m excited to be able to share.

Registration is open now, so don’t delay in getting your tickets!

Iowa Tech Summit

read more

User added in Jenkins doesn't have access

I was helping a team at work recently and we needed to add a few users to Jenkins. We added the users and then asked them to login and make sure they could run jobs. 2 out of 3 people were able to run jobs, but the 3rd person was not. We had added them the same as everyone else, but it wasn’t working. I had them logout and back in and that’s when I realized the issue - Jenkins is case sensitive If you add a user as mrbusche but they login as MRBUSCHE they’re not recognized in Jenkins.

Long story short

Jenkins is case sensitive

read more

Spring JPA add default timestamp to column

Spring JPA is awesome, but I ran into some issues adding a default timestamp to the column. The database should be set to have a default value, but that wasn’t an option here. I found the annotation pretty quickly, but instead of checking the database to see if it worked I was debugging in IntelliJ and that’s where the hiccup occurred. The value isn’t set on the object at object creation it’s only set once the entity has been saved. The following is what I ended up using

@Column(name = "creationDate")
@CreationTimestamp //this adds the default timestamp on save
private Timestamp createDate;

read more

Spring Boot DB2 and MSSQL Configuration

By default Spring boot does a lot for you in datasource configuration, but if you’re using two separate database types – DB2, MSSQL, MySQL, Oracle, etc. It doesn’t know how to infer which database type each is, so if you are configuring multiple different database types in Spring you need to specify the jpa.database type. In a yaml configuration your datasources should be defines like so.

spring:
  datasource:
    url: jdbc:sqlserver://${server}:${port};databaseName=${databaseName}
    username: ${username}
    password: ${password}
  jpa:
    database: sql_server
db2:
  datasource:
    jdbcurl: jdbc:db2://${server}:${port}/${databaseName}
    username: ${username}
    password: ${password}
  jpa:
    database: db2

read more