dilluns, 1 de gener del 2018

RAD in java


Some tools to rapidly create a java/groovy application  or RAD applications 

Jeddict

Grails

Spring Roo

JHipster

dissabte, 9 de desembre del 2017


Configuration of the CentOS 7 to be accesible the deamon from outside

Stop Docker

[root@localhost jordi]# systemctl stop docker

[root@localhost jordi]# cat /lib/systemd/system/docker.service

look at the

ExecStart=/usr/bin/dockerd

It is risky touch direcly the file direcly there is a edit utility in linux services

systemctl edit docker

[Service]
ExecStart=
 ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock

 finally start docker

[root@localhost jordi]# systemctl start docker
[root@localhost jordi]# systemctl restart docker
[root@localhost jordi]# curl http://localhost:2375 {"message":"page not found"}
[root@localhost jordi]# docker run ubuntu echo "helo world" helo world


Remember set up the firewall, A rapid to way this issue around is disable it

[root@localhost jordi]# systemctl disable firewalld

dimecres, 6 de desembre del 2017

Tomcat embed with anotated Servlet

Recently I have playing in with the Tomcat embed version. Currently Spring Boot gives a fancy, easy and rapid creation of the Main class invoking a instanting a Tomcat server. However there is a lack of official information that it makes me doubt about of readiness for production. I belive that the classic war and deployment it is going to be safer in the future and it of course much more portable . But an embeded version can have a futture for testin. I will chose war solution for cloud PaaS envirotments or container solutions such us Cloud Foundry unless Apache will decide to publich formal and clear documentation. Spring give us a OSGI version which wrap tomcat, this seeems be valid for production but Spring is Spring and I personally hate it because they reinvent the heel constantly, I lke JEE a littel bit more but my feeling is that you will never be safe either Spring nor JEE.

It is my intention to do the same test but in a JEE cointainer like Payara or Payara-micro which give us much better documentation.

Having said that. Here is the issues or poblems that I found. My goal was instanciate a Tomcat with a anotated Servlet with no web.xml and no adding explicti Servlet at all. Remember Servlet 3.0 support is a must and tomcat +7 is necessary.

I built the solution using gradle but only with java plugin, the first issue was find out the exacly dependences.

The dependeces list are in the build.gradle but is intersted notice that not all the tomcat versions worked. Also be carefull in that you maven or gradle include the anotations solution for Tomcat otherwise you can face issues.


    compile  "org.apache.tomcat:tomcat-catalina:$tomcatVersion"
    compile  "org.apache.tomcat:tomcat-util:$tomcatVersion"
    compile  "org.apache.tomcat:tomcat-jasper:$tomcatVersion"
    compile  "org.apache.tomcat:tomcat-jasper-el:$tomcatVersion" 
    compile  "org.apache.tomcat:tomcat-jsp-api:$tomcatVersion"
    compile  "org.apache.tomcat.embed:tomcat-embed-core:$tomcatVersion"
    compile  "org.apache.tomcat.embed:tomcat-embed-logging-juli:$tomcatVersion"
    compile  "org.apache.tomcat.embed:tomcat-embed-jasper:$tomcatVersion"

To be the Servlet reconzied your tomcat classpath must have the class but also the context must have the access to the servlet.class file. The easy and standart way to achieve this is include the class inside of jar file and execute it using java -jar my.jar along with all the dependences uncompress in the same jar file.

To achieve this in gradle I used the shadow gradle plugin, in Maven you can achieve the same with the maven-assembly-plugin

to run the sample the sources are in  https://github.com/jordiesc/java/tree/master/embedtomcat/JavaTomcatEmbed

$ gradle build shadowJar
$ cd build/libs
$ java -jar GroovyTomcatEmbed-all.jar

https://github.com/jordiesc/java/tree/master/embedtomcat/GroovyTomcatEmbed

Moreover you will see two versions of the project. they are almost identical apart form some details. The most important is the groovy incompatibility with Java annotations. where you must to turn curly bracktest {} into [] otherwishe the compiler will interpret a Groovy Clousre

The Java way

@WebServlet(
    name = "dataServlet",
    urlPatterns = {"/datajava"}
)

The Groovy way

@WebServlet(
    name = "dataServlet",
    urlPatterns = ["/datagroovy"]
)

just run http://localhost:8080/datajava or http://localhost:8080/datagroovy

diumenge, 12 de novembre del 2017

CSS POSITON.

