SlideShare una empresa de Scribd logo
1 de 29
Descargar para leer sin conexión
SEAM ON GLASSFISH
   A SLIDECAST

      DAN ALLEN
  JBOSS, A DIVISION OF RED HAT
package org.example.vehicles.action;

import javax.ejb.Remove;...

@Stateful
@Name(quot;vehicleTradequot;)
public class VehicleTradeBean implements VehicleTrade
{
    @Logger private Log log;

    @In FacesMessages facesMessages;

    private String value;

    public void trade()
    {
        log.info(quot;vehicleTrade.trade() action called with: #{vehicleTrade.value}quot;);
        facesMessages.add(quot;trade #{vehicleTrade.value}quot;);
    }

    @Length(max = 10)
    public String getValue()
    {
        return value;
    }

    public void setValue(String value)
    {
        this.value = value;
    }

    @Destroy @Remove
    public void destroy() {}

}
package org.example.vehicles.action;

import javax.ejb.Stateless;...

@Stateless
@Name(quot;authenticatorquot;)
public class AuthenticatorBean implements Authenticator
{
    @Logger private Log log;

    @In Identity identity;
    @In Credentials credentials;

    public boolean authenticate()
    {
        log.info(quot;authenticating {0}quot;, credentials.getUsername());
        //write your authentication logic here,
        //return true if the authentication was
        //successful, false otherwise
        if (quot;adminquot;.equals(credentials.getUsername()))
        {
            identity.addRole(quot;adminquot;);
            return true;
        }
        return false;
    }

}
/build.properties

jboss.home = /home/dallen/opt/jboss-as
jboss.domain = default
glassfish.home = /home/dallen/opt/glassfish-v2
glassfish.domain = domain1

                                                 Tells script which GlassFish
                                                 installation to target.
Adding GlassFish targets

  Define in separate Ant build file
  –   glassfish.build.xml
  Prefix targets to avoid naming conflict
  –   prefix: “gf-”
  Import into build.xml (before first target)
<import file=quot;${basedir}/glassfish.build.xmlquot;/>
asadmin macro
<macrodef name=quot;asadminquot;>
    <attribute name=quot;cmdquot;/>
    <attribute name=quot;argsquot; default=quot;quot;/>
    <attribute name=quot;logquot; default=quot;truequot;/>
    <element name=quot;pre-conditionsquot; optional=quot;truequot;/>
    <sequential>
        <fail unless=quot;glassfish.homequot;>glassfish.home not set</fail>
        <pre-conditions/>
        <exec executable=quot;${glassfish.home}/bin/asadminquot;>
            <arg value=quot;@{cmd}quot;/>
            <arg line=quot;@{args}quot;/>
            <redirector outputproperty=quot;gf.cmd.outputquot; alwayslog=quot;@{log}quot;/>
        </exec>
    </sequential>
</macrodef>
Using the asadmin macro

  Starting the server
<asadmin cmd=quot;start-domainquot; args=quot;${glassfish.domain}quot;>
    <pre-conditions>
        <fail unless=quot;glassfish.domainquot;>glassfish.domain not set</fail>
    </pre-conditions>
</asadmin>


  Stopping the server
<asadmin cmd=quot;stop-domainquot; args=quot;${glassfish.domain}quot;>
    <pre-conditions>
        <fail unless=quot;glassfish.domainquot;>glassfish.domain not set</fail>
    </pre-conditions>
</asadmin>


  Registering a data source
<asadmin cmd=quot;add-resourcesquot;
    args=quot;${basedir}/resources/glassfish-resources-${profile}.xmlquot;/>
<target name=quot;gf-deploy-hibernatequot;
    description=quot;Deploys Hibernate to be a JPA provider on GlassFishquot;>
    <fail unless=quot;glassfish.homequot;>glassfish.home not set</fail>
    <fail unless=quot;glassfish.domainquot;>glassfish.domain not set</fail>
    <copy todir=quot;${glassfish.home}/domains/${glassfish.domain}/lib/extquot;>
        <fileset dir=quot;${basedir}/libquot;>
            <include name=quot;antlr.jarquot;/>
            <include name=quot;asm.jarquot;/>
            <include name=quot;asm-attrs.jarquot;/>
            <include name=quot;cglib.jarquot;/>
            <include name=quot;commons-collections.jarquot;/>
            <include name=quot;commons-logging.jarquot;/>
            <include name=quot;concurrent.jarquot;/>
            <include name=quot;dom4j.jarquot;/>
            <include name=quot;hibernate.jarquot;/>
            <include name=quot;hibernate-*.jarquot;/>
            <exclude name=quot;hibernate-search.jarquot;/>
            <include name=quot;javassist.jarquot;/>
            <include name=quot;jboss-common-core.jarquot;/>
            <include name=quot;jta.jarquot;/>
            <include name=quot;persistence-api.jarquot;/>
            <include name=quot;mysql-connector-java-5.1.6.jarquot;/>
        </fileset>
    </copy>
</target>
/resources/META-INF/persistence-dev.xml

<?xml version=quot;1.0quot; encoding=quot;UTF-8quot;?>
<persistence>
    <persistence-unit name=quot;vehicleseequot;>
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <jta-data-source>vehicleseeDatasource</jta-data-source>
        <properties>
            ...
            <property name=quot;hibernate.transaction.manager_lookup_classquot;
                value=quot;@transactionManagerLookupClass@quot; />
        </properties>
    </persistence-unit>
</persistence>
                                                                  Strip proprietary JNDI
                                                                  prefix java:/
/resources/vehiclesee-dev-ds.xml

<?xml version=quot;1.0quot; encoding=quot;UTF-8quot;?>
<datasources>
   <local-tx-datasource>
      <jndi-name>vehicleseeDatasource</jndi-name>
      <use-java-context>false</use-java-context>
      <connection-url>jdbc:mysql://localhost/vehicles</connection-url>
      <driver-class>com.mysql.jdbc.Driver</driver-class>
      <user-name>dallen</user-name>
      <password>dallen</password>
   </local-tx-datasource>
</datasources>
/resources/glassfish-resources-dev.xml

<?xml version=quot;1.0quot; encoding=quot;UTF-8quot;?>
<resources>

   <jdbc-connection-pool
       name=quot;vehicleseePoolquot;
       datasource-classname=quot;com.mysql.jdbc.jdbc2.optional.MysqlDataSourcequot;
       res-type=quot;javax.sql.DataSourcequot;>
       <property name=quot;userquot; value=quot;dallenquot;/>
       <property name=quot;passwordquot; value=quot;dallenquot;/>
       <property name=quot;urlquot; value=quot;jdbc:mysql://localhost/vehiclesquot;/>
   </jdbc-connection-pool>

   <jdbc-resource                                             Uses DataSource rather
       jndi-name=quot;vehicleseeDatasourcequot;                       than JDBC driver
       pool-name=quot;vehicleseePoolquot;
       enabled=quot;truequot;
       object-type=quot;userquot;/>

</resources>
                                    JNDI name referenced           GlassFish Admin Console
                                    in persistence.xml
/build.xml (top of jar target)

<!-- defaults, can be overridden in preceding target or from commandline flag -->
<property name=quot;ejbJndiPatternquot; value=quot;${project.name}/#{ejbName}/localquot;/>
<property name=quot;transactionManagerLookupClassquot;
    value=quot;org.hibernate.transaction.SunONETransactionManagerLookupquot;/>

                                                               Token replacements for
                                                               components.properties
<filterset id=quot;seamquot;>
    <filter token=quot;ejbJndiPatternquot; value=quot;${ejbJndiPattern}quot;/>
    <filter token=quot;seamBootstrapPuquot; value=quot;${seamBootstrapPu}quot;/>
    <filter token=quot;seamEmfquot; value=quot;${seamEmf}quot;/>
    <filter token=quot;puJndiNamequot; value=quot;${puJndiName}quot;/>
</filterset>

                                                               Token replacements for
                                                               persistence.xml
<filterset id=quot;persistencequot;>
    <filter token=quot;transactionManagerLookupClassquot; value=quot;${transactionManagerLookupClass}quot;/>
</filterset>
/build.xml (jar target)

<copy tofile=quot;${jar.dir}/META-INF/persistence.xmlquot;
    file=quot;${basedir}/resources/META-INF/persistence-${profile}.xmlquot;
    overwrite=quot;truequot;>
    <filterset refid=quot;persistencequot;/>
</copy>
                                                             Apply token replacements


/build.xml (war target)

<copy tofile=quot;${war.dir}/WEB-INF/classes/components.propertiesquot;
    file=quot;${basedir}/resources/components-${profile}.propertiesquot;
    overwrite=quot;truequot;>
    <filterset refid=quot;seamquot;/>
</copy>
/resources/WEB-INF/components.xml

<components xmlns=quot;http://jboss.com/products/seam/componentsquot;
    ...
    xmlns:persistence=quot;http://jboss.com/products/seam/persistencequot;
    xsi:schemaLocation=quot;
        ...
        http://jboss.com/products/seam/persistence
        http://jboss.com/products/seam/persistence-2.1.xsdquot;>

   <persistence:entity-manager-factory name=quot;entityManagerFactoryquot;
       persistence-unit-name=quot;vehicleseequot;/>

   <persistence:managed-persistence-context name=quot;entityManagerquot;
       entity-manager-factory=quot;#{entityManagerFactory}quot; auto-create=quot;truequot;/>

</components>


                                              Seam bootstraps persistence unit ==
                                              application-managed persistence
/resources/WEB-INF/components.xml

<components xmlns=quot;http://jboss.com/products/seam/componentsquot;
    ...
    xmlns:tx=quot;http://jboss.com/products/seam/transactionquot;
    xsi:schemaLocation=quot;
        ...
        http://jboss.com/products/seam/transaction
        http://jboss.com/products/seam/transaction-2.1.xsdquot;>

   <tx:ejb-transaction/>

</components>

                                  Allows Seam to pass along transaction synchronization
                                  events to other Seam components.

                                  Before completion:

                                  - org.jboss.seam.beforeTransactionCompletion

                                  After successful completion:

                                  - org.jboss.seam.afterTransactionCompletion(true)

                                  After transaction failure:

                                  - org.jboss.seam.afterTransactionCompletion(false)
/build.xml

<copy tofile=quot;${war.dir}/WEB-INF/classes/components.propertiesquot;
    file=quot;${basedir}/resources/components-${profile}.propertiesquot;>
    <filterset refid=quot;seamquot;/>
</copy>
                                                +     /resources/components-dev.properties

                                                      jndiPattern=@ejbJndiPattern@




                         /WEB-INF/classes/components.properties

                         jndiPattern=java:comp/env/vehiclesee/#{ejbName}/local




                         /WEB-INF/components.xml

                         <components>
                             <core:init jndiPattern=quot;@jndiPattern@quot;/>
                         </compoennts>
/resources/WEB-INF/web.xml (end of file)

<ejb-local-ref>
    <ejb-ref-name>vehiclesee/EjbSynchronizations/local</ejb-ref-name>
    <ejb-ref-type>Session</ejb-ref-type>
    <local-home/>
    <local>org.jboss.seam.transaction.LocalEjbSynchronizations</local>
</ejb-local-ref>

<ejb-local-ref>
    <ejb-ref-name>vehiclesee/AuthenticatorBean/local</ejb-ref-name>
    <ejb-ref-type>Session</ejb-ref-type>
    <local-home/>
    <local>org.example.vehicles.action.Authenticator</local>
</ejb-local-ref>

<ejb-local-ref>
    <ejb-ref-name>vehiclesee/VehicleTradeBean/local</ejb-ref-name>
    <ejb-ref-type>Session</ejb-ref-type>
    <local-home/>
    <local>org.example.vehicles.action.VehicleTrade</local>
</ejb-local-ref>
/build.xml (war target)

<target name=quot;warquot; ...>
    ...
        <fileset dir=quot;${basedir}/viewquot;>
            <include name=quot;**/*.xcssquot;/>
        </fileset>
        <fileset dir=quot;${basedir}/resourcesquot;>   Add fileset to copy the provided theme
            <include name=quot;**/*.xcssquot;/>
                                               resource (theme.xcss) to the classpath
        </fileset>
    ...                                        to workaround bug in RichFaces with
</target>                                      GlassFish.
Achieving hot deploy

jboss-seam.jar must be exploded since it
contains an EJB
–   Deploy exploded EAR from staging area
–   gf-explode uses “adadmin deploydir”
Run staging target
–   gf-hotdeploy runs “ant stage”
Seam's hot deploy classloader works!
–   The catch: only works with a WAR, not an EAR
Container-managed persistence

Persistence unit must be deployed in a
separate JAR
JAR must be in EAR lib directory and
cannot be exploded
Requires additional configuration in
components.xml, persistence.xml, and
web.xml
Allows you to use @PersistenceContext
Commands to develop by
gf-start - Starts GlassFish
gf-stop - Stops GlassFish
gf-restart - Restarts GlassFish
gf-datasource - Registers the datasource and connection pool for the
profile
gf-explode - Deploys the exploded archive to GlassFish (initial)
gf-hotdeploy - Hot deploys Java classes and components (exploded only)
gf-deploy - Deploys the packaged archive to GlassFish
gf-undeploy - Undeploys the exploded or packaged archive from GlassFish
gf-deploy-hibernate - Deploys Hibernate as a JPA provider to GlassFish

Más contenido relacionado

La actualidad más candente

Zf2 how arrays will save your project
Zf2   how arrays will save your projectZf2   how arrays will save your project
Zf2 how arrays will save your project
Michelangelo van Dam
 
Hide Versus Expose
Hide Versus ExposeHide Versus Expose
Hide Versus Expose
LiquidHub
 
Jquery presentation
Jquery presentationJquery presentation
Jquery presentation
guest5d87aa6
 

La actualidad más candente (20)

Creating fast, dynamic ACLs in Zend Framework (Zend Webinar)
Creating fast, dynamic ACLs in Zend Framework (Zend Webinar)Creating fast, dynamic ACLs in Zend Framework (Zend Webinar)
Creating fast, dynamic ACLs in Zend Framework (Zend Webinar)
 
Creating fast, dynamic ACLs in Zend Framework
Creating fast, dynamic ACLs in Zend FrameworkCreating fast, dynamic ACLs in Zend Framework
Creating fast, dynamic ACLs in Zend Framework
 
New methods for exploiting ORM injections in Java applications
New methods for exploiting ORM injections in Java applicationsNew methods for exploiting ORM injections in Java applications
New methods for exploiting ORM injections in Java applications
 
Protractor Training in Pune by QuickITDotnet
Protractor Training in Pune by QuickITDotnet Protractor Training in Pune by QuickITDotnet
Protractor Training in Pune by QuickITDotnet
 
前端概述
前端概述前端概述
前端概述
 
Os Harris
Os HarrisOs Harris
Os Harris
 
Orbitz and Spring Webflow Case Study
Orbitz and Spring Webflow Case StudyOrbitz and Spring Webflow Case Study
Orbitz and Spring Webflow Case Study
 
jQuery from the very beginning
jQuery from the very beginningjQuery from the very beginning
jQuery from the very beginning
 
Introduction into Struts2 jQuery Grid Tags
Introduction into Struts2 jQuery Grid TagsIntroduction into Struts2 jQuery Grid Tags
Introduction into Struts2 jQuery Grid Tags
 
QA for PHP projects
QA for PHP projectsQA for PHP projects
QA for PHP projects
 
Zend framework 04 - forms
Zend framework 04 - formsZend framework 04 - forms
Zend framework 04 - forms
 
Zend Framework
Zend FrameworkZend Framework
Zend Framework
 
Zf2 how arrays will save your project
Zf2   how arrays will save your projectZf2   how arrays will save your project
Zf2 how arrays will save your project
 
Building High Performance Web Applications and Sites
Building High Performance Web Applications and SitesBuilding High Performance Web Applications and Sites
Building High Performance Web Applications and Sites
 
Hide Versus Expose
Hide Versus ExposeHide Versus Expose
Hide Versus Expose
 
PHPUnit Episode iv.iii: Return of the tests
PHPUnit Episode iv.iii: Return of the testsPHPUnit Episode iv.iii: Return of the tests
PHPUnit Episode iv.iii: Return of the tests
 
Os Leonard
Os LeonardOs Leonard
Os Leonard
 
Basics of Java Script (JS)
Basics of Java Script (JS)Basics of Java Script (JS)
Basics of Java Script (JS)
 
Jquery presentation
Jquery presentationJquery presentation
Jquery presentation
 
Introduction to PHP Lecture 1
Introduction to PHP Lecture 1Introduction to PHP Lecture 1
Introduction to PHP Lecture 1
 

Destacado (6)

Slideshare
SlideshareSlideshare
Slideshare
 
Ejemplo Matematicas Slideshare2
Ejemplo Matematicas Slideshare2Ejemplo Matematicas Slideshare2
Ejemplo Matematicas Slideshare2
 
Keynote Globs
Keynote GlobsKeynote Globs
Keynote Globs
 
Imagina
ImaginaImagina
Imagina
 
Letter Written In 2070
Letter Written In 2070Letter Written In 2070
Letter Written In 2070
 
Ayatli Linea De Accion 1
Ayatli Linea De Accion 1Ayatli Linea De Accion 1
Ayatli Linea De Accion 1
 

Similar a Seam Glassfish Slidecast

Solr and symfony in Harmony with SolrJs
Solr and symfony in Harmony with SolrJsSolr and symfony in Harmony with SolrJs
Solr and symfony in Harmony with SolrJs
Wildan Maulana
 
Система рендеринга в Magento
Система рендеринга в MagentoСистема рендеринга в Magento
Система рендеринга в Magento
Magecom Ukraine
 
Devclub Servicemix Jevgeni Holodkov 23 04 09
Devclub Servicemix Jevgeni Holodkov 23 04 09Devclub Servicemix Jevgeni Holodkov 23 04 09
Devclub Servicemix Jevgeni Holodkov 23 04 09
helggeist
 
GTAC: AtomPub, testing your server implementation
GTAC: AtomPub, testing your server implementationGTAC: AtomPub, testing your server implementation
GTAC: AtomPub, testing your server implementation
David Calavera
 
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
Kirill Chebunin
 

Similar a Seam Glassfish Slidecast (20)

Solr and symfony in Harmony with SolrJs
Solr and symfony in Harmony with SolrJsSolr and symfony in Harmony with SolrJs
Solr and symfony in Harmony with SolrJs
 
Extending MySQL Enterprise Monitor
Extending MySQL Enterprise MonitorExtending MySQL Enterprise Monitor
Extending MySQL Enterprise Monitor
 
Система рендеринга в Magento
Система рендеринга в MagentoСистема рендеринга в Magento
Система рендеринга в Magento
 
Migration testing framework
Migration testing frameworkMigration testing framework
Migration testing framework
 
Developing and testing ajax components
Developing and testing ajax componentsDeveloping and testing ajax components
Developing and testing ajax components
 
Devclub Servicemix Jevgeni Holodkov 23 04 09
Devclub Servicemix Jevgeni Holodkov 23 04 09Devclub Servicemix Jevgeni Holodkov 23 04 09
Devclub Servicemix Jevgeni Holodkov 23 04 09
 
GTAC: AtomPub, testing your server implementation
GTAC: AtomPub, testing your server implementationGTAC: AtomPub, testing your server implementation
GTAC: AtomPub, testing your server implementation
 
Javascript Basic
Javascript BasicJavascript Basic
Javascript Basic
 
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
 
Spring 2.0
Spring 2.0Spring 2.0
Spring 2.0
 
Spring 2.0
Spring 2.0Spring 2.0
Spring 2.0
 
Plone Interactivity
Plone InteractivityPlone Interactivity
Plone Interactivity
 
What's new in Rails 2?
What's new in Rails 2?What's new in Rails 2?
What's new in Rails 2?
 
User Experience is dead. Long live the user experience!
User Experience is dead. Long live the user experience!User Experience is dead. Long live the user experience!
User Experience is dead. Long live the user experience!
 
Ajax On S2 Odp
Ajax On S2 OdpAjax On S2 Odp
Ajax On S2 Odp
 
Struts2
Struts2Struts2
Struts2
 
Introduction to JQuery
Introduction to JQueryIntroduction to JQuery
Introduction to JQuery
 
Front End on Rails
Front End on RailsFront End on Rails
Front End on Rails
 
Page Caching Resurrected
Page Caching ResurrectedPage Caching Resurrected
Page Caching Resurrected
 
Alfresco Search Internals
Alfresco Search InternalsAlfresco Search Internals
Alfresco Search Internals
 

Más de Eduardo Pelegri-Llopart

Más de Eduardo Pelegri-Llopart (20)

Juggling at freenome
Juggling   at freenomeJuggling   at freenome
Juggling at freenome
 
Csumb capstone-fall2016
Csumb capstone-fall2016Csumb capstone-fall2016
Csumb capstone-fall2016
 
Digital activitymanagement
Digital activitymanagementDigital activitymanagement
Digital activitymanagement
 
Progress next iot_pelegri
Progress next iot_pelegriProgress next iot_pelegri
Progress next iot_pelegri
 
Pelegri Desarrollando en una nueva era de software
Pelegri   Desarrollando en una nueva era de software Pelegri   Desarrollando en una nueva era de software
Pelegri Desarrollando en una nueva era de software
 
Market trends in IT - exchange cala - October 2015
Market trends in IT - exchange cala - October 2015Market trends in IT - exchange cala - October 2015
Market trends in IT - exchange cala - October 2015
 
The impact of IOT - exchange cala - 2015
The impact of IOT - exchange cala - 2015The impact of IOT - exchange cala - 2015
The impact of IOT - exchange cala - 2015
 
IOT - Presentation to PEP @ Progress
IOT - Presentation to PEP @ ProgressIOT - Presentation to PEP @ Progress
IOT - Presentation to PEP @ Progress
 
Node.js as an IOT Bridge
Node.js as an IOT BridgeNode.js as an IOT Bridge
Node.js as an IOT Bridge
 
What is IoT and how Modulus and Pacific can Help - Featuring Node.js and Roll...
What is IoT and how Modulus and Pacific can Help - Featuring Node.js and Roll...What is IoT and how Modulus and Pacific can Help - Featuring Node.js and Roll...
What is IoT and how Modulus and Pacific can Help - Featuring Node.js and Roll...
 
What is the Internet of Things and How it Impacts You
What is the Internet of Things and How it Impacts YouWhat is the Internet of Things and How it Impacts You
What is the Internet of Things and How it Impacts You
 
Community Update 25 Mar2010 - English
Community Update 25 Mar2010 - EnglishCommunity Update 25 Mar2010 - English
Community Update 25 Mar2010 - English
 
GlassFish Community Update 25 Mar2010
GlassFish Community Update 25 Mar2010GlassFish Community Update 25 Mar2010
GlassFish Community Update 25 Mar2010
 
Glass Fish Portfolio C1 West V3.Mini
Glass Fish Portfolio C1 West V3.MiniGlass Fish Portfolio C1 West V3.Mini
Glass Fish Portfolio C1 West V3.Mini
 
Virtual Box Aquarium May09
Virtual Box Aquarium May09Virtual Box Aquarium May09
Virtual Box Aquarium May09
 
Introduction To Web Beans
Introduction To Web BeansIntroduction To Web Beans
Introduction To Web Beans
 
Ehcache Architecture, Features And Usage Patterns
Ehcache Architecture, Features And Usage PatternsEhcache Architecture, Features And Usage Patterns
Ehcache Architecture, Features And Usage Patterns
 
OpenDS Primer Aquarium
OpenDS Primer AquariumOpenDS Primer Aquarium
OpenDS Primer Aquarium
 
Fuji Overview
Fuji OverviewFuji Overview
Fuji Overview
 
Nuxeo 5.2 Glassfish
Nuxeo 5.2 GlassfishNuxeo 5.2 Glassfish
Nuxeo 5.2 Glassfish
 

Último

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Último (20)

Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 

Seam Glassfish Slidecast

  • 1. SEAM ON GLASSFISH A SLIDECAST DAN ALLEN JBOSS, A DIVISION OF RED HAT
  • 2.
  • 3.
  • 4.
  • 5.
  • 6. package org.example.vehicles.action; import javax.ejb.Remove;... @Stateful @Name(quot;vehicleTradequot;) public class VehicleTradeBean implements VehicleTrade { @Logger private Log log; @In FacesMessages facesMessages; private String value; public void trade() { log.info(quot;vehicleTrade.trade() action called with: #{vehicleTrade.value}quot;); facesMessages.add(quot;trade #{vehicleTrade.value}quot;); } @Length(max = 10) public String getValue() { return value; } public void setValue(String value) { this.value = value; } @Destroy @Remove public void destroy() {} }
  • 7. package org.example.vehicles.action; import javax.ejb.Stateless;... @Stateless @Name(quot;authenticatorquot;) public class AuthenticatorBean implements Authenticator { @Logger private Log log; @In Identity identity; @In Credentials credentials; public boolean authenticate() { log.info(quot;authenticating {0}quot;, credentials.getUsername()); //write your authentication logic here, //return true if the authentication was //successful, false otherwise if (quot;adminquot;.equals(credentials.getUsername())) { identity.addRole(quot;adminquot;); return true; } return false; } }
  • 8.
  • 9.
  • 10. /build.properties jboss.home = /home/dallen/opt/jboss-as jboss.domain = default glassfish.home = /home/dallen/opt/glassfish-v2 glassfish.domain = domain1 Tells script which GlassFish installation to target.
  • 11. Adding GlassFish targets Define in separate Ant build file – glassfish.build.xml Prefix targets to avoid naming conflict – prefix: “gf-” Import into build.xml (before first target) <import file=quot;${basedir}/glassfish.build.xmlquot;/>
  • 12. asadmin macro <macrodef name=quot;asadminquot;> <attribute name=quot;cmdquot;/> <attribute name=quot;argsquot; default=quot;quot;/> <attribute name=quot;logquot; default=quot;truequot;/> <element name=quot;pre-conditionsquot; optional=quot;truequot;/> <sequential> <fail unless=quot;glassfish.homequot;>glassfish.home not set</fail> <pre-conditions/> <exec executable=quot;${glassfish.home}/bin/asadminquot;> <arg value=quot;@{cmd}quot;/> <arg line=quot;@{args}quot;/> <redirector outputproperty=quot;gf.cmd.outputquot; alwayslog=quot;@{log}quot;/> </exec> </sequential> </macrodef>
  • 13. Using the asadmin macro Starting the server <asadmin cmd=quot;start-domainquot; args=quot;${glassfish.domain}quot;> <pre-conditions> <fail unless=quot;glassfish.domainquot;>glassfish.domain not set</fail> </pre-conditions> </asadmin> Stopping the server <asadmin cmd=quot;stop-domainquot; args=quot;${glassfish.domain}quot;> <pre-conditions> <fail unless=quot;glassfish.domainquot;>glassfish.domain not set</fail> </pre-conditions> </asadmin> Registering a data source <asadmin cmd=quot;add-resourcesquot; args=quot;${basedir}/resources/glassfish-resources-${profile}.xmlquot;/>
  • 14. <target name=quot;gf-deploy-hibernatequot; description=quot;Deploys Hibernate to be a JPA provider on GlassFishquot;> <fail unless=quot;glassfish.homequot;>glassfish.home not set</fail> <fail unless=quot;glassfish.domainquot;>glassfish.domain not set</fail> <copy todir=quot;${glassfish.home}/domains/${glassfish.domain}/lib/extquot;> <fileset dir=quot;${basedir}/libquot;> <include name=quot;antlr.jarquot;/> <include name=quot;asm.jarquot;/> <include name=quot;asm-attrs.jarquot;/> <include name=quot;cglib.jarquot;/> <include name=quot;commons-collections.jarquot;/> <include name=quot;commons-logging.jarquot;/> <include name=quot;concurrent.jarquot;/> <include name=quot;dom4j.jarquot;/> <include name=quot;hibernate.jarquot;/> <include name=quot;hibernate-*.jarquot;/> <exclude name=quot;hibernate-search.jarquot;/> <include name=quot;javassist.jarquot;/> <include name=quot;jboss-common-core.jarquot;/> <include name=quot;jta.jarquot;/> <include name=quot;persistence-api.jarquot;/> <include name=quot;mysql-connector-java-5.1.6.jarquot;/> </fileset> </copy> </target>
  • 15. /resources/META-INF/persistence-dev.xml <?xml version=quot;1.0quot; encoding=quot;UTF-8quot;?> <persistence> <persistence-unit name=quot;vehicleseequot;> <provider>org.hibernate.ejb.HibernatePersistence</provider> <jta-data-source>vehicleseeDatasource</jta-data-source> <properties> ... <property name=quot;hibernate.transaction.manager_lookup_classquot; value=quot;@transactionManagerLookupClass@quot; /> </properties> </persistence-unit> </persistence> Strip proprietary JNDI prefix java:/ /resources/vehiclesee-dev-ds.xml <?xml version=quot;1.0quot; encoding=quot;UTF-8quot;?> <datasources> <local-tx-datasource> <jndi-name>vehicleseeDatasource</jndi-name> <use-java-context>false</use-java-context> <connection-url>jdbc:mysql://localhost/vehicles</connection-url> <driver-class>com.mysql.jdbc.Driver</driver-class> <user-name>dallen</user-name> <password>dallen</password> </local-tx-datasource> </datasources>
  • 16. /resources/glassfish-resources-dev.xml <?xml version=quot;1.0quot; encoding=quot;UTF-8quot;?> <resources> <jdbc-connection-pool name=quot;vehicleseePoolquot; datasource-classname=quot;com.mysql.jdbc.jdbc2.optional.MysqlDataSourcequot; res-type=quot;javax.sql.DataSourcequot;> <property name=quot;userquot; value=quot;dallenquot;/> <property name=quot;passwordquot; value=quot;dallenquot;/> <property name=quot;urlquot; value=quot;jdbc:mysql://localhost/vehiclesquot;/> </jdbc-connection-pool> <jdbc-resource Uses DataSource rather jndi-name=quot;vehicleseeDatasourcequot; than JDBC driver pool-name=quot;vehicleseePoolquot; enabled=quot;truequot; object-type=quot;userquot;/> </resources> JNDI name referenced GlassFish Admin Console in persistence.xml
  • 17. /build.xml (top of jar target) <!-- defaults, can be overridden in preceding target or from commandline flag --> <property name=quot;ejbJndiPatternquot; value=quot;${project.name}/#{ejbName}/localquot;/> <property name=quot;transactionManagerLookupClassquot; value=quot;org.hibernate.transaction.SunONETransactionManagerLookupquot;/> Token replacements for components.properties <filterset id=quot;seamquot;> <filter token=quot;ejbJndiPatternquot; value=quot;${ejbJndiPattern}quot;/> <filter token=quot;seamBootstrapPuquot; value=quot;${seamBootstrapPu}quot;/> <filter token=quot;seamEmfquot; value=quot;${seamEmf}quot;/> <filter token=quot;puJndiNamequot; value=quot;${puJndiName}quot;/> </filterset> Token replacements for persistence.xml <filterset id=quot;persistencequot;> <filter token=quot;transactionManagerLookupClassquot; value=quot;${transactionManagerLookupClass}quot;/> </filterset>
  • 18. /build.xml (jar target) <copy tofile=quot;${jar.dir}/META-INF/persistence.xmlquot; file=quot;${basedir}/resources/META-INF/persistence-${profile}.xmlquot; overwrite=quot;truequot;> <filterset refid=quot;persistencequot;/> </copy> Apply token replacements /build.xml (war target) <copy tofile=quot;${war.dir}/WEB-INF/classes/components.propertiesquot; file=quot;${basedir}/resources/components-${profile}.propertiesquot; overwrite=quot;truequot;> <filterset refid=quot;seamquot;/> </copy>
  • 19. /resources/WEB-INF/components.xml <components xmlns=quot;http://jboss.com/products/seam/componentsquot; ... xmlns:persistence=quot;http://jboss.com/products/seam/persistencequot; xsi:schemaLocation=quot; ... http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.1.xsdquot;> <persistence:entity-manager-factory name=quot;entityManagerFactoryquot; persistence-unit-name=quot;vehicleseequot;/> <persistence:managed-persistence-context name=quot;entityManagerquot; entity-manager-factory=quot;#{entityManagerFactory}quot; auto-create=quot;truequot;/> </components> Seam bootstraps persistence unit == application-managed persistence
  • 20. /resources/WEB-INF/components.xml <components xmlns=quot;http://jboss.com/products/seam/componentsquot; ... xmlns:tx=quot;http://jboss.com/products/seam/transactionquot; xsi:schemaLocation=quot; ... http://jboss.com/products/seam/transaction http://jboss.com/products/seam/transaction-2.1.xsdquot;> <tx:ejb-transaction/> </components> Allows Seam to pass along transaction synchronization events to other Seam components. Before completion: - org.jboss.seam.beforeTransactionCompletion After successful completion: - org.jboss.seam.afterTransactionCompletion(true) After transaction failure: - org.jboss.seam.afterTransactionCompletion(false)
  • 21. /build.xml <copy tofile=quot;${war.dir}/WEB-INF/classes/components.propertiesquot; file=quot;${basedir}/resources/components-${profile}.propertiesquot;> <filterset refid=quot;seamquot;/> </copy> + /resources/components-dev.properties jndiPattern=@ejbJndiPattern@ /WEB-INF/classes/components.properties jndiPattern=java:comp/env/vehiclesee/#{ejbName}/local /WEB-INF/components.xml <components> <core:init jndiPattern=quot;@jndiPattern@quot;/> </compoennts>
  • 22. /resources/WEB-INF/web.xml (end of file) <ejb-local-ref> <ejb-ref-name>vehiclesee/EjbSynchronizations/local</ejb-ref-name> <ejb-ref-type>Session</ejb-ref-type> <local-home/> <local>org.jboss.seam.transaction.LocalEjbSynchronizations</local> </ejb-local-ref> <ejb-local-ref> <ejb-ref-name>vehiclesee/AuthenticatorBean/local</ejb-ref-name> <ejb-ref-type>Session</ejb-ref-type> <local-home/> <local>org.example.vehicles.action.Authenticator</local> </ejb-local-ref> <ejb-local-ref> <ejb-ref-name>vehiclesee/VehicleTradeBean/local</ejb-ref-name> <ejb-ref-type>Session</ejb-ref-type> <local-home/> <local>org.example.vehicles.action.VehicleTrade</local> </ejb-local-ref>
  • 23. /build.xml (war target) <target name=quot;warquot; ...> ... <fileset dir=quot;${basedir}/viewquot;> <include name=quot;**/*.xcssquot;/> </fileset> <fileset dir=quot;${basedir}/resourcesquot;> Add fileset to copy the provided theme <include name=quot;**/*.xcssquot;/> resource (theme.xcss) to the classpath </fileset> ... to workaround bug in RichFaces with </target> GlassFish.
  • 24.
  • 25.
  • 26.
  • 27. Achieving hot deploy jboss-seam.jar must be exploded since it contains an EJB – Deploy exploded EAR from staging area – gf-explode uses “adadmin deploydir” Run staging target – gf-hotdeploy runs “ant stage” Seam's hot deploy classloader works! – The catch: only works with a WAR, not an EAR
  • 28. Container-managed persistence Persistence unit must be deployed in a separate JAR JAR must be in EAR lib directory and cannot be exploded Requires additional configuration in components.xml, persistence.xml, and web.xml Allows you to use @PersistenceContext
  • 29. Commands to develop by gf-start - Starts GlassFish gf-stop - Stops GlassFish gf-restart - Restarts GlassFish gf-datasource - Registers the datasource and connection pool for the profile gf-explode - Deploys the exploded archive to GlassFish (initial) gf-hotdeploy - Hot deploys Java classes and components (exploded only) gf-deploy - Deploys the packaged archive to GlassFish gf-undeploy - Undeploys the exploded or packaged archive from GlassFish gf-deploy-hibernate - Deploys Hibernate as a JPA provider to GlassFish