Thursday, September 17, 2009

How to find which application is using port 80 on Windows

I wanted to install Apache Http Server but after the installation, it gave error that it is not able to run on port 80 as it was already being used by some other application. Using the following procedure, I came to know that Skype is using port 80 and its not IIS that I had initially thought of.

Procedure to find which application is using port 80:

  1. Open command prompt using "cmd" on Run window
  2. Type - netstat -ano findstr '80' - If this command does not yield anything use command - netstat -o
  3. It will give you a list of in which last column would contain the process id that is using the port. Normally you get something like this when you run this command -
    Proto Local Address Foreign Address State PID
    TCP pcx61s:http localhost:3376 ESTABLISHED 5288
  4. Thus now you know that process id - 5288 is using your port 80.
  5. Open windows Task Manager and see which application has the process id. By default, the process id column is not visible in Task manager. You can add the column using Windows Task Manager >> View >> Select Columns and select PID (Process Identifier) checkbox and click OK.

How to change Glassfish server default 8080 port in Windows

Very simple steps
  1. Open (in notepad or other text editor) domain.xml located in /glassfish/domains/domain1/config folder.
  2. Search for 8080 (there should be one occurance only ideally)
  3. Change it to 80 or 8088 or 8090 - whatever port no. you like and start the server.
  4. There is no step 4 :-)

All your calls to glassfish server now do not require 8080 in your url. This should work same on other platforms as well though I have not tested it. This way you should be able to change glassfish server other ports as well.

Thursday, September 10, 2009

Use of right join in Hibernate

Consider the following scenario where Company table has a foreign key pointing to CompanyType table and ContactPerson has a foreign key pointing to Company table.

ContactPerson –> Company –> CompanyType

In this case I want to get list of all companies with their company type name (rather than id) and name of employee. It doesn’t matter if there is any contact person available for the company or not. I at least should get the company details.

Now if you write an sql statement using left join, we would definitely get list of all companies. However with Hibernate, writing the hql statement using left join might not yield you the desired results and hence you need to use the right join as in the following example.

select
company.id as ID,
companytype.type as TYPE,
company.name as COMPNAME,
company.url as URL,
company.address as ADDRESS,
company.phone as PHONE,
contactperson.name as CONTACTPERSONNAME
from
hs.pojo.db.Companytype as companytype,
hs.pojo.db.contactperson as contactperson
right outer join
contactperson.comp as company
where
companytype.id <16 and
companytype.id >4 and
company.closed = 0 and
companytype.id = company.companytype