Note : les informations suivantes sont valables pour toute la série de Jboss-4.2.x :

Jboss-4.2.3.GA      Stable      95 MB      2008-07-18      LGPL
Jboss-4.2.2.GA      Stable      92 MB      2007-10-22      LGPL
Jboss-4.2.1.GA      Stable      90 MB      2007-07-16      LGPL
Jboss-4.2.0.GA      Stable      90 MB      2007-05-11      LGPL

Jboss est en écoute seulement sur l'interface local

Il faut rajouter l'option "-b" au lancement de Jboss :

./run.sh -c default -b 0.0.0.0

Que ce soit sous linux ou sous windows, JBoss AS démarre en se liant à toutes les interfaces réseau. C'est ce qu'il est possible de voir dans les logs de démarrage lorsqu'au lieu de l'adresse IP il affiche "0.0.0.0" . C'est pour ça qu'en utilisant la commande "run.sh -b 0.0.0.0" on obtiens le même résultat.

Si ça ne marche pas ---> il faut aller voir celui qui administre la machine. La plupart du temps il y a plusieurs carte réseaux et seulement une partie est visible. Il faudra démarrer JBoss AS en précisant cette interface avec la commande ci-dessus et en remplaçant "0.0.0.0" par l'adresse IP visible.

Attention : l'option "-B" permet de spécifier un répertoire où aller chercher les librairies nécessaires au démarrage de JBoss AS. Rien à voir donc avec l'option "-b" qui permet de spécifier l'interface réseau (l'adresse IP) sur laquelle JBoss AS doit écouter. Merci à developpez.net pour la solution.

Pensez a rajouter l'option dans le script de démarrage : /etc/init.d/jboss

JBOSSSH=${JBOSSSH:-"$JBOSS_HOME/bin/run.sh -c $JBOSS_LVL -b 0.0.0.0"}

Jboss est en écoute seulement sur le port par défaut 8080

Changer ou ajouter un port d'écoute tel que le port 80

jboss-4.2.3.GA/server/default/deploy/jboss-web.deployer/server.xml :

<Connector port="8080" address="${jboss.bind.address}"    
         maxThreads="250" maxHttpHeaderSize="8192"
         emptySessionPath="true" protocol="HTTP/1.1"
         enableLookups="false" redirectPort="8443" acceptCount="100"
         connectionTimeout="20000" disableUploadTimeout="true" />
 
    <Connector port="80" address="${jboss.bind.address}"    
         maxThreads="250" maxHttpHeaderSize="8192"
         emptySessionPath="true" protocol="HTTP/1.1"
         enableLookups="false" redirectPort="8443" acceptCount="100"
         connectionTimeout="20000" disableUploadTimeout="true" />

Puisque Jboss réponds sur toutes les interfaces, il faut bloquer l'accès anonyme à l'administration.

jmx-console http://localhost:8080/jmx-console/

Activation de l'authentification pour la jmx-console

jboss-4.2.3.GA/server/default/deploy/jmx-console.war/WEB-INF/jboss-web.xml

<!-- Uncomment the security-domain to enable security. You will
      need to edit the htmladaptor login configuration to setup the
      login modules used to authentication users.
   -->
      <security-domain>java:/jaas/jmx-console</security-domain>
   <!-- -->

jboss-4.2.3.GA/server/default/deploy/jmx-console.war/WEB-INF/web.xml :

