Monday, September 21, 2020

Preparing Pivotal Spring Certification

I have bought "Core Spring 5 Certification in Detail" By: Ivan Krizsan on Kobo, only 5 USD and it's quite good. 

Previously I have tried the book by Iuliana Cosmina, but it's too verbose for my taste, I get lost in words, I like only very succinct statement with code samples where needed. Especially I hate "sample applications" developed for the sake of demonstrating the framework... normally they turn into overcomplicated examples where the same patterns are applied "ad nauseam".





Sunday, September 20, 2020

Viewing Spring transaction information

enable these flags: 

logging.level.org.springframework.orm.jpa=TRACE

logging.level.org.springframework.transaction=TRACE

 

 and you will see this in the logs: 

 

2020-09-20 18:40:00.788 DEBUG 4904 --- [ restartedMain] o.s.orm.jpa.JpaTransactionManager : Opened new EntityManager [SessionImpl(239595802<open>)] for JPA transaction 

2020-09-20 18:40:00.794 DEBUG 4904 --- [ restartedMain] o.s.orm.jpa.JpaTransactionManager : Exposing JPA transaction as JDBC [org.springframework.orm.jpa.vendor.HibernateJpaDialect$HibernateConnectionHandle@12096038] 

2020-09-20 18:40:00.805 DEBUG 4904 --- [ restartedMain] o.s.orm.jpa.JpaTransactionManager : Found thread-bound EntityManager [SessionImpl(239595802<open>)] for JPA transaction 

2020-09-20 18:40:00.805 DEBUG 4904 --- [ restartedMain] o.s.orm.jpa.JpaTransactionManager : Participating in existing transaction 

2020-09-20 18:40:00.834 DEBUG 4904 --- [ restartedMain] o.s.orm.jpa.JpaTransactionManager : Initiating transaction commit 2020-09-20 18:40:00.839 DEBUG 4904 --- [ restartedMain] o.s.orm.jpa.JpaTransactionManager : Committing JPA transaction on EntityManager [SessionImpl(239595802<open>)] 

2020-09-20 18:40:00.856 DEBUG 4904 --- [ restartedMain] o.s.orm.jpa.JpaTransactionManager : Closing JPA EntityManager [SessionImpl(239595802<open>)] after transaction 

 plus a lot of TRACE information equally useful (omitted here)

Demo code is available here https://github.com/vernetto/txdemo



Monday, August 10, 2020

Cookies sharing in Spring boot applications

    @GetMapping("/greeting")
    public String greeting(HttpSession session, HttpServletRequest request, HttpServletResponse response, @RequestParam(name="name", required=false, defaultValue="World") String name, Model model) {
        model.addAttribute("name", name);
        System.out.println(session);
        System.out.println(request);
        for (Cookie cookie : request.getCookies()) {
            System.out.println(cookie.getName() + " " + cookie.getValue());
        }
        Cookie uiColorCookie = new Cookie("color2", "red2");
        uiColorCookie.setDomain("localhost");
        uiColorCookie.setPath("/");
        response.addCookie(uiColorCookie);
        return "greeting";
    }

the code of the 2 applications is: 

https://github.com/vernetto/demosession01 

https://github.com/vernetto/demosession02 

http://localhost:8181/books01/greeting?name=pirla 

http://localhost:8282/books02/greeting?name=pirla 

In Firefox, use F12 and "storage" to examine cookies. 

Using embedded Tomcat, the session turns out to be:

org.apache.catalina.session.StandardSessionFacade https://tomcat.apache.org/tomcat-7.0-doc/api/org/apache/catalina/session/StandardSessionFacade.html



Sunday, June 21, 2020

Oracle monitoring session


https://orahow.com/find-long-running-queries-in-oracle/

http://www.dba-oracle.com/t_find_long_running_sql_queries.htm

WITH blocked_resources AS (select id1 ,id2 ,SUM(ctime) as blocked_secs ,COUNT(1) as blocked_count ,type from v$lock where request > 0 group by type,id1,id2 ) ,blockers AS (select L.id1, L.id2, L.type, L.sid ,BR.blocked_secs ,BR.blocked_count from v$lock L ,blocked_resources BR where BR.type = L.type and BR.id1 = L.id1 and BR.id2 = L.id2 and L.lmode > 0 and L.block <> 0 ) select /*+ MERGE(@"SEL$22") MERGE(@"SEL$109DB78D") MERGE(@"SEL$5") MERGE(@"SEL$38") MERGE(@"SEL$470E2127") MERGE(@"SEL$7286615E") MERGE(@"SEL$62725911") MERGE(@"SEL$2EC965E0") MERGE(@"SEL$C8360722") MERGE(@"SEL$874CA85A") MERGE(@"SEL$74A24351") MERGE(@"SEL$71D7A081") MERGE(@"SEL$7") MERGE(@"SEL$24") CARDINALITY(@"SEL$AF73C875" "S"@"SEL$4" 1000) CARDINALITY(@"SEL$AF73C875" "R"@"SEL$4" 1000) */ B.id1||'_'||B.id2||'_'||S.sid||'_'||S.serial# as id ,'SID,SERIAL:'||S.sid||','||S.serial#||',LOCK_TYPE:'||B.type||',PROGRAM:'||S.program||',MODULE:'||S.module||',ACTION:'||S.action||',MACHINE:'||S.machine||',OSUSER:'||S.osuser||',USERNAME:'||S.username as info ,B.blocked_secs ,B.blocked_count from v$session S ,blockers B where B.sid = S.sid;


Recommended the use of TOAD for DBA (Database browser)

Saturday, May 23, 2020

Automating Keyboard and Mouse in Java


