Friday September 04, 2009
TOTD #101: Applying Servlet 3.0/Java EE 6 “web-fragment.xml” to Lift – Deploy on GlassFish v3
TOTD #100 explained how to deploy Lift framework applications on GlassFish v3. As explained in TOTD #91, Java EE 6 defines how the framework configuration deployment descriptor can be defined in “META-INF/web-fragment.xml” in the JAR file of the framework instead of mixing it with "WEB-INF/web.xml" which is intended for application deployment descriptor aspects.
This Tip Of The Day (TOTD) explains how to leverage ”web-fragment.xml” to deploy a Lift application on a Java EE 6 compliant container. The original "lift-*.jar" files are untouched and instead a new JAR file is included that contains only the framework configuration deployment descriptor.
The generated "web.xml" from TOTD #100 looks like:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<filter>
<filter-name>LiftFilter</filter-name>
<display-name>Lift Filter</display-name>
<description>The Filter that intercepts lift calls</description>
<filter-class>net.liftweb.http.LiftFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>LiftFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
The deployment descriptor defines a Servlet Filter (LiftFilter) that registers the Lift framework with the Web container. And then it defines a URL mapping to "/*". All of this information is required by the Lift framework for request dispatching. And so that makes this fragment suitable for "web-fragment.xml".
Here are simple steps to make this change:
<dependencies>
. . .
<!– web-fragment –>
<dependency>
<groupId>org.glassfish.extras</groupId>
<artifactId>lift-web-fragment</artifactId>
<version>1.0</version>
<scope>runtime</scope>
</dependency>
</dependencies>
. . .
<repositories>
<repository>
<id>maven2-repository.dev.java.net</id>
<name>Java.net Repository for Maven</name>
<url>http://download.java.net/maven/2/</url>
</repository>
</repositories>
This file contains only “META-INF/web-fragment.xml” with the following content:
<web-fragment>
<filter>
<filter-name>LiftFilter</filter-name>
<display-name>Lift Filter</display-name>
<description>The Filter that intercepts lift calls</description>
<filter-class>net.liftweb.http.LiftFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>LiftFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-fragment>
<build>
. . .
<plugins>
. . .
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1-beta-1</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
That's it, now now you can create a WAR file using “mvn package” and deploy this web application on GlassFish v3 latest promoted build (61 as of today) as explained in TOTD #100.
Technorati: totd glassfish v3 lift scala javaee6 servlet web-fragment
Posted by Arun Gupta in General | Comments[0]
|
|
|
|
|
Thursday September 03, 2009
TOTD #100: Getting Started with Scala Lift on GlassFish v3
Yaaay, 100th tip! Read earlier tips here.
![]() |
Scala is a strongly typed JVM language that provides benefits of functional programming and dynamic languages on the JVM. As a result you get flexibility of language such as Ruby and performance of Java. Lift is an MVC-based Web framework, based on Scala, that claims to pick the best of Rails (ease of development), Seaside (highly granular sessions and security), Django (access control), and Wicket (designer-friendly templating system). |
Lift applications can run inside any Java application server. GlassFish v3 can run Rails and Django applications natively and can also run Wicket applications. This Tip Of The Day (TOTD) explains how to get started with Lift applications and run inside GlassFish v3.
~/samples/v3/lift >mvn archetype:generate -U -DarchetypeGroupId=net.liftweb
-DarchetypeArtifactId=lift-archetype-blank -DarchetypeVersion=1.0
-DremoteRepositories=http://scala-tools.org/repo-releases
-DgroupId=demo.helloworld -DartifactId=helloworld
-Dversion=1.0-SNAPSHOT
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'archetype'.
[INFO] org.apache.maven.plugins: checking for updates from central
. . .
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 14 seconds
[INFO] Finished at: Tue Sep 01 16:11:34 PDT 2009
[INFO] Final Memory: 12M/80M
[INFO] ------------------------------------------------------------------------
~/samples/v3/lift/helloworld >find .
.
./pom.xml
./src
./src/main
./src/main/resources
./src/main/scala
./src/main/scala/bootstrap
./src/main/scala/bootstrap/liftweb
./src/main/scala/bootstrap/liftweb/Boot.scala
./src/main/scala/demo
./src/main/scala/demo/helloworld
./src/main/scala/demo/helloworld/comet
./src/main/scala/demo/helloworld/comet/.keep
./src/main/scala/demo/helloworld/model
./src/main/scala/demo/helloworld/model/.keep
./src/main/scala/demo/helloworld/snippet
./src/main/scala/demo/helloworld/snippet/.keep
./src/main/scala/demo/helloworld/snippet/HelloWorld.scala
./src/main/scala/demo/helloworld/view
./src/main/scala/demo/helloworld/view/.keep
./src/main/webapp
./src/main/webapp/index.html
./src/main/webapp/templates-hidden
./src/main/webapp/templates-hidden/default.html
./src/main/webapp/WEB-INF
./src/main/webapp/WEB-INF/web.xml
./src/test
./src/test/resources
./src/test/scala
./src/test/scala/demo
./src/test/scala/demo/helloworld
./src/test/scala/demo/helloworld/AppTest.scala
./src/test/scala/LiftConsole.scala
./src/test/scala/RunWebApp.scala
~/samples/v3/lift/helloworld >mvn package [INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building helloworld
[INFO] task-segment: [package]
[INFO] ------------------------------------------------------------------------
[INFO] artifact org.scala-tools:maven-scala-plugin: checking for updates from scala-tools.org
[INFO] artifact org.scala-tools:maven-scala-plugin: checking for updates from central
. . .
[INFO] Building war: /Users/arungupta/samples/v3/lift/helloworld/target/helloworld-1.0-SNAPSHOT.war
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 9 minutes 25 seconds
[INFO] Finished at: Tue Sep 01 16:42:32 PDT 2009
[INFO] Final Memory: 24M/80M
[INFO] ------------------------------------------------------------------------
~/tools/glassfish/v3/61/glassfishv3 >./bin/asadmin start-domain --verbose
Sep 2, 2009 3:43:09 PM com.sun.enterprise.admin.launcher.GFLauncherLogger info
INFO: JVM invocation command line:
. . .
Sep 2, 2009 3:46:01 PM OSGiModuleImpl start
INFO: Started bundle org.glassfish.security [174]
Sep 2, 2009 3:46:02 PM OSGiModuleImpl start
INFO: Started bundle org.glassfish.deployment.javaee-full [51]
~/samples/v3/lift/helloworld >~/tools/glassfish/v3/8-31/glassfishv3/bin/asadmin deploy target/helloworld-1.0-SNAPSHOT.war
Command deploy executed successfully.
What application server are you using to deploy your Lift applications ?
Please leave suggestions on other TOTD that you’d like to see. A complete archive of all the tips is available here.
Technorati: totd scala lift glassfish v3
Posted by Arun Gupta in General | Comments[0]
|
|
|
|
|
Monday August 31, 2009
TOTD #97 showed how to install GlassFish Tools Bundle for Eclipse 1.1. Basically there are two options - either install Eclipse 3.4.2 with WTP and pre-bundled/configured with GlassFish v2/v3, MySQL JDBC driver and other features. Or if you are using Eclipse 3.5, then you can install the plug-in separately and get most of the functionality.
TOTD #98 showed how to create a simple Metro/JAX-WS compliant Web service using that bundle and deploy on GlassFish.
This Tip Of The Day (TOTD) shows how to create a simple Java EE 6 application that reads data from a MySQL database using JPA 2.0 and Servlet 3.0 and display the results. A more formal support of Java EE 6/Servlet 3.0 is coming but in the meanwhile the approach mentioned below will work.
Lets get started!














@WebServlet(urlPatterns="/ServletClient")
public class ServletClient extends HttpServlet {
@PersistenceUnit
EntityManagerFactory factory;
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
ServletOutputStream out = resp.getOutputStream();
List list = factory.createEntityManager().createQuery("select f from Film f where f.title like 'GL%';").getResultList();
out.println("<html><table>");
for (Object film : list) {
out.print("<tr><td>" + ((Film)film).getTitle() + "</tr></td>");
}
out.println("</table></html>");
}
}
import java.io.IOException; import java.util.List; import javax.persistence.EntityManagerFactory; import javax.persistence.PersistenceUnit; import javax.servlet.ServletException; import javax.servlet.ServletOutputStream; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import model.Film;Basically, this is a Servlet 3.0 specification compliant Servlet that uses @WebServlet annotation. It uses @PersistenceUnit to inject the generated JPA Persistence Unit which is then used to query the database. The database query return all the movies whose title start with "GL" and the response is displayed in an HTML formatted table.