<!-- A security constraint that restricts access to the HTML JMX console
   to users with the role JBossAdmin. Edit the roles to what you want and
   uncomment the WEB-INF/jboss-web.xml/security-domain element to enable
   secured access to the HTML JMX console.
   -->
   <security-constraint>
     <web-resource-collection>
       <web-resource-name>HtmlAdaptor</web-resource-name>
       <description>An example security config that only allows users with the
         role JBossAdmin to access the HTML JMX console web application
       </description>
       <url-pattern>/*</url-pattern>
       <http-method>GET</http-method>
       <http-method>POST</http-method>
     </web-resource-collection>
     <auth-constraint>
       <role-name>JBossAdmin</role-name>
     </auth-constraint>
   </security-constraint>
   <!-- -->

Changement du mot de passe pour la jmx-console

jboss-4.2.3.GA/server/default/conf/props/jmx-console-users.properties:

# A sample users.properties file for use with the UsersRolesLoginModule
#admin=admin
admin=motDePasse

jmx-console et web-console, informations détaillées :

  1. Sécuriser la JMX Console and Web Console
  2. Livre blanc sur les techniques de sécurisation de JMX destiné aux administrateurs système et les développeurs pour JBoss installé dans des environnements de production.

web-console http://localhost:8080/web-console/

Activation de l'authentification pour la web-console

jboss-4.2.3.GA/server/default/deploy/management/console-mgr.sar/web-console.war/WEB-INF/jboss-web.xml :

<!-- Uncomment the security-domain to enable security. You will
   need to edit the htmladaptor login configuration to setup the
   login modules used to authentication users.
   -->
      <security-domain>java:/jaas/web-console</security-domain>
   <!-- -->

jboss-4.2.3.GA/server/default/deploy/management/console-mgr.sar/web-console.war/WEB-INF/web.xml :

<!-- A security constraint that restricts access to the HTML JMX console
   to users with the role JBossAdmin. Edit the roles to what you want and
   uncomment the WEB-INF/jboss-web.xml/security-domain element to enable
   secured access to the HTML JMX console.
   -->
   <security-constraint>
   <web-resource-collection>
   <web-resource-name>HtmlAdaptor</web-resource-name>
   <description>An example security config that only allows users with the
   role JBossAdmin to access the HTML JMX console web application
   </description>
   <url-pattern>/*</url-pattern>
   <http-method>GET</http-method>
   <http-method>POST</http-method>
   </web-resource-collection>
   <auth-constraint>
   <role-name>JBossAdmin</role-name>
   </auth-constraint>
   </security-constraint>
   <!-- -->

Changement du mot de passe pour la web-console

jboss-4.2.3.GA/server/default/deploy/management/console-mgr.sar/web-console.war/WEB-INF/classes/web-console-users.properties :

# A sample users.properties file for use with the UsersRolesLoginModule
#admin=admin
admin=motDePasse

Alternative aux fichiers textes locaux

Si toute fois vous souhaitez configurer un realm gérant les utilisateurs et les groupes en base de donnée (MySQL), vous pouvez consulter rechercher un tutoriel abordant la sécurité sous Jboss (realm MySQL). Cette solution offre l'avantage de partager via la base, les utilisateurs et les rôles pour l'accès au services sécurisés (authentifiés).

jboss-4.2.3.GA/server/default/conf/login-config.xml :

<!--
      Configuration de securite pour monLogiciel
    -->
    <application-policy name="securiteDeMonLogiciel">
        <authentication>
          <login-module code="org.jboss.security.auth.spi.DatabaseServerLoginModule" flag="required">
            <module-option name="dsJndiName">java:/jndiRealmMonLogiciel</module-option>
            <module-option name="principalsQuery">SELECT passwd FROM Users WHERE username=?</module-option>
            <module-option name="rolesQuery">SELECT userRoles,'Roles' FROM UserRoles WHERE username=?</module-option>
            <module-option name="hashAlgorithm">MD5</module-option>
            <module-option name="hashEncoding">base64</module-option>
          </login-module>
        </authentication>
    </application-policy>

Jboss ROOT, changer la page d'accueil par défaut de Jboss

Voyez le post modification du context root de Jboss pour changer la page accueil

Ejb3 entity, erreurs à ne pas commettre :

  • nommer son fichier à la française : persistance.xml à la place de persistence.xml
  • recopier le fichier persistence.xm depuis le web à la place de le copier depuis les exemples fournis dans la documentation de jboss-4.2.3.GA/docs/examples/jca/mysql-ds.xml

Manager de transaction (JTA)

L'accès a plusieurs ressources dans une seule transaction n'est plus autorisé par défaut par le nouveau manager de transaction. Si vous obtenez un message :

[com.arjuna.ats.internal.jta.transaction.arjunacore.lastResource.disallow] [com.arjuna.ats.internal.jta.transaction.arjunacore.lastResource.disallow] Adding multiple last resources is disallowed. Current resource is org.jboss.resource.connectionmanager.TxConnectionManager$LocalXAResource@723646

This is not a bug. You're trying to access multiple one phase resources in a single transaction. This was allowed with the old transaction manager, but it's not allowed in the new one. It is possible to set a property in the transaction service to allow multiple one phase resources, but that could lead to transaction problems. Better use two phase resources.

Editez le fichier file "jboss-4.2.3.GA/server/default/conf/jbossjta-properties.xml" et ajoutez la propriété "com.arjuna.ats.jta.allowMultipleLastResources" avec la valeur "true":

<properties depends="arjuna" name="jta">
  <property name="com.arjuna.ats.jta.allowMultipleLastResources" value="true"/>
 
  <!-- ... other properties ... -->
 </properties>

Vous obtiendrez désormais le message suivant :

[com.arjuna.ats.internal.jta.transaction.arjunacore.lastResource.multipleWarning] [com.arjuna.ats.internal.jta.transaction.arjunacore.lastResource.multipleWarning] Multiple last resources have been added to the current transaction. This is transactionally unsafe and should not be relied upon. Current resource is org.jboss.resource.connectionmanager.TxConnectionManager$LocalXAResource@1c24b451

Les tâches planifiées (cron), avec Jboss il s'agit de scheduler (programmateur)

Le schedul (cron) Jboss s'administre depuis ces 2 fichiers : jboss-4.2.3.GA/server/default/deploy/schedule-manager-service.xml jboss-4.2.3.GA/server/default/deploy/scheduler-service.xml

Vous pouvez également définir des taches programmées qui seront automatiquement déployées depuis votre programme lors de la publication de celui ci sur le serveur. Il faut ajouter dans votre application un répertoire WEB-INF et le fichier de configuration pour Jboss : jboss-service.xml Voici un exemple de contenu du fichier WEB-INF/jboss-service.xml de votre programme :

<?xml version="1.0" encoding="UTF-8"?>
 <server>
 
         <!-- 
         7.1. org.jboss.varia.scheduler.Scheduler
 
 The Scheduler differs from the TimerMBean in that the Scheduler directly invokes a callback on
 an instance of a user defined class, or an operation of a user specified MBean.
 * InitialStartDate: Date when the initial call is scheduled. It can be either:
  * NOW: date will be the current time plus 1 seconds
  * A number representing the milliseconds since 1/1/1970
  * Date as String able to be parsed by SimpleDateFormat with default format pattern "M/d/yy
     h:mm a". If the date is in the past the Scheduler will search a start date in the future with
     respect to the initial repetitions and the period between calls. This means that when you
     restart the MBean (restarting JBoss etc.) it will start at the next scheduled time. When no
     start date is available in the future the Scheduler will not start.
  For example, if you start your Schedulable everyday at Noon and you restart your JBoss
  server then it will start at the next Noon (the same if started before Noon or the next day if
  start after Noon).
 * InitialRepetitions: The number of times the scheduler will invoke the target's callback. If -1
  then the callback will be repeated until the server is stopped.
 * StartAtStartup: A flag that determines if the Scheduler will start when it receives its
  startService life cycle notification. If true the Scheduler starts on its startup. If false, an
  explicit startSchedule operation must be invoked on the Scheduler to begin.
 * SchedulePeriod: The interval between scheduled calls in milliseconds. This value must be
  bigger than 0.  
            -->
 
         <!-- 
 http://docs.jboss.com/jbossas/javadoc/4.0.5/varia/org/jboss/varia/scheduler/Scheduler.html	  
 FixedRate : The default scheduling to use, fixed-rate or fixed-delay (false, default)
 
 void 	restartSchedule()
          Stops the server right now and starts it right now.
 void 	setDateFormat(String dateFormat)
          Sets the date format used to parse date/times
 void 	setFixedRate(boolean fixedRate)
          The default scheduling to use, fixed-rate or fixed-delay (false, default)
 void 	setInitialRepetitions(long pNumberOfCalls)
          Sets the initial number of scheduled calls.
 void 	setInitialStartDate(String pStartDate)
          Sets the first scheduled call.
 void 	setSchedulableArguments(String pArgumentList)
          The arguments to pass to the schedule
 void 	setSchedulableArgumentTypes(String pTypeList)
          Sets the comma seperated list of argument types for the Schedulable class.
 void 	setSchedulableClass(String pSchedulableClass)
          Sets the fully qualified Class name of the Schedulable Class being called by the Scheduler.
 void 	setSchedulableMBean(String pSchedulableMBean)
          Sets the fully qualified JMX MBean name of the Schedulable MBean to be called.
 void 	setSchedulableMBeanMethod(String pSchedulableMBeanMethod)
          Sets the method name to be called on the Schedulable MBean.
 void 	setSchedulePeriod(long pPeriod)
          Sets the Schedule Period between two scheduled call.
 void 	setStartAtStartup(boolean pStartAtStartup)
          Set the scheduler to start when MBean started or not.
 void 	setTimerName(String pTimerName)
          The JMX Timer to use (or create if not there) 
           -->
 
        <!-- Les temps
     1000 1 seconde
    30000 30 secondes
    60000 1 minute
   600000 10 minutes
  3600000 1 heure	   
 86400000 1 jour
          -->
 
        <!-- Test ->
        <!--  
    <mbean code="org.jboss.varia.scheduler.Scheduler"
           name="MonAppTest:service=Scheduler">
        <attribute name="StartAtStartup">true</attribute>
        <attribute name="SchedulableClass">com.placeoweb.schedul.Test</attribute>
        <attribute name="InitialStartDate">NOW</attribute>
        <attribute name="SchedulePeriod">10000</attribute>
        <attribute name="InitialRepetitions">-1</attribute>
        <attribute name="FixedRate">true</attribute>
    </mbean>
    --> 
 
        <!-- JBoss Scheduler avec la initial start date définie à une heure précise -->
        <!--  
    <mbean code="org.jboss.varia.scheduler.Scheduler" name="MyName:service=Scheduler">
        <attribute name="StartAtStartup">true</attribute>
        <attribute name="SchedulableClass">full.package.for.MySchedulableImpl</attribute>
        <attribute name="InitialStartDate">22/10/2009 11:30</attribute>
        <attribute name="DateFormat">dd/MM/yy HH:mm</attribute>
        <attribute name="SchedulePeriod">86400000</attribute>
        <attribute name="InitialRepetitions">-1</attribute>
    </mbean>
    -->
 
        <!-- JBoss Scheduler avec la initial start date définie à une heure précise -->
        <!--  
    <mbean code="org.jboss.varia.scheduler.Scheduler" name="MyName:service=Scheduler">
        <attribute name="StartAtStartup">true</attribute>
        <attribute name="SchedulableClass">full.package.for.MySchedulableImpl</attribute>
        <attribute name="InitialStartDate">22/10/2009 11:30</attribute>
        <attribute name="DateFormat">dd/MM/yy HH:mm</attribute>
        <attribute name="SchedulePeriod">86400000</attribute>
        <attribute name="InitialRepetitions">-1</attribute>
    </mbean>
    -->
 
 </server>

Et le programme à lancer :

package com.placeoweb.schedul;
 
import java.util.Date;
 
import org.jboss.logging.Logger;
import org.jboss.varia.scheduler.Schedulable;
 
/**
 * CRON - Taches automatisées
 *
 */
public class Test implements Schedulable {
 
	private final Logger logger = Logger.getLogger(this.getClass());
 
	public void perform(Date now, long remainingRepetitions) {
 
        logger.info("perform, now: " + now +
                ", remainingRepetitions: " + remainingRepetitions);
 
        System.out.println(this.getClass()+" SCHEDUL DEBUT "+new Date());
        try {
                MaClasse maClasse = new MaClasse();
                maClasse.lancer();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
        System.out.println(this.getClass()+" SCHEDUL FIN "+new Date());
 
	}
 
}

Variable d'environnement JBoss avec le système de gestion des Properties : SystemProperties

Une bonne solution pour configurer ses applications en dehors des fichiers de déploiement inclus dans les archives, est d'utiliser le PropertiesService avec un fichier de propriétés dédié à votre application pour lister les variables d'environnement.

Créer un fichier <nomApp>.properties dans le répertoire conf (JBOSS_HOME/default/conf par défaut) où tu liste les différentes variables d'environnement nécessaires à ton application sous la forme :

clé1=valeur1
clé2=valeur2

Puis modifier le fichier properties-service.xml (dans le répertoire où est deployé ton application JBOSS_HOME/default/deploy par exemple) : en ajoutant les lignes suivantes :


<!-- ==================================================================== -->
  <!-- System Properties Service                                            -->
  <!-- ==================================================================== -->
 
