Welcome at microwebservices.eu, my interests: microservices.com.pl, Java, cloud on AWS, J2EE, containerization/Dockerization, Kubernetes, JEE, EJB, JSP, Maven, Web Services, SOAP, REST, High Availability Systems, Genetic Algorithms, Neural Networks etc. See linkedin.com/in/grathor33/, bitbucket.org and https://github.com/grathor33/
Sunday, August 18, 2019
Friday, August 16, 2019
Saturday, July 6, 2019
microservices like a coral reef ecosystem
For me working microservices are simmilar to... coral reef ecosystem.
There are a lot of producers and consumers of resources...
The ubiquity of microservices in commercial sofware is very trendy today.
This is because the concept of microservices implements real SOA rules... It really do that!
Circuit-breaker? (Netfilix Hystrix?):
The ubiquity of microservices in commercial sofware is very trendy today.
This is because the concept of microservices implements real SOA rules... It really do that!
Circuit-breaker? (Netfilix Hystrix?):
Service discovery? (Netfilix Eureka? Hashicorp Consul?):
Proxy and API Gateway? (Netflix Zuul?):
Security with OAuth2?
Debugging distributed chains of actions (tracing and debug)?
Data Streams? (Kafka? Spark?):
Sunday, June 30, 2019
AWS Elastic Beanstalk
AWS Elastic Beanstalk is...
an orchestration service offered by Amazon Web Services for deploying applications which orchestrates various AWS services, including EC2, S3, Simple Notification Service (SNS), CloudWatch, autoscaling, and Elastic Load Balancers.
https://aws.amazon.com/elasticbeanstalk/
https://en.wikipedia.org/wiki/AWS_Elastic_Beanstalk
an orchestration service offered by Amazon Web Services for deploying applications which orchestrates various AWS services, including EC2, S3, Simple Notification Service (SNS), CloudWatch, autoscaling, and Elastic Load Balancers.
https://aws.amazon.com/elasticbeanstalk/
https://en.wikipedia.org/wiki/AWS_Elastic_Beanstalk
Thursday, May 30, 2019
Thursday, March 7, 2019
Vagrantfile
Vagrantfile
Vagrantfile:
Vagrant.configure("2") do |config|
config.vm.provision "docker" do |d|
d.build_image "/vagrant/app"
end
end
More:
Thursday, February 28, 2019
LAMBDA function on AWS
LAMBDA function on AWS
AWS Lambda is Amazon's serverless compute service to reduce the configuration of servers, OS etc.
You can use it in data pipelines or to respond to web requests.
You can run your code on it without having to manage servers or even containers.
At the very begining we should specify a handler. There are 3 ways of creating such handler:
a.Implementing the RequestHandler interface
b.Creating a custom MethodHandler
c.Implementing the RequestStreamHandler interface
public class LRequestHandler
implements RequestHandler {
public String handleRequest(String input, Context context) {
return "Hello World, " + input;
}
}
public class LMethodHandler {
public String handleRequest(String input, Context context) {
return "Hello World, " + input;
}
}
public class LRequestStreamHandler
implements RequestStreamHandler {
public void handleRequest(InputStream inputStream,
OutputStream outputStream, Context context) {
outputStream.write(("Hello World").getBytes());
}
}
Monday, February 11, 2019
JConsole and OutOfMemoryError
jconsole and java.lang.OutOfMemoryError
JConsole is a graphical monitoring tool to monitor Java Virtual Machine (JVM) and Java applications both on a local or remote machine.
The graphical console can be started using "jconsole" command in every "bin" location of JDK installation.
The documentation of how to use jconsole: The documentation of how to use jconsole:
Other such tools (used via CLI): https://github.com/patric-r/jvmtop
JVM and memory
Big applications with large code-base can quickly fill up the segment of the memory, which will cause java.lang.OutOfMemoryError which is related directly with Perm Gen (Permanent generation).Generally we can meet the way how is the Java memory pool divided at very interesting articles on these forums:
- https://stackoverflow.com/questions/1262328/how-is-the-java-memory-pool-divided
- https://www.oracle.com/technetwork/java/javase/tech/vmoptions-jsp-140102.html
- https://stackoverflow.com/questions/38330176/difference-between-xms-and-xmx-and-xxmaxpermsize
- https://www.journaldev.com/2856/java-jvm-memory-model-memory-management-in-java
- https://i.stack.imgur.com/uDdEk.png
https://www.optaplanner.org/blog/2015/07/31/WhatIsTheFastestGarbageCollectorInJava8.html
https://openjdk.java.net/jeps/291 (JEP 291: Deprecate the Concurrent Mark Sweep (CMS) Garbage Collector)
https://plumbr.io/handbook/garbage-collection-algorithms
https://stackify.com/java-performance-tools-8-types-tools-need-know/
https://blog.idrsolutions.com/2014/06/java-performance-tuning-tools/
https://dzone.com/articles/java-performance-troubleshooti-0
https://dzone.com/articles/top-9-free-java-process-monitoring-tools-amp-how-t
https://www.dnsstuff.com/jvm-performance
http://karunsubramanian.com/websphere/how-to-choose-the-correct-garbage-collector-java-generational-heap-and-garbage-collection-explained/
https://www.petefreitag.com/articles/gctuning/
http://javahonk.com/how-many-types-memory-areas-allocated-by-jvm/
https://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/cms.html
https://codeahoy.com/2017/08/06/basics-of-java-garbage-collection/
https://dzone.com/articles/understanding-the-java-memory-model-and-the-garbag
http://all-about-java-and-weblogic-server.blogspot.com/2014/01/what-are-java-heap-young-old-and.html
http://blog.icodejava.com/tag/jvm-option-parameter-xxuseconcmarksweepgc/
Heap Memory Usage - Memory Pools:
Eden Space
Survivor Space
Tenured Gen
Non-Heap Memory Usage - Memory Pools:
Code Cache
Perm Gen
Heap memory
The heap memory is the runtime data area from which the Java VM allocates memory for all class instances and arrays. The heap may be of a fixed or variable size. The garbage collector is an automatic memory management system that reclaims heap memory for objects.
- Eden Space: The pool from which memory is initially allocated for most objects.
- Survivor Space: The pool containing objects that have survived the garbage collection of the Eden space.
- Tenured Generation or Old Gen: The pool containing objects that have existed for some time in the survivor space.
Non-heap memory
Non-heap memory includes a method area shared among all threads and memory required for the internal processing or optimization for the Java VM. It stores per-class structures such as a runtime constant pool, field and method data, and the code for methods and constructors. The method area is logically part of the heap but, depending on the implementation, a Java VM may not garbage collect or compact it. Like the heap memory, the method area may be of a fixed or variable size. The memory for the method area does not need to be contiguous.
- Permanent Generation: The pool containing all the reflective data of the virtual machine itself, such as class and method objects. With Java VMs that use class data sharing, this generation is divided into read-only and read-write areas.
- Code Cache: The HotSpot Java VM also includes a code cache, containing memory that is used for compilation and storage of native code.
Java objects reside in an area called the heap, while metadata such as class objects and method objects reside in the Permanent generation or Perm Gen area. The permanent generation is not part of the heap.
The heap is created when the JVM starts up and may increase or decrease in size while the application runs. When the heap becomes full, garbage is collected. During the garbage collection objects that are no longer used are cleared, thus making space for new objects.
-Xmssize Specifies the initial heap size.
-Xmxsize Specifies the maximum heap size.
-XX:MaxPermSize=size Sets the maximum permanent generation space size. This option was deprecated in JDK 8, and superseded by the -XX:MaxMetaspaceSize option.
Full specification of Java HotSpot VM Options are available at:- https://www.oracle.com/technetwork/java/javase/tech/vmoptions-jsp-140102.html
- https://docs.oracle.com/javase/8/docs/technotes/tools/unix/java.html
- https://docs.oracle.com/javase/8/docs/technotes/tools/windows/java.html
Big difference between Agile and Microservices
Big difference between Agile and Microservices (... as a joke)
Any differences or similarities between Agile and Microservices?
AGILE = a recipe of how to make order out from the mess, so that it can be cleaned and cleaned up by itself forever :-)
MICROSERVICES =
a recipe of how to make a mess from the order, so that it controls itself, monitors itself, repairs itself and can grow infinitely without losing the expected functionality :-)
Sunday, February 10, 2019
Converting Properties Files to Escaped Unicode
Converting Properties Files to Escaped Unicode
Using Unicode characters in Java with properties files is somethimes problematic, when we want to show signs and symbols that are not ASCII characters...
Converting Properties Files to Escaped Unicode is a must!
when we have problem with displaying especial signs:
So we want to send u-escaped Unicode, using \uXXXX.
As not only Java, but also JavaScript/JSON knows this convention, we only need this u-escaping in java on the server.
Solution:
- https://stackoverflow.com/questions/38990131/reading-unicode-characters-from-properties-file-java
- https://docs.oracle.com/cd/E23095_01/Platform.93/ATGProgGuide/html/s1816convertingpropertiesfilestoescap01.html
- http://www.cs.technion.ac.il/~imaman/programs/unicodeprops.html
Symbols, icons, "visual thinking" signs and letters:
- https://en.wikipedia.org/wiki/List_of_Unicode_characters
- https://www.compart.com/en/unicode/
- https://unicode-table.com/en/#latin-extended-a
- https://www.fileformat.info/info/unicode/category/So/list.htm
- http://xahlee.info/comp/unicode_sex_symbols.html
- https://www.toptal.com/designers/htmlarrows/symbols/
- https://tutorialzine.com/2014/12/you-dont-need-icons-here-are-100-unicode-symbols-that-you-can-use
Pushing on Github and Credentials and 403 error
Pushing on Github and Credentials and 403 error
Sometimes when we can work on Github with more than one account, we can obtain an error 403!!git push (...)
remote: Permission to (...) denied to (...)
fatal: unable to access (...) The requested URL returned error: 403
The error is that our computer has saved a git username and password for Github in Windows Credentials, so if we shift to another account the error 403 will appear.
Below is the solution:
Control panel > user accounts > credential manager > Windows credentials > Generic credentials
(IN POLISH: Panel sterowania\Konta użytkowników i Filtr rodzinny\Menedżer poświadczeń)
Next remove the Github keys and log in again.
Wednesday, February 6, 2019
OWASP TOP 10
OWASP TOP 10
As we can read at https://www.owasp.org/index.php/Category:OWASP_Top_Ten_Project
and https://blog.sucuri.net/2018/10/owasp-top-10-security-risks-part-i.html the Top 10 OWASP security vulnerabilities are:
As we can read at https://www.owasp.org/index.php/Category:OWASP_Top_Ten_Project
and https://blog.sucuri.net/2018/10/owasp-top-10-security-risks-part-i.html the Top 10 OWASP security vulnerabilities are:
- Injection
- Broken Authentication
- Sensitive data exposure.
- XML External Entities (XXE)
- Broken Access control.
- Security misconfigurations.
- Cross Site Scripting (XSS)
- Insecure Deserialization.
- Using Components with known vulnerabilities.
- Insufficient logging and monitoring.
Tuesday, February 5, 2019
NETFLIX
NETFLIX
As we can read at http://spring.io/projects/spring-cloud-netflix and https://netflix.github.io/ do You know that Spring Cloud Netflix provides Netflix OSS integrations for Spring Boot apps through autoconfiguration and binding to the Spring Environment and other Spring programming model idioms?
@EnableEurekaClient
With a few simple annotations you can quickly enable and configure the common patterns inside your application and build large distributed systems with battle-tested Netflix components. The patterns provided include Service Discovery (Eureka), Circuit Breaker (Hystrix), Intelligent Routing (Zuul) and Client Side Load Balancing (Ribbon)..
@EnableEurekaClient
Spring Cloud Netflix features:
- Service Discovery: Eureka instances can be registered and clients can discover the instances using Spring-managed beans
- Service Discovery: an embedded Eureka server can be created with declarative Java configuration
- Circuit Breaker: Hystrix clients can be built with a simple annotation-driven method decorator
- Circuit Breaker: embedded Hystrix dashboard with declarative Java configuration
- Declarative REST Client: Feign creates a dynamic implementation of an interface decorated with JAX-RS or Spring MVC annotations
- Client Side Load Balancer: Ribbon
- External Configuration: a bridge from the Spring Environment to Archaius (enables native configuration of Netflix components using Spring Boot conventions)
- Router and Filter: automatic registration of Zuul filters, and a simple convention over configuration approach to reverse proxy creation
Very interesting information related to microservices and Netflix technologies:
and http://callistaenterprise.se/blogg/teknik/2015/05/20/blog-series-building-microservices/, http://callistaenterprise.se/blogg/teknik/2015/04/10/building-microservices-with-spring-cloud-and-netflix-oss-part-1/
Monday, February 4, 2019
Tribute to Wanda Rutkiewicz
Tribute to Wanda Rutkiewicz
Wanda Rutkiewicz was born on February 4, 1943 and known as the first woman to successfully climb K2 (Chhogori or Mount Godwin-Austen, at 8,611 metres / 28,251 ft above sea level). She was a Polish computer engineer and mountain climber.https://en.wikipedia.org/wiki/Wanda_Rutkiewicz
https://www.fakt.pl/sport/inne-sporty/wanda-rutkiewicz-25-lat-od-zaginiecia-himalaistki-tracila-bliskich/wwns0sl
Spring Boot example
Spring Boot example
application.properties:
# ===============================
# H2 CONSOLE
# ===============================
spring.h2.console.path=/h2
# To See H2 Console in Browser:
# http://localhost:8080/h2
# Enabling H2 Console
spring.h2.console.enabled=true
# ===============================
# DB
# ===============================
spring.datasource.url=jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=
# ===============================
# JPA / HIBERNATE
# ===============================
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.H2Dialect
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.hibernate.ddl-auto = update
spring.jpa.properties.hibernate.show_sql=false
spring.jpa.properties.hibernate.use_sql_comments=false
spring.jpa.properties.hibernate.format_sql=false
-------------------
package eu.microwebservices.awesomeappproject;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RestController;
@RestController
@SpringBootApplication
public class AwesomeApp {
public static void main(String[] args) {
SpringApplication.run(AwesomeApp.class, args);
}
}
package eu.microwebservices.awesomeappproject.model;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
@Entity
@Table(name = "tab_user")
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
/**
* Sorry but, there is no validation here with email!
* It is not secure because of no validation from user input! See https://www.owasp.org
* It is only for educational purposes...
*/
@NotNull
private String email;
/**
* This is a name generally, which could be the nickname or the firstname,
* but if the user prefer it could be last name...
* There is no validation here!
* It is only for educational purposes...
*/
@NotNull
private String name;
public User() {
}
public User(Long id) {
this.id = id;
}
public User(String email, String name) {
this.email = email;
this.name = name;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
@Override
public String toString() {
return "User{" +
"id=" + id +
", name='" + name + '\'' +
", email=" + email +
'}';
}
}
package eu.microwebservices.awesomeappproject.model;
import org.springframework.data.repository.*;
import org.springframework.transaction.annotation.*;
@Transactional
public interface UserDao extends CrudRepository
/**
* This method will find an User instance in the database by its email.
* Note that this method is not implemented and its working code will be
* automagically generated from its signature by Spring Data JPA.
*/
public User findByEmail(String email);
/**
* This method will find an User instance in the database by its name.
* Note that this method is not implemented and its working code will be
* automagically generated from its signature by Spring Data JPA.
*/
public User findByName(String name);
}
package eu.microwebservices.awesomeappproject.controller;
import eu.microwebservices.awesomeappproject.model.User;
import eu.microwebservices.awesomeappproject.model.UserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class UserController {
/**
* HOW TO TEST:
* $ mvn spring-boot:run
* http://localhost:8080/
* Use the following urls:
* /create-user?email=[email]&name=[name]: create a new user with an auto-generated id and email and name as passed values.
* /delete-user?id=[id]: delete the user with the passed id.
* /get-user-by-email?email=[email]: retrieve the id for the user with the passed email address.
* /update-user?id=[id]&email=[email]&name=[name]: update the email and the name for the user indentified by the passed id.
*/
@Autowired
private UserDao userDao;
/**
* /create-user --> Create a new user and save it in the database.
* It is not secure operation here! There is no validation here! See https://www.owasp.org
* It is only for REST educational purposes...
*
* @param email User's email
* @param name User's name
* @return A string describing if the user is successfully created or not.
*/
@RequestMapping("/create-user")
@ResponseBody
public String create(String email, String name) {
User user = null;
try {
user = new User(email, name);
userDao.save(user);
}
catch (Exception ex) {
return "Error while creating the user: " + ex.toString();
}
return "User created succesfully!! (id = " + user.getId() + ")";
}
/**
* /delete-user --> Delete the user having the passed id.
* It is not secure operation here! There is no validation here!
* It is only for REST educational purposes...
*
* @param id The id of the user to delete
* @return A string describing if the user is successfully deleted or not.
*/
@RequestMapping("/delete-user")
@ResponseBody
public String delete(Long id) {
try {
User user = new User(id);
userDao.delete(user);
}
catch (Exception ex) {
return "Error while deleting the user: " + ex.toString();
}
return "User deleted successfully!!";
}
/**
* /get-user-by-email --> Return the id for the user having the passed email.
* It is not secure operation here! There is no validation here!
* It is only for REST educational purposes...
*
* @param email The email to search in the database.
* @return The user id or a message error if the user is not found.
*/
@RequestMapping("/get-user-by-email")
@ResponseBody
public String getByEmail(String email) {
Long userId;
try {
User user = userDao.findByEmail(email);
if (user != null) {
userId = user.getId();
} else {
return "User not found!!";
}
}
catch (Exception ex) {
return "User not found!!";
}
return "The user is found, and id is: " + userId;
}
/**
* /update-user --> Update the email and the name for the user in the database
* having the passed id.
* It is not secure operation here! There is no validation here!
* It is only for REST educational purposes...
*
* @param id The id for the user to update.
* @param email The new email.
* @param name The new name.
* @return A string describing if the user is successfully updated or not.
*/
@RequestMapping("/update-user")
@ResponseBody
public String updateUser(long id, String email, String name) {
try {
User user = userDao.findOne(id);
user.setEmail(email);
user.setName(name);
userDao.save(user);
}
catch (Exception ex) {
return "Error while updating the user: " + ex.toString();
}
return "User updated successfully!!";
}
}
pom.xml:
Subscribe to:
Posts (Atom)