Glassfish: Difference between revisions
| Line 87: | Line 87: | ||
* un JSP [[ECOM/hello.jsp|hello.jsp]] |
* un JSP [[ECOM/hello.jsp|hello.jsp]] |
||
* une Servlet [[ECOM/HelloServlet.java|HelloServlet.java]] |
* une Servlet [[ECOM/HelloServlet.java|HelloServlet.java]] |
||
| ⚫ | |||
| ⚫ | |||
* une Servlet [[WebSocket]] |
* une Servlet [[WebSocket]] |
||
* une Servlet asynchrone (en utilisant les annotations [[JSR315]]) |
* une Servlet asynchrone (en utilisant les annotations [[JSR315]]) |
||
| Line 105: | Line 103: | ||
* http://localhost:8080/hello/hello.jsp?name=Didier |
* http://localhost:8080/hello/hello.jsp?name=Didier |
||
* http://localhost:8080/hello/helloann?name=Didier |
* http://localhost:8080/hello/helloann?name=Didier |
||
| ⚫ | |||
| ⚫ | |||
Regardez le contenu du journal du domaine. |
Regardez le contenu du journal du domaine. |
||
| Line 113: | Line 109: | ||
</pre> |
</pre> |
||
===Web Service=== |
|||
Modifiez et r-construisez votre application en ajoutant : |
|||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
Redéployez |
|||
Ouvrez |
|||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
<pre> |
<pre> |
||
cd .. |
cd .. |
||
| Line 120: | Line 127: | ||
cd hellowsclient |
cd hellowsclient |
||
wsimport -p fr.polytechgrenoble.ricm.ecom.ws.client http://localhost:8080/hello/HelloWSService?wsdl |
wsimport -p fr.polytechgrenoble.ricm.ecom.ws.client http://localhost:8080/hello/HelloWSService?wsdl |
||
</pre> |
|||
===RESTFul Service=== |
|||
Modifiez et r-construisez votre application en ajoutant : |
|||
* un [[REST]]ful Service [[ECOM/HelloREST.java|HelloREST.java]] |
|||
Redéployez |
|||
Utilisez curl pour interoger le service |
|||
<pre> |
|||
</pre> |
</pre> |
||
Revision as of 13:47, 5 September 2014
Serveur d'application JavaEE open-source
Installation & Démarrage
Vérifiez la version de votre JRE : Java 7 est requis.
javac -version
Téléchargez le zip depuis https://glassfish.java.net/download.html
Lisez https://glassfish.java.net/getstarted.html
unzip glassfish-4.0-ml.zip cd glassfish4 ./bin/asadmin ./bin/asadmin start-domain
Ouvrez la console Web http://localhost:4848
IMPORTANT : Sécurisez votre console d'administration qui n'est pas sécurisé par défaut : https://glassfish.java.net/docs/4.0/security-guide.pdf
Installez le plugin Glassfish dans votre IDE : https://glassfish.java.net/ide.html
Créez une application simple Hello avec Maven
cd ..
mvn -DarchetypeGroupId=org.codehaus.mojo.archetypes \
-DarchetypeArtifactId=webapp-javaee7 \
-DarchetypeVersion=0.4-SNAPSHOT \
-DarchetypeRepository=https://nexus.codehaus.org/content/repositories/snapshots/ \
-DgroupId=fr.polytech-grenoble.ricm.ecom \
-DartifactId=hello \
-Dversion=0.1.0-SNAPSHOT \
-Dpackage=ecom \
-Darchetype.interactive=false \
--batch-mode \
--update-snapshots \
archetype:generate
Remarque: il y a d'autres archetypeArtifactId disponibles
cd hello mvn clean package
Remarque : il est possible de déployer l'artefact à l'issue du packaging en modifiant le pom.xml au préalable.
mvn clean package glassfish:deploy
Déploiement
Vous pouvez déployer votre application (ejbjar, war, ear) via la console ou bien via la ligne de commande suivante
./bin/asadmin list-applications ./bin/asadmin deploy --name hello ../hello/target/hello-0.1.0-SNAPSHOT.war ./bin/asadmin list-applications ./bin/asadmin list-applications --type war ./bin/asadmin list-sub-components --appname hello hello.ear
Ouvrez http://localhost:8080/hello-0.1.0-SNAPSHOT/
Modifiez et re-construisez votre application
en ajoutant :
- un JSP hello.jsp
- une Servlet HelloServlet.java
- une Servlet WebSocket
- une Servlet asynchrone (en utilisant les annotations JSR315)
- une Servlet HelloAServlet.java (en utilisant les annotations JSR315)
- un Filter (en utilisant les annotations JSR315)
Rédeployez celle-ci
./bin/asadmin redeploy --name hello --contextroot "hello" ../hello/target/hello-0.1.0-SNAPSHOT.war
Ouvrez
- http://localhost:8080/hello
- http://localhost:8080/hello/hello.jsp?name=Didier
- http://localhost:8080/hello/helloann?name=Didier
Regardez le contenu du journal du domaine.
tail glassfish/domains/domain1/logs/server.log
Web Service
Modifiez et r-construisez votre application en ajoutant :
- un Web Service HelloWS.java
- un RESTful Service HelloREST.java
Redéployez
Ouvrez
Générez une application client pour le WebService
cd .. mkdir hellowsclient cd hellowsclient wsimport -p fr.polytechgrenoble.ricm.ecom.ws.client http://localhost:8080/hello/HelloWSService?wsdl
RESTFul Service
Modifiez et r-construisez votre application en ajoutant :
- un RESTful Service HelloREST.java
Redéployez
Utilisez curl pour interoger le service
Undeploy
./bin/asadamin undeploy hello
Arrêt
IMPORTANT : pensez à arrêter votre serveur et la VM sur lequel il s'exécute quand vous utilisez une plateforme Cloud.
./bin/asadamin stop-domain domain1
Complément
VisualVM
Lancez la console VisualVM. Installez le plugin pour Glassfish (Tools > Plugins > Available Plugins). Relancez la console VisualVM Connectez vous au serveur en utilisant la console VisualVM.
jvisualvm &
OSGi Felix
Accès aux commandes du Gogo Shell de Felix
./bin/asadmin osgi lb -l
Lire http://docs.oracle.com/cd/E26576_01/doc.312/e24928/overview.htm#gjjxt