package org.pierre.robot;

import java.awt.*;
import java.awt.event.KeyEvent;

public class RobotSnapshot {
    public static void main(String[] args) throws AWTException {
        Robot robot = new Robot();
        for (int i = 0; i < 2000; i++) {
            robot.delay(2000);
            robot.keyPress(KeyEvent.VK_RIGHT);
            robot.keyRelease(KeyEvent.VK_RIGHT);
            robot.delay(2000);
            robot.keyPress(KeyEvent.VK_PRINTSCREEN);
            robot.keyRelease(KeyEvent.VK_PRINTSCREEN);
        }
    }
}




Sunday, April 26, 2020

dcevm

https://github.com/dcevm/dcevm

https://github.com/TravaOpenJDK/trava-jdk-11-dcevm/releases

I down load and extract the JDK 11 with dcevm hotswap agent, and I configure it as JDK in Intellij (Project Structure):

When I run my application, it's using:

D:\pierre\Java\dcevm-11.0.6+1\bin\java.exe


HOTSWAP AGENT: 21:08:29.718 INFO (org.hotswap.agent.HotswapAgent) - Loading Hotswap agent {1.4.0} - unlimited runtime class redefinition.
HOTSWAP AGENT: 21:08:30.048 INFO (org.hotswap.agent.config.PluginRegistry) - Discovered plugins: [JdkPlugin, Hotswapper, WatchResources, ClassInitPlugin, AnonymousClassPatch, Hibernate, Hibernate3JPA, Hibernate3, Spring, Jersey1, Jersey2, Jetty, Tomcat, ZK, Logback, Log4j2, MyFaces, Mojarra, Omnifaces, ELResolver, WildFlyELResolver, OsgiEquinox, Owb, Proxy, WebObjects, Weld, JBossModules, ResteasyRegistry, Deltaspike, GlassFish, Vaadin, Wicket, CxfJAXRS, FreeMarker, Undertow, MyBatis]
Starting HotswapAgent 'D:\pierre\Java\dcevm-11.0.6+1\lib\hotswap\hotswap-agent.jar'






Spring Boot Web Security

Jetbrains excellent introduction here https://www.youtube.com/playlist?list=PLqq-6Pq4lTTYTEooakHchTGglSvkZAjnE

Intro here https://spring.io/guides/gs/securing-web/

My demo code here https://github.com/vernetto/sbwebsecurity



Saturday, March 21, 2020

Aspects to log enter and exit method

https://github.com/vernetto/logaspect

The idea is:

use @EnableAspectJAutoProxy in a @Configuration

create an annotation EntryExitLogger to mark the method(s) you want to be logged for entry/exit

have a @Component annotated with @Aspect and inside it you specify the aspects:

@Around("@annotation(EntryExitLogger)")
public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable{
}


That's all.

Detailed post on the topic https://medium.com/@wkrzywiec/moving-into-next-level-in-user-log-events-with-spring-aop-3b4435892f16

Doc of AspectJ here https://docs.spring.io/spring/docs/2.0.x/reference/aop.html

Good Aspectj cookbock here https://blog.espenberntsen.net/2010/03/20/aspectj-cheat-sheet/

Wednesday, February 19, 2020

github and line separators

https://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration#_formatting_and_whitespace " You can tell Git to convert CRLF to LF on commit but not the other way around by setting core.autocrlf to input:

$ git config --global core.autocrlf input "



https://www.jetbrains.com/help/idea/configuring-line-endings-and-line-separators.html this one also helps



Per-repository settings

Optionally, you can configure a .gitattributes file to manage how Git reads line endings in a specific repository. When you commit this file to a repository, it overrides the core.autocrlf setting for all repository contributors. This ensures consistent behavior for all users, regardless of their Git settings and environment.


in Intellij there is an "Inconsistent line separators inspection", to check if the files have "line terminator" different from the default setup for the project
"This inspection detects files with line separators different from the project default. E.g. you set the line separator to "\n" in the Settings|Code Style|Line separator, and the file you are editing uses '\r\n' as a line separator"





Thursday, February 13, 2020

Spring Integration

https://youtu.be/oQ2CBtYrSYo?list=PLO0KWyajXMh6HbVTnf7YqwbEeZU6kuKJa nice tutorial here

code is available at https://github.com/vernetto/sidemo.git



Sunday, February 9, 2020

Activiti BPM

Activiti is related to Alfresco.


https://en.wikipedia.org/wiki/Activiti_(software) wikipedia

https://www.activiti.org/userguide/index.html here the userguide


https://youtu.be/UTl9LJ_Ob98 here excellent Activiti BPM presentation based on Eclipse


The Intellij Activiti BPM plugin doesn't seem to work any more (last update 2014)

Activiti gitub is here https://github.com/Activiti/Activiti




Friday, January 3, 2020

Lasse Koskela, Effective Unit Testing

https://www.manning.com/books/effective-unit-testing


I am really enjoying this book, the Author reflects about the STRATEGIC importance of well written Unit Tests as a way to DRIVE development.

It focuses also on the importance of writing SIMPLE CODE and avoid unnecessary complication:

"One of the worst offenders of code quality and a major contributor to
developers’ productivity crawling to a halt is accidental complexity.
Accidental complexity is unnecessary complexity. It’s complexity that could
be avoided by substituting a simpler design that still meets the requirements. Sometimes
we programmers like to demonstrate our mental capacity by producing such
complex designs that we have trouble understanding them ourselves. I will bet you
recognize that primal instinct in yourself, too. The problem with complex designs is
that complexity kills productivity and unnecessary complexity is, well, unnecessary
and counterproductive."