JNDI lookup Wildfly and Spring

A quick reference to load JNDI resource from Wildfly application server. Let’s do this with java api and spring.

Adding JNDI resources to wildfly

First, edit standalone/configuration/standalone.xml and add this lines into subsystem.

<subsystem xmlns="urn:jboss:domain:naming:2.0">
    <bindings>
        <simple name="java:global/MyString" value="MyValue"/>
        <simple name="java:global/MyNumber" value="100" type="int"/>
    </bindings>
</subsystem>

Seguir leyendo

Spring and JPA with two data sources (with annotations)

A few days I received a comment from my friend @sock_osg (you can follow on twitter) he recommends me to rewrite my previous post with annotations.

And well here is it. But the are more few things to comment about it, for example in the previous post there are not a Transactional capabilities between DB’s because I’m not using JTA transaction type.

Now for this example I write the code to support transactions between multiple data bases with different data sources, like I read on stack overflow:

if you find yourself with multiple entity managers, with corresponding tx managers, then you should consider using a single JtaTransactionManager instead. The entity managers should be able to participate in JTA transactions, and this will give you full transactionality across both entity managers, without having to worry about which entity manager you’re in at any one time.

You can download all code here, it’s hosted on my Github account, pull the code from the branch named «annotations».

Let’s review the most important files, first the DAO classes: Seguir leyendo

Spring and JPA with two data sources

JPA it’s the most used standard in java to manage the persistence and I ever want to write about this topic.

In this entry I want to share how configure a java project to use JPA with spring with two data sources, you can view all source of this project on my github repository.

Most of the configuration is in spring, in the application context you need declare:

  • 2 Data Sources
  • 2 Entity Manager Factories
  • 2 Transaction Manager

This is explained by self:

Seguir leyendo

EJB 3 Overview


Recientenmente he tenido que analizar un proyecto web que se encuentra divido en dos partes (backend y frontend), el entregable es un ear con un jar y un war.

Todo el backend esta constriudo con EJB’s y aunque siempre he escuchado pestes de esta tecnología nunca le he dado un vistazo. Así que comencé por leer algunos artículos y en realidad me parece que los EJB’s son una buena iniciativa en Java para simplificar el desarrollo y adoptar mejores prácticas. Particularmente me ha encantado este:

http://refcardz.dzone.com/refcardz/dependency-injection-in-ejb3 Seguir leyendo

OZ Ejemplo Cajero ATM

¿Que vamos a desarrollar?

Una aplicación que simule el funcionamiento de un cajero automático, mostrando el uso de múltiples frameworks Java para crear un sistema modular y extendible.

Requisitos

  • Apache Maven >= 3.X
  • Java JDK >=  1.6
  • Netbeans >= 6.5
  • Base de Datos MySQL

Análisis

Supongamos que tenemos el siguiente requerimiento por parte del cliente o del analista:

Crear un cajero que permita realizar dos operaciones, Retirar efectivo y hacer Transferencias a otro Banco.

Veamos como se vería en un diagrama de casos de uso:

El usuario unicamente va a realizar dos operaciones retiro y transferencia.

Bien ahora la base de datos, vamos a utilizar este script para generarla.  Ejecutas el archivo en tu gestor favorito y te  creará el esquema llamado OZ_TEST, con las siguiente tablas:

Seguir leyendo

Spring Security, problemas con proxy Apache

He participado en un desarrollo web donde me ha tocado configurar un proxy con el servidor apache (mis últimos artículos han sido sobre este tema), la idea es exponer una aplicación web en Java por medio de un proxy con Apache.

Tengo una aplicación Java que utiliza Spring Security y todo funciona de maravilla cuando entras a la página web, sin embargo al colocar el proxy frente a este servidor Spring Security puede provocar algunos problemas:

Problema 1: Login, Authentication method not supported: GET

A la fecha no entiendo como puede ser esto posible, dentro del form está estrictamente definido que los datos se envían por POST y no por GET:

Este es el formulario: Seguir leyendo