views:

147

answers:

1

Hi there, guys!

I'm currently developing a set of webservices in Java, to host on Axis2 running over WebLogic 10.3.0. These webservices receive and return SOAP messages.

As I have a clustered environment on WebLogic, I would like to have the WebLogic's server name (the one I configured using the Administration Console) returned in the response message body. Is there any way I can do this programmatically or by configuration on the Administration Console?

Thanks in advance for your help solving this out!

+1  A: 

You can get the name of the server via localhost like this:

String hostname = InetAddress.getLocalHost().getHostName();

Update

The above returns the name of the server it runs in, so it would give the name of the webservice host.

If you need the name of the server in front of the webservice, you can get that from the request:

String hostname = request.getRemoteHost();

should do the trick. Beware that the remote hostname is what the socket client used to set up the connection, this need not be the DNS name. If you need the DNS name, you can use:

String hostname = InetAddress.getByName(request.getRemoteAddr()).getHostName();

Update 2

If what you mean is not related to the server (solution 1) or a forwarding proxy (solution 2) but a kind of logical cluster name, you could define that in your web.xml as context parameter:

<context-param>
    <param-name>clustername</param-name>
    <param-value>OurPrettyCluster</param-value>
</context-param>

and read that in your servlet:

ServletContext context = getServletContext();
String clustername = context.getInitParameter("clustername");

If this is also not helping, you need to update your question and describe your cluster configuration because with the information given not much more can be done.

rsp
this is het hostname of the server, not the name of the weblogic server
Salandur
As Salandur said, your solution outputs the the machine (host) name and IP address. I want to output the WebLogic's server name, that don't coincide with the host name (server/physical machine where WebLogic is deployed).
XpiritO
Following your last update (Update 2) to your reply, I have deployed a Web Application into a clustered environment with 2 instances. I'm currently using "HttpClusterServlet" for (load-balancing purposes) on the Admin Server (not clustered), which then redirects the request to one of the 2 clustered instances. What I want is to return the instance name (configured in the cluster's config.xml file) where the request was processed (the instance selected by the Admin Server on redirection). I want to use the cluster's config.xml file, that has the clustered servers names. Is that possible?
XpiritO
My first reply would tell you the hostname of the clustered server that handled the request after the redirect. If that is not what you need, you must retrieve the logical information from the servlet context which is defined in the web.xml of the clustered machine. If Weblogic does not update the cluster web.xml's, you need to do that by hand once and use code like in my 3rd answer.
rsp
Thanks "yesterday", I solved this out with a solution based on your 2nd update. +1!
XpiritO