STATIC. es el posicionamiento por defecto del navegador poniendo los elementos segun aparecen en el html, dom. es como si no hubiera posicionamiento. si se pone static el navegador no hace caso de los left,right,top, botton.

RELATIVE el navegador conserva el espacio que habia despues de moverlo. los porcentages solo funcionan si esta el heigh del padre. Es inportante saber que el espacio dejado despues de desplazarse continuara reservado
ABSOLUTE. los elemenos se posicionan en base a su inmediato padre , posicionado, o sea que tiene posiciones relative,absolute o fixed. El espacio no es reservado.
El ancho de un elemento absolute depende de su contenido.

FIXED. como absoluta no reserva la posicion, se ajusta al contenido las cordenatdas se calculan segun el navegador o ventana asi que  nunca se escrolla. los elementos fixed quedan fijos pero se salen del flujo de colocacion.

Posicionamiento por ejes

Siempre son posiciones desplazadas desde el margen hacia adentro. Por ejemplo top 2px moviera el elemento desde el top hacia el centro o sea hacia abajo

Solo puede haber un posicionamiento vertical y uno horizonal, css solo toma uno si hay varios.

Horizontal left, right
Vertical -> top, botton

3 dimension- z-index

MARGIN collapse.

Los top and bootion margin colapsan. con elementos posicionados absoluto no colapsan https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Box_Model/Mastering_margin_collapsing

dilluns, 6 de novembre del 2017


Groovy con Gradle

Hay una manera facil de ejecutar Groovy scripts sin llegar a instalar Groovy si se tiee Gradle

$ gradle init

Genera un proyecto gradle. El fichero build.gradle

task inicio{}

println "hola mundo"
h

con el comando gradle inicio. se vera la siguiente salida

$ gradle inicio
hola mundo
:inicio UP-TO-DATE

BUILD SUCCESSFUL in 1s


task inicio{}

def lista = ["uno","dos",3]

lista.forEach {
println it
}
produce

$ gradle inicio
uno
dis
3
:inicio UP-TO-DATE

BUILD SUCCESSFUL in 1s

divendres, 1 de setembre del 2017


Los webcomponents son la base de los ultimos frameworks aparecidos como Angular 2 o 4, Polymer, Aurelia, X-tag e incluso React tiene una aire.

Todos hacen lo mismo encapsulan html modularmente y bindean objetos de datos.

Vanilla ES6 permite escribir web compoents NATIVOS, esto quiere decir mas rapidos en ejecucion y mas entendibles pq no hay magia. Por contra habra que hacer un poquito mas de codigo para el binding de datos pero con ES6 las arrows y typescript tampoco es que sea muy dificil.

Como son NATIVOS se pueden incorporar en todos los frameworks, y como son NATIVOS van a durar mucho mas que no los frameworks q tienen un ciclo de vida de 2 añitos.Y nos olvidaremos de migraciones

Para los navegadores que no soportan WC nativos ya hay polyfills. Es mas todos los frameworks anteriores o incorporan el mismo polyfill o lo has de poner.

La especificación de webcomponents y en concreto los Custom Elements se puede ver en los enlaces de abajo

https://html.spec.whatwg.org/multipage/custom-elements.html#custom-elementss

y un fantastico enlace en castellano

https://developers.google.com/web/fundamentals/getting-started/primers/customelements

Los custom elements llevan el gion normalmentepor ejemplo <my-app></my-app>. Eso es parte de la especificacion.

Lo basico es crear una clase que extienda de HtmlElement o del element que sea HtmlButton... y implementar algunas de las funciones para interctuar con el DOM.

Para poner atributtos en el htmlelement se deben de declarar con get y set.

get attributename()
set attributename()

Si ademas queremos que esos atribures notifiquen a nuestra clase cuando se cambian hay que declarar el array

static get observableattributes y despues el metodo attributeChangedCallback

Mi personal test con custom elelments v1 que incluye dos custom tags y con sus porpios eventos

https://github.com/jordiesc/webcomponents

dilluns, 28 d’agost del 2017

Typescript basic setup for webcomponents


Install globally TypeScript with
npm install -g typescript

create tsconfig

/customElements/typedelement $ tsc -init
message TS6071: Successfully created a tsconfig.json file.

Edit the tsconfig.json in the compile section set.

  "compilerOptions": {
    /* Basic Options */
    "target": "ES2015",

to develop and automatically compile tsc -w it will create a foo.js from each foo.ts.

Enjoy!!!