Simple, easy and clean!
How are you using Eclipse and GlassFish - the consolidated bundle or standalone Eclipse + GlassFish plugin ?
Download GlassFish Tools Bundle for Eclipse now.
Please send your questions and comments to users@glassfishplugins.dev.java.net.
Please leave suggestions on other TOTD that you’d like to see. A complete archive of all the tips is available here.
Technorati: glassfish eclipse mysql jpa database
Posted by Arun Gupta in General | Comments[0]
|
|
|
|
|
Tuesday August 25, 2009
TOTD #98: Create a Metro JAX-WS Web service using GlassFish Tools Bundle for Eclipse
Now that you've installed GlassFish Tools Bundle for Eclipse 1.1, lets use this bundle to create a simple Metro/JAX-WS compliant Web service and deploy on GlassFish. These steps will work with either Eclipse 3.4.2 or 3.5 with WTP Java EE support.


public String sayHello(String name) {
return "Hello " + name + "!!";
}










Posted by Arun Gupta in webservices | Comments[2]
|
|
|
|
|
Friday August 21, 2009
TOTD #97: GlassFish Plugin with Eclipse 3.5
A new version of GlassFish Tools Bundle for Eclipse (ver 1.1) was recently
released. The build contains








Posted by Arun Gupta in General | Comments[2]
|
|
|
|
|
Wednesday August 19, 2009
GlassFish
Monitoring allows you to monitor the state of various runtime
components of the application server. This information is used to
identify performance bottlenecks and tuning the system for optimal
performance, to aid capacity planning, to predict failures, to do root
cause analysis in case of failures and sometimes to just ensure that
everything is functioning as expected.
GlassFish Management allows you to manage the running Application
Server instance such as query/create/delete resources (JDBC, JMS, etc),
stop/restart the instance, rotate the log and other similar functions.
GlassFish v3 exposes Monitoring and Management data using a REST
Interface. This Tip
Of The Day (TOTD) shows how
to play with this new functionality. Rajeshwar's blog
has lot of useful information on this topic.
Most of the functionality available in
web-based Admin Console and CLI (asadmin) is now available using the
REST interface. Both of these are pre-built
tools that ships with the GlassFish bundle. The REST interface is a
lower level API that enables toolkit developers and IT administrators
to write their custom scripts/clients using language of their choice
such as Java, JavaScript, Ruby or Groovy.
The default URL for the REST interface of monitoring is
"http://localhost:4848/monitoring/domain" and for the management is
"http://localhost:4848/management/domain". Each URL provides an XML,
JSON and HTML representation of the
resources. If a web browser is used then a HTML representation is
returned and displayed nicely in the browser. Rajeshwar's
blog described a Java
client written using Jersey
Client APIs that can be used to make all the
GET/PUT/POST/DELETE requests. This blog will use something more basic,
and extremely popular,
to make all the RESTful invocations - cURL.
At this time the monitoring resources are read-only (GET) and
management can
be done using GET/POST/DELETE methods. POST is used for creating and
updating resources/objects and the updates can be partial.
Lets get started.
| ~/tools/glassfish/v3/2023/glassfishv3 >./bin/asadmin start-domain
--verbose Aug 19, 2009 9:52:45 AM com.sun.enterprise.admin.launcher.GFLauncherLogger info INFO: JVM invocation command line: /System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home/bin/java -cp . . . INFO: felix.fileinstall.dir /Users/arungupta/tools/glassfish/v3/2023/glassfishv3/glassfish/domains/domain1/autodeploy-bundles Aug 19, 2009 9:53:05 AM INFO: felix.fileinstall.debug 1 Aug 19, 2009 9:53:05 AM INFO: felix.fileinstall.bundles.new.start true |
| ~/tools/glassfish/v3/2023/glassfishv3 >curl -H "Accept:
application/json" http://localhost:4848/monitoring/domain -v * About to connect() to localhost port 4848 (#0) * Trying ::1... connected * Connected to localhost (::1) port 4848 (#0) > GET /monitoring/domain HTTP/1.1 > User-Agent: curl/7.16.3 (powerpc-apple-darwin9.0) libcurl/7.16.3 OpenSSL/0.9.7l zlib/1.2.3 > Host: localhost:4848 > Accept: application/json > < HTTP/1.1 200 OK < Content-Type: application/json < Transfer-Encoding: chunked < Date: Wed, 19 Aug 2009 17:40:29 GMT < {Domain:{},"child-resources":["http://localhost:4848/monitoring/domain/server"]} * Connection #0 to host localhost left intact * Closing connection #0 |
| {Domain:{},"child-resources":["http://localhost:4848/monitoring/domain/server"]} |
| ~/tools/glassfish/v3/2023/glassfishv3 >curl -H "Accept: application/xml"
http://localhost:4848/monitoring/domain -v * About to connect() to localhost port 4848 (#0) * Trying ::1... connected * Connected to localhost (::1) port 4848 (#0) > GET /monitoring/domain HTTP/1.1 > User-Agent: curl/7.16.3 (powerpc-apple-darwin9.0) libcurl/7.16.3 OpenSSL/0.9.7l zlib/1.2.3 > Host: localhost:4848 > Accept: application/xml > < HTTP/1.1 200 OK < Content-Type: application/xml < Transfer-Encoding: chunked < Date: Wed, 19 Aug 2009 17:43:51 GMT < <Domain> <child-resource>http://localhost:4848/monitoring/domain/server</child-resource> </Domain> * Connection #0 to host localhost left intact * Closing connection #0 |
| <Domain> <child-resource>http://localhost:4848/monitoring/domain/server</child-resource> </Domain> |

| </tools/glassfish/v3/2023/glassfishv3
>curl -H "Accept:
application/json" http://localhost:4848/monitoring/domain/server -v * About to connect() to localhost port 4848 (#0) * Trying ::1... connected * Connected to localhost (::1) port 4848 (#0) > GET /monitoring/domain/server HTTP/1.1 > User-Agent: curl/7.16.3 (powerpc-apple-darwin9.0) libcurl/7.16.3 OpenSSL/0.9.7l zlib/1.2.3 > Host: localhost:4848 > Accept: application/json > < HTTP/1.1 200 OK < Content-Type: application/json < Transfer-Encoding: chunked < Date: Wed, 19 Aug 2009 17:56:41 GMT < {Server:{},"child-resources":["http://localhost:4848/monitoring/domain/server/webintegration", "http://localhost:4848/monitoring/domain/server/transaction-service", "http://localhost:4848/monitoring/domain/server/network", "http://localhost:4848/monitoring/domain/server/jvm", "http://localhost:4848/monitoring/domain/server/web", "http://localhost:4848/monitoring/domain/server/realm", "http://localhost:4848/monitoring/domain/server/http-service"]} * Connection #0 to host localhost left intact * Closing connection #0 |

| ~/tools/glassfish/v3/2023/glassfishv3 >curl -X OPTIONS
http://localhost:4848/management/domain -v * About to connect() to localhost port 4848 (#0) * Trying ::1... connected * Connected to localhost (::1) port 4848 (#0) > OPTIONS /management/domain HTTP/1.1 > User-Agent: curl/7.16.3 (powerpc-apple-darwin9.0) libcurl/7.16.3 OpenSSL/0.9.7l zlib/1.2.3 > Host: localhost:4848 > Accept: */* > < HTTP/1.1 200 OK < Content-Type: application/json < Transfer-Encoding: chunked < Date: Wed, 19 Aug 2009 18:07:14 GMT < { "Method":"GET" "Method":"PUT" } * Connection #0 to host localhost left intact * Closing connection #0 |
| ~/tools/glassfish/v3/2023/glassfishv3 >curl -H "Accept:
application/json" http://localhost:4848/management/domain -v * About to connect() to localhost port 4848 (#0) * Trying ::1... connected * Connected to localhost (::1) port 4848 (#0) > GET /management/domain HTTP/1.1 > User-Agent: curl/7.16.3 (powerpc-apple-darwin9.0) libcurl/7.16.3 OpenSSL/0.9.7l zlib/1.2.3 > Host: localhost:4848 > Accept: application/json > < HTTP/1.1 200 OK < Content-Type: application/json < Transfer-Encoding: chunked < Date: Wed, 19 Aug 2009 18:14:46 GMT < {Domain:{"log-root" : "${com.sun.aas.instanceRoot}/logs","application-root" : "${com.sun.aas.instanceRoot}/applications","locale" : "","version" : "re-continuous"},"child-resources":["http://localhost:4848/management/domain/configs", "http://localhost:4848/management/domain/resources","http://localhost:4848/management/domain/servers", "http://localhost:4848/management/domain/property","http://localhost:4848/management/domain/applications", "http://localhost:4848/management/domain/system-applications","http://localhost:4848/management/domain/stop", "http://localhost:4848/management/domain/restart","http://localhost:4848/management/domain/uptime", "http://localhost:4848/management/domain/version","http://localhost:4848/management/domain/rotate-log", "http://localhost:4848/management/domain/host-port"]} * Connection #0 to host localhost left intact * Closing connection #0 |
| curl -H "Accept: application/json" http://localhost:4848/management/domain/host-port -v |
| {"GetHostAndPort":{"value" : "dhcp-usca14-132-79.SFBay.Sun.COM:8080"}} |
| curl -H "Accept: application/json" http://localhost:4848/management/domain/system-applications/application/__admingui -v |
| {__admingui:{"libraries" : "","availability-enabled" : "false","enabled" : "true","context-root" : "","location" : "${com.sun.aas.installRootURI}/lib/install/applications/__admingui","description" : "","name" : "__admingui","directory-deployed" : "true","object-type" : "system-admin"},"child-resources":["http://localhost:4848/management/domain/system-applications/application/__admingui/module"]} |
| curl -H "Accept: application/json" http://localhost:4848/management/domain/configs/config/server-config/monitoring-service/module-monitoring-levels -v |
| {ModuleMonitoringLevels:{"transaction-service" : "OFF","ejb-container" : "OFF","jdbc-connection-pool" : "OFF","orb" : "OFF","http-service" : "OFF","connector-connection-pool" : "OFF","jms-service" : "OFF","connector-service" : "OFF","jvm" : "OFF","thread-pool" : "OFF","web-container" : "OFF"},"child-resources":[]} |
| ~/tools/glassfish/v3/2023/glassfishv3 >curl -X POST -d
"web-container=ON" -H "Accept: application/json"
http://localhost:4848/management/domain/configs/config/server-config/monitoring-service/module-monitoring-levels
-v * About to connect() to localhost port 4848 (#0) * Trying ::1... connected * Connected to localhost (::1) port 4848 (#0) > POST /management/domain/configs/config/server-config/monitoring-service/module-monitoring-levels HTTP/1.1 > User-Agent: curl/7.16.3 (powerpc-apple-darwin9.0) libcurl/7.16.3 OpenSSL/0.9.7l zlib/1.2.3 > Host: localhost:4848 > Accept: application/json > Content-Length: 16 > Content-Type: application/x-www-form-urlencoded > < HTTP/1.1 200 OK < Content-Type: application/json < Transfer-Encoding: chunked < Date: Wed, 19 Aug 2009 22:01:31 GMT < * Connection #0 to host localhost left intact * Closing connection #0 "http://localhost:4848/management/domain/configs/config/server-config/monitoring-service/module-monitoring-levels" updated successfully |
| ~/tools/glassfish/v3/2023/glassfishv3 >curl -H "Accept:
application/json"
http://localhost:4848/management/domain/configs/config/server-config/monitoring-service/module-monitoring-levels
-v * About to connect() to localhost port 4848 (#0) * Trying ::1... connected * Connected to localhost (::1) port 4848 (#0) > GET /management/domain/configs/config/server-config/monitoring-service/module-monitoring-levels HTTP/1.1 > User-Agent: curl/7.16.3 (powerpc-apple-darwin9.0) libcurl/7.16.3 OpenSSL/0.9.7l zlib/1.2.3 > Host: localhost:4848 > Accept: application/json > < HTTP/1.1 200 OK < Content-Type: application/json < Transfer-Encoding: chunked < Date: Wed, 19 Aug 2009 22:36:47 GMT < * Connection #0 to host localhost left intact * Closing connection #0 {ModuleMonitoringLevels:{"transaction-service" : "OFF","ejb-container" : "OFF","jdbc-connection-pool" : "OFF","orb" : "OFF","http-service" : "OFF","connector-connection-pool" : "OFF","jms-service" : "OFF","connector-service" : "OFF","jvm" : "OFF","thread-pool" : "OFF","web-container" : "ON"},"child-resources":[]} |
| curl -H "Accept: application/json" http://localhost:4848/management/domain/stop -v |
| curl -H "Accept: application/json" http://localhost:4848/management/domain/restart -v |
| curl -H "Accept: application/json" http://localhost:4848/management/domain/resources -v |
| {Resources:{},"child-resources":["http://localhost:4848/management/domain/resources/jdbc-connection-pool", "http://localhost:4848/management/domain/resources/jdbc-resource"]} |
| curl -H "Accept: application/json" http://localhost:4848/management/domain/resources/jdbc/connection-pool -v |
| {JdbcConnectionPool:{},"child-resources":["http://localhost:4848/management/domain/resources/jdbc-connection-pool/__TimerPool", "http://localhost:4848/management/domain/resources/jdbc-connection-pool/DerbyPool"]} |
| curl "Accept: application/json" http://localhost:4848/management/domain/resources/jdbc-resource -v |
| {JdbcResource:{},"child-resources":["http://localhost:4848/management/domain/resources/jdbc-resource/jdbc/__TimerPool", "http://localhost:4848/management/domain/resources/jdbc-resource/jdbc/__default"]} |
| curl -X OPTIONS -H "Accept: application/json" http://localhost:4848/management/domain/resources/jdbc-resource -v |
| { "Method":"POST", "Message Parameters":{ "id":{"Acceptable Values":"","Default Value":"","Type":"class java.lang.String","Optional":"false"}, "enabled":{"Acceptable Values":"","Default Value":"true","Type":"class java.lang.Boolean","Optional":"true"}, "description":{"Acceptable Values":"","Default Value":"","Type":"class java.lang.String","Optional":"true"}, "target":{"Acceptable Values":"","Default Value":"","Type":"class java.lang.String","Optional":"true"}, "property":{"Acceptable Values":"","Default Value":"","Type":"class java.util.Properties","Optional":"true"}, "connectionpoolid":{"Acceptable Values":"","Default Value":"","Type":"class java.lang.String","Optional":"false"} } "Method":"GET" |
| ~/tools/glassfish/v3/2023/glassfishv3 >curl -d
"id=jdbc/sample&connectionpoolid=DerbyPool"
http://localhost:4848/management/domain/resources/jdbc-resource -v * About to connect() to localhost port 4848 (#0) * Trying ::1... connected * Connected to localhost (::1) port 4848 (#0) > POST /management/domain/resources/jdbc-resource HTTP/1.1 > User-Agent: curl/7.16.3 (powerpc-apple-darwin9.0) libcurl/7.16.3 OpenSSL/0.9.7l zlib/1.2.3 > Host: localhost:4848 > Accept: */* > Content-Length: 42 > Content-Type: application/x-www-form-urlencoded > < HTTP/1.1 201 Created < Content-Type: text/html < Transfer-Encoding: chunked < Date: Wed, 19 Aug 2009 20:45:51 GMT < * Connection #0 to host localhost left intact * Closing connection #0 "http://localhost:4848/management/domain/resources/jdbc-resource/jdbc/sample" created successfully. |
| curl -H "Accept: application/json" http://localhost:4848/management/domain/resources/jdbc-resource -v |
| {JdbcResource:{},"child-resources":["http://localhost:4848/management/domain/resources/jdbc-resource/jdbc/__TimerPool", "http://localhost:4848/management/domain/resources/jdbc-resource/jdbc/__default", "http://localhost:4848/management/domain/resources/jdbc-resource/jdbc/sample"]} |
| ~/tools/glassfish/v3/2023/glassfishv3 >curl -H "Accept: application/xml"
http://localhost:4848/management/domain -v * About to connect() to localhost port 4848 (#0) * Trying ::1... connected * Connected to localhost (::1) port 4848 (#0) > GET /management/domain HTTP/1.1 > User-Agent: curl/7.16.3 (powerpc-apple-darwin9.0) libcurl/7.16.3 OpenSSL/0.9.7l zlib/1.2.3 > Host: localhost:4848 > Accept: application/xml > < HTTP/1.1 200 OK < Content-Type: application/xml < Transfer-Encoding: chunked < Date: Wed, 19 Aug 2009 18:17:07 GMT < <Domain log-root="${com.sun.aas.instanceRoot}/logs" application-root="${com.sun.aas.instanceRoot}/applications" locale="" version="re-continuous"> <child-resource>http://localhost:4848/management/domain/configs</child-resource> <child-resource>http://localhost:4848/management/domain/resources</child-resource> <child-resource>http://localhost:4848/management/domain/servers</child-resource> <child-resource>http://localhost:4848/management/domain/property</child-resource> <child-resource>http://localhost:4848/management/domain/applications</child-resource> <child-resource>http://localhost:4848/management/domain/system-applications</child-resource> <child-resource>http://localhost:4848/management/domain/stop</child-resource> <child-resource>http://localhost:4848/management/domain/restart</child-resource> <child-resource>http://localhost:4848/management/domain/uptime</child-resource> <child-resource>http://localhost:4848/management/domain/version</child-resource> <child-resource>http://localhost:4848/management/domain/rotate-log</child-resource> <child-resource>http://localhost:4848/management/domain/host-port</child-resource> * Connection #0 to host localhost left intact * Closing connection #0 |

Posted by Arun Gupta in General | Comments[8]
|
|
|
|
|
Monday August 17, 2009
TOTD
#93
showed how to get started with Java EE 6
using NetBeans
6.8 M1 and
GlassFish v3 by
building a simple Servlet 3.0 + JPA 2.0 web
application. TOTD
#94 built upon it by using Java Server Faces 2 instead of
Servlet 3.0 for displaying the results. However we are still using a
POJO
for all the database interactions. This works fine if we are only
reading values from the database but that's not how a typical web
application behaves. The web application would typically perform all
CRUD operations. More typically they like to perform one or more CRUD
operations within the context of a transaction. And how do you do
transactions in the context of a web application ? Java EE 6 comes to
your rescue.
The EJB 3.1
specification (another new specification in Java EE 6) allow
POJO classes to be annotated with @EJB and bundled within
WEB-INF/classes of a WAR file. And so you get all transactional
capabilities in your web application very easily.
This Tip
Of The Day (TOTD) shows how
to enhance the application created in TOTD #94 and use EJB 3.1 instead
of the JSF managed bean
for
performing the business logic. There are two ways to achieve this
pattern as described below.
Lets call this TOTD #95.1
| @javax.ejb.Stateless @ManagedBean public class StateList { @PersistenceUnit EntityManagerFactory emf; public List<States> getStates() { return emf.createEntityManager().createNamedQuery("States.findAll").getResultList(); } } |


| @Stateless public class StateBeanBean { @PersistenceUnit EntityManagerFactory emf; public List<States> getStates() { return emf.createEntityManager().createNamedQuery("States.findAll").getResultList(); } } |
| @ManagedBean public class StateList { @EJB StateBeanBean bean; public List<States> getStates() { return bean.getStates(); } } |
| @Stateless public class StateBeanBean { @PersistenceContext EntityManager em; public List<States> getStates() { return em.createNamedQuery("States.findAll").getResultList(); } } |

Posted by Arun Gupta in General | Comments[1]
|
|
|
|
|
Friday August 14, 2009
TOTD
#93
showed how to get started with Java EE 6
using NetBeans
6.8 M1 and
GlassFish v3 by
building a simple Servlet 3.0 + JPA 2.0 web
application. JPA 2.0 + Eclipselink was used for the database
connectivity
and Servlet 3.0 was used for displaying the results to the user. The
sample demonstrated how the two technologies can be mixed to create a
simple web application. But Servlets are meant for server-side
processing rather than displaying the results to end user. JavaServer
Faces 2 (another new specification in Java EE 6) is designed
to fulfill
that purpose.
This Tip
Of The Day (TOTD) shows how
to enhance the application created in TOTD #93 and use JSF 2 for
displaying the results.


| package server; import java.util.List; import javax.faces.bean.ManagedBean; import javax.persistence.EntityManagerFactory; import javax.persistence.PersistenceUnit; import states.States; /** * @author arungupta */ @ManagedBean public class StateList { @PersistenceUnit EntityManagerFactory emf; public List<States> getStates() { return emf.createEntityManager().createNamedQuery("States.findAll").getResultList(); } } |
| Show States |
|
<h:dataTable var="state" value="#{stateList.states}"
border="1"> <h:column><h:outputText value="#{state.abbrev}"/></h:column> <h:column><h:outputText value="#{state.name}"/></h:column> </h:dataTable> |


Posted by Arun Gupta in General | Comments[3]
|
|
|
|
|
Thursday August 13, 2009
NetBeans
6.8 M1 introduces support for creating Java EE 6 applications
... cool!
This Tip Of The Day (TOTD) shows how
to create a simple web application using JPA 2.0 and Servlet 3.0 and
deploy on GlassFish v3 latest
promoted build (58
as of this writing). If you can work with the one week older build then
NetBeans 6.8 M1 comes pre-bundled with 57. The example below should
work fine on that as well.
| ~/tools/glassfish/v3/58/glassfishv3/bin >sudo mysql --user root Password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1592 Server version: 5.1.30 MySQL Community Server (GPL) Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> create database states; Query OK, 1 row affected (0.02 sec) mysql> CREATE USER duke IDENTIFIED by 'glassfish'; Query OK, 0 rows affected (0.00 sec) mysql> GRANT ALL on states.* TO duke; Query OK, 0 rows affected (0.24 sec) mysql> use states; Database changed mysql> CREATE TABLE STATES ( -> id INT, -> abbrev VARCHAR(2), -> name VARCHAR(50), -> PRIMARY KEY (id) -> ); Query OK, 0 rows affected (0.16 sec) mysql> INSERT INTO STATES VALUES (1, "AL", "Alabama"); INSERT INTO STATES VALUES (2, "AK", "Alaska"); . . . mysql> INSERT INTO STATES VALUES (49, "WI", "Wisconsin"); Query OK, 1 row affected (0.00 sec) mysql> INSERT INTO STATES VALUES (50, "WY", "Wyoming"); Query OK, 1 row affected (0.00 sec) |
| ~/tools/glassfish/v3/58/glassfishv3/bin >asadmin start-domain |
| ~/tools/glassfish/v3/58/glassfishv3/bin >./asadmin
create-jdbc-connection-pool --datasourceclassname
com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource --restype
javax.sql.DataSource --property
"User=duke:Password=glassfish:URL=jdbc\:mysql\://localhost/states"
jdbc/states Command create-jdbc-connection-pool executed successfully. ~/tools/glassfish/v3/58/glassfishv3/bin >./asadmin ping-connection-pool jdbc/states Command ping-connection-pool executed successfully. ~/tools/glassfish/v3/58/glassfishv3/bin >./asadmin create-jdbc-resource --connectionpoolid jdbc/states jdbc/jndi_states Command create-jdbc-resource executed successfully. |





| @PersistenceUnit EntityManagerFactory emf; |
|
List<States> list =
emf.createEntityManager().createNamedQuery("States.findAll").getResultList(); out.println("<table border=\"1\">"); for (States state : list) { out.println("<tr><td>" + state.getAbbrev() + "</td><td>" + state.getName() + "</td></tr>"); } out.println("</table>"); |



Posted by Arun Gupta in General | Comments[5]
|
|
|
|
|
Wednesday August 12, 2009
TOTD #92: Session Failover for Rails applications running on GlassFish
The GlassFish
High Availability
allows to setup a cluster of GlassFish instances and achieve highly
scalable architecture using in-memory session state replication. This
cluster can be very
easily created and tested using the "clusterjsp" sample
bundled with GlassFish. Here are some clustering related entries
published on this blog so far:
| ~/samples/jruby/session >~/tools/jruby/bin/jruby
script/generate controller home index JRuby limited openssl loaded. gem install jruby-openssl for full support. http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL exists app/controllers/ exists app/helpers/ create app/views/home exists test/functional/ create test/unit/helpers/ create app/controllers/home_controller.rb create test/functional/home_controller_test.rb create app/helpers/home_helper.rb create test/unit/helpers/home_helper_test.rb create app/views/home/index.html.erb |
| class HomeController < ApplicationController include Java def index @server_served = servlet_request.get_server_name @port = servlet_request.get_server_port @instance = java.lang.System.get_property "com.sun.aas.instanceName" @server_executed = java.net.InetAddress.get_local_host().get_host_name() @ip = java.net.InetAddress.get_local_host().get_host_address @session_id = servlet_request.session.get_id @session_created = servlet_request.session.get_creation_time @session_last_accessed = servlet_request.session.get_last_accessed_time @session_inactive = servlet_request.session.get_max_inactive_interval if (params[:name] != nil) servlet_request.session[params[:name]] = params[:value] end @session_values = "" value_names = servlet_request.session.get_attribute_names unless (value_names.has_more_elements) @session_values = "<br>No parameter entered for this request" else @session_values << "<UL>" while (value_names.has_more_elements) param = value_names.next_element unless (param.starts_with?("__")) value = servlet_request.session.get_attribute(param) @session_values << "<LI>" + param + " = " + value + "</LI>" end end @session_values << "</UL>" end end def adddata servlet_request.session.set_attribute(params[:name], params[:value]) render :action => "index" end def cleardata servlet_request.session.invalidate render :action => "index" end end |
| <h1>Home#index</h1> <p>Find me in app/views/home/index.html.erb</p> <B>HttpSession Information:</B> <UL> <LI>Served From Server: <b><%= @server_served %></b></LI> <LI>Server Port Number: <b><%= @port %></b></LI> <LI>Executed From Server: <b><%= @server_executed %></b></LI> <LI>Served From Server instance: <b><%= @instance %></b></LI> <LI>Executed Server IP Address: <b><%= @ip %></b></LI> <LI>Session ID: <b><%= @session_id %></b></LI> <LI>Session Created: <%= @session_created %></LI> <LI>Last Accessed: <%= @session_last_accessed %></LI> <LI>Session will go inactive in <b><%= @session_inactive %> seconds</b></LI> </UL> <BR> <% form_tag "/session/home/index" do %> <label for="name">Name of Session Attribute:</label> <%= text_field_tag :name, params[:name] %><br> <label for="value">Value of Session Attribute:</label> <%= text_field_tag :value, params[:value] %><br> <%= submit_tag "Add Session Data" %> <% end %> <% form_tag "/session/home/cleardata" do %> <%= submit_tag "Clear Session Data" %> <% end %> <% form_tag "/session/home/index" do %> <%= submit_tag "Reload Page" %> <% end %> <BR> <B>Data retrieved from the HttpSession: </B> <%= @session_values %> |
| ~/samples/jruby/session >~/tools/jruby/bin/jruby -S warble
war:webxml mkdir -p tmp/war/WEB-INF ~/samples/jruby/session >cp tmp/war/WEB-INF/web.xml config/ |
| <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app> |
| <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> |
| <distributable/> |
| ~/samples/jruby/session >~/tools/jruby/bin/jruby -S warble mkdir -p tmp/war/WEB-INF/gems/specifications cp /Users/arungupta/tools/jruby-1.3.0/lib/ruby/gems/1.8/specifications/rails-2.3.2.gemspec tmp/war/WEB-INF/gems/specifications/rails-2.3.2.gemspec . . . mkdir -p tmp/war/WEB-INF cp config/web.xml tmp/war/WEB-INF jar cf session.war -C tmp/war . |
| ~/samples/jruby/session >asadmin deploy --target wines --port 5048 --availabilityenabled=true session.war |








Posted by Arun Gupta in General | Comments[2]
|
|
|
|
|
Tuesday August 11, 2009
TOTD #91: Applying Java EE 6 "web-fragment.xml" to Apache Wicket - Deploy on GlassFish v3
"Extensibility" is a major theme of Java EE 6.
This theme enables seamless pluggability of other popular Web
frameworks with Java EE 6.
Before
Java EE 6, these frameworks have to rely upon registering servlet
listeners/filters in "web.xml" or some other similar mechanism to
register the framework with the Web container. Thus your application
and framework deployment descriptors are mixed together. As an
application developer you need to figure out the magical descriptors of
the framework that will make this registration.
What if you are
using multiple frameworks ? Then "web.xml" need to have multiple of
those listeners/servlets. So your deployment descriptor becomes
daunting and maintenance nightmare even before any application
deployment artifacts are added.
Instead you should focus on your
application descriptors and let the framework developer provide the
descriptors along with their jar file so that the registration is
indeed magical.
For that, the Servlet
3.0 specification introduces "web module deployment
descriptor fragment" (aka "web-fragment.xml"). The spec defines it as:
A
web fragment is a logical partitioning of the web app in such a way
that the frameworks being used within the web app can define all the
artifacts without asking devlopers to edit or add information in the
web.xml.
Basically, the framework configuration
deployment descriptor can now be defined in "META-INF/web-fragment.xml"
in the JAR file of the framework. The Web container picks up and use
the configuration for registering the framework. The spec clearly
defines the rules around ordering, duplicates and other complexities.
TOTD
#86 explained how to get started with Apache Wicket on
GlassFish. This Tip Of The Day (TOTD) explains
how to
leverage "web-fragment.xml" to deploy a Wicket application on
GlassFish v3. The basic concepts are also discussed here.
For the "Hello World" app discussed in TOTD
#86, the generated "web.xml" looks like:
| <?xml version="1.0"
encoding="ISO-8859-1"?> <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4"> <display-name>helloworld</display-name> <!-- There are three means to configure Wickets configuration mode and they are tested in the order given. 1) A system property: -Dwicket.configuration 2) servlet specific <init-param> 3) context specific <context-param> The value might be either "development" (reloading when templates change) or "deployment". If no configuration is found, "development" is the default. --> <filter> <filter-name>wicket.helloworld</filter-name> <filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class> <init-param> <param-name>applicationClassName</param-name> <param-value>org.glassfish.samples.WicketApplication</param-value> </init-param> </filter> <filter-mapping> <filter-name>wicket.helloworld</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app> |
|
<dependencies> . . . <!-- web-fragment --> <dependency> <groupId>org.glassfish.extras</groupId> <artifactId>wicket-quickstart-web-fragment</artifactId> <version>1.0</version> <scope>runtime</scope> </dependency> </dependencies> . . . <repositories> <repository> <id>maven2-repository.dev.java.net</id> <name>Java.net Repository for Maven</name> <url>http://download.java.net/maven/2/</url> </repository> </repositories> |
| <web-fragment> <filter> <filter-name>wicket.helloworld</filter-name> <filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class> <init-param> <param-name>applicationClassName</param-name> <param-value>org.glassfish.samples.WicketApplication</param-value> </init-param> </filter> <filter-mapping> <filter-name>wicket.helloworld</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-fragment> |
|
<plugins> . . . <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.1-beta-1</version> <configuration> <failOnMissingWebXml>false</failOnMissingWebXml> </configuration> </plugin> . . . </plugins> |
| helloworld-1.0-SNAPSHOT helloworld-1.0-SNAPSHOT/META-INF helloworld-1.0-SNAPSHOT/WEB-INF helloworld-1.0-SNAPSHOT/WEB-INF/classes helloworld-1.0-SNAPSHOT/WEB-INF/classes/log4j.properties helloworld-1.0-SNAPSHOT/WEB-INF/classes/org helloworld-1.0-SNAPSHOT/WEB-INF/classes/org/glassfish helloworld-1.0-SNAPSHOT/WEB-INF/classes/org/glassfish/samples helloworld-1.0-SNAPSHOT/WEB-INF/classes/org/glassfish/samples/HomePage.class helloworld-1.0-SNAPSHOT/WEB-INF/classes/org/glassfish/samples/HomePage.html helloworld-1.0-SNAPSHOT/WEB-INF/classes/org/glassfish/samples/WicketApplication.class helloworld-1.0-SNAPSHOT/WEB-INF/lib helloworld-1.0-SNAPSHOT/WEB-INF/lib/log4j-1.2.14.jar helloworld-1.0-SNAPSHOT/WEB-INF/lib/slf4j-api-1.4.2.jar helloworld-1.0-SNAPSHOT/WEB-INF/lib/slf4j-log4j12-1.4.2.jar helloworld-1.0-SNAPSHOT/WEB-INF/lib/wicket-1.4.0.jar helloworld-1.0-SNAPSHOT/WEB-INF/lib/wicket-quickstart-web-fragment-1.0.jar |

Posted by Arun Gupta in web2.0 | Comments[5]
|
|
|
|
|
Wednesday July 29, 2009
TOTD# 86: Getting Started with Apache Wicket on GlassFish
![]() |
Apache Wicket is an application framework to build web applications using HTML for markup and POJOs to capture the business logic and all other processing. Why Wicket digs more into the motivation behind this framework. |
| ~/samples/wicket
>mvn
archetype:create -DarchetypeGroupId=org.apache.wicket
-DarchetypeArtifactId=wicket-archetype-quickstart
-DarchetypeVersion=1.3.6 -DgroupId=org.glassfish.samples
-DartifactId=helloworld [INFO] Scanning for projects... [INFO] Searching repository for plugin with prefix: 'archetype'. [INFO] ------------------------------------------------------------------------ [INFO] Building Maven Default Project [INFO] task-segment: [archetype:create] (aggregator-style) [INFO] ------------------------------------------------------------------------ [INFO] Setting property: classpath.resource.loader.class => 'org.codehaus.plexus.velocity.ContextClassLoaderResourceLoader'. [INFO] Setting property: velocimacro.messages.on => 'false'. [INFO] Setting property: resource.loader => 'classpath'. [INFO] Setting property: resource.manager.logwhenfound => 'false'. [INFO] [archetype:create] [WARNING] This goal is deprecated. Please use mvn archetype:generate instead [INFO] Defaulting package to group ID: org.glassfish.samples [INFO] ---------------------------------------------------------------------------- [INFO] Using following parameters for creating OldArchetype: wicket-archetype-quickstart:1.3.6 [INFO] ---------------------------------------------------------------------------- [INFO] Parameter: groupId, Value: org.glassfish.samples [INFO] Parameter: packageName, Value: org.glassfish.samples [INFO] Parameter: package, Value: org.glassfish.samples [INFO] Parameter: artifactId, Value: helloworld [INFO] Parameter: basedir, Value: /Users/arungupta/samples/wicket [INFO] Parameter: version, Value: 1.0-SNAPSHOT [INFO] ********************* End of debug info from resources from generated POM *********************** [INFO] OldArchetype created in dir: /Users/arungupta/samples/wicket/helloworld [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------ [INFO] Total time: 3 seconds [INFO] Finished at: Tue Jul 28 15:30:21 PDT 2009 [INFO] Final Memory: 12M/80M [INFO] ------------------------------------------------------------------------ |
| ~/samples/wicket/helloworld
>mvn jetty:run [INFO] Scanning for projects... [INFO] Searching repository for plugin with prefix: 'jetty'. [INFO] ------------------------------------------------------------------------ [INFO] Building quickstart [INFO] task-segment: [jetty:run] [INFO] ------------------------------------------------------------------------ [INFO] Preparing jetty:run [INFO] [resources:resources] [INFO] Using default encoding to copy filtered resources. [INFO] [compiler:compile] [INFO] Compiling 2 source files to /Users/arungupta/samples/wicket/helloworld/target/classes [INFO] [resources:testResources] [INFO] Using default encoding to copy filtered resources. [INFO] [compiler:testCompile] [INFO] Compiling 2 source files to /Users/arungupta/samples/wicket/helloworld/target/test-classes [INFO] [jetty:run] [INFO] Configuring Jetty for project: quickstart [INFO] Webapp source directory = /Users/arungupta/samples/wicket/helloworld/src/main/webapp [INFO] Reload Mechanic: automatic [INFO] Classes = /Users/arungupta/samples/wicket/helloworld/target/classes 2009-07-28 15:31:35.820::INFO: Logging to STDERR via org.mortbay.log.StdErrLog [INFO] Context path = /helloworld [INFO] Tmp directory = determined at runtime [INFO] Web defaults = org/mortbay/jetty/webapp/webdefault.xml [INFO] Web overrides = none . . . INFO - WebApplication - [WicketApplication] Started Wicket version 1.3.6 in development mode ******************************************************************** *** WARNING: Wicket is running in DEVELOPMENT mode. *** *** ^^^^^^^^^^^ *** *** Do NOT deploy to your live server(s) without changing this. *** *** See Application#getConfigurationType() for more information. *** ******************************************************************** 2009-07-28 15:31:37.333::INFO: Started SelectChannelConnector@0.0.0.0:8080 [INFO] Started Jetty Server |

| ~/samples/wicket/helloworld
>mvn package [INFO] Scanning for projects... [INFO] ------------------------------------------------------------------------ [INFO] Building quickstart [INFO] task-segment: [package] . . . [INFO] Processing war project [INFO] Webapp assembled in[494 msecs] [INFO] Building war: /Users/arungupta/samples/wicket/helloworld/target/helloworld-1.0-SNAPSHOT.war [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------ [INFO] Total time: 6 seconds [INFO] Finished at: Tue Jul 28 15:35:59 PDT 2009 [INFO] Final Memory: 14M/80M [INFO] ------------------------------------------------------------------------ |
| ~/samples/wicket/helloworld
>~/tools/glassfish/v3/preview/glassfishv3/bin/asadmin deploy
target/helloworld-1.0-SNAPSHOT.war Command deploy executed successfully. |

Posted by Arun Gupta in web2.0 | Comments[3]
|
|
|
|
|
Thursday June 18, 2009
TOTD #85: Getting Started with Django Applications on GlassFish v3
GlassFish v3 is an extensible App server. Basically the core App server
functionality can be easily extended using add-ons such as an OSGi
module. This allows to keep the core light-weight and install the
required features on demand. The add-ons can be easily installed using
the Update
Center. The what/why/how about extensibility is described in
the GlassFish
v3 Extensibility One-pager.
GlassFish v3 provides support for Dynamic Languages and Web Frameworks
such as Ruby-on-Rails, Groovy/Grails, and Python/Django using this
extensibility. This blog has published multiple tips on using
Ruby-on-Rails at rubyonrails+totd
and a few tips on Groovy/Grails at grails+totd.
This blog will explain how to get started with deploying Python/Django
applications on GlassFish
v3 Preview. The blog will use Jython interpreter
which is the Java implemention of Python.
Vivek already blogged about the detailed
instructions and this blog shows how to run the pre-bundled
samples.
| java -jar ~/Downloads/jython_installer-2.5.0.jar |

| alias
jython25=~/tools/jython2.5.0/bin/jython alias django-admin-jy="jython25 ~/tools/jython2.5.0/bin/django-admin.py" |
| ~/tools/jython/jython2.5rc4 >jython25 Jython 2.5rc4 (Release_2_5rc4:6470, Jun 8 2009, 13:23:16) [Java HotSpot(TM) 64-Bit Server VM (Apple Inc.)] on java1.6.0_13 Type "help", "copyright", "credits" or "license" for more information. >>> |
| ~/tools >tar xzvf
~/Downloads/Django-1.0.2-final.tar.gz Django-1.0.2-final/ Django-1.0.2-final/AUTHORS Django-1.0.2-final/django/ . . . Django-1.0.2-final/scripts/rpm-install.sh Django-1.0.2-final/setup.cfg Django-1.0.2-final/setup.py ~/tools/Django-1.0.2-final >jython25 setup.py install running install running build running build_py . . . running install_egg_info Writing /Users/arungupta/tools/jython/jython2.5.0/Lib/site-packages/Django-1.0.2_final-py2.5.egg-info |
| ~/tools/glassfish/v3/preview/glassfishv3/bin >./updatetool |

| ~/tools/glassfish/v3/preview/glassfishv3/glassfish >./bin/asadmin start-domain |
| ~/tools/glassfish/v3/preview/glassfishv3/glassfish
>./bin/asadmin
create-jvm-options -Djython.home=/Users/arungupta/tools/jython2.5.0
created 1 option(s) Command create-jvm-options executed successfully. |
| ~/tools/Django-1.0.2-final/examples >~/tools/glassfish/v3/preview/glassfishv3/glassfish/bin/asadmin
deploy . Command deploy executed successfully. |



| ~/tools/Django-1.0.2-final/examples >jython25 manage.py runserver Validating models... 0 errors found Django version 1.0.2 final, using settings 'examples.settings' Development server is running at http://127.0.0.1:8000/ Quit the server with CONTROL-C. |

Posted by Arun Gupta in web2.0 | Comments[3]
|
|
|
|
|
Tuesday June 16, 2009
TOTD #84: Using Apache + mod_proxy_balancer to load balance Ruby-on-Rails running on GlassFish
TOTD
#81 explained how to install/configure nginx for
load-balancing/front-ending a cluster of Rails application running on GlassFish
Gem. Another popular approach in the Rails community is to
use Apache HTTPD
+ mod_proxy_balancer.
A user asked the exact details of this
setup on the GlassFish
Gem Forum. This Tip
Of The Day (TOTD) will
clearly explain the steps.
| LoadModule proxy_balancer_module libexec/apache2/mod_proxy_balancer.so |
| <Proxy balancer://glassfishgem> BalancerMember http://localhost:3000 BalancerMember http://localhost:3001 BalancerMember http://localhost:3002 </Proxy> |
| ProxyPass / balancer://glassfishgem/ CustomLog /var/log/glassfishgem.log/apache_access_log combined |
| CustomLog /var/log/glassfishgem.log/apache_access_log combined |
| ~/tools/jruby/rails/runner >../../bin/jruby -S glassfish -e
production -c myapp Starting GlassFish server at: 10.0.177.178:3000 in production environment... Writing log messages to: /Users/arungupta/tools/jruby-1.3.0/rails/runner/log/production.log. Press Ctrl+C to stop. . . . ~/tools/jruby/rails/runner >../../bin/jruby -S glassfish -e production -c myapp -p 3001 Starting GlassFish server at: 10.0.177.178:3001 in production environment... Writing log messages to: /Users/arungupta/tools/jruby-1.3.0/rails/runner/log/production.log. Press Ctrl+C to stop. . . . ~/tools/jruby/rails/runner >../../bin/jruby -S glassfish -e production -c myapp -p 3002 Starting GlassFish server at: 10.0.177.178:3002 in production environment... Writing log messages to: /Users/arungupta/tools/jruby-1.3.0/rails/runner/log/production.log. Press Ctrl+C to stop. |
| ProxyPass /myapp/
balancer://glassfishgem/myapp/ |
| LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\" \"%{BALANCER_WORKER_NAME}e\"" custom |
| CustomLog /var/log/glassfishgem.com/apache_access_log custom |
| ::1 - - [17/Jun/2009:10:53:53 -0700] "GET /runlogs
HTTP/1.1" 304 - "-" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5;
en-US; rv:1.9.0.11) Gecko/2009060214 Firefox/3.0.11"
"http://localhost:3002" ::1 - - [17/Jun/2009:10:54:04 -0700] "GET /runlogs HTTP/1.1" 200 621 "-" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.11) Gecko/2009060214 Firefox/3.0.11" "http://localhost:3000" ::1 - - [17/Jun/2009:10:54:05 -0700] "GET /runlogs HTTP/1.1" 304 - "-" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.11) Gecko/2009060214 Firefox/3.0.11" "http://localhost:3001" |
Posted by Arun Gupta in web2.0 | Comments[4]
|
|
|
|
|
Thursday May 21, 2009
TOTD #83: Eclipse Tools Bundle for GlassFish 1.0 - Now Available!
The GlassFish
Tools Bundle for Eclipse 1.0 is now available.

An earlier
blog entry explains how to get started using this bundle.
If you used an earlier version (0.99.x) of this bundle, then an upgrade
is not supported. However backwards compatibility will be maintained
going forward!
Here are some pointers to get you started:
Posted by Arun Gupta in General | Comments[3]
|
|
|
|
|
Today's Page Hits: 1172
Total # blog entries: 1009