You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Seidhi H <se...@yahoo.com> on 2002/04/12 22:21:10 UTC

HOW-to get Host IP from within SOAP

Hi,
Greetings....
Is there a method to query and find the IP
address of the HOST that is currently used by the
server from SOAP/Axis.

I have a peculiar situation in which the WIN2K box
that runs Tomcat 4.0.1 [Catalina] has more than one
NIC. When i use the
InetAddress.getLocalHost().getHostAddress() from my a
handler that is called by the SOAP router, i get the
IP address that is other than the one on which Tomcat
is currently serving. But Tomcat seems to start fine
and is listening and serving clients if accessed using
the correct IP..... So how does AXIS retrieve this
information for it to work correctly.... Is there an
extensive validation before one can find the IP that
can be used for a web service/server???


TIA for your help,
S.


__________________________________________________
Do You Yahoo!?
Yahoo! Tax Center - online filing with TurboTax
http://taxes.yahoo.com/

RE: HOW-to get Host IP from within SOAP

Posted by Seidhi H <se...@yahoo.com>.
Hi Jack,
Greetings. I am sorry to get back on this after a
delay. I got engrossed in one other issue...
Thanks for your input and i shall be looking into this
today and post my feedback later today.
Currently i am investigating into SOAP and i am sure i
will find similar capabilities within SOAP. I may do
the same with AXIS later.....

Thanks again for the pointer.... 

Cheers!!!
S.
--- ajack <aj...@openbiz.biz> wrote:
> Seidhi,
> 
> I am no expert, but reading the code for AXIS beta 1
> I do not see a simpler
> way than:
> 
> 1)	Get the message context (call this inside your
> code, and it ought be set
> to the current call.)
> 
> 	MessageContext axisContext =
> MessageContext.getCurrentContext();
> 
> Note: I suspect this will return null if you are
> unit testing outside of
> AXIS, so check then.
> 
> 2) Get the servlet request object, using key :
> 
>       	HTTPConstants.MC_HTTP_SERVLETREQUEST
> 
> and extract the server name using something on that
> class, e.g.
> 
> 
>
http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/ServletRequest.h
> tml#getServerName()
> 
> 
> BTW: Not what you are asking for directly, but what
> I do is I get the remote
> IP address [so I can add it to my log4j context] so
> all errors/logs within
> that AXIS operation are logged with an IP address as
> context. Some
> properties are placed directly into the message
> context, mine is, I do not
> see the one that you want.
> 
> 	MessageContext axisContext =
> MessageContext.getCurrentContext();
> 
>      	if ( null != axisContext )
>       	{
>       								//
>       								//	Stash the IP address...
>       								//
>      	 	WSLogger.log.debug("AXIS Context (" +
> axisContext + ")");
>       		String ip	=
>
axisContext.getProperty(Constants.MC_REMOTE_ADDR).toString();
>       		if ( null != ip )
> 	      		WSLogger.log.pushContext("[Client: " + ip +
> "]");
>       	}
> 
> regards
> 
> Adam
> 
> -----Original Message-----
> From: Seidhi H [mailto:seidhi@yahoo.com]
> Sent: Friday, April 12, 2002 2:21 PM
> To: auser
> Subject: HOW-to get Host IP from within SOAP
> 
> 
> Hi,
> Greetings....
> Is there a method to query and find the IP
> address of the HOST that is currently used by the
> server from SOAP/Axis.
> 
> I have a peculiar situation in which the WIN2K box
> that runs Tomcat 4.0.1 [Catalina] has more than one
> NIC. When i use the
> InetAddress.getLocalHost().getHostAddress() from my
> a
> handler that is called by the SOAP router, i get the
> IP address that is other than the one on which
> Tomcat
> is currently serving. But Tomcat seems to start fine
> and is listening and serving clients if accessed
> using
> the correct IP..... So how does AXIS retrieve this
> information for it to work correctly.... Is there an
> extensive validation before one can find the IP that
> can be used for a web service/server???
> 
> 
> TIA for your help,
> S.
> 
> 
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Tax Center - online filing with TurboTax
> http://taxes.yahoo.com/
> 


__________________________________________________
Do You Yahoo!?
Yahoo! Tax Center - online filing with TurboTax
http://taxes.yahoo.com/

RE: HOW-to get Host IP from within SOAP

Posted by ajack <aj...@openbiz.biz>.
Seidhi,

I am no expert, but reading the code for AXIS beta 1 I do not see a simpler
way than:

1)	Get the message context (call this inside your code, and it ought be set
to the current call.)

	MessageContext axisContext = MessageContext.getCurrentContext();

Note: I suspect this will return null if you are unit testing outside of
AXIS, so check then.

2) Get the servlet request object, using key :

      	HTTPConstants.MC_HTTP_SERVLETREQUEST

and extract the server name using something on that class, e.g.


http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/ServletRequest.h
tml#getServerName()


BTW: Not what you are asking for directly, but what I do is I get the remote
IP address [so I can add it to my log4j context] so all errors/logs within
that AXIS operation are logged with an IP address as context. Some
properties are placed directly into the message context, mine is, I do not
see the one that you want.

	MessageContext axisContext = MessageContext.getCurrentContext();

     	if ( null != axisContext )
      	{
      								//
      								//	Stash the IP address...
      								//
     	 	WSLogger.log.debug("AXIS Context (" + axisContext + ")");
      		String ip	=
axisContext.getProperty(Constants.MC_REMOTE_ADDR).toString();
      		if ( null != ip )
	      		WSLogger.log.pushContext("[Client: " + ip + "]");
      	}

regards

Adam

-----Original Message-----
From: Seidhi H [mailto:seidhi@yahoo.com]
Sent: Friday, April 12, 2002 2:21 PM
To: auser
Subject: HOW-to get Host IP from within SOAP


Hi,
Greetings....
Is there a method to query and find the IP
address of the HOST that is currently used by the
server from SOAP/Axis.

I have a peculiar situation in which the WIN2K box
that runs Tomcat 4.0.1 [Catalina] has more than one
NIC. When i use the
InetAddress.getLocalHost().getHostAddress() from my a
handler that is called by the SOAP router, i get the
IP address that is other than the one on which Tomcat
is currently serving. But Tomcat seems to start fine
and is listening and serving clients if accessed using
the correct IP..... So how does AXIS retrieve this
information for it to work correctly.... Is there an
extensive validation before one can find the IP that
can be used for a web service/server???


TIA for your help,
S.


__________________________________________________
Do You Yahoo!?
Yahoo! Tax Center - online filing with TurboTax
http://taxes.yahoo.com/