on 07-06-2017 1:34 PM
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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 🙂
Did u select the External control option the CC monitoring?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Rohit!
I'm not quite sure but I guess that you should apply user name/password in request parameters as well:
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
User | Count |
---|---|
88 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.