You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Wojciech Ciesielski <wc...@f1.pl> on 2006/03/16 15:25:02 UTC

obtaining server URL (or ip and port) from plugin

Hi there,

I need to find URL to my application (http://myhost:8080/myAppContext) 
from within init() method of struts plugin (implementing PlugIn 
interface). Any ideas how can I do this programatically without 
specifying it explicitly in one of application configuration files?

Thanks in advance,

Wojtek

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: obtaining server URL (or ip and port) from plugin

Posted by Dave Newton <ne...@pingsite.com>.
Antonio Petrelli wrote:
> Wojciech Ciesielski ha scritto:
>> I need to find URL to my application
>> (http://myhost:8080/myAppContext) from within init() method of struts
>> plugin (implementing PlugIn interface). Any ideas how can I do this
>> programatically without specifying it explicitly in one of
>> application configuration files?
> You can't do it, in any part of your web-app! But what do you need
> your application URL for?

getServletContextName from ServletContext will give you the app context
(I think).

AFAIK the only way you can get the host and port etc. is by servicing a
request, but I have no idea if that's really true or not.

Dave



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: obtaining server URL (or ip and port) from plugin

Posted by Leon Rosenberg <ro...@googlemail.com>.
<2cents>
> try {
>   InetAddress addr = InetAddress.getLocalHost();
>   String hostname = addr.getHostName();
> } catch (UnknownHostException e) { }

This could easily return "localhost" (and the ip of 127.0.0.1) or
something as useless as this depending on your /etc/hosts. There is no
valid way to find out your address, since the url/domain that maps to
your server is not the domain your server runs at (think about vhosts,
loadbalancers, proxies and so on)

IMHO configuring it in an external file is the best reliable way to
get the data.
</2cents>

Leon

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: obtaining server URL (or ip and port) from plugin

Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
On Thu, March 16, 2006 10:52 am, Wojciech Ciesielski said:
>
>>>
>>> I need to find URL to my application
>>> (http://myhost:8080/myAppContext) from within init() method of struts
>>> plugin (implementing PlugIn interface). Any ideas how can I do this
>>> programatically without specifying it explicitly in one of
>>> application configuration files?
>> You can't do it, in any part of your web-app! But what do you need
>> your application URL for?
>> Ciao
>> Antonio

Well, that certainly *is* information you can get within a webapp... it's
fairly easy to construct that URL from with an Action for instance.  From
a plug-in though, I'm not so sure (interestingly, this question comes up
frequently... would make for a good Wiki post...)

Let's walk the object hierarchy and see if we can't find any help...
Remember we're trying to construct http://myhost:8080/myAppContext
dynamically...

PlugIn:
void init(ActionServlet servlet, ModuleConfig config)

Ok, we have an ActionServlet instance... ActionServlet extends from
HttpServlet... HttpServlet exposes a getServletContext() method...

ServletContext:
getServletContextName()

Ah, ok, we have the myAppContext portion at least!  Can we get host name? 
Well, generically we can:

try {
  InetAddress addr = InetAddress.getLocalHost();
  String hostname = addr.getHostName();
} catch (UnknownHostException e) { }

Ok, so now we need the port and the protocol... and I'm stumped :)  I
don't think you could get the protocol without making a request, and the
port I would think you would *have* to know before-hand anyway.  Can you
use config params for those two pieces of information?  If it's always
HTTP, then you just need to get the port, but again, that seems like
something that would be OK as an init param.

Frank

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: obtaining server URL (or ip and port) from plugin

Posted by Antonio Petrelli <br...@tariffenet.it>.
Wojciech Ciesielski ha scritto:
> We are trying to create distributed computing environment based on 
> web-apps with one master server where multiple processing servers 
> register themselves. Communication is done by calling action via HTTP. 
> And therefore I have to let master server know about URL of processing 
> server interface...
This is easier then. When the "slave" server registers itself, the 
"master" server can know its IP address by using 
ServletRequest.getRemoteAddr (or .getRemoteHost).
The context name can be passed by the "slave" server (as Dave wrote, 
ServletContext.getServletContextName).
For the port... I have no idea...
HTH a bit
Antonio

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [OT ]Re: obtaining server URL (or ip and port) from plugin

Posted by Dave Newton <ne...@pingsite.com>.
DGraham@EvergreenInvestments.com wrote:
> Did you even _LOOK_ at the url that I sent the first time?  Your slave 
> starts and fires init() and makes a call to the master, the master will 
> take the request and reconstruct the URL from the slave.
>   

How does this help? This is the URL that the slave requested; the OP
needs to know where the request came from--the _slave's_ hostname and port.

The port is the killer, AFAICT; I'm not sure if getRemoteHost includes
that, or if it did, if it would be useful since the port used to make
the request wouldn't be the post the server would _answer_ requests on.

Dave




---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [OT ]Re: obtaining server URL (or ip and port) from plugin

Posted by DG...@EvergreenInvestments.com.
Did you even _LOOK_ at the url that I sent the first time?  Your slave 
starts and fires init() and makes a call to the master, the master will 
take the request and reconstruct the URL from the slave.

Posted again JUST IN CASE: 
http://javaalmanac.com/egs/javax.servlet/GetReqUrl.html

-Dennis





Wojciech Ciesielski <wc...@f1.pl> 
03/16/2006 11:14 AM
Please respond to
"Struts Users Mailing List" <us...@struts.apache.org>


To
Struts Users Mailing List <us...@struts.apache.org>
cc

Subject
Re: [OT ]Re: obtaining server URL (or ip and port) from plugin








DGraham@EvergreenInvestments.com wrote:
> Assuming all of the "slaves" know the id of the "master", then maybe you 

> have a RegisterServlet that's called by a slave processing servers 
during 
> their init? http://javaalmanac.com/egs/javax.servlet/GetReqUrl.html
>
> -Dennis
> 
The problem is that slaves know master's URL but master also needs to 
know URL of slave server because it calls their methods (like 
http://myslave:8080/myProcessingApp/process.do) with tasks to process. 
And I can't find a good way to determine URL of slave servers :-/

Wojtek


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org



Re: [OT ]Re: obtaining server URL (or ip and port) from plugin

Posted by Wojciech Ciesielski <wc...@f1.pl>.

DGraham@EvergreenInvestments.com wrote:
> Assuming all of the "slaves" know the id of the "master", then maybe you 
> have a RegisterServlet that's called by a slave processing servers during 
> their init? http://javaalmanac.com/egs/javax.servlet/GetReqUrl.html
>
> -Dennis
>   
The problem is that slaves know master's URL but master also needs to 
know URL of slave server because it calls their methods (like 
http://myslave:8080/myProcessingApp/process.do) with tasks to process. 
And I can't find a good way to determine URL of slave servers :-/

Wojtek


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


[OT ]Re: obtaining server URL (or ip and port) from plugin

Posted by DG...@EvergreenInvestments.com.
Assuming all of the "slaves" know the id of the "master", then maybe you 
have a RegisterServlet that's called by a slave processing servers during 
their init? http://javaalmanac.com/egs/javax.servlet/GetReqUrl.html

-Dennis




Wojciech Ciesielski <wc...@f1.pl> 
03/16/2006 10:52 AM
Please respond to
"Struts Users Mailing List" <us...@struts.apache.org>


To
Struts Users Mailing List <us...@struts.apache.org>
cc

Subject
Re: obtaining server URL (or ip and port) from plugin







>>
>> I need to find URL to my application 
>> (http://myhost:8080/myAppContext) from within init() method of struts 
>> plugin (implementing PlugIn interface). Any ideas how can I do this 
>> programatically without specifying it explicitly in one of 
>> application configuration files?
> You can't do it, in any part of your web-app! But what do you need 
> your application URL for?
> Ciao
> Antonio
We are trying to create distributed computing environment based on 
web-apps with one master server where multiple processing servers 
register themselves. Communication is done by calling action via HTTP. 
And therefore I have to let master server know about URL of processing 
server interface...

Wojtek

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org



Re: obtaining server URL (or ip and port) from plugin

Posted by Wojciech Ciesielski <wc...@f1.pl>.
>>
>> I need to find URL to my application 
>> (http://myhost:8080/myAppContext) from within init() method of struts 
>> plugin (implementing PlugIn interface). Any ideas how can I do this 
>> programatically without specifying it explicitly in one of 
>> application configuration files?
> You can't do it, in any part of your web-app! But what do you need 
> your application URL for?
> Ciao
> Antonio
We are trying to create distributed computing environment based on 
web-apps with one master server where multiple processing servers 
register themselves. Communication is done by calling action via HTTP. 
And therefore I have to let master server know about URL of processing 
server interface...

Wojtek

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: obtaining server URL (or ip and port) from plugin

Posted by Antonio Petrelli <br...@tariffenet.it>.
Wojciech Ciesielski ha scritto:
> Hi there,
>
> I need to find URL to my application (http://myhost:8080/myAppContext) 
> from within init() method of struts plugin (implementing PlugIn 
> interface). Any ideas how can I do this programatically without 
> specifying it explicitly in one of application configuration files?
You can't do it, in any part of your web-app! But what do you need your 
application URL for?
Ciao
Antonio

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org