Skip to Content

Operating communication channel externally using UDF.

Jul 06, 2017 at 12:34 PM


avatar image

Hi Gurus,

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

I've read this blog I am trying to use the same approach to execute the URL from UDF but It's not working.


if (var1.equals("Yes"))


try{ URL myURL = new URL("http://hostname:portname/AdapterFramework/ChannelAdminServlet?party=*&service=*&channel=xxx∾tion=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.



10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

4 Answers

Best Answer
Evgeniy Kolmakov Jul 07, 2017 at 07:09 AM

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();
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while ((line = rd.readLine()) != null)
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.

Show 3 Share
10 |10000 characters needed characters left characters exceeded

Brilliant ! works perfectly on 7.31 as well.


Hi Manoj!

Thank you very much for your positive response.

Regards, Evgeniy.


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

Cheers :)

Raghuraman S Jul 06, 2017 at 12:58 PM

Did u select the External control option the CC monitoring?

Show 1 Share
10 |10000 characters needed characters left characters exceeded

Yes, External Control has already been selected.

Nikhil Bose Jul 07, 2017 at 01:22 PM

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

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

10 |10000 characters needed characters left characters exceeded
Evgeniy Kolmakov Jul 06, 2017 at 12:45 PM

Hi Rohit!

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



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.

Show 2 Share
10 |10000 characters needed characters left characters exceeded

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 :'(


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.