cancel
Showing results for 
Search instead for 
Did you mean: 

How to get Host name and port inside UDF

Former Member
0 Kudos

Hi,

I want to access the Host and port in UDF to pass it to a link http://host:port/AdapterFramework/ChannelAdminServlet?party=&service=&channel=*&action=status dynamically.

How can I acieve it?

Manisha

Accepted Solutions (0)

Answers (3)

Answers (3)

former_member181985
Active Contributor
0 Kudos

in UDF use this snippet to get host name dynamically

java.net.InetAddress.getLocalHost().getCanonicalHostName()

Former Member
0 Kudos

Hi

I am new to Java, Let me know what are the iports to access the method.

And which host name it will return? AS JAVA?? or Central instance?

Accordingly port has to pass. Is there any way to access port as well?

Giv me the deatil code to achieve this.

Manisha

former_member181985
Active Contributor
0 Kudos

Hi Manisha,

No special imports are required as the statement uses builtin JAVA SDK API.

>And which host name it will return? AS JAVA?? or Central instance?

Central Instance if all stacks are in one physical machine

>Accordingly port has to pass. Is there any way to access port as well?

Not sure.....But may be we can access the SAP system Number and based on this we can guess port in dynamic fashion.

If SAP INSTANCE NUMBER= XX

then

PORT = 50000+(Instance number *100)

Note: You can also get the instance by some code logic by working on general directory structure "\usr\sap\<SAPSID>\<Instance_Name>\j2ee". Use this option if you dont find any other way.

Edited by: Praveen Gujjeti on Mar 22, 2010 12:59 PM

Former Member
0 Kudos

Hi

With this code. I am getting error:

try

{

java.net.InetAddress addr = java.net.InetAddress.getLocalHost();

String host = addr.getCanonicalHostName();

}

catch (UnknownHostException e){}

if (ProcessMode.equals("P"))

{

try{

String xyz="/AdapterFramework/ChannelAdminServlet?party=&service=&channel="Name"&action=stop";

URL server = new URL("http", host, 8XXX, xyz);

tring userPassword =Userid + ":" + Password;

String encoding = new sun.misc.BASE64Encoder().encode (userPassword.getBytes());

URLConnection uc=server.openConnection();

uc.setRequestProperty ("Authorization", "Basic " + encoding);

BufferedReader br = new BufferedReader(new InputStreamReader(uc.getInputStream()));

while ((inputLine = br.readLine()) != null)

output+=inputLine;

br.close();

}

catch (Exception e){}

}

ERROR:

cannot resolve symbol

symbol : variable host location: class com.sap.xi.tf._MM_CommunicationChannel_Stop

_ URL server = new URL("http", host, 8xxx, xyz);

^ 1 error

Any other way to get host and port?

Manisha

former_member181985
Active Contributor
0 Kudos

Declare this in the top as a global variable.

String host = null;
try
{
java.net.InetAddress addr = java.net.InetAddress.getLocalHost();
host = addr.getCanonicalHostName();
}
catch (UnknownHostException e){}
.....
.....//remaining code

Former Member
0 Kudos

Thanks Praveen,

I got the host name dynamically any help for port access?

former_member181985
Active Contributor
0 Kudos

Check for note in my previous reply............

Former Member
0 Kudos

Hi Praveen,

Thanks a lot.

I got port as well:

int port = 0;

String instanceNumber = System.getProperty("SAPSYSTEM").toString(); //"SAPSYSTEM" returns System Number

port = 50000 + 100 * Integer.parseInt( instanceNumber);

~Manisha

former_member207622
Contributor
0 Kudos

Hi Manisha ,

In order to access port and hostname in java , please follow this link it has the source code ,

let me know if it suits your requirement .

http://www.roseindia.net/software-tutorials/detail/24223

Regards

Ninad

former_member200962
Active Contributor
0 Kudos

The URL you mentioned is of some channel in XI/ PI and hence the Host and port will also be of XI/ PI. For host you can use SAPSYSTEMNAME parameter.....for port i guess there is no parameter available.

Regards,

Abhishek.