I got this annoying error on Intellij community in a Java project when trying to run a main class: Error:java: javacTask: source release 1.8 requires target release 1.8 This was triggered after I implemented a few things that exists only in Java 8. How to fix In the “Project Structure” I had changed already to Language Level 8, so it didn’t triggered any errors in the editor. In order to fix this problem, you must have a JDK 8 installed and then set the bytecode to version 1.8: Go to: File -> Settings -> Build, Execution, Deployment -> Compiler ->...
Posted on Oct 13, 2016

Appengine and datastore is a great cloud provider and database to try out on new projects. It supports Java, Python and Go and has a great free layer. This is a tutorial about how to setup the objectify framework in a java google AppEngine project in order to access datastore in a Java + gradle project. An entity representing a Comment without relationships will be created. Add dependencies in build.gradle edit and add the dependencies: compile group: 'com.googlecode.objectify', name: 'objectify', version: '5.1.13' compile 'com.google.appengine:appengine:+' compile group: 'com.google.appengine', name: 'appengine-api-1.0-sdk', version: '1.9.42' Create a mapped entity import com.googlecode.objectify.annotation.Entity; import com.googlecode.objectify.annotation.Id; import...
Posted on Oct 13, 2016

This post is a tutorial / list to make a Google AppEngine Java web application serve static files (html, js, css) Check out the google’s sample code or download the code git clone https://github.com/GoogleCloudPlatform/java-docs-samples.git Or Download Link for master.zip The baseline for this tutorial is in java-docs-samples/appengine/helloworld cd java-docs-samples/appengine/helloworld Map the static configuration for AppEngine Edit appengine-web.xml: vim src/main/webapp/WEB-INF/appengine-web.xml Then add <public-root>/static</public-root> add folder static in WEB-INF mkdir src/main/webapp/WEB-INF/static Add welcome-file vim src/main/webapp/WEB-INF/web.xml <welcome-file-list> <welcome-file>index.html</welcome-file> </welcome-file-list> Add a index.html touch src/main/webapp/WEB-INF/index.html Edit it and add: <!DOCTYPE html> <html> <head> <title>Hello World</title> </head> <body> <h1>This is a Heading</h1> <p>This is a...
Posted on Oct 12, 2016

I was playing with AppEngine, and studying for the getParameter vs getAttribute post. An then an strange error occurred (stacktrace below). Searching, I found out that this happens because of the JDK version. Since I use JDK8 for another projects, my method was to use jEnv to quickly change between JKD versions. In this post I will describe how I fixed this error in Ubuntu 14.04 Install jEnv jEnv is an equivalent of rbenv for ruby. http://www.jenv.be/ jEnv allows you to change between installed JDKs git clone https://github.com/gcuisinier/jenv.git ~/.jenv echo 'export PATH="$HOME/.jenv/bin:$PATH"' >> ~/.bashrc echo 'eval "$(jenv init -)"' >>...
Posted on Oct 7, 2016

In this post I will list and write a couple of things about SEO, its tools and a few tips. Its a tutorial / brief list to make the desired website be more likely to appear in search engines (google, bing, yahoo, etc) Google Search Console Register and add your site in the console. This provides useful information about how many clicks and keywords are being used to send data to your website. Google Search Console Link Google Adsense Adsense is a common tool to generate revenue in websites. Its not an SEO tool / topic, but google seems to...
Posted on Oct 7, 2016

In this post I will write a little bit about the difference between getParameter vs getAttribute in javax.servlet.http.HttpServletRequest in Java. getParameter getParameter processes http request parameters. Its the stuff that is passed from the client to the server, so it can only return a String value: getAttribute getAttribute is intented to be used for server side only. Lets say you want to pass an attribute from the servlet to the JSP, you use HttpServletRequest.setAttribute. Then in the JSP you read it using getAttribute: Example code RootServlet.java: package mussatto.servlet; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; @SuppressWarnings("serial") public...
Posted on Oct 6, 2016

In this post how to to setup H2 database with web console on spring boot. This is a good feature / database for development. Remember to remove this in production! Setup First, lets add some dependencies in the pom.xml <dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> </dependency> Then lets add a new managed bean. @Bean public ServletRegistrationBean h2servletRegistration() { ServletRegistrationBean registration = new ServletRegistrationBean(new WebServlet()); registration.addUrlMappings("/console/*"); return registration; } Then the database’s connection URI and login information in application.properties: spring.datasource.url=jdbc:h2:mem:AZ;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE spring.datasource.driverClassName=org.h2.Driver spring.datasource.username=sa spring.datasource.password= spring.jpa.database-platform=org.hibernate.dialect.H2Dialect The code Github Link
Posted on Oct 4, 2016

In this post I will describe how to get user info from the SpringSecurityCore context when using OAuth2 as authentication in the website. Setup Following the last post’s code, I will add more code about how to get the logged user’s info: @RequestMapping("/secured") public String secured() { OAuth2Authentication oAuth2Authentication = (OAuth2Authentication) SecurityContextHolder.getContext() .getAuthentication(); Authentication userAuthentication = oAuth2Authentication.getUserAuthentication(); System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>"); Map<String, String> details = (Map<String, String>) userAuthentication.getDetails(); System.out.println(details); return "Hello, " + details.get("name"); } Then login on http://localhost:8080/secured and it will get your name on facebook. The code Github Link
Posted on Oct 3, 2016

In this post how to perform oauth2 authentication on spring boot and facebook. Setup The project is a web application, with root context set to permitAll, showing a static html and a rest controller with a secure path, and a insecure path. The SpringBootApplication This java class will contain the security config, and starts the spring boot application: package com.mussatto; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.security.oauth2.client.EnableOAuth2Sso; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; @SpringBootApplication @EnableOAuth2Sso public class BoilerplateApplication extends WebSecurityConfigurerAdapter { public static void main(String[] args) { SpringApplication.run(BoilerplateApplication.class, args); } @Override protected void configure(HttpSecurity http) throws Exception { http .antMatcher("/**") .authorizeRequests() .antMatchers("/", "/greeting",...
Posted on Oct 3, 2016

In this post I will describe the install steps for maven on Ubuntu 14.04. Download the binary Go to Maven Download and download the binary .tar.gz: mkdir ~/dev cd dev wget http://www-us.apache.org/dist/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz tar -xvf apache-maven-3.3.9-bin.tar.gz Setup the environment tools edit the file ~/.bashrc, and add the lines: export M2_HOME=/home/mussatto/dev/apache-maven-3.3.9 export M2=$M2_HOME/bin export MAVEN_OPTS="-Xms256m -Xmx1024m" export PATH=$PATH:$M2 Export the .bashrc file: source ~/.bashrc Test the install ~ $ mvn --version Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T17:41:47+01:00) Maven home: /home/mussatto/dev/apache-maven-3.3.9 Java version: 1.8.0_101, vendor: Oracle Corporation Java home: /usr/lib/jvm/java-8-oracle/jre Default locale: en_GB, platform encoding: UTF-8 OS name: "linux", version: "3.19.0-32-generic", arch: "amd64", family:...
Posted on Oct 2, 2016