cancel
Showing results for 
Search instead for 
Did you mean: 

How to get the client IP using Web Dynpro API?

Former Member
0 Kudos

Hello,

Is it possible, using the Web Dynpro API, to get the IP of the client who called the application?

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Roy,

Use this code:


String ipAddress = WDProtocolAdapter
                   .getProtocolAdapter()
                   .getRequestObject()
                   .getClientHostAddress();

But please note that, this doesn't take care of proxy server issues.

Regards,

Satyajit.

Message was edited by: Satyajit Chakraborty

Former Member
0 Kudos

Hello Satyajit,

Thank you for your quick reply.

Where do I find WDProtocolAdapter? the NWDS can't locate it at any of the available imports...

Former Member
0 Kudos

Roy,

Are you using NW04s? If not then WDProtocolAdapter will not be available to you.

Regards,

Satyajit.

Former Member
0 Kudos

No I am not.

Is there any way to do it with version prior NW04s?

Former Member
0 Kudos

Roy,

There's a way but it uses internal WD non-api methods. And using such an approach is highly discouraged. So I think you'll have to modify what you are doing.

By the way, why do you want to get the client IP?

Regards,

Satyajit.

Former Member
0 Kudos

I need the IP since we have few branches who are using the portal and I need to costumise a certain behaviour according to the branch. At the moment, each branch has it's own proxy which generates an IP. I need this IP.

Could you please elaborate regarding non-api methods approach even though it is highly discouraged?

Former Member
0 Kudos

Roy,

May the WD gods have mercy on me for giving this solution


String ipAddress = WDWebContextAdapter
                   .getWebContextAdapter()
                   .getHttpServletRequest()
                   .getRemoteHost();

For using this approach, or to even see the getHttpServletRequest() method you should have the servlet.jar file in the classpath.

But beware that in the next version this method will be made non-public and your application will no longer run.

I would suggest using Java servlets for this purpose.

Regards,

Satyajit.

Former Member
0 Kudos

So what you suggest is create a Servlet and use it from the DynPro application? How can I consume a Servlet from the DynPro application?

Former Member
0 Kudos

Hi

Add the servlet.jar to your application buildpath.

HttpServletRequest request = ((IWebContextAdapter) WDWebContextAdapter.getWebContextAdapter()).getHttpServletRequest();

HttpSession session = request.getSession(true);

String ip=String.valueOf(request.getRemoteHost());

Kind Regards

Mukesh

Former Member
0 Kudos

Hello Mukesh,

But if I understand correctly it is the same method as Satyajit suggested and said it is not recommended. If this is the only way I assume I will go with it...

Former Member
0 Kudos

Hi

In my application I solved it by this way.But I am not sure this is the only solution.

Kind Regards

Mukesh

Former Member
0 Kudos

Satyajit,

Could you please elaborate the Java servlets solution which doesn't involve using these problematic methods which might be changed on later Dynpro versions?

Former Member
0 Kudos

Hi,

Go through <a href="/people/valery.silaev/blog/2005/06/29/apojo--almostplain-old-java-objects-as-model blog by Valery Silaev. This ought to give you some ideas.

Regards,

Satyajit.

Former Member
0 Kudos

thanx for the help, I will...

Former Member
0 Kudos

Hi Satyajit, you wrote that method getRemoteHost() has proxy issue.

Where can i find any info about this issue? This method sometimes returns multiple IP's in my application

Answers (0)