Last News

Tags

Hey everyone, how are you?

I know that I am absent in these last days, but I want to show you some of the things I’ve been doing:

Dashboard Project

  • I gathered the people of the Spring Brasil group (Telegram) so we can do a project together. The chosen project was a Dashboard of issues, which can integrate with Bitbucket, Github and etc.
  • The project is still in the beginning and is Open Source. The URL is: https://github.com/SpringBrasil/spring-dashboard-bitbucket

OLX Medium (PT-BR)

Speeches

  • I am preparing some lectures to be able to present, of the most varied subjects: BDD (Behavior Driven Development), Spring, SOLID and etc.
Advertisements

Curiosities: Default ports

Tags

,

I recently saw a problem of a service running on a specific port. For reasons of limited access to the source code and to the machine, it was difficult to figure out what might be running on that port. So, this motivated me to do this post, to know what are the default ports of some of the services, just out of curiosity:

Default ports

Service Port Additional Information
SQL Server 1433
OracleDB 1521
Express 3000 NodeJS Framework
Rails 3000 Ruby Framework (Ruby On Rails)
MySQL 3306
PostgreSQL 5432
Kibana 5601
RabbitMQ 5672
Redis 6379
Weblogic 7001 Administration Server
Weblogic 7002 SSL Administration Server
Django 8000 Python Framework
Jenkins 8080
Tomcat 8080
Spring Boot 8080 Java Framework (it uses Tomcat)
ElasticSearch 9200 For REST
ElasticSearch 9300 For nodes communication
MongoDB 27017
MongoDB 27018 When running with –shardsvr
MongoDB 27019 When running with –configsvr
MongoDB 28017 Web status page

This post may be updated. If you have any suggestion of service, just say that I add. In the next post I will try to talk about Java 9 and its news.

Guide – Spring MVC

Tags

,

In the previous posts about Spring Boot (Part 01 e Part 02), some people asked me about Spring MVC because they did not know how it works. In this post, I will not teach how to configure Spring MVC, but rather give an overview of the main features.

What it is?

Spring MVC is a Spring web framework and action-based that works with MVC architecture (Model-View-Controller) and it helps in building flexible and loosely coupled web applications, besides being easy to use.

Example of use (calling a page)

@Controller
public class UserController {

    @RequestMapping(value="/", method=RequestMethod.GET)
    public String index() {
        return "home";
    }
}

Example of use (REST)

@RestController
public class UserRestController {

    @RequestMapping(value="/users", method=RequestMethod.GET)
    public List<User> listUsers() {
        //... get users 
        return users;
    }
}

Main things to know

@Controller

  • It is the main annotation to define a class as a Spring MVC Controller. The Controller is responsible for mapping and receiving requests sent by the client.

@RestController

  • Defines a class as a Spring MVC REST Controller. The main difference for @Controller is that the RestController does not look for a page when returning a value, but returns exactly that value.
  • Example: When returning the String: “ralph”, the @Controller would look for a file (HTML, JSP, or any configured format) with that name. The @RestController would return exactly “ralph”.

@RequestMapping

  • Main annotation to define mappings. In it is defined the HTTP method to be used, which Path to call, what will be the accepted data type and the return type of the content.
  • Examples:
@RequestMapping(value="/users", method=RequestMethod.GET)
public String somePath() { /*code*/ }

@RequestMapping(value="/users", method=RequestMethod.POST,
 consumes=MediaType.APPLICATION_JSON_VALUE,
 produces=MediaType.APPLICATION_JSON_VALUE )
public String someOtherPath(User user) { /*code*/ }

Continue reading

Guide – Spring Boot (Part 02)

Tags

,

YAML

In the last post we used the application.properties config file, but Spring supports YAML for config too. So, the same config file from the last post (link in the end of the post) would be like this in a application.yml:

server:
    context-path: /
    port: 8081
spring:
    datasource:
        url: jdbc:h2:file:~/conscious_it
        username: sa
        password:
  • IMPORTANT: if there are both files, the priority is .properties

Configurations By Environment

  • Spring has the ability of being separated by environments. It means that I can have development and production configs separately and choose which to run dynamically. This feature is called Profile.
  • To choose which environment to execute, just pass the parameter -Dspring.profiles.active to JVM:
java -Dspring.profiles.active=dev -jar my_spring_boot_project.jar
  • This configuration would search the files:
application-dev.properties
application-dev.yml
  • The profile file pattern is:
application-{profile}.properties (ou yml)
  • In case of running in the IDE, just pass the parameter to the class that executes the SpringApplication.run
  • With Spring, it’s also possible set different implementations using the same parameter (spring.profiles.active) in the JVM. For this you need to use the Spring @Profile annotation.
    • Let’s suppose I have a UploadService interface and I want it to be AWS in production but for development I want it to be File. Using the annotation, it would look like this:

Continue reading

Guide – Spring Boot (Part 01)

Tags

,

  • Required knowledge of dependency injection. Preferably Spring, but can be CDI as well.
  • “Any time spent writing configuration is time spent not writing application logic” – (WALLS, Craig – Spring Boot In Action)

What it is?

It is a framework that eases the configuration of a Spring-based application. You can download the dependency of Spring Boot and its related projects as any other dependency of Maven / Gradle, but you can create a project configured using the site: start.spring.io/ (Note: For better visualization, click Switch to the Full version.)

