Create a WAR from RAP Application with Libra WAR Product [step2]

juin 13, 2012 3 commentaires

In the [step1] we have installed (My) WAR Product Plug-in. In this article we will create two WAR products from the 2 RAP launches:

  • RAP Client – JPA Dao launch starts RAP Application which displays paginated users list from Database Derby (it uses JPA implementation for Dao).
  • RAP Client – Mock Dao launch starts RAP Application which displays paginated users list from Java Map (it uses Mock implementation for Dao).

At the end of this article we will have 2 WAR Products :

In the next article [step3] we will generate two WARs from the two WAR Products created in this article by using the Export WAR action.

Lire la suite…

Catégories :Eclipse RAP, Libra, WAR Product

Create a WAR from RAP Application with Libra WAR Product [step1]

juin 12, 2012 5 commentaires

In the Eclipse RCP/RAP with Spring DM, Spring Data JPA and Remoting [step10] article we have created a RAP Application which displays list of user with pagination :

Now we wish create a classic WAR of the RAP Application to deploy the RAP Application with any HTTP Server (which doesn’t support OSGi, like Apache Tomcat). This WAR will be created by using the Libra WAR Product.

You can see the online demo of the rap-jpa.war created with WAR Product deployed on CloudBees which provides an Apache Tomcat at http://rap-war.opensagres.cloudbees.net/eclipsespring.

Lire la suite…

Catégories :Eclipse RAP, Libra, WAR Product

Eclipse RCP/RAP and Remoting with JAX-RS, Spring Data JPA and CXF DOSGi [step3]

juin 6, 2012 4 commentaires

In [step2] we have implemented the JAX-RS Client which consumes the UserService#findAll() with JAX-RS:

@Path("/user")
public interface UserService {

	@GET
	@Path("/findAll")
	@Produces(MediaType.APPLICATION_JSON)
	Collection<User> findAll();
...
}

We have seen that JAX-RS Client fails when UserService#findAll(Pageable pageable) is called, because we have not annoted this method with JAX-RS:

1031 [Thread-5] ERROR org.apache.cxf.jaxrs.client.ClientProxyImpl  - Method fr.opensagres.services.UserService.findAll is not a valid resource method
	at org.apache.cxf.jaxrs.client.ClientProxyImpl.reportInvalidResourceMethod(ClientProxyImpl.java:546)

In this article we wish to export and import with JAX-RS the UserService#findAll(Pageable pageable) which returns the paginated list of the User which uses Spring Data – Commons structures :

  • Pageable : this parameter is the pagination request.
  • Page: the findAll method returns this structure which is the result of the pagination.

On other words we will annotate the UserService#findAll(Pageable pageable) like this :

@POST
@Path("/findAllPage")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
Page<User> findAll(Pageable pageable);

However when I have managed JAX-RS with Spring Data structure, I had 2 big problems coming from :

  • Spring Data – Commons: Spring Data Page and Pageable are interfaces and not Pojo. JAX-RS works with Pojo which are annotated with JAXB annotations. How do manage Spring Data Page and Pageable interfaces with JAX-RS? Fortunately, JAXB 2.0 provides XmlJavaTypeAdapter (please read Using JAXB 2.0’s XmlJavaTypeAdapter) which gives the capability to serialize Page and Pageable interfaces with JAXB. I have suggested this idea to Oliver Gierke, the lead of the Spring Data and he is developing JAXB Adapter with SpringDataJaxb.java. However in this article we will not use this class (because this class is not finished) but we will create our own JAXB adapter which will be more simply to understand how to work the JAXB Adapter.
  • Apache CXF: on server side when CXF tries to serialize the Page class with JAXB, it fails because the JAXBContext doesn’t know the User class. This problem comes from that CXF is not able to populate the JAXBContext automaticly with Parameterized class (in our case , we have Page<T> and T=User, the JAXBContext is filled just with Page but not with User). You can fix the problem by setting extra class to the JSONProvider :
    <bean id="jsonProvider" class="org.apache.cxf.jaxrs.provider.JSONProvider">
    	<property name="singleJaxbContext" value="true" />
    	<property name="extraClass">
    		<list>
    			<value>fr.opensagres.domain.User</value>
    		</list>
    	</property>
    </bean>
    

    We will do that in this article, but I have created the patch CXF-4359 which fixes the explained problem below to avoid declaring extra classes for JSONProvider.

Lire la suite…

