En el próximo post vamos a hablar sobre el proyecto Spring Mobile deSpringsource. Este proyecto pretende facilitar la realización de aplicaciones web sobre dispositivos móviles utilizando los controladores de Spring MVC.
Archivo de la etiqueta: Spring
REST Web Services with Apache CXF and Spring
In the next two post we are gonna to talk about how develop REST web services with java. To that end we’re gonna use two different technologies, Apache CXF and Spring REST web services.
Continue reading it on Java4Developers
Groovy integration inside a Spring project
In this post we are going to talk a little bit about how to integrate Groovy (or another Scripting language like JRuby or BeanShell) within a Spring project. Achiving that is not really complicated, the only thing you need to do is add your Groovy scripts with a special schema within your application context. The example I am going to show you is uploaded to my Github account. You can find it right here.
And what are we going to do?. We are create a simple sample, based in the official Spring documentation you may find here or here too. We are going to write our Spring MVC controller, but thanks to Groovy we are going to be able to redefine our controller redirection with no need to compile our code again.
The example is pretty simple, imaging you have a controller related to a specified url (say home.htm). What we want is changing the page the controller eventually render. So we need to write our code using Groovy.
The application structure looks like as follows:

We have two controller classes:
- HomeController: It’s a java class that implements the Controller class imported from Spring MVC. The class itself do nothing, another Controller that we code in Groovy is injected within the class. This Groovy controller will be responsible to redirect the request. So we have to call its handleRequest method inside the handleRequest method of our HomeController.
package com.hopcroft.examples.controller; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.Controller; public class HelloController implements Controller { private Controller helloGroovyController; public Controller getHelloGroovyController() { return helloGroovyController; } public void setHelloGroovyController(Controller helloGroovyController) { this.helloGroovyController = helloGroovyController; } public ModelAndView handleRequest(HttpServletRequest arg0, HttpServletResponse arg1) throws Exception { return helloGroovyController.handleRequest(arg0, arg1); } } - HomeGroovyController: this Groovy class is code in Groovy and as we previously mentioned, do the redirect job. It seems like another Java class but we save it as a Groovy script/file.
package com.hopcroft.examples.controller; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.Controller; public class HelloGroovyController implements Controller { protected final Log logger = LogFactory.getLog(getClass()); public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { logger.info("Returning index view"); return new ModelAndView("index.jsp"); } }
Wiring the controller in the Spring context.
To define the controller within our context we need to use the tag. Take a look at the context definition below.
<pre class="brush: xml; gutter: true; first-line: 1"><?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:soap="http://cxf.apache.org/bindings/soap"
xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:lang="http://www.springframework.org/schema/lang"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
http://cxf.apache.org/bindings/soap http://cxf.apache.org/schemas/configuration/soap.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-2.0.xsd"
default-autowire="byName">
<lang:groovy id="helloGroovyController" script-source="classpath:groovy/HelloGroovyController.groovy"></lang:groovy>
<bean name="/helloGroovy.htm" id="controller" class="com.hopcroft.examples.controller.HelloController">
<property name="helloGroovyController" ref="helloGroovyController" />
</bean>
</beans></pre>
As you may notice, it’s not really difficult to understand. We have two bean definition, one is a Groovy file where you add the script-source property to define the location of the Groovy Controller. The other one is a common bean to which we’ll inject the previous Groovy bean as a property.
And that’s all, now you can deploy your web application to you favourite web container and see how it’s working. You can change your Groovy controller in runtime and notice the changes with no reploying.
Another important thing to bold is the pom file. In order to compile our Groovy file (to be sure that isn’t going to fail once the server is up) we have add the build-helper-maven plugin to our project.
Don’t forget you can read the post in my new blog here
Selenium , testing framework for acceptance tests
Selenium is a testing framework that allows you automatizing your acceptance tests. Selenium gives us the opportunity to test the interaction between our application pages and the users. Basically Selenium framework allows us to do two different things:
Read the rest of this entry »
Spring MVC basic example with Maven
In the following post we are going to talk about the Spring MVC project. But before that I have been thinking about writing some other posts about the Spring framework. I’m going to talk about some SpringSource projects such as Spring MVC, Spring Web Flow, Spring Security (O Auth) or Spring Faces to name a few. Moreover I’m planning to start writing about continuous integration and testing with (Hudson / Jenkins, Sonar, Cobertura, Selenium, Checkstyles, PMD, …). I’d also like write about Cloud Computing , as a novice developer in this particular subject, analyzing some frameworks and tools such as the Google App Engine (GAE) or Micro Cloud Foundry. But there is much left to all I have just mentioned so …. it is time to start with Spring MVC.
Ejemplo básico de Spring MVC con Maven
En el siguiente post vamos a hablar un poco de Spring MVC. Pero antes comentar que tengo pensado hacer una serie de post (el primero es este) sobre Spring. En concreto intentaré hablar un poco de proyecto de SpringSource como Spring MVC, Spring Web Flow, Spring Security (O Auth) ó Spring Faces. Además voy a hablar un poco de desarrollo e integración continua y pruebas (Hudson / Jenkins, Sonar, Cobertura, Selenium, Checkstyles, PMD, …). También me gustaría tratar temas de Cloud Computing , siempre como absoluto novato en la materia, analizando herramientas como Google App Engine (GAE) ó Micro Cloud Foundry. Pero para ello todavía queda …. así que empezaré con Spring MVC.
Spring Web Flow basic example
Visit my new website http://java4developers.com
In this post we are going to see a Spring Web Flow simple example. For that, we need to use the Java code we talked about in JPA basic example with EntityManager , Spring and Maven and Criteria JPA 2.0 and database metamodel auto generation with Maven. Spring Web Flow allow us to create our own web application in an easy and fast way using flows. Transitions happens from some pages to others depending on which actions are ocurring, as clicking a specified button for example.
JPA basic example with EntityManager , Spring and Maven
Visit my new website http://java4developers.com
In this post we are going to make a project that allows us to get from a mySql database a car list. The technologies we are going to use are Maven for the dependency management, JPA to interact with the database, Spring to define the our application context (besides of wiring everything), and finally we use JUnit to our application tests.
Ejemplo básico de Spring Web Flow
Visit my new website http://java4developers.com
En este post vamos a ver como hacer un ejemplo sencillo de Spring Web Flow e integrarlo con los ejemplos que estamos haciendo en los últimos post (Ejemplo básico JPA con EntityManager , Spring y Maven ó Generación del metamodelo de base de datos con Maven y uso en Criteria JPA 2.0). Spring Web Flow nos permite construir nuestras aplicación Web de una manera rápida basandonos en flujos. Esto es, las transaciones entre unas páginas y otras en función de las acciones que suceden, como por ejemplo pulsar un determinado botón.

