Skip to Content
avatar image
Former Member

Operating communication channel externally using UDF.

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Best Answer
    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();
    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.

    Add comment
    10|10000 characters needed characters exceeded

  • Jul 06, 2017 at 12:58 PM

    Did u select the External control option the CC monitoring?

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    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

    Add comment
    10|10000 characters needed characters exceeded

  • 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:

    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.

    Add comment
    10|10000 characters needed characters exceeded

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