Insert Witty Irony Here

vince kraemer's Weblog


20070524 Thursday May 24, 2007

GlassFish Integration Features: NB 6.0

I noticed that planetnetbeans.org is pointing to this very idle feed for my blog, so many of my recent entries are not getting picked up. I figured I would provide an "index" entry here, until the planet folks get this worked out....

I recently started a new series of entries. You can follow this link to a search for all of my entries about new GlassFish integration features for NetBeans 6.0.

I also have some information about an experiment I am doing with web and enterprise projects related to keybindings. I looked at web application development in this first entry. I will post more results about enterprise project development sometime next week.

Insert a link to the news about the NetBeans 5.5.1 release here.

If you want to get the live feed of my NetBeans related entries, you will probably want to subscribe to: http://blogs.sun.com/vkraemer/feed/entries/rss?cat=%2FNetBeans
(2007-05-24 09:17:34.0) Permalink

20060204 Saturday February 04, 2006

What will you find here In this category, I document some of the things that I am doing to test the 'Ease of development' of Java EE 5.

For my tests, I develop Java EE 5 modules and application using NetBeans 5, which is quickly approaching release, instead of the bleeding edge NetBeans for Java EE 5 builds.

I will be using my Mac, which is running Mac OS X 10.4.3, Apple's JRE/JDK (build 1.5.0_05-72), recent NetBeans 5.0 builds and recent promoted GlassFish builds.

Since NetBeans 5 doesn't "support" Java EE 5 development, I figure this will really put the claims of the Java EE folks to the test.

So, ride along if you want. The trip may get bumpy, so be sure to hold on tight. I'll try to shout-out the bigger bumps so you can avoid them when you start doing you own development. (2006-02-04 09:42:45.0) Permalink

20060110 Tuesday January 10, 2006

Lazy people rejoice! I have been making people work too hard in the notes I have been writing in entries about using NetBeans 5 to create Java EE 5 artifacts. If a Web or Enterprise project is targetted for GlassFish, the javaee.jar file is already a library for that project [Explore the project's library node to see it].

Folks will need to remember that javaee.jar needs to be added to General projects (Java Application and Java Class Library) that need to use Java EE 5 annotations. (2006-01-10 08:38:58.0) Permalink

20060108 Sunday January 08, 2006

Fastest Web Service Development in the West Well, I read through this extensive article about creating Web Services and am ready to give you an alternative approach. After I show you how I approach doing Web Service development, I will compare the two approaches.

Get Ready

You need to install GlassFish and NetBeans 5. I am using GlassFish build 32 and a nightly build of NetBeans 5 (which will be an RC any day now). Once you install these, register the GlassFish instance with NetBeans.

Implement A Service

I will create a web-app based service, just like the other author did.

So, I create a web-app.

I create a class that will implement my service.

I add the service annotations.

    package services;
    
    import javax.jws.WebMethod;
    import javax.jws.WebService;
    
    @WebService
    public class Greeting {
        @WebMethod public String sayHello(String name) {
            return "May I be of service, "+name+"?";
        }
    }
    
I change the web.xml file, so that the web app will be deployed as a Java EE 5 component, instead of a J2EE 1.4 component. To do this you just need to change the web-app element from
<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">
to
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
	 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
	 version="2.5">
I deploy the project.

Testing the Service

The GlassFish implementation of Java EE 5 includes the ability to test web services from within the Admin Console. Testing is just one of the features of the web service management capabilities in the Admin Console.

You can open the Admin console from within NetBeans, using the context menu of the target instance.

There are two sets of pages associated with web services. The first set provides general information about the services deployed on your instance. The other tab in the set allows you to create a catalog of registries.

The second set of pages/tabs allows you to manipulate individual services. The General tab provides all sorts of detailed information and has the Test button.

A new browser window opens when you press the Test button.

After you enter the arguments for the service, pressing the operation button provides the result and detailed informatiion about the SOAP messages exchanged between the service and the client.

Comparison of the two implementation methods

Both processes use JAX-WS 2.0 to implement a web service. Both methods deploy that service onto GlassFish. Both methods use NetBeans 5.0 as the development environment.

The method outlined in the other article stays within the boundries of what NetBeans 5.0 supports. My method goes outside that supported environment slightly, since changing the web-app element disables the web.xml multiview editor. If you need to do a lot of web.xml editing, change the web-app element LAST, so you can take advantage of the GUI editing capabilities.

The other method requires that you change the build.xml file for your web application. This is supported. The method that I outline in this entry pushes most of the "work" to the GlassFish deployment processing. This is also supported. It may be a bit less error-prone, since you won't need to remember to edit the build.xml for each SEI that is in the implementation WAR file.

Conclusion

At this point, you have a couple different strategies to implement JAX-WS 2.0 web services in NetBeans for deployment to GlassFish. Both are pretty easy to do.

You also have a couple different strategies for testing your web services.

You have seen some of the Web Service Management features exposed by the Admin Console.

Updates

Ludo pointed out a mistake in this note... If you register a project for deployment to a GlassFish domain, javaee.jar is ALREADY a library! To see it, explore the Libraries node of your web project. I have updated this note to account for that. I love it when things get easier! (2006-01-08 09:51:47.0) Permalink Comments [3]

20051230 Friday December 30, 2005

Creating a Web Service and a Web Service Client It looks like somebody beat me to the punch on this entry. There is an extensive article that covers this.

I may revisit this, soon, though.

I guess, I will need to take a look at this from the lazy man's perspective. (2005-12-30 01:38:13.0) Permalink

20051227 Tuesday December 27, 2005

What about Eclipse.... Though some of my co-workers may call me a traitor, I saw this article on developing EJB 3.0 using GlassFish with Eclipse.

As further evidence of Java EE 5's "ease of development", I don't think Filippo Diotalevi is using Eclipse's WTP. (2005-12-27 17:57:27.0) Permalink Comments [2]

20051223 Friday December 23, 2005

Application Client/EJB 3.0 "Hello, <User>!"

In this entry, I am going to extend the EJB that I created for my entry about creating a web application/EJB 3.0 version of "Hello, world!" to support a remote interface and create an application client that uses that interface.

An application client is an alternative to using a web based front-end. They are similar to plain old J2SE applications, except they typically run in a special environment, an Application Client Container or ACC.

Getting your client and the container to a remote machine hasn't been a trivial task. Project GlassFish includes a very interesting app client deployment feature: Java Web Start integration, that helps eliminate the pain. I will use it in this entry.

Since the app client is going to run in an external JVM, we need to add a remote interface to the EJB in the Greeter project. The code for that is pretty trival (and looks very similar to the code for the Local interface that you created in the previous entry.

    package beans;
    
    import javax.ejb.Remote;
    
    @Remote public interface DistantGreeting {
        String returnPoliteGreeting(String name);    
    }
    

The implementation of the bean needs to be modified, to implement this new additional interface.

    package impl;
    
    import beans.DistantGreeting;
    import beans.FriendlyGreeting;
    import javax.ejb.Local;
    import javax.ejb.Stateless;
    
    @Stateless public class GreetingImpl implements FriendlyGreeting, DistantGreeting {
        
        public String returnFriendlyGreeting(String name) {
            return "Well, good to see you again, "+name+"!";
        }
    
        public String returnPoliteGreeting(String name) {
            return "It is a pleasure to make your aquantance, "+name+".";
        }    
    }
    

At this point we can start to create the project that will be our Java EE 5 app client. It is going to be a standard Java Application Project.

I will call the new project, Client.

You will need to add javaee.jar and the Greeter project as libraries for compilation. You use the Libraries "page" of the Client's Properties dialog to do this.

The code for the client is very straight-forward. You will notice that it looks very similar to the code in the web application module. This is an "added feature" of using a ACC based client, over an RMI/IIOP client that accesses an EJB. For a very quick intro to the difference, you should look at an entry Petr Blaha wrote. The Developer's Guide has a detailed discussion of both flavors of application client.

    package client;
    
    import beans.DistantGreeting;
    import javax.ejb.EJB;
    
    public class Main {
        // NOTE: This bean MUST bean static for injection to work!
        // It is in the spec...
        static @EJB DistantGreeting bean;
        
        public static void main(String[] args) {
            System.out.println(bean.returnPoliteGreeting("Mr. Kraemer"));
        }    
    }
    

Now we need to add this new project to the Enterprise Application. The first step is adding an entry for the client in the application.xml file of the SampleOne project.

    <module><java>Client.jar</java></module>
    

Add the Client project to the Enterprise Application, using the Properties dialog for the SampleOne project.

You need to deploy your modified application, to get the new bits (the client and modified EJB ready for users to access).

After the application deploys successfully, you will be able to access a new URL on your server that will Java Web Start the application client. In my case, the URL is http://localhost:8080/sampleone/Client. If you have Java Web Start enabled, you will see a Java Web Start processing for a few seconds. Java Web Start will ask if you want to run code that has an invalid signature. (You will need to press Run for the rest of the magic to happen...)

Then...

Nothing appears to happen!?!

That's right. You will need to enable the Java Console to see the output of the application client. This is covered in detail as part of this entry in the GlassFish Project's Issue Tracker. I have an entry that talks about enabling the Java Console on Mac OS X. Another source has information about enabling the Java Console on various flavors of Windows.

Another alternative is to create an application client that has a graphical user interface written in Swing.
(2005-12-23 11:31:55.0) Permalink

20051222 Thursday December 22, 2005

Web Application/EJB 3.0 "Hello, <USER>!" This entry covers the "usual" first Java EE 5 application: Hello, World.

The first thing you need to do is create a new project that will be deployed onto the GlassFish instance that you registered earlier.

There are a couple different approaches you could take here. I recommend that you create an Enterprise Application, and let the wizard create the Web Application subproject. Part of the reason for this is lets you be lazy later on. While you may like creating servlets by hand, I like to let the wizards do it. Since the Servlet wizard is associated with Web Application projects, using an approach that doesn't use the Web Application project will mean you need to do more work.

One other thing to notice about the wizard is the fact that I have 'Set Source Level to 1.4' UNCHECKED. This will allow you to use annotation later on, so make sure you have it unchecked, too.

After the wizard finishes, create a java library project. It is going to be the project where you do the EJB 3.0 devlopment.

The Web Application and Java Library project needs to have access to the javaee.jar file, which is in <GlassFish-Install>/lib. It has the definition of the various Java EE 5 annotations that you'll use later on. You use the Project Properties dialog to add this jar file to the Web Application and Java Library projects.


This image is from the Web Application project.

The two Project Properties dialogs are very similar. You will see an additional column in the Web Application project's properties dialog. Make sure 'Package' is unchecked when you add javaee.jar to the Web Application project. Otherwise, the jar will be packaged in your web application's WEB-INF/lib directory, which is redundant....

You need to add the Java Library project to the compile properties of the Web Application, and the packaging properties of the Enterprise Application project. (Don't forget to uncheck the 'Package' attribute when you add the library project to the Web Application project).


Web Application Properties


Enterprise Application Properties

You need to add the Java Library that will implement your EJB 3.0 beans to the application.xml manually. Double clicking on the application.xml node, shown below, will open the file in an XML editor. It is easy to add the following:

    <module><ejb>Greeter.jar</ejb></module>
    
immediately following the module entry for PleasedToMeetYou.war.


Expanded Enterprise Application Project: application.xml visible

At this point the infrastructure is in place and it is time to start writing Java EE 5 code. The coding required to create an EJB 3.0 bean is wonderfully concise (compared to EJB 2.1).

First, we define the interface that says what a bean can do. This the text of the interface that I created.

    package beans;
    
    import javax.ejb.Local;
    
    @Local public interface FriendlyGreeting {   
        public String returnFriendlyGreeting(String name);    
    }
    

After defining the interface we need to create the implementation. That is relatively straight-forward, too.

    package impl;
    
    import beans.FriendlyGreeting;
    import javax.ejb.Local;
    import javax.ejb.Stateless;
    
    @Stateless public class GreetingImpl implements FriendlyGreeting {
        
        public String returnFriendlyGreeting(String name) {
            return "Well, good to see you again, "+name+"!";
        }
        
    }
    
Since NetBeans supports annotation and NetBeans 5.0 has some significant editor improvements, writing this code is easy. Since there are fewer interrelated files, many of the wizards that create EJB 2.1 artifacts seem heavy.
The one exception would probably be in the development of entity beans, which still require a lot of meta-data.

Once the bean is ready, it is time to call it. In my example, I am going to create a servlet to do that. Other folks have demonstrated other methods for calling your EJB 3.0 bean from a Web Application.

The easy way to create the servlet is to use the New item from the Web Application project's right-click menu.

Here is the text of my servlet.

    package lets;
    
    import beans.FriendlyGreeting;
    import java.io.*;
    import java.net.*;
    import javax.ejb.EJB;
    
    import javax.servlet.*;
    import javax.servlet.http.*; 
    
    public class EJB3Greeting extends HttpServlet {
        
        @EJB FriendlyGreeting bean;
        
        /** Processes requests for both HTTP GET and POST methods.
         * @param request servlet request
         * @param response servlet response
         */
        protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
            response.setContentType("text/html;charset=UTF-8");
            PrintWriter out = response.getWriter();
            //* TODO output your page here
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Servlet EJB3Greeting</title>");
            out.println("</head>");
            out.println("<body>");
            out.println("<h1>Servlet EJB3Greeting at " + request.getContextPath () + "</h1>"+
                    bean.returnFriendlyGreeting(request.getParameter("name")));
            out.println("</body>");
            out.println("</html>");
             //*/
            out.close();
        }
    
I have left out the boilerplate code that NetBeans has put into a code fold. If you want to see it, click on the boxed-plus icon that appears along the left hand side of the editor (after you use the wizard to create servlet).

At this point we are almost done. There is still one thing that needs to be changed and NetBeans has been finicky lately when I do this edit. You need to change the text of the web.xml, so that it refers to a Java EE 5 schema, instead of the J2EE 1.4 schema. The thing to do is replace the initial web-app element (which will look something like:

<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">
with somehting like this
<web-app version="2.5" 
         xmlns="http://java.sun. com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
The easiest way to make this stick is to copy the text above and paste it over the "old" web-app element in the web.xml file.

At this point you are ready to run the application. The thing to do is make sure that the project SampleOne is the Main Project. You can use the 'Set Main Project' item from the Enterprise Application right click menu to make it so. If it is the main project, then you can use the F6 key, to trigger the 'Run Main Project' item of the Run menu.

The IDE will start the server, deploy the application and open the browser. It will trigger the default welcome-file, index.jsp. If you append "/EJB3Greeting?name=foobar" to the URL, you will see this:

After going through this initial exercise, I would say that the Java EE 5 has done a good job of simplifying 'Hello, World!'. Java EE 5 covers a lot more technologies that what I've used here. I will look at some of these other technologies and see wheher they have the improved their ease of development. (2005-12-22 07:07:23.0) Permalink

20051220 Tuesday December 20, 2005

Register a Java EE 5 server While NetBeans 5 doesn't support Java EE 5, it does allow you to register a Java EE 5 implementation as a deployment target.

I found some instructions for registering a GlassFish instance into the NetBeans 5 Beta environment. Fortunately, they are mostly incorrect now. [Folks had a lot of trouble using the UI that was there in NetBeans 5 Beta, so we fixed it.] One important point from those instructions is still valid though; you must start NetBeans with J2SE 5.0 (aka jdk 1.5). I will walk you through the new screens and choices that are available in NetBeans 5.

Servers are registered in the NetBeans environment on the Runtime explorer (or tab).

Right click on the Servers node to expose the 'Add Server...' item and select it.

Choose 'Sun Java System Application Server' as the Server and provide Name for it.

The next page gives you a number of different options. Most users that install GlassFish will be using a private copy with its default domain. This is the option that is selected by default. Once the user enters the value of the 'Platform Location', the Domain combobox is automatically populated.

If you enter the path to a GlassFish installation, you may see an error message, if you have started the IDE in J2SE 1.4. GlassFish (and all of Java EE 5, really) depends on J2SE 5.0 features. NetBeans needs to load classes from the libraries that ship with GlassFish. The NetBeans FAQ has an entry about sepecifiying the JDK to use.

There are other options that are supported by additional pages of the wizard. The user can register a domain that they have created using 'asadmin create-domain', by choosing 'Register Local Domain'. If the user needs to deploy modules and applications to a remote server, they can register it using 'Register Remote Domain'.

In previous version of the IDE and plugin, there has been the ability to create a personal domain in situations where the user cannot use one of the other local domains. This had been a hidden feature, unlocked by analyzing the application server's installation and default domains. in this release, we expose the feature explicitly. There is a fair bit of data verification that the you need to do, so be prepared.

Once your server is registered, you can right click on it to expose actions to control it, view the log file and open the web-based administration interface, known as the Admin Console. Most of these actions only apply to LOCAL domains, since the plugin depends on various scripts in the insatllation directory to implement the actions.


Expanded Servers Node: GlassFish instance visible.

When you start the server, the server log is exposed. This allows you to diagnose start-up issue. The log is also exposed when you Run/Debug/Deploy projects to a Sun Java System Application Server.

The glyphs on the left side of the log window let you Start, Debug, Restart, Stop and Refresh the server status in a single click. (2005-12-20 18:24:02.0) Permalink

Calendar

« May 2008
SunMonTueWedThuFriSat
    
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
       
Today

RSS Feeds

XML
All
/5 in 5
/Compile Time
/Ease of Evolution
/General
/GlassFish
/Gotchas
/Java
/Music
/NetBeans

About Me

Photo of Vince Kraemer
Short Bio

Search

Links


Navigation



Subscribe with Bloglines Add to Technorati Favorites

Referers

Today's Page Hits: 280