cancel
Showing results for 
Search instead for 
Did you mean: 

Operating communication channel externally using UDF.

Former Member
0 Kudos

Hi Gurus,

We've a requirement where I need to start communication channel externally from message mapping.

I've read this blog https://blogs.sap.com/2007/05/04/control-communication-channels-externally-without-using-rwb/. I am trying to use the same approach to execute the URL from UDF but It's not working.

UDF:

if (var1.equals("Yes"))

{

try{ URL myURL = new URL("http://hostname:portname/AdapterFramework/ChannelAdminServlet?party=*&service=*&channel=xxx&action=start");

URLConnection myURLConnection = myURL.openConnection(); myURLConnection.connect();

}

catch (MalformedURLException e)

{

// new URL() failed // ...

}

catch (IOException e)

{

// openConnection() failed // ...

}

}

return var1;

AFAIK, this is able to connect to the channel but is unable to execute the URL as expected.

Do I need to add any missing functions or piece of code to execute the communication channel externally?

Any pointer would be appreciated.

Thanks,

Rohit

Accepted Solutions (1)

Accepted Solutions (1)

former_member190293
Active Contributor

Hi Rohit!

This code works fine on my PI 7.4 system:

public class CommChannelSwitcher {
 public String setCCState(String httpString) {
String result = "";
StringBuilder response = new StringBuilder();
try {
URL url = new URL(httpString);
Authenticator.setDefault (new Authenticator() {protected PasswordAuthentication getPasswordAuthentication() {return new PasswordAuthentication ("user", "password".toCharArray());}});
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while ((line = rd.readLine()) != null)
response.append(line);
rd.close();
result = response.toString();
}
catch (Exception e) {
result = e.getMessage();
}
return result;
}
public static void main(String[] args) {
String getString = "http://pi_system:port/AdapterFramework/ChannelAdminServlet?party=&service=BC_MyComp&channel=CC_MyChannel&action=stop";
CommChannelSwitcher httpCaller = new CommChannelSwitcher();
System.out.println(httpCaller.setCCState(getString)); } }

Regards, Evgeniy.

manoj_khavatkopp
Active Contributor

Brilliant ! works perfectly on 7.31 as well.

former_member190293
Active Contributor

Hi Manoj!

Thank you very much for your positive response.

Regards, Evgeniy.

Former Member

This solution worked and I am able to automate the start/stop of channel using External control from Message Map.

Cheers 🙂

Answers (3)

Answers (3)

former_member186851
Active Contributor

Did u select the External control option the CC monitoring?

Former Member
0 Kudos

Yes, External Control has already been selected.

nikhil_bose
Active Contributor
0 Kudos

use browser to hit the url http://hostname:portname/AdapterFramework/ChannelAdminServlet?party=*&service=*&channel=xxx∾tion=sta...

action(s) you can try are: start | stop | status This would show the URL is working fine (and) the external control option is enabled for the particular comm channel.

Regards -Nikhil

former_member190293
Active Contributor
0 Kudos

Hi Rohit!

I'm not quite sure but I guess that you should apply user name/password in request parameters as well:

http://hostname:portname/AdapterFramework/ChannelAdminServlet?party=*&service=*&channel=xxx&action=s...&

sap-username=xxx&sap-password=xxx

But I'd suggest to add the following lines to your code:

Authenticator.setDefault (new Authenticator() {  protected PasswordAuthentication getPasswordAuthentication() {  return new PasswordAuthentication ("username", "password".toCharArray());  } });

Regards, Evgeniy.

Former Member
0 Kudos

This URL gets executed with or without username & password when I use it in the browser. However the same isn't being called upon via UDF.

Tried with adding your piece of code as well.

I think we're missing something in the code which is failing to execute the URL from udf :'(

former_member190293
Active Contributor

Hi Rohit!

The point is that your browser stores your user credentials in cache after first login. If you log out from your PI system next time you'll be asked for user name and password while attempting to perform HTTP query. And when you make the query from java code you need to apply user credentials within that call.

Regards, Evgeniy.