  <!--
     | Allows rich access to system properties.
   -->
 
  <mbean code="org.jboss.varia.property.SystemPropertiesService" 
	 name="jboss:type=Service,name=SystemProperties">
 
    <!-- 
       | Load properties from each of the given comma seperated URLs
 
    <attribute name="URLList">
      http://somehost/some-location.properties,
      ./conf/somelocal.properties
    </attribute>
 
    -->
 
    <attribute name="URLList">
      ./conf/<nomApp>.properties
    </attribute>

Vous pouvez ensuite accéder aux variables dans votre application :

System.getProperty("clé1");

Arrêter proprement le serveur

./shutdown.sh -S

ou

./shutdown.sh --shutdown

Sauf que si vous avez spécifier, un mot de passe pour votre console jmx, il faudra s'en servir avec les options -u (user) et -p (password) pour arrêter correctement votre serveur, sinon vous aurez le message :

Exception in thread "main" java.lang.SecurityException: Failed to authenticate principal=null, securityDomain=jmx-console

Pensez a rajouter l'option dans le script de d'arrêt : /etc/init.d/jboss

CMD_STOP="java -classpath $JBOSSCP org.jboss.Shutdown --shutdown -u admin -p votreMotDePasse"

Erreurs rencontrées

Caused by: javax.management.MBeanRegistrationException: preRegister() failed: [ObjectName='jboss.remoting:service=NetworkRegistry', Class=org.jboss.remoting.network.NetworkRegistry

Il s'agit d'une erreur lors du lancement du serveur car il n'arrive pas s'identifier sur le réseau, vérifiez que le /etc/hosts inclus la boucle locale 127.0.0.1 et d'une résolution lan (selon le hostname) est possible par exemple avec un ping.

class javax.naming.NameNotFoundException javax.naming.NameNotFoundException: MyEjbClassImp not bound

Si vous passez d'un déploiment d'EJB simple à un EAR (pour Enterprise ARchive, format de fichier utilisé par Java EE pour empaqueter un ou plusieurs 'modules' dans une seule archive, de façon à pouvoir déployer ces modules sur un serveur d'applications en une seule opération, et de façon cohérente.), faite attention au nom de votre ressource dans la JNDI.

Lorsqu'elle est déployé en en EAR le nom par défaut est préfixé par le nom de l'EAR, tel que c'est indiqué dans un post Help: how to look up ejb3 deployed in ear using jndi sur la communauté Jboss. Ceci est expliqué en détail dans le JBoss EJB3 Tutorials (pour Jboss 5 et EJB 3) dans le chapitre Binding your beans in JNDI

On retouve le même problème sur developpez dont la solution est indiquée comme :

L'erreur se trouve surement dans ton lookup ... 
En effet, tu précise uniquement "BEAN/INTERFACE" alors qu'il faut normalement préciser "EAR/BEAN/INTERFACE" ...
En gros, modifie ton lookup en "hellouser/UserBean/local" ...

Personnellement, j'ai utilisé l'autre solution qui n'impacte le client selon le mode déploiement, j'ai déclaré le nom des mes ressources. Par conséquent le nom n'est pas attribué par défaut lors du déploiement.

@LocalBinding(jndiBinding="MyAnyString/MyEjbClassImp/local")
@RemoteBinding(jndiBinding="MyAnyString/MyEjbClassImp/remote")

Logs SANS EAR

[org.jboss.ejb3.ProxyDeployer] no declared remote bindings for : MyEjbClassImp
[org.jboss.ejb3.ProxyDeployer] there is remote interfaces for MyEjbClassImp
[org.jboss.ejb3.ProxyDeployer] default remote binding has jndiName of MyEjbClassImp/remote

Logs AVEC EAR

[org.jboss.ejb3.ProxyDeployer] no declared remote bindings for : MyEjbClassImp
[org.jboss.ejb3.ProxyDeployer] there is remote interfaces for MyEjbClassImp
[org.jboss.ejb3.ProxyDeployer] default remote binding has jndiName of MyEAR/MyEjbClassImp/remote

Logs avec déclaration du nom dans le Binding

[org.jboss.ejb3.stateless.BaseStatelessProxyFactory] Binding proxy for MyEjbClassImpin JNDI at MyAnyString/MyEjbClassImp/local

Ressources