Catégories :Apache CXF, DOSGi, Spring Data JPA

Eclipse RCP/RAP and Remoting with JAX-RS, Spring Data JPA and CXF DOSGi [step2]

Mai 31, 2012 2 commentaires

In [step1] we have downloaded CXF DOSGi « Multi Bundle Distribution » and created the fr.opensagres.remoting.exporter.dosgi.jaxrs bundle
to export on server side the UserService#findAll() with JAX-RS:

@Path("/user")
public interface UserService {

	@GET
	@Path("/findAll")
	@Produces(MediaType.APPLICATION_JSON)
	Collection<User> findAll();
...
}

In this article we will create the importer bundle fr.opensagres.remoting.importer.dosgi.jaxrs which will create a JAX-RS Client with Spring bean :

<jaxrs:client id="jaxrsUserService" address="http://127.0.0.1:9000/fr/opensagres/services/UserService"
	serviceClass="fr.opensagres.services.UserService" inheritHeaders="true">
</jaxrs:client>

and will register this JAX-RS Client in the OSGi register services as UserService :

<osgi:service ref="jaxrsUserService" interface="fr.opensagres.services.UserService" />

For recall, the Simple Client bundle fr.opensagres.simpleclient consumes a UserService in the Thread FindAllUsersThread from the OSGi registry services and display User list every 5 seconds. In our case the UserService instance will be the JAX-RS Client retrieved from the OSGi registry services :

<osgi:reference id="userService" interface="fr.opensagres.services.UserService" cardinality="0..1" timeout="1000" />

This JAX-RS Client UserService will be setted in the FindAllUsersThread with Dependency Injection :

<bean id="FindAllUsersThread" class="fr.opensagres.simpleclient.FindAllUsersThread"
		init-method="start" destroy-method="interrupt">
	<property name="userService" ref="userService"></property>
</bean>

This FindAllUsersThread (client side) consumes the UserService#findAll() every 5 seconds to display user list on the console :

// 1) findAll
users = userService.findAll();
displayUsers("findAll", users);

Lire la suite…

Catégories :Apache CXF, DOSGi

Eclipse RCP/RAP and Remoting with JAX-RS, Spring Data JPA and CXF DOSGi [step1]

Mai 29, 2012 5 commentaires

The Eclipse RCP/RAP with Spring DM, Spring Data JPA and Remoting [step11] article explains that we wish to manage remoting for UserService :

package fr.opensagres.services;

import java.util.Collection;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

import fr.opensagres.domain.User;

public interface UserService {

	Collection<User> findAll();

	Page<User> findAll(Pageable pageable);
		
	Collection<User> findByFirstNameLikeAndLastNameLike(String firstName,
			String lastName);

	Page<User> findByFirstNameLikeAndLastNameLike(String firstName,
			String lastName, Pageable pageable);

	User saveUser(User user);

}
  • the server side will export the UserService which retrieves User from Database with JPA.
  • the client side, RCP Application, RAP Application and OSGi Bundle Activator will import the UserService to consume the exported UserService.

In this article I will explain how to manage remoting with CXF DOSGi with JAX-RS. DOSGi Releases provides 2 distributions:

  • Multi Bundle Distribution: This distribution is a zip file containing the Distributed OSGi bundles, as well as all their dependencies.
  • Single Bundle Distribution: This is a convenience distribution of a single bundle that embeds all the dependencies.

In our case we will use « Multi Bundle Distribution » which is more complex to use it than « Single Bundle Distribution », but we need to do that because we have already Spring DM.

When I have used CXF DOSGi to manage remoting with our UserService, I have met several problems :

  • « Multi Bundle Distribution » is very hard to use, because you need install a lot of bundles and set the Auto-Start to true for some bundles.
  • Using JAX-RS was not simply with the UserService because it uses Spring Data Page and Pageable interfaces (and not Pojo).

I will explain that in the Eclipse RCP/RAP and Remoting with JAX-RS, Spring Data JPA and CXF DOSGi articles. In this article we will export the UserService#findAll() with JAX-RS:

package fr.opensagres.services;

import java.util.Collection;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import fr.opensagres.domain.User;

@Path("/user")
public interface UserService {

	@GET
	@Path("/findAll")
	@Produces(MediaType.APPLICATION_JSON)
	Collection<User> findAll();
...
}

On other words, we will

Lire la suite…

Catégories :Apache CXF, DOSGi

