Jboss-4.2.x.GA déploiement d'application : Jboss-4.2.0.GA Jboss-4.2.1.GA Jboss-4.2.2.GA Jboss-4.2.3.GA
Par placeoweb, mercredi 18 juillet 2007 à 00:08 :: JAVA :: #78 :: rss
Déployer une application avec le serveur Jboss n'est pas si simple, voici les erreurs fréquemment rencontrées.
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"}
Puisque Jboss réponds sur toutes les interfaces, il faut bloquer l'accès anonyme à l'administration.
jmx-console http://localhost:8080/jmx-console/
jboss-4.2.1.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>
<! >
jboss-4.2.1.GA/server/default/conf/props/jmx-console-users.properties:
# A sample users.properties file for use with the UsersRolesLoginModule admin=admin
jmx-console et web-console, informations détaillées :
- Sécuriser la JMX Console and Web Console
- 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/
jboss-4.2.1.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.1.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> <!>
jboss-4.2.1.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
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 le 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).
Ejb3 entity, erreurs a 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 fournits dans la documentation de jboss-4.2.1.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
Editez le fichier file "jboss-4.2.1.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.1.GA/server/default/deploy/schedule-manager-service.xml jboss-4.2.1.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="ScotTest: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>
-->
</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()); } }
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"
Ressources
- Jboss : Téléchargement officiel.
- Jboss : Documentation officielle.
- Hibernate, annotations Entity Beans.
- Un très bon et simple tuto sur les ejb3 persistant avec jboss.
Commentaires
Aucun commentaire pour le moment.
Ajouter un commentaire
Les commentaires pour ce billet sont fermés.