Basic Concepts

  • The created project with Spring Boot can be in JAR or WAR format. If it is JAR and Web, Spring Boot starts an embedded Tomcat each time it is started.
  • Spring Boot needs a class with a method main that executes the method SpringApplication.run
  • By default, The @SpringBootApplication annotation is used in this class. Basically it is an annotation that adds other annotations:
    • @Configuration – It marks the class as a bean definition source.
    • @EnableAutoConfiguration – Add some beans based on Classpath and other settings.
    • @ComponentScan – Tells Spring where to look for other components, configurations, and services.
    • @EnableWebMvc – If spring-webmvc is on classpath, this annotation is also added, with all Spring MVC configuration.
  • If the class that runs SpringApplication.run (let’s call it MainApplication) is in the com.conscious.it package, it’s not necessary to create the beans with default constructor. Spring maps all packages and subpackages from MainApplication package.

Continue reading

Tracks – You might have lost 01

Tags

Professional Career

Good Practices

DevOps Related

Tests

Web

Improving the Knowledge

Tips

How to measure performance – Java

Tags

, ,

How to know how much the app is consuming from memory? Where is the application bottleneck? How are the application Threads? How many classes are being loaded? How many instances are being created?

You can answer these questions by monitoring the JVM and using Profiling (this is the process of monitoring parameters at the JVM level, such as Method Execution, Thread Execution, Object Creation, and Garbage Collection).

In the post about testing tools (Let’s try something different: Testing Tools 01) it was possible to measure if the application tolerates X accesses, the response time of the application and etc. Now let’s measure HOW the JVM is reacting to this.

For this example, we will use VisualVM because it is free, easy to use and has a good amount of information, and we will also use the java-sample-project project. The use of VisualVM is very simple: when downloaded, you unzip it and execute the visualvm file inside bin folder. Follow the guidelines in the Java Sample Project to run the project. When VisualVM and the project are started, VisualVM should look like this:

Continue reading

Early Access: JUnit 5

Tags

, , ,

I was testing one of the news that are about to be released: JUnit 5. The first impression is that it has a lot of cool functionalities, such as parameterized tests, improved Exception assert, grouping tests by Tags and etc.

I created a branch of my java-sample-project project using some JUnit 5 features with Spring Boot and I will summarize just some of the features:

Parameterized Tests

  • It gives you the ability to run the same test with different parameters, coming from different sources: Inline Values (String, Integer, etc.), Enum, CSV, Methods…
  • In my project, I used @MethodSource to exemplify:

  • With this, the test will search for a method called createUsers that returns a Stream<Arguments>:

  • The expected parameters in my test method are: a User and an Integer, and in that Stream I’m passing both. The test will run first with userOne () and 1, and then with userTwo () and 2.

Exceptions Assert

  • With JUnit 4 it was possible to test exceptions, both with @Test(expected=…) and Exception Rule (ExpectedException). This last one could still validate the exception message. But I believe nothing compares to this assertThrows:

Continue reading

Let’s try something different: Testing Tools 01

Tags

, , , ,

For testing tools and some other examples, I recommend one of these projects: python-sample-project ou java-sample-project, pretty simple projects for testing easily and quick.

Locust

  • A simple load testing tool, but powerful. You write Python code on tests, so the flexibility is a little bigger.
  • Prerequisites:
    • Python 2.7.4+ or 3.3+

Pros:

  • Some flexibility on tests
  • Easy to Install
  • Easy to Configure
  • Easy to Use
  • Multiplataform

Cons:

  • Although showing the main information, it could show more useful information and / or charts
  • The test never stops unless you click to
  • Tests HTTP calls but doesn’t test flows as a real user would do in a browser

Result Example:

locustio

SOURCE: http://locust.io/

Link: http://locust.io/

Httperf

  • It’s a simple but also powerful performance testing tool.

Pros:

  • Easy to Install
  • Easy to Use
  • Great amount of info
  • Great amount of customization of calls
  • Can limit the total of requests

Cons:

  • Linux Only
  • Tests HTTP calls but doesn’t test flows as a real user would do in a browser (but it is not what it proposes to do)

Result Example:

httperf

Source: http://www.labs.hpe.com/research/linux/httperf/httperf-man-0.9.pdf

Links: https://github.com/httperf/httperf and https://linux.die.net/man/1/httperf

In my list of tools, the next to be tested is Multi-Mechanize. If you have any suggestions, send me.

Why do you do what you do?

Tags

, ,

It seems like a simple question, but you need to think hard about why we work with what we work with. As a developer, I see a lot of people saying they program because of the money. Others say they program because of the number of jobs they have and so on.

Why am I asking you this? After all, I myself entered the programming area because I did not go through electrical engineering and Computer Science was one of the few courses where I was not very life-threatening (ironically, it is one of the most stressful ones to me, which apparently is not very good for health).

The first thing to be a good professional, regardless of the area, is to love what you do. When you love what you do, you dedicate yourself, you study, you want to improve, because you love what you do.

“Choose a job you love, and you will never have to work a day in your life.” (Confucius)

Another point I would like to highlight is: seek professional happiness. You may love your profession but work in a place that does not give you the satisfaction you need to perform well. Maybe, problems with the boss, problems with the company’s culture, maybe even salary. We know that there is no perfect company, but if you are not happy, have talked and not resolved, do not be afraid to seek your happiness.

The second last point is: do not be afraid to change, be afraid to stand still. It has happened that I am doing what I like, in a place I like and not evolving, and I do not mean job levels or positions in the company, I mean knowledge, professional growth, knowing more and more. Some people like routine and always doing the same thing, but the fact that you are not evolving has to bother you. You love what you do, you have to feel like learning more and more.

The last and not least point is: always do your best. Depending on the work area, the chance that you will work with someone who has worked with you is very large. Your professional image tells a lot about you. Do not be known as the person who “even worked, but …”. Rest assured that in all your work you have given your best and do not be afraid to be happy.