Friday, July 11, 2008

Single Sign On using Sun Access Manager and JRuby

A couple of emails to achieve Single Sign On using Sun Access Manager in a Rails app - that's pretty cool! A brief summary of the solution is:



Warbler builds a war file out of your Rails app using jruby-rack. Drop your .jar libraries in the rails lib dir. Muck with your web.xml so you can make it use a filter. Drop the .war file on your server. Done. A little method called servlet_request is now magically available to you. Call servlet_request.getUserPrincipal : it's populated. It's not magic- it's JRuby!



Read complete details here. And guess what, this is deployed on GlassFish :)



The blog summarizes the power of Java and agility of JRuby/Rails:



Anyway, that's why JRuby is even more awesome. Let them write Java- I'll call it if I need it.



Technorati: rubyonrails jruby ruby glassfish accessmanager singlesignon sso stories

Thursday, July 10, 2008

Getting Started with GlassFish in IntelliJ IDEA



IntelliJ IDEA 7.0.x include plugins that provide support for configuring GlassFish. This blog provides clear instructions on how to get started by developing and deploying a JSP, Servlet and Web services using GlassFish in IntelliJ. The instructions are using IntelliJ 7.0.3 Build #7757 (with no additional plugins).


  1. Create a new project


    1. Clicking on "Create New Project" or "File", "New Project". Take the default as shown below:






      and click on "Next >".

    2. Enter the project name as "GlassFishRocks" and take all defaults as shown:







      and click on "Next >".


    3. Take another default for the source directory as shown:







      and click on "Next >".

    4. For the first time use, JDK needs to be specified. Click on "+" in top-left corner as shown here:







      Take the default option of "JSDK" and specify the Home Directory as shown:







      Click on "OK" and then click on "Next >".

    5. Let's create a Web application. Select the list of technologies as shown:







      and finally (phew!) click on "Finish". The expanded project looks like:





  2. Create a GlassFish configuration


    1. Select "Run", "Edit Configurations" as shown:






    2. Click on "+" on top-left corner and select GlassFish as shown below:






    3. Specify the location of GlassFish Application server at:







      by clicking on "Configure" button and enter the values as shown:







      and click on "OK". You can download and install GlassFish v2 UR2 from here.


    4. Enter the "Name" and select the "Server Domain" as shown:







      and click on "OK".


  3. Deploy the Web application


    1. Click on the green button in the toolbar:






    2. Click
      on the "Fix" button on the bottom and then click "Run". The recently created Web module is selected to be deployed as shown:




    3. This starts the GlassFish v2 UR2 Application Server and deploys the Web application showing the console as:







      and also shows the default page at "http://localhost:8080/GlassFishRocksWeb/". You can edit "index.jsp", re-deploy the Web facet and refresh the page to see the updated message.



      Notice, even though project's name is "GlassFishRocks", the application context root is "GlassFishRocksWeb".


  4. Now lets create/deploy a new Servlet.


    1. Create a new project as described above and name it "KillerServlet".

    2. Right-click on the project and select "New", "Servlet" as shown:




    3. Enter the values as shown:







      and click on "OK".

    4. The "Java EE: Structure" shows the project as:






    5. Double-click on "HelloServlet" (nested one) and add the following fragment to "doGet" method:









             
      java.io.PrintWriter out = response.getWriter();

             
      try {

                 
      out.println("<html>");

                 
      out.println("<head>");

                 
      out.println("<title>Servlet
      NewServlet</title>");

                 
      out.println("</head>");

                 
      out.println("<body>");

                 
      out.println("<h1>Servlet NewServlet at " +
      request.getContextPath () + "</h1>");

                 
      out.println("</body>");

                 
      out.println("</html>");

             
      } finally {

                 
      out.close();

              }



      NetBeans IDE auto-generates this code for a Servlet ;-) And add the following to "doPost" method:









           
       doGet(request, response);


    6. Double-click on "web.xml" and then select "Assembly Descriptor" tab.

    7. Click on "+" in Servlet Mappings and specify the values as:






    8. Deploy the project (as described above) and output from Servlet is displayed at "http://localhost:8080/KillerServletWeb/hello". Read more details in Creating Java EE Apps and Servlets with IntelliJ IDEA.



      Remember the weird context root, it's "KillerServletWeb" instead of "KillerServlet". Now there may be a good reason to do so but nothing obvious.


  5. Now lets create a simple Web service using the Metro Web services stack (the stack baked into GlassFish)


    1. Create a new project with name "GlassFishWS" following the instructions given above.

    2. Select the list of technologies as shown:




    3. The default generated Web service looks like:




    4. The default generated Web service uses light-weight Endpoint API to host the endpoint. Run the Web service by right-clicking in the editor pane and selecting "Run" as shown or default shortcut of Ctrl+Shift+F10:




    5. The WSDL is now available at
      "http://localhost:9000/HelloWorld?wsdl".

    6. Right-click on the project and select "New", "Web Service Client" as shown:







      enter the value as "WSClient" and click on "OK".

    7. In the next dialog, enter the values as shown:




    8. The generated client code has some errors as shown:







      Change the code to:









           
      client.HelloWorld service = new
      client.HelloWorldService().getHelloWorldPort();

            //invoke business
      method

           
      System.out.println(service.sayHelloWorldFrom("Duke"));


      and run WSClient.main to see the result as:







      Now you deployed a Metro Web service using light-weight Endpoint API.  The bundled plugin version is 0.9 build 2 and the steps are so much cleaner from 0.7 version of the plugin.



      Read more about Web Services support in IntelliJ IDEA.

    9. Deploying this Web service on GlassFish is really simple.


      1. Create a new GlassFish configuration as explained above.

      2. Run the project using this configuration and the Web service is now hosted
        at "http://localhost:8080/GlassFishWSWeb/services/HelloWorld?wsdl".

      3. Generate a client using the steps described above.




Here are few issues filed:


  • JEEAS-180 does not allow an application to be re-deployed to GlassFish and that's why the examples above use different projects.

  • JEEAS-181  asks for better integration of GlassFish logs in the IDE.

  • JEEAS-182 require support for GlassFish v3 in the GlassFish plugin. Please help by voting for this issue.

  • WSVC-61 reports the errors generated in Web services client code


So whether you are using Eclipse, IntelliJ or NetBeans - you can easily configure GlassFish and deploy your applications directly from within the IDE. Here are some related links:


However of all the IDEs, NetBeans IDE still provides the most comprehensive coverage
in terms of development and deployment of Java EE applications (JSP, Servles, Java Server Faces, SOAP-based
.NET 3.0-interoperable Web service, RESTful Web services, JPA, EJBs) and server plug-ins (GlassFish, Tomcat, JBoss, WebLogic, WebSphere, OC4J, SAP BusinessOne and JOnAS).





Technorati: glassfish
intellij idea jsp servlets metro webservices

GlassFish Family in Readers Choice Awards 2008 Finalists



2008
Readers Choice Awards
from href="http://soa.sys-con.com/">SYS-CON SOA World Magazine
are announced. There are quite a few projects from href="http://glassfish.org">GlassFish and sister
communities. The nominations are:



cellspacing="5">






style="width: 160px; height: 197px;" alt=""
src="http://blogs.sun.com/arungupta/resource/images/SOAWorld-2008RCAlogo.jpg">

cellpadding="2" cellspacing="2">














































href="http://glassfish.org/">GlassFish Best
App Server
href="http://hudson.dev.java.net/">Hudson Best
Automation Tool
href="http://metro.dev.java.net/">Metro Best
Framework
href="http://netbeans.org/">NetBeans Best
IDE
href="http://www.sun.com/software/javaenterprisesystem/javacaps/index.jsp">Java
CAPS
Best
Integration Tool
href="http://openesb.dev.java.net/">Project OpenESB Best
Open Source SOA Tool
href="http://metro.dev.java.net/">Metro: XML and Web
Services Security &  href="http://www.sun.com/software/products/access_mgr/">Sun
Access Manager/OpenSSO
Best
Security Solution
href="http://www.sun.com/software/javaenterprisesystem/javacaps/index.jsp">Sun
Java CAPS
Best
SOA Platform
href="http://www.sun.com/software/javaenterprisesystem/javacaps/index.jsp">Sun
Java CAPS
Best
SOA Tool
href="http://jaxp.dev.java.net/">Java API for XML Processing
(JAXP)
Best
Web Services Utility
href="http://jaxp.dev.java.net/">Java API for XML Processing
(JAXP)
Best
XML Parser




Even though voting startd on Jun 23 and finishes, after a looong voting
period, on Nov 15 the voting process is still not intuitive. Trying
different browsers on different machines didn't help either. Anyway, I
sent an email using their "Contact Us" link and hopefully will hear
from them soon :)



In the meanwhile, each of the nominated products above can brag with the logo on
their website.



Technorati: syscon
awards
glassfish
hudson
javacaps
metro href="http://technorati.com/tag/jaxp">jaxp

Wednesday, July 9, 2008

Ladies and gentlemen, this is Java EE 5!

My Google Alerts
href="http://plunchete.wordpress.com/2008/07/09/the-java-ee-5-song/">pointed
me to an href="http://blogs.sun.com/roumen/entry/new_song_java_ee_5">old
song on Java EE 5 by Roumen.



Enjoy a blogger's
geekiness about technology
and the lyrics are:



Ladies and gentlemen,
this is Java EE 5!




One, two, three, four,
five


There's a technology I
use day and night


For my application with
a web frontend


They told me to use .Net style="font-style: italic;">
But I really don´t wanna style="font-style: italic;">


So many bugs I fixed
last week.


My code is neat and talk
is a cheap


I like Glassfish, JSF,
persistence API


And as I continue you
know they´re gettin´ sweeter
style="font-style: italic;">


So what can I do I
really beg you my Lord


To me codin' it´s just
like a sport


All the bad code from
the past, let me dump it


Please set in the trumpet style="font-style: italic;">


A little bit of
injection in my life


A little bit of
persistence by my side


A little bit of NetBeans
is all I need


A little bit of EJB's
what I see


A little bit of
standards in the sun


A little bit of XML all
night long


A little bit web
services here I am


A little bit of code
makes me real man




This is Java EE 5! style="font-style: italic;">


Jump up and down and
move your code around


Shake your head to the
sound bury bad code under ground
style="font-style: italic;">
Move one step left and
one step right


One to the front and one
to the side


Refactor it once and
refactor it twice


If it looks like this
you're doin´ it right




A little bit of
injection in my life


A little bit of
persistence by my side


A little bit of NetBeans
is all I need


A little bit of EJB's is
what I see


A little bit of
standards in the sun


A little bit of XML all
night long


A little bit web
services here I am


A little bit of code
makes me real man




This is Java EE 5!



This is outright hilarious! Roman has moved onto a href="http://blogs.sun.com/roumen/entry/my_new_role_at_sun">different
role within Sun recently and is missed. But this song truly
conveys part of what I do on daily basis. I guess I should record one
for GlassFish ;-)



Technorati: javaee5
song href="http://technorati.com/tag/glassfish">glassfish

Tuesday, July 8, 2008

NetBeans 6.5 M1: GlassFish v3 + Rails



NetBeans IDE 6.5 Milestone 1 is now href="http://www.netbeans.org/servlets/NewsItemView?newsItemID=1254">available.
The New
and Noteworthy
feature list certainly makes it worthy for the
install - comprehensive PHP support ( href="http://www.netbeans.org/kb/docs/php/php-editor-screencast.html">Editor
Screencast and href="http://www.netbeans.org/kb/trails/php.html">PHP
Learning Trail), href="http://wiki.netbeans.org/NewAndNoteWorthyMilestone1NB65#section-NewAndNoteWorthyMilestone1NB65-JavaScriptDebugger">JavaScript
Debugger, href="http://wiki.netbeans.org/NewAndNoteWorthyMilestone1NB65#section-NewAndNoteWorthyMilestone1NB65-Groovy">Groovy
Editor, href="http://wiki.netbeans.org/NewAndNoteWorthyMilestone1NB65#section-NewAndNoteWorthyMilestone1NB65-GrailsSupport">Grails
support and Numerous improvements in other areas are some of
them.



Let's get started!


  1. Download href="http://bits.netbeans.org/download/6.5/m1/">NetBeans
    6.5 M1. Installation is pretty straight-forward and I
    customized it with the following options:



    src="http://blogs.sun.com/arungupta/resource/netbeans/nb6.5m1-custom-install.png">



    After a simple installation process, check the "About" box as:



    src="http://blogs.sun.com/arungupta/resource/netbeans/nb6.5m1-about.png">






  2. GlassFish v3
    plug-in and TP2
    is baked into the main release and so it is pre-configured for you. No
    need to install the href="http://blogs.sun.com/arungupta/entry/screencast_24_getting_started_with">additional
    plugin.



    This blog walks you through creating a simple Rails app and shows the
    nice improvements along the way.


  3. Let's create a simple Rails app:



    src="http://blogs.sun.com/arungupta/resource/netbeans/nb6.5m1-new-rails.png">



    Notice, GlassFish v3 is chosen as the default Server.

  4. Specify the database connection as:



    src="http://blogs.sun.com/arungupta/resource/netbeans/nb6.5m1-new-rails-db.png">



    and click on "Finish". NetBeans is bundled with JRuby 1.1.2 and Rails
    2.1.0.


  5. Start MySQL as "sudo mysqld_safe --user root".

  6. Running Rake commands from within is more natural now.
    Right-click on the project and select "Run/Debug Rake Task ..."



    src="http://blogs.sun.com/arungupta/resource/netbeans/nb6.5m1-run-rake.png">



    The dialog shows all the Rails rake tasks available. Typing the Rake
    command prunes the list matching

    the pattern and shows:



    src="http://blogs.sun.com/arungupta/resource/netbeans/nb6.5m1-rake-tasks.png">



    Type "db:create" and select "Run".


  7. Create a new Scaffold by right-clicking on "Project" and
    selecting "Generate..." and entering the value as shown:



    src="http://blogs.sun.com/arungupta/resource/netbeans/nb6.5m1-rails-new-scaffold.png">



    and clicking on "OK".


  8. Migrate the database by invoking Rake command as shown:



    src="http://blogs.sun.com/arungupta/resource/netbeans/nb6.5m1-rails-rake-db-migrate.png">



    and selecting "Run".


  9. Right-select the project and select "Run" as shown:



    src="http://blogs.sun.com/arungupta/resource/netbeans/nb6.5m1-rails-run.png">



    The default App Server page at "http://localhost:8080" is shown. This
    will be href="http://www.netbeans.org/issues/show_bug.cgi?id=139188">updated
    to "http://localhost:8080/RailsApplication19" which is the default
    Rails page for the final release.


  10. After adding couple of entries the final output looks like:



    src="http://blogs.sun.com/arungupta/resource/netbeans/nb6.5m1-rails-output.png">


With NetBeans 6.5, you can easily run your Rails applications on
GlassFish v3 by taking most of the defaults. href="http://developers.sun.com/appserver/reference/techart/rails_gf/">Rails
powered by the GlassFish Application Server explains the
reasons to do so.

Subsequent blog entries will highlight other aspects of NetBeans IDE
6.5 M1.



Technorati: href="http://technorati.com/tag/netbeans">netbeans
glassfish
v3 href="http://technorati.com/tag/rubyonrails">rubyonrails
mysql

Monday, July 7, 2008

Thursday, July 3, 2008

Running San Francisco Marathon 2008





Exactly 1 month later (Aug 3, 2008), I'll be running the San Francisco Marathon (First Half) - the coolest marathon right in the middle of Summer. Register Now!


Read the 2nd newlsetter for all the latest developments. Here are some of the features that make this marathon cool:

Watch the entire course of full marathon in the video footage that follows a group of runners, led by Dean Karnazes (the ultra marathon man).

Part 1 at ...





And then part 2 (starting @ mile 10) ...




This will be the 4th addition to my list of marathons:

I completed PG&E @ Rancho last weekend in 84 minutes (run+walk 56 mins to the
top starting from the first parking lot and downhill running) and
hope to run 4 more times in as many weekends before the race.

Technorati: running
marathon
runsfm

Wednesday, July 2, 2008

Hello blogspot!

Hello there!

I'm Arun Gupta and currently work for Sun Microsystems. I've been blogging for past 3 years at blogs.sun.com/arungupta and weblogs.java.net/blog/arungupta. A majority of content for this blog will be mirrored from those blogs. Sometimes I may blog additional content exclusively on this blog. I may even backdate some of the posts on this blog to make it more interesting.

Hope you'll like it, happy reading!