Difference between revisions of "EclipseLink/Examples/JPA/GlassFishV3 Web Tutorial"

From Eclipsepedia

Jump to: navigation, search
m (Enabling the Security Manager in GlassFish 3)
m (Enabling the Security Manager in GlassFish 3)
Line 191: Line 191:
 
[#|2011-01-14T12:18:45.513-0430|INFO|glassfish3.0.1|javax.enterprise.system.core.security.com.sun.enterprise.security|_ThreadID=11;_ThreadName=Thread-1;|SEC1001: Security Manager is ON.|#]
 
[#|2011-01-14T12:18:45.513-0430|INFO|glassfish3.0.1|javax.enterprise.system.core.security.com.sun.enterprise.security|_ThreadID=11;_ThreadName=Thread-1;|SEC1001: Security Manager is ON.|#]
 
</source>
 
</source>
 +
*If you attach JConsole to your secured GlassFish 3.0.1 or 3.1 server after you exercise the EE application ''(to create a session)'' you will see the following view.
 +
[[Image:Jconsole_mbean_view_security_manager_on_glassfish301.JPG]]
  
 
==References==
 
==References==

Revision as of 13:17, 14 January 2011

Contents

EclipseLink JPA Deployed on GlassFish 3 using Eclipse 3.5

Please refer to the GlassFish V2 page for generic EclipseLink on GlassFish Issues. --old content start-- If you want to get a small web application running quickly on the GlassFish V3 application server using the Eclipse IDE, follow the instructions in this tutorial.

This basic example details how to use Eclipse to run/debug a minimum J2EE 5/6 web application servlet using EclipseLink JPA as the persistence provider. The goal of this example is to detail the minimum steps needed to run EclipseLink inside GlassFish V3 using the Eclipse IDE - at this point no presentation/controller layer such as JSF, Spring or Struts will be used beyond a basic HttpServlet so we can concentrate on the the integration layer JPA setup.

The DALI project was used to generate Entities from a schema with sequences already populated.

Tutorial Source

And the DDL generation J2SE JPA application used to populate the database schema.

http://dev.eclipse.org/svnroot/rt/org.eclipse.persistence/trunk/examples/org.eclipse.persistence.example.jpa.server.common.ddlgen

Development Environment

Software: Eclipse IDE for Java EE 3.5 Galileo (June 2009 +) , JavaDB (part of GlassFish), SUN Java JDK 1.6.0_xx, GlassFish V3 Prelude

This example will also run fine with any Database that EclipseLink supports.

Prerequisites

Install Eclipse EE

  • I installed a clean version of Eclipse 3.5 Galileo (June 2009)

Install a Database

  • In this example I am the included JavaDB that is part of GlassFish V3, the table schemas have already been created manually and all entity java classes have been generated using the Eclipse DALI tool.

Install GlassFish

Install Glassfish Tools Bundle for Eclipse

Install Eclipse GlassFish Server Plugin

  • Currently the "Download additional server adapters" link on the "New Server" dialog will not work with Eclipse 3.5 - Use the "Help | Install New Software" menu instead via the https://ajax.dev.java.net/eclipse/site.xml update site to get version 32+ of the plugin that is compatible with Galileo.
    • You may refer to the details of Eclipse Bug # 280365.
  • Currently we get
    • cannot Deploy org.eclipse.persistence.example.jpa.server.glassfishv3.EnterpriseEAR
 Deployment Error for module: org.eclipse.persistence.example.jpa.server.glassfishv3.EnterpriseEAR: Exception while deploying the app : java.lang.IllegalArgumentException: Application [org.eclipse.persistence.example.jpa.server.glassfishv3.EnterpriseEAR] contains no valid components%%%EOL%%%

EclipseLink Library Location

  • The EclipseLink modules ship as 5 separate jars in the standard modules directory (Note EclipseLink SDO and JAXB are precluded by the libraries shipped with GlassFish - the milestone version is from the JPA 2.0 trunk branch.
    • \glassfish\modules
      • org.eclipse.persistence.antlr.jar
      • org.eclipse.persistence.asm.jar
      • org.eclipse.persistence.core.jar
      • org.eclipse.persistence.jpa.jar
      • org.eclipse.persistence.jpa.modelgen.jar
      • org.eclipse.persistence.oracle.jar (optional)

JPA Specification Library Location

  • javax.persistence.jar ships with GlassFish in the standard modules directory.

Updating EclipseLink Bundles Shipped with GlassFish

Progress

  • NetBeans 6.8.1M1 20090822 with an embedded GlassFish b58 is working fine.
  • I am testing on NetBeans from now on and will investigate ant/eclipse deployment later
  • All of deployment, JNDI setup, persistence.xml configuration, jpql query example - in progress ......


--old content end--

Deploying a secure EAR on GlassFish

  • This section 20110112
  • Download Eclipse 3.6 Helios EE edition
  • Update the server plugins by adding the latest Oracle GlassFish Server Tools Plugin - GlassFish 3 OSS and Commercial will arrive with this one.
    • "Download additional server adapters" link on the top right of the define a new server dialog
    • Use Oracle GlassFish Server Tools - 1.6.1 version
  • Download GlassFish 3.0.1 standalone EE server (not the one in NetBeans) so we can create a server in Eclipse
  • Use the default derby datasource
[#|2011-01-13T12:03:09.065-0430|CONFIG|oracle-glassfish3.0.1|org.eclipse.persistence.session.file:/C:/opt/glassfishv301com/glassfish/domains/domain1/applications/org.eclipse.persistence.example.jpa.server.glassfishv3.EnterpriseEAR
/org.eclipse.persistence.example.jpa.server.glassfishv3.EnterpriseEJB_jar/
_enterprise.connection|_ThreadID=29;_ThreadName=Thread-1;
|Connected: jdbc:derby://localhost:1527/sun-appserv-samples;;create=true
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
    <persistence-unit name="enterprise" transaction-type="JTA">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <jta-data-source>jdbc/__default</jta-data-source>
        <properties>
            <property name="eclipselink.target-server" value="SunAS9"/>
            <!-- property name="eclipselink.target-database" 
                      value="org.eclipse.persistence.platform.database.DerbyPlatform"/-->
            <property name="eclipselink.logging.level" value="FINEST"/>
            <!-- turn off DDL generation after the model is stable -->            
            <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
            <property name="eclipselink.ddl-generation.output-mode" value="database"/>
        </properties>
    </persistence-unit>
</persistence>
  • Create EAR application
  • Deploy or drop EAR on server
    • GlassFish V3.0.1 is running EclipseLink 2.0.1 SVN rev# 6600 from Feb 2010
[#|2011-01-13T12:03:09.049-0430|INFO|oracle-glassfish3.0.1|org.eclipse.persistence.session.file:/C:/opt/glassfishv301com/glassfish/domains/domain1/applications/org.eclipse.persistence.example.jpa.server.glassfishv3.EnterpriseEAR
/org.eclipse.persistence.example.jpa.server.glassfishv3.EnterpriseEJB_jar/_enterprise
|_ThreadID=29;_ThreadName=Thread-1;|EclipseLink, version: Eclipse Persistence Services - 2.0.1.v20100213-r6600|#]
  • Browser results

Glassfishv013 enterprise app browser screencap.JPG

  • Now we will secure GlassFish and upgrade EclipseLink to the latest 2.3 version so we can debug sychronized source in Eclipse.
    • Creating GlassFish bundles (5) from the EclipseLink trunk
    • Run the following target
C:\view_22a\2.2\trunk>ant dev-package-bundles
look in
C:\view_22a\2.2\trunk\plugins
  • Note:The updated bundles are picked up by timestamp - you will need to clear the osgi-cache if the dates are older than the bundles currently on the modules dir.

Enabling the Security Manager in GlassFish 3

  • In the following $GlassFish$/glassfish/bin directory off the server perform these commands to run on the security manager (off by default in WebLogic and GlassFish)
  • Turning on the security manager in GlassFish is very simple. It is WebLogic that has some issues that we need to look at surrounding any custom JTA datasources and their specific grants
  • Just an fyi that no Grant elements are required in the EAR if you use the default datasource.
<jta-data-source>jdbc/__default</jta-data-source>
  • We can use the existing code for both and configure the server on the fly by creating and deleting the following two security properties.
asadmin start-domain
asadmin --user admin create-jvm-options -Djava.security.manager
asadmin --user admin create-jvm-options -Declipselink.security.usedoprivileged=true
asadmin stop-domain
asadmin start-domain
  • Look for the following log to verify.
[#|2011-01-14T12:18:45.513-0430|INFO|glassfish3.0.1|javax.enterprise.system.core.security.com.sun.enterprise.security|_ThreadID=11;_ThreadName=Thread-1;|SEC1001: Security Manager is ON.|#]
  • If you attach JConsole to your secured GlassFish 3.0.1 or 3.1 server after you exercise the EE application (to create a session) you will see the following view.

Jconsole mbean view security manager on glassfish301.JPG

References