At XPWeek2011 we learned TDD coding, and the importance of OOP principles to develop applications. I spent great days there, thanks to Carlos Ble and iExpertos.

Continuing with the last kata series. I will show you how I solved FizzBuzz kata, maybe not the best, but I like the solution because the expressive final code:

  • say(FIZZ, WHEN_FIZZ_FACTOR);
  • say(BUZZ, WHEN_BUZZ_FACTOR);
  • elseSayNumber();

Here you have KataFizzBuzz

Here you have the code: fizzbuzz.zip

And here you have the video:

In a previous project we saw how to create a Weblogic basic web project. Based on this we will create a very basic view with JSF.

JSF has some advantages:

  • Clean Cross browsing: we can forget styles and javascript, and navigator sigularities.
  • Encapsulates the view components
  • It is XML, then is text, then is always editable.
  • Standards based = XHTML + JavaScript + JSP + Java (JEE5+)
  • Some libraries (oracle-ADF, richfaces, icefaces) allow Rich Inernet Applications development.

Continue reading

Veíamos en un post anterior como crear un proyecto básico para Weblogic. A partir de este vamos a crear una vista muy básica con JSF.

JSF tiene varias ventajas:

  • Cross browsing limpio: nos permite abstraernos de javascript y los estilos, y las peculiaridades de cada navegador
  • Encapsula en componentes la vista
  • Es xml de forma que es editable siempre
  • Basado en estándares = XHTML + JavaScript + JSP + Java (JEE5+)
  • Algunas librerías (oracle-ADF, richfaces, icefaces) permiten el desarrollo de Rich Inernet Applications

Continue reading

Today we will create a SOAP Web Service, based on LebrijoSchool project which we were making in early weeks over Oracle-Weblogic Architechture.

First of all is to add the Web Services facet. Right button > Properties … :

Add WS facet

After, we will create the class from a Spring Service class. Right button > New > WebLogic Web Service for Spring Beans:

Expose Spring as a WS

Choose the Service, and the methods that we want to publish as Web Service.

Finally put it in the logical package: lebrijo.school.webservices. And name it as “SchoolCertificatesWS”.

This is the code:

	@Autowired
	@Qualifier("RegistryService")
	private IRegistryService springServ;
 
	@WebMethod
	public Registry findRegistryById(java.lang.String id) throws Exception {
		return springServ.findRegistryById( id );
	}

We have a Weblogic client to test the WS, we can acces thru the URL http://localhost:7001/wls_utc/.

Hoy crearemos un servicio web SOAP, basándonos en el proyecto LebrijoSchool que hemos venido haciendo sobre la arquitectura Oracle-Weblogic en artículos anteriores.

Lo primero es añadir el facet de Web Services. Botón derecho > Properties … :

Add WS facet

Después, creamos el WS a partir de una clase de servicio de Spring. Botón derecho > New > WebLogic Web Service for Spring Beans:

Expose Spring as a WS

Elegimos el servicio, y los métodos que queremos publicar publicar como WS.

Finalmente lo ponemos en el paquete adecuado: lebrijo.school.webservices. Y le damos un nombre “SchoolCertificatesWS”.

Nos queda un WS con este código:

	@Autowired
	@Qualifier("RegistryService")
	private IRegistryService springServ;
 
	@WebMethod
	public Registry findRegistryById(java.lang.String id) throws Exception {
		return springServ.findRegistryById( id );
	}

Para ver como funciona en WS tenemos un cliente en Weblogic, al que podemos acceder a través de la URL http://localhost:7001/wls_utc/.

Hoy vamos a crear un WS que diga Hola sobre Weblogic con su ditribución de Eclipse OEPE.
Creamos Nuevo proyecto > Web Service Project:

Create project

Hemos creado la siguiente clase:

package services;import javax.jws.*;
@WebService
public class Hello {
@WebMethod
    public String sayHello(String name) {
        return "Hello, "+name+".";
    }
}

Con estas dos anotaciones podemos servir el WS, con botón derecho sobre la clases y Run as > Run on Server. Con esto aparece la interfaz de test en el navegador del WS:

WS Test

Para acceder al WSDL: http://localhost:7001/wsc/HelloService?WSDL
Para hacer test de cualquier WSDL publicado: http://localhost:7001/wls_utc/begin.do

Today we are going to see ho to create a WS which says Hello over Weblogic, with its IDE Eclipse OEPE.
We will create a New project > Web Service Project:

Create project

We created teh following class:

package services;import javax.jws.*;
@WebService
public class Hello {
@WebMethod
    public String sayHello(String name) {
        return "Hello, "+name+".";
    }
}

With these annotations we can serve the WS, and with right button on the classes and Run as > Run on Server. It launches the test WS application in the navigator:

WS Test

To access to WSDL: http://localhost:7001/wsc/HelloService?WSDL
To test every WSDL published: http://localhost:7001/wls_utc/begin.do

Voy a ver como instalar el plugin de GAE en mi Eclipse, y a hacer y subir mi primera aplicación sencilla para ver como gestiona el ciclo de vida básico de las aplicaciones dicho plugin.

Nos basaremos en el paquete Eclipse Galileo R2 para JEE projects de 64 bits. Y en el Google Plugin for Eclipse, que soporta las tecnologías GWT y GAE, en su versión para Galileo.

Instalar Eclipse es inmediato, se descarga y se descomprime en la carpeta que gustemos. Luego lo ejecutamos.

Para instalar el plugin de Google, Help > Install New Software … > Add, añadimos la url  Google Plugin for Eclipse for Galileo. E instalamos el plugin y las dos SDK.

Creamos la aplicación Web File > New > Web Application Project:

Creating project

Para probarla en modo local, en el menú conextual Debug As > Web Application. Así vemos como se debuguea la aplicación con el debuger de Eclipse de forma normal.

Para desplegarla en el servidor tenemos que tener cuenta en https://appengine.google.com,  y crear un ID (pe: firstapp-lebrijo). Este lo introduciremos a través del menú contextual Google > App Engine Settings… De esta forma Eclipse sabrá donde desplegarla cuando hagamos Google > Deploy to App Engine.

Tengo mi primera aplicación en: http://firstapp-lebrijo.appspot.com/

My First GAE App

Here we are going to see how to install GAE plug-in in Eclipse, and to make and deploy my first basic application, in order to see how to manage the life deployment cycle this plug-in.

We will base in the Eclipse Galileo R2 for JEE projects on 64 bits package. And Google Plugin for Eclipse, which supports the GWT and GAE technologies, in Galileo version.

Eclipse installation is easy, download and unzip where you want. Then we execute it.

To install Google plug-in, Help > Install New Software … > Add, add the url Google Plugin for Eclipse for Galileo. And install Eclipse and both SDKs.

Create the application in Web File > New > Web Application Project:

Creating project

To test it in local mode, in the contextual menu choose Debug As > Web Application. Then we can how to debug an application with the usual eclipse debugger.

To deploy in the server we must enter in https://appengine.google.com, and create an ID (pe: firstapp-lebrijo). We configure it through the contextual menu Google > App Engine Settings… Then Eclipse knows where deploy it when we do Google > Deploy to App Engine.

I have my first application in: http://firstapp-lebrijo.appspot.com/

My First GAE App

Para implementar la capa de servicios y aprovechar su inyección de dependencias vamos a utilizar Spring.

Con Spring 2.5.6, que es la versión soportada por OEPE, para acomodar nuestro desarrollo.

Primero añadimos la Facet de Spring a nuestro proyecto. En el menu contextual del proyecto > Properties… :

Add Spring Facet

Luego generamos las clases ORM. Se generan con el menú contextual del proyecto > Spring > Generate Spring ORM Classes …

Creating new ORM Services

Como se observa, sobre las entidades JPA definidas en nuestro paquete de persistencia, se definen las clases de acceso y las de servicio. Os recomiendo echarle un buen vistazo a los paquetes lebrijo.school.services y lebrijo.school.dao.

Lo normal es que debamos limpiar estas clases de métodos, ya que genera todas las posibilidades (remove, persist, findById,…). Por ejemplo, si una entidad de nuestro modelo es una vista, no tendrá sentido mantener un DAO con los métodos persist y remove.

Aquí os dejo el zip del proyecto eclipse tras estas modificaciones.

In order to make the service layer and use the dependency injection we will take Spring.

Spring 2.5.6 is the OEPE default version supported.

First we will add the Spring Facet to our project. Right mouse button over the project > Properties… :

Add Spring Facet

After genertate the ORM classes. They will generate with contextual menu > Spring > Generate Spring ORM Classes …

Creating new ORM Services

You can see, about the JPA defined in our persistence package, it will create th access classes and services ones. I recommend you see the lebrijo.school.services and lebrijo.school.dao packages.

After we must clean this class of methods, the generator generates all possibilities (remove, persist, findById,…). For example, if one entity of our model is a view, we can destroy persist or remove methods.

Here I keep the zip eclipse project after these steps.

Veamos como implementar la persistencia en un proyecto de Eclipse con el estándar JPA implementado por EclipseLink.

Nos basaremos en el proyecto de Eclipse creado en el artículo anterior.  En las propiedades (botón derecho) del proyecto añadimos el “poder” de manejar Entidades JPA, añadiendo el Facet:

Adding JPA facet

Utilizaremos EclipseLink 1.1.2 ya que es la implementación de JPA por defecto en WebLogic 11g.

Generar Entidades desde las tablas

Sobre el proyecto en el menu contextual (botón derecho), JPA > Generate Entities from Tables… Elegimos la conexión SCHOOL creada anteriormente, y las tablas REGISTRY y SCHOOLCERTIFICATES. Generando las entidades en el paquete lebrijo.school.model:

Generating entities from tables

Para mantener la coherencia de JPA debemos añadir un Identificador a todas las clases, Registry lo tiene, pero a SchoolCertificates hay que añadírselo:

Add Identifier

Es muy interesante observar el fichero src/META-INF/persistence.xml, como se configura la conexión y se mapean las entidades.

<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="school" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
 	<class>lebrijo.school.model.Registry</class>
 
 	<class>lebrijo.school.model.Schoolcertificate</class>
		<properties>
			<property name="eclipselink.target-server" value="WebLogic_10"/>
			<property name="eclipselink.jdbc.driver" value="oracle.jdbc.OracleDriver"/>
			<property name="eclipselink.jdbc.url" value="jdbc:oracle:thin:@192.168.0.7:1521:xe"/>
			<property name="eclipselink.jdbc.user" value="school"/>
			<property name="eclipselink.jdbc.password" value="school"/>
			<property name="eclipselink.logging.level" value="FINEST"/>
		</properties>
 </persistence-unit>
</persistence>

Aquí os dejo el zip del proyecto eclipse tras estas modificaciones.

Today we will see how to make the persistence in a Eclipse project with EclipseLink JPA implementation.

We will base in the last post Eclipse project. In the project properties (right buton) we will add the power to manage JPA entities, adding the facet:

Adding JPA facet

We will ue EclipseLink 1.1.2, it is the JPA implementation by defect in WebLogic 11g.

Generating entities from tables

Over the project, in the contextual menu (right button), JPA > Generate Entities from Tables… We choose the conection SCHOOL, created in other posts, and tables REGISTRY and SCHOOLCERTIFICATES. Generating the entities in the package lebrijo.school.model:

Generating entities from tables

To maintain the JPA coherence we must add an Identifier on every classes, Registry has one, but we must add one to SchoolCertificates:

Add Identifier

You may see the file src/META-INF/persistence.xml, how it configures the connection and map the entities.

<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="school" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
 	<class>lebrijo.school.model.Registry</class>
 
 	<class>lebrijo.school.model.Schoolcertificate</class>
		<properties>
			<property name="eclipselink.target-server" value="WebLogic_10"/>
			<property name="eclipselink.jdbc.driver" value="oracle.jdbc.OracleDriver"/>
			<property name="eclipselink.jdbc.url" value="jdbc:oracle:thin:@192.168.0.7:1521:xe"/>
			<property name="eclipselink.jdbc.user" value="school"/>
			<property name="eclipselink.jdbc.password" value="school"/>
			<property name="eclipselink.logging.level" value="FINEST"/>
		</properties>
 </persistence-unit>
</persistence>

here I leaveth eclipse zip project after these steps.

There is a very basic choice for templating creation with JSP based on “includes. It could be useful to response quickly to a client, very little project, avoid to use heavy technologies, or we want to deploy our project on every application server.

The technique creates little JSP code chunks for header and footer. After create all pages from a template.

Continue reading

Existe una forma de crear plantillas muy básica con JSP a base de includes, que nos puede servir para salir del paso, para un proyecto muy pequeño, por que no queramos utilizar tecnologías más pesadas, o queramos desplegar nuestro proyecto en cualquier servidor de aplicaciones.

La técnica trata de crear pequeños trozos de código en JSP (jsf, tags,…) para cabecera y pie. Y luego crear todas las páginas del proyectos a partir de una plantila.

Continue reading

Eclipse has a project called EMF (Eclipse Modelling Framework) cool for drawing UML2 Diagrams. But my goal in this post is to draw UML2 class diagrams and create the java skeleton for the classes.

In the application architecture is recommended separate the domain model from services, business logic etc. EMF gives you the tool to create class diagrams and to generate the code with them.

Continue reading