Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Retrieving port information without using request object

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Hi,

I have a servlet coded and need to display the port number on which the server is running in the initialization of the servlet.

The problem is, when the servlet initializes, I don't have a HttpServletRequest object to get the port number. Is there a way by which the port number can be retreived during the init() of a servlet.

Please let me know.

Thanks,
Sumesh
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
"Sumesh",
Please check your private messages.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
You won't know the port number until a request comes in.
Containers can bind to more than one port.
In fact, they can host multiple virtual hosts which can each bind to several ports.
 
Sumesh Kumar
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Hi Ben,

Thanks for the prompt reply.

I still have a doubt. Doesn't every servlet have a port on which it waits for requests to come when it is initialized (I am sorry if that was a naive thing to ask). Since it is server side, it needs to behave like an application that listens on some port and accepts connection requests from client.

Thanks - Sumesh
 
Sumesh Kumar
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Hi Ben,

Few notes to add. Isn't it possible to access a Bootstrap port during the init to get the number. I am not referring to the ports assigned to multiple request but, referring to the ORB Bootstrap port at server side.

Thanks - Sumesh
 
Sheriff
Posts: 26791
82
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator

Originally posted by Sumesh Kumar:
Doesn't every servlet have a port on which it waits for requests to come when it is initialized (I am sorry if that was a naive thing to ask).

No. Servlets don't wait for requests at all. It's the container (Tomcat, Websphere, etc) that waits for requests, and when it gets a request then it passes the request to the servlet designated to handle it.

And as Ben already said, the container may wait for requests on several ports.

Really those port numbers are none of the application's business. Why do you think your servlet needs to know it?
 
Sumesh Kumar
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Hi Ben,

The scenario is a bit different from the usual servlets that we see.

I have an application server, which when started will load a servlet. However, on startup, only the init will be executed. The port that I am referring to is the ORB Bootstrap port that is found in server.xml file which contains all the properties of the server.

It is this port number that I need to retrieve.

Please let me know of your thoughts on this.

Thanks - Sumesh
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
There is nothing in the servlet API for doing this.

If you want to know the port numbers to which the container is binding, you would have to dig into the internals of the container (if Open Source) or parse the config file yourself.
 
Sumesh Kumar
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Thanks a lot for the information Ben. I guess, I will have to try some other means. Anyways, I will come up with other doubts too.
 
Sumesh Kumar
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Hi,

I would also like to let you know that my friend has implemented this using some IBM Websphere internal API. Please let me know if there is any provision like this in Websphere.

Thanks - Sumesh
 
Sheriff
Posts: 67590
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Questions on using container-proprietary features (which I would personally advise against using) should be asked in the forum for the specific container. Please post a new question in the Websphere forum.
    Bookmark Topic Watch Topic
  • New Topic