SlideShare a Scribd company logo
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

More Related Content

What's hot

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
 

What's hot (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
 

Viewers also liked (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 to 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 to 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
 

More from Eduardo Pelegri-Llopart

More from 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
 

Recently uploaded

Recently uploaded (20)

From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutes
 
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone KomSalesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
 
What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
 
IESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIESVE for Early Stage Design and Planning
IESVE for Early Stage Design and Planning
 
AI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekAI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří Karpíšek
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
 
UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Optimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through ObservabilityOptimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through Observability
 
IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024
 

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