Eclipse RCP/RAP with Spring DM, Spring Data JPA and Remoting [step11]

Mai 29, 2012 2 commentaires

In [step10] we have created RAP Application from the RCP Application. At this step we have several Client Layer :

  • OSGi Bundle Activator (simpleclient)
  • RCP Application
  • RAP Application

which consumes Service Layer : UserService (from Mock Dao, JPA Dao) to retrieve list of User :

package fr.opensagres.services;

import java.util.Collection;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

import fr.opensagres.domain.User;

public interface UserService {

	Collection<User> findAll();

	Page<User> findAll(Pageable pageable);
		
	Collection<User> findByFirstNameLikeAndLastNameLike(String firstName,
			String lastName);

	Page<User> findByFirstNameLikeAndLastNameLike(String firstName,
			String lastName, Pageable pageable);

	User saveUser(User user);

}

Here, The Client and Service Layer are in the same OSGi container. Now we wish manage Client/Server architecture to have :

  • Client Layer in an OSGi container
  • Service Layer in an other OSGi container

the Client Layer will consume Service Layer with remoting mean.

Lire la suite…

Catégories :Apache CXF, DOSGi, ECF, Spring Remoting

Eclipse RCP/RAP with Spring DM, Spring Data JPA and Remoting [step10]

avril 16, 2012 6 commentaires

In [step9] we have displayed the User List with pagination by using Nebula Pagination Control and Spring Data JPA. As Nebula Pagination Control supports RAP, it’s possible with few modifications of the fr.opensagres.richclient to support WEB mode too with Eclipse RAP:

At the end of this article we will have an Application which supports:

The sources of the fr.opensagres.richclient Plug-In will be the same: it’s called Single-Sourcing.

Lire la suite…

Eclipse RCP/RAP with Spring DM, Spring Data JPA and Remoting [step9]

avril 16, 2012 7 commentaires

In [step8] we have developed a Rich Client with RCP Application to display User list in a SWT Table by consuming the UserService by using Spring DM by using the SpringExtensionFactory from Martin Lippert.

In this article we will display the User List with pagination by using Nebula Pagination Control.

The sort of column will be done by the UserService by using Spring Data Sort Structure:

Lire la suite…

Eclipse RCP/RAP with Spring DM, Spring Data JPA and Remoting [step8]

avril 15, 2012 2 commentaires

In [step7] we have seen how to use Spring Data JPA to add custom methods to the Dao to manage criteria and pagination.

In this article we will implement a Rich Client with RCP Application to display User list in a SWT Table :

We will see how to we can consume the UserService by using Spring DM by using the SpringExtensionFactory from Martin Lippert.

Lire la suite…

Eclipse RCP/RAP with Spring DM, Spring Data JPA and Remoting [step7]

avril 13, 2012 2 commentaires

In [step6] we have implemented the API Dao UserDao with JPA by using Spring Data JPA :

  • the API Dao fr.opensagres.dao.UserDao extends the Spring Data org.springframework.data.repository.PagingAndSortingRepository.
  • the JPA User Dao implementation is created on runtime by Spring Data JPA by declaring a jpa:repository:
    <!-- Spring Data JPA-->
    <jpa:repositories base-package="fr.opensagres.dao">
      <jpa:repository id="userDao" />
    </jpa:repositories>
    

At this step the UserDao provides the CRUD methods and pagination methods for User entity like :

  • Iterable findAll(): to find all entity.
  • T save(T model): to save an entity.
  • Page findAll(Pageable pageable): to find all entity with pagination.

With Spring Data JPA, it’s possible to add your own method to manage search entities by criteria : to do that the method name of the UserDao must just follow some convention name (see Query creation for more information). In this article we will add the 2 following methods to the UserDao :

  • findByFirstNameLikeAndLastNameLike to retrieve a list of User by first name (like) and last name (like):
    List<User> findByFirstNameLikeAndLastNameLike(String firstName,	String lastName);
    
  • findByFirstNameLikeAndLastNameLike to retrieve a list of User by first name (like) and last name (like) with pagination:
    Page<User> findByFirstNameLikeAndLastNameLike(String firstName,	String lastName, Pageable pageable);
    

Just add those 2 methods to UserDao API and Spring Data JPA will manage for you the JPA implementation!

Lire la suite…

Catégories :Spring Data JPA
Concevoir un site comme celui-ci avec WordPress.com
Commencer