Skip to Content
0

Operating communication channel externally using UDF.

Jul 06, 2017 at 12:34 PM

147

avatar image

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∾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.

Thanks,

Rohit

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
2

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.

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

Brilliant ! works perfectly on 7.31 as well.

1

Hi Manoj!

Thank you very much for your positive response.

Regards, Evgeniy.

2

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

Cheers :)

1
Raghuraman S Jul 06, 2017 at 12:58 PM
1

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.

0
Nikhil Bose Jul 07, 2017 at 01:22 PM
-3

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

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

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=start&

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.

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

0

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.

2