How to Integrate Glassfish with IIS

After working a new project for awhile (I’m working with PHP and Java).  As a quick background story, I’m using Symfony2 and Guzzle to make my calls to my Java webservices.  This was working out great except for one minor issue.  Well, minor if you count not being able to call my REST services through Guzzle.  My problem was that IIS is running my PHP application on port 80 while my Glassfish REST services were running on port 8080 (the Glassfish default).  I needed to set up my applications forward requests to Glassfish.  So I’ll quickly guide you how to set this up.  This will work for any application server, not just Glassfish.

  1. Make sure you have Glassfish and IIS installed.  I’m using Glassfish 3.1.2 and IIS 7.5.  Any other versions should work with a few modifications.  You can download the latest version of Glassfish here http://glassfish.java.net/ and all your latest IIS needs can probably be found here http://www.iis.net/.
  2. Download Microsoft Web Platform Installer 3.0.  You can find a download here http://www.microsoft.com/web/downloads/platform.aspx.  After you’ve finished your download install it.
  3. After you’ve install Microsoft Web Platform Installer 3.0 you need to install Web Farm Framework.  To do this launch IIS (Click start, run, then type IIS).
  4. You should see Web Platform Installer installed in the bottom pane of IIS.  Double click on it and then do a search for Web Farm Framework.  Image
  5. Click add and then Install.  You might have a few other components that need to be installed.  Go ahead and click accept.Image
  6. Woohoo that was awfully easy.  Now navigate to the main screen of IIS.  You should have a Server Farms node.  Click on Create Server Farm in the right panel.Image
  7. Enter the name of the server farm and click next.  Click finish without adding a server.  Click yes to add routing rules for the server.
  8. Select Servers then click Add Servers on the right pane.Image
  9. Enter the IP address or server name of the server you’re adding to the farm.  In my case this is localhost.  Click on Add and this will add the server to your farm.
  10. Click on Advanced settings and select the server you’ve added.  You should see the ports that you can assign to your server. Enter your port number for HTTP and HTTPS.  I’m entering 8080 because that’s what my Glassfish Server is running on.Image
  11. Great we’re almost there.  All we have to do now is set up some routing rules.  I only want certain URLs getting routed to Glassfish.  Select your server farm and then double click on Routing Rules.Image
  12. Now just add the rules you want to exclude.  Everything else will be forwarded.  I don’t want any PHP extensions forwarded nor do I want anything that’s URL contains app_dev.php (Development purposes with PHP).  My rules look like this.Image
  13. You’re all set!  Now you can hit your Glassfish URL’s without entering the port.  This fixed one of the issues I was having with Guzzle.

Now that we’ve set this up I’ll show you how to set up Symfony2 and Guzzle so you can start writing a PHP application that makes REST calls.

About these ads

14 thoughts on “How to Integrate Glassfish with IIS

    • If you’ve followed the tutorial it should be working. Please note that in your case you do not need any rewrite rules. IIS reroutes everything by default so only add what should not be redirected. I hope that helps.

  1. What did you have to do to get the farm for 64 bit installed on windows 7? I have Win 7 pro, with IIS 7.5. Web platform installer 4.0 contains only server farm 1.1, not 2.X. I tried to install off the Microsoft site, and refused to install it.

  2. I found this as practically the only info on the web to get glassfish working with IIS. However, I’ve had absolutely no luck at all. I finally was able to work through getting all of the correct versions installed so that things look correct. I’ve got my 3.1.2.2 glassfish running on a machine called enterprise. I’ve added the server farm, and created the server instance, which is a java servlet running on port 62162 (it’s a dev environment, so I’m not using 8080), I haven’t created any rules since I don’t know if that’s necessary. I’ve got a URL rewrite which looks for my URL and forwards to the server farm. I test the URL pattern and it matches. Do I need the load-balancing plugin for glassfish? I’m using the open source version so I know that’s not available. Any help is greatly appreciated.

    • Its been awhile since i wrote this. I didnt need the load balancing plugin when I wrote it but it could be required now. Are you running this on a production or development server?

      • The IIS server is a production server as it’s the only one in the company right now that has an SSLcert. My glassfish server is a Dev machine. My glassfish hosted application runs behind port 62162 at /OrderPortal. I’ve followed your steps, and everything seems to be set up correctly, but when I request ABC.com/OrderPortal, no forwarding to the server farm happens. The IIS logs show that the request came in the way I would expect, but it just returns a 404 error. Perhapsbi just need to learn more about the rewrite rules and how they are applied.

      • It sounds like its not redirecting properly. I know a few other people were having this issue. Id try seeing if you can access the development machine from another computer to see that the port isnt blocked. If that works then try playing around with the rewrite rules. The glassfish logs should tell you if a request is getting sent. It maybe sending a request but to the wrong url. Its possible another extension may need to be installed on iis which helped a few other people

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s