Seam Glassfish Slidecast

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    Favorites, Groups & Events

    Seam Glassfish Slidecast - Presentation Transcript

    1. SEAM ON GLASSFISH A SLIDECAST DAN ALLEN JBOSS, A DIVISION OF RED HAT
    2. package org.example.vehicles.action; import javax.ejb.Remove;... @Stateful @Name(\"vehicleTrade\") public class VehicleTradeBean implements VehicleTrade { @Logger private Log log; @In FacesMessages facesMessages; private String value; public void trade() { log.info(\"vehicleTrade.trade() action called with: #{vehicleTrade.value}\"); facesMessages.add(\"trade #{vehicleTrade.value}\"); } @Length(max = 10) public String getValue() { return value; } public void setValue(String value) { this.value = value; } @Destroy @Remove public void destroy() {} }
    3. package org.example.vehicles.action; import javax.ejb.Stateless;... @Stateless @Name(\"authenticator\") public class AuthenticatorBean implements Authenticator { @Logger private Log log; @In Identity identity; @In Credentials credentials; public boolean authenticate() { log.info(\"authenticating {0}\", credentials.getUsername()); //write your authentication logic here, //return true if the authentication was //successful, false otherwise if (\"admin\".equals(credentials.getUsername())) { identity.addRole(\"admin\"); return true; } return false; } }
    4. /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.
    5. 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=\"${basedir}/glassfish.build.xml\"/>
    6. asadmin macro <macrodef name=\"asadmin\"> <attribute name=\"cmd\"/> <attribute name=\"args\" default=\"\"/> <attribute name=\"log\" default=\"true\"/> <element name=\"pre-conditions\" optional=\"true\"/> <sequential> <fail unless=\"glassfish.home\">glassfish.home not set</fail> <pre-conditions/> <exec executable=\"${glassfish.home}/bin/asadmin\"> <arg value=\"@{cmd}\"/> <arg line=\"@{args}\"/> <redirector outputproperty=\"gf.cmd.output\" alwayslog=\"@{log}\"/> </exec> </sequential> </macrodef>
    7. Using the asadmin macro Starting the server <asadmin cmd=\"start-domain\" args=\"${glassfish.domain}\"> <pre-conditions> <fail unless=\"glassfish.domain\">glassfish.domain not set</fail> </pre-conditions> </asadmin> Stopping the server <asadmin cmd=\"stop-domain\" args=\"${glassfish.domain}\"> <pre-conditions> <fail unless=\"glassfish.domain\">glassfish.domain not set</fail> </pre-conditions> </asadmin> Registering a data source <asadmin cmd=\"add-resources\" args=\"${basedir}/resources/glassfish-resources-${profile}.xml\"/>
    8. <target name=\"gf-deploy-hibernate\" description=\"Deploys Hibernate to be a JPA provider on GlassFish\"> <fail unless=\"glassfish.home\">glassfish.home not set</fail> <fail unless=\"glassfish.domain\">glassfish.domain not set</fail> <copy todir=\"${glassfish.home}/domains/${glassfish.domain}/lib/ext\"> <fileset dir=\"${basedir}/lib\"> <include name=\"antlr.jar\"/> <include name=\"asm.jar\"/> <include name=\"asm-attrs.jar\"/> <include name=\"cglib.jar\"/> <include name=\"commons-collections.jar\"/> <include name=\"commons-logging.jar\"/> <include name=\"concurrent.jar\"/> <include name=\"dom4j.jar\"/> <include name=\"hibernate.jar\"/> <include name=\"hibernate-*.jar\"/> <exclude name=\"hibernate-search.jar\"/> <include name=\"javassist.jar\"/> <include name=\"jboss-common-core.jar\"/> <include name=\"jta.jar\"/> <include name=\"persistence-api.jar\"/> <include name=\"mysql-connector-java-5.1.6.jar\"/> </fileset> </copy> </target>
    9. /resources/META-INF/persistence-dev.xml <?xml version=\"1.0\" encoding=\"UTF-8\"?> <persistence> <persistence-unit name=\"vehiclesee\"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <jta-data-source>vehicleseeDatasource</jta-data-source> <properties> ... <property name=\"hibernate.transaction.manager_lookup_class\" value=\"@transactionManagerLookupClass@\" /> </properties> </persistence-unit> </persistence> Strip proprietary JNDI prefix java:/ /resources/vehiclesee-dev-ds.xml <?xml version=\"1.0\" encoding=\"UTF-8\"?> <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>
    10. /resources/glassfish-resources-dev.xml <?xml version=\"1.0\" encoding=\"UTF-8\"?> <resources> <jdbc-connection-pool name=\"vehicleseePool\" datasource-classname=\"com.mysql.jdbc.jdbc2.optional.MysqlDataSource\" res-type=\"javax.sql.DataSource\"> <property name=\"user\" value=\"dallen\"/> <property name=\"password\" value=\"dallen\"/> <property name=\"url\" value=\"jdbc:mysql://localhost/vehicles\"/> </jdbc-connection-pool> <jdbc-resource Uses DataSource rather jndi-name=\"vehicleseeDatasource\" than JDBC driver pool-name=\"vehicleseePool\" enabled=\"true\" object-type=\"user\"/> </resources> JNDI name referenced GlassFish Admin Console in persistence.xml
    11. /build.xml (top of jar target) <!-- defaults, can be overridden in preceding target or from commandline flag --> <property name=\"ejbJndiPattern\" value=\"${project.name}/#{ejbName}/local\"/> <property name=\"transactionManagerLookupClass\" value=\"org.hibernate.transaction.SunONETransactionManagerLookup\"/> Token replacements for components.properties <filterset id=\"seam\"> <filter token=\"ejbJndiPattern\" value=\"${ejbJndiPattern}\"/> <filter token=\"seamBootstrapPu\" value=\"${seamBootstrapPu}\"/> <filter token=\"seamEmf\" value=\"${seamEmf}\"/> <filter token=\"puJndiName\" value=\"${puJndiName}\"/> </filterset> Token replacements for persistence.xml <filterset id=\"persistence\"> <filter token=\"transactionManagerLookupClass\" value=\"${transactionManagerLookupClass}\"/> </filterset>
    12. /build.xml (jar target) <copy tofile=\"${jar.dir}/META-INF/persistence.xml\" file=\"${basedir}/resources/META-INF/persistence-${profile}.xml\" overwrite=\"true\"> <filterset refid=\"persistence\"/> </copy> Apply token replacements /build.xml (war target) <copy tofile=\"${war.dir}/WEB-INF/classes/components.properties\" file=\"${basedir}/resources/components-${profile}.properties\" overwrite=\"true\"> <filterset refid=\"seam\"/> </copy>
    13. /resources/WEB-INF/components.xml <components xmlns=\"http://jboss.com/products/seam/components\" ... xmlns:persistence=\"http://jboss.com/products/seam/persistence\" xsi:schemaLocation=\" ... http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.1.xsd\"> <persistence:entity-manager-factory name=\"entityManagerFactory\" persistence-unit-name=\"vehiclesee\"/> <persistence:managed-persistence-context name=\"entityManager\" entity-manager-factory=\"#{entityManagerFactory}\" auto-create=\"true\"/> </components> Seam bootstraps persistence unit == application-managed persistence
    14. /resources/WEB-INF/components.xml <components xmlns=\"http://jboss.com/products/seam/components\" ... xmlns:tx=\"http://jboss.com/products/seam/transaction\" xsi:schemaLocation=\" ... http://jboss.com/products/seam/transaction http://jboss.com/products/seam/transaction-2.1.xsd\"> <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)
    15. /build.xml <copy tofile=\"${war.dir}/WEB-INF/classes/components.properties\" file=\"${basedir}/resources/components-${profile}.properties\"> <filterset refid=\"seam\"/> </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=\"@jndiPattern@\"/> </compoennts>
    16. /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>
    17. /build.xml (war target) <target name=\"war\" ...> ... <fileset dir=\"${basedir}/view\"> <include name=\"**/*.xcss\"/> </fileset> <fileset dir=\"${basedir}/resources\"> Add fileset to copy the provided theme <include name=\"**/*.xcss\"/> resource (theme.xcss) to the classpath </fileset> ... to workaround bug in RichFaces with </target> GlassFish.
    18. 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
    19. 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
    20. 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

    + pelegripelegri, 2 years ago

    custom

    3470 views, 0 favs, 0 embeds more stats

    A SlideCast on how to use GlassFish and Seam togeth more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 3470
      • 3470 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 0
    • Downloads 98
    Most viewed embeds

    more

    All embeds

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories