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.

JConsole provides information on performance and resource consumption of applications running on the Java platform and it comes as part of Java Development Kit (JDK).

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://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:


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:




Symbols, icons, "visual thinking" signs and letters:



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:

  1. Injection
  2. Broken Authentication
  3. Sensitive data exposure.
  4. XML External Entities (XXE)
  5. Broken Access control.
  6. Security misconfigurations.
  7. Cross Site Scripting (XSS)
  8. Insecure Deserialization.
  9. Using Components with known vulnerabilities.
  10. Insufficient logging and monitoring.