Tuesday, September 27, 2011

How to use Shrinkwrap MavenDependencyResolver

If you use Maven to build your application and you want to test it with Arquillian, Be sure that you will be looking for a way to include some of your libraries (artifact) from Maven into your archive file (war, ear...).

In this article we show you how to use the Shrinkwrap MavenDependencyResolver to read artifact from pom file using the maven setting file.

For this purpose you just need to add your maven setting file in a folder mvn_settings under src/test/ressources and add this entry in your @Deployment method !

.addAsLibraries(DependencyResolvers.use(MavenDependencyResolver.class)
.configureFrom("src/test/resources/mvn_settings/settings.xml")
.artifact("GROUPID:ARTIFACTID:TYPE:VERSION")
.resolveAs(GenericArchive.class))


For further details about Resolver extension in ShrinkWrap, refer to: https://github.com/shrinkwrap/resolver

Saturday, September 24, 2011

JSFUnit 2.0.0.Beta 2 is Out


The Beta 2 version for JSFUnit2 is available from the middle of this month (September) with a fully support for junit 4, JSF2 and Arquillian , for more details check this blog entry and the release note

Have a look at this related getting started example and enjoy it!!

Friday, September 23, 2011

How to configure Arquillian with a remote Jboss AS7


If you want to use Arquillian to connect and run against a remote(different JVM, different machine) running previous version of Jboss server, you need to use JNDI properties for that !

In Jboss AS 7, the jndi.properties file is not used... So If you have set the managementAddress configuration option to where the management api is bound, Arquillian should read out from the server (remote or local jvm/machine) where the ip_adress/port_number are bound.

All this configuration is done in the arquillian.xml file as bellow:
 

IP_ADR
PORT_NUM


For JBoss AS 7.0.0.Final, you need to configure the jmx protocol used by adding:

REMOTE

under the container tag ...

Monday, August 29, 2011

How it's easy to configure ports in Jboss AS7

If you want to change/configure your ports server on Jboss AS7, all you need is to modify entries under socket-binding-group for standalone.xml and socket-binding-groups for domain.xml, for example in standalone.xml:















Very easiest way! doens't it ?

Sunday, August 28, 2011

Ldap Realm configuration on Jboss AS7

In Jboss 6 and lower the ldap Realm was configured in the login-config.xml file like :
 


com.sun.jndi.ldap.LdapCtxFactory
simple
....



On jboss 7 the ldap Realm configuration has a little changed, it become on the standalone.xml (or in domain.xml) as a security domain under :
 
As bellow:







...




Note that the xml parser has changed in Jboss 7, so you should convert every module-option tag so that the lowest level data element for the module-option tag was replaced by the attribute value= and the tag was converted to a self-closing tag, for example:


com.sun.jndi.ldap.LdapCtxFactory

Become:




For our blog ldap directory, the wall configuration become :



















also,




needs to be changed to:







else ModuleClassLoader won't load the com.sun.jndi.ldap.LdapCtxFactory which is needed in ldap authentication modules, and obviously you ll need org.jboss.security.auth.spi.LdapLoginModule on classpath.

Saturday, August 20, 2011

Configure your Jboss AS7 to be accessible from the network

If you want to have the web console as well as your web application accessible from the network, you have to change the default configuration of JBoss.

1) go to standalone/configuration
2) Open the file standalone.xml (or domain.xml)
3) Look for the lines :








4) Change both IP address from 127.0.0.1 to the ip address of your network interface. Note that your complex deployment the server may have 2 ip adresses 1 for business flows and 1 for management flows.
5) Kill JBossAS and restart

The Admin console should be accessible now from your desktop computer at http://:9990/console ;-)

Sunday, August 7, 2011

Spring3 and JSF2 integration using CDI annotations

In this blog i show you how to use @Inject in your JSF managed beans to directly inject the Spring beans instead of instantiating a Spring application context and using the getBean methode from that context and also how Spring will manage your JSF beans ;-)


In order to inject Spring beans into JSF managed beans using @Inject, the following needs to be done:


1)web.xml

 
org.springframework.web.context.ContextLoaderListener


contextConfigLocation

classpath:/applicationContext.xml


org.springframework.web.context.request.RequestContextListener


2) faces-config.xml

 
org.springframework.web.jsf.el.SpringBeanFacesELResolver

3) applicationContext.xml





4) JSF Managed bean

 @ManagedBean(name="blogJSFBean")
@Controller
@ViewScoped
public class MainBean implements Serializable {
private static final long serialVersionUID = -5012655116147710604L;
@Inject
private SpringBean myBlogBean;


To keep it standard i have changed @Managedean to @Named witch is a CDI standard annotation suported by Spring also (as an alternate to @Service and @Controller)

The big problem i have found that the scope view (@ViewScoped) isn't supported by Spring (also Flash scope …) so i have developped the view scope as Spring custom scope following this article: http://cagataycivici.wordpress.com/2010/02/17/port-jsf-2-0s-viewscope-to-spring-3-0/


my bean become:

 @Named("blogJSFBean")
@Scope (value="view")
public class MainBean implements Serializable {
private static final long serialVersionUID = -5012655116147710604L;
@Inject
private SpringBean myBlogBean;


In general the big difference i have found is that Spring and JSF bean from Java EE 6 use a different scoping! Spring do not support standard scope annotation used in JSF and CDI. To get it work i have followed a workaround to import JSF/CDI bean into Spring:

http://matthiaswessendorf.wordpress.com/2010/05/06/using-cdi-scopes-with-spring-3/

Finaly with all this configuration and workarounds, i have been able to inject Spring beans into JSF using @Inject and @Named Java EE standard annotaion and a custom Spring scope to import JSF/CDI scope