Showing posts with label Glassfish. Show all posts
Showing posts with label Glassfish. Show all posts

Tuesday, August 3, 2010

Glassfish ESB, easier than you think. Part II

To continue from Part I, which simply just went in and out of the BPEL process, I will now add a couple EJBs to show a nice little Glassfish ESB structured activity, namely: Flow

Since this is now getting a little larger, I have made all the demo source available ... here.

So using the EJB project Wizard I create 2 EJB projects: DemoEJB1, DemoEJB2
once you have the project, Add a webservice:



For demo purposes I am going to have 2 web services with 2 methods, gatherAppData and gatherHistoryData, these 2 functions can happen concurrently and cause you no pain as long as you change different data in your object model.
Once that is done, from the project menu select the web service, drag it over to the right hand side of the BPEL editor, on the orange circle.



Then update the Partner Link information that pops up.


To execute the 2 web service calls concurrently you will need a "flow", grab that from the structured activities.



From the web service palette grab 2 invoke objects and place them in the flow.

Edit the invoke objects, choosing the different webservices.


Create variables for both, in and out. Try stick to a naming convention of some sorts as when you get to 20ish components it can get very messy.



So now the BPEL will look something like the following.


You can add as many concurrent steps to a flow as you like or as many different values you have within your object model.
To get these 2 invokes to function we need to assign the input and output variables and then assign the result of both to the output variable of the BPEL process. For each assign, map the input variable of the BPEL to the input variable of the relevant data for the service that is being called. In the 3rd assign map the relevant part of the each output variable to the output variable of the BPEL.

just for clarity here is the last assign in the mapper view.



And that is it... 2 concurrent web service requests within a Glassfish ESB process



The final steps are to add the newly created EJBs to the "Service Assembly" in the composite application, you can just drag the EJB project directly onto the middle JBI section, build, deploy and test.

Sunday, July 25, 2010

Glassfish ESB, easier than you think. Part I

Over the last 2 years I got to learn, use and enjoy OpenESB, we switched to GlassfishESB when it was released with the support of Sun. Unfortunately I am not using it anymore at work and I missed the 2.2 release in which there seems to have been a couple nice changes, but to get to the point. The concept of a ESB (Enterpise Service Bus) will seem daunting or intimidating to some people, this post is to get rid of that and show how developer friendly GlassfishESB can be. Another huge benefit people do not often mentioned is working on very large distributed applications a tool like GlassfishESB with it's visual representation of your entire deployment makes maintenance and system structural updates a lot simpler.

Anyways to begin...
Go download GlassfishESB / Netbeans / Glassfish and any other components you need here

Install it, start it up and you are probably half way done, it is that simple.

Ok so first thing you want to do is create a standard Java project.. and create some classes, for this demo I am just creating a simple "message" with a Header and Body:


Now the next bit is my way of "cheating" to actually have anything connect to the ESB process you need to have an webservice, you get that by defining a WSDL and XSD and adding them to the BPEL, but who wants to type out all that boring XML...

So now create an EJB Project:


Click next..



Click next... Finish

Add the Java project to the libs of the EJB project.



Create a new webservice...



And make sure that ... the EJBs' code looks like



Now for the cheat ...



This will generate the WSDL and XSD...

Now we create the BPEL Project


Copy the WSDL and XSD from the EJB Project..
Open the bpel... Drag the WSDL onto the little orange circle on the left, the following will popup:



Now your BPEL looks like:




Add a Receive, Assign and Reply to the BPEL, the edit the Receive:



Edit the Reply:



Click on the Assign and then on "mapper" in the bpel editor window, drag the contents of the In variable to the contents of the Out variable



Save, and done...

Now just add a composite application.



Open the Service Assmbly and drag the BPEL project onto the JBI module section:

:

Add some Endpoints from the Palette, connect the arrows:



Deploy.. and you are done.

If you like you can add a test to the Composite Application, very simple, On the Test folder, right click add, choose your main WSDL, choose the method you wanna test, it generates test xml based on the XSD. On the properties of the test set the port in ${HttpDefaultPort} in the properties of the test...and test...

In Part II , I will add some more EJBs, so that this actually becomes a functioning application and some more awesome GlassfishESB functionality.

Tuesday, July 13, 2010

Spring 3: RESTful Web service Support... Take 2 with JPA and on Glassfish 3

In my original example. I just used a horrible static list in a controller as state for the CRUD methods. I couldn't leave it like that so I have now updated that version to use JPA to a MySQL DB.

This updated source code, config and POM files are available in SVN

I am not going to go through all the code like in my first example, but just go through a couple things I changed and new things picked up while making the change

1.
This thing, that actually cost me quite a bit of time...
The exception:
"A JDBC Driver or DataSource class name must be specified in the ConnectionDriverName property"

Which actually meant in my example
"I couldn't find your persistence.xml" imagine that... obviously very clear.

When you have a web application you can not just put your JPA persistence.xml in the META-INF folder like you would with a EJB application. Sad thing is I actually (after struggling for quite a while) remembered I had read this while studying for the SCBCD exam like 2 months ago. Doh!

So you need it in a META-INF in with your source, so you can either put in in a jar or if you lazy just have a META-INF in java/main/src.

2.
Trying to get Hibernate to run on Glassfish 3 was more effort that I thought it would be, and plain straight JPA was quick and simple.

3.
I used MySQL many years back, and it was alright. This latest version 5.2 Rocks... Seriously, go download the DB server, the divers and the Workbench.. The workbench is the winner... simple easy admin, almost instant EER / ERD diagrams, nice SQL query interface too, for my own home development I doubt I will look any further.

4.
For the last project I worked on we used Hibernate, and we used the generation tools to create our mappings and DAOs, which left us will a ton of Abstract and Implementation classes. I was never a fan of all those so went searching while doing this example and came across the Java Generic DAO implementation, which is very nice.

So you create a base DAO with the Key and Entity defined as generic parameters, just for ease of reading i went with "key" and "entity" instead of the usual K and E.


You then just have the following very small implementations just defining the actual Class type.


Very neat.

5.
In my original controller I had:
@RequestMapping(value="/users/", method=RequestMethod.POST) on each method.

Much nicer to have that on Controller level and just the following on the methods:
@RequestMapping(method=RequestMethod.POST)


6.
I mapped my dto purely through JPA annotations:

Monday, July 12, 2010

Gah...This was annoying... Glassfish 3.0.1 on Vista...

I have some time off... So I decide to check out Glassfish 3.0.1 (yes that is very geeky), it should be a nice new toy even with and evil red logo on it now. I am quite fond of glassfish, it was a pleasure to work with as a developer. I had spent a good almost 2 years using and fighting for the use of Glassfish 2.1 / OpenESB or Glassfish ESB... and lost the month I decided to get married and go on honeymoon...
That is probably lesson in itself, with some kind of motto:Never go on leave

.... anyway ....

Back to my current annoying discovery:
I try start up Glassfish after the install... (in Netbeans 6.9) and it fails with a silly little error:
"Address family not supported by protocol family: bind: 7676"
and then proceeds to shutdown..

So off to google...
Read quite a few useless forum posts...
Eventually find the below... pay it no attention of course... and carry on reading useless posts...
"
Hi,

Try to change configuration of localhost in file
C:\Windows\System32\drivers\etc\hosts
from
::1 localhost
to
127.0.0.1 localhost
"

After another couple minutes, I decide "what the hell", and I go find the host file, make the change...big surprise... Windows doesn't let me.
Download "Unlocker", pretty neat utility if you want to overpower the Windows file locks, but it picks up no lock.
Another trip to google.... Only to find you need to run the edit application as an administrator obviously...

Make the change, and Tah Dah! Nice new Glassfish 3.0.1 server up and running.

Building KubeSkippy: Learnings from a thought experiment

So, I got Claude Code Max and I thought of what would be the most ambitious thing I could try "vibe"? As my team looks after Kuber...