Skip to Content
Author's profile photo Raghu Vamseedhar Reddy Kadipi Reddy

How to consume web services hosted by SAP PI / PO

This blog is about how to consume web services hosted by SAP PI / PO

Direct link: Consume web services hosted by SAP PI PO

Please test these web services in sandbox using SoapUI, as there is little SAP documentation of these web services. SAP may even add more web services in future.


Code used in the video:-


Java Language:-
-----------------------------
package com.web;
import java.net.Authenticator;
import java.net.HttpURLConnection;
import java.net.PasswordAuthentication;
import java.net.URL;
public class TestMain {
  public static void main(String[] args) throws Exception {
  Authenticator.setDefault(new Authenticator() {
  // This method is called when a password-protected URL is accessed
  @Override
  protected PasswordAuthentication getPasswordAuthentication() {
  return new PasswordAuthentication("UserId", "Password".toCharArray());
  }
  });
  HttpURLConnection con = (HttpURLConnection) new URL("http://Server:50200/ChannelAdminService/ChannelAdmin").openConnection();
  con.setRequestMethod("POST");
  con.setRequestProperty("content-type", "text/xml");
  con.setDoOutput(true);
  String s = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:urn=\"urn:com:sap:netweaver:pi:monitoring\">" +
  "   <soapenv:Header/>" +
  "   <soapenv:Body>" +
  "      <urn:getChannelAutomationStatus>" +
  "         <!--Zero or more repetitions:-->" +
  "         <channels name=\"CC_File_Sender\" service=\"BC_Test\" party=\"\">" +
  "         </channels>" +
  "      </urn:getChannelAutomationStatus>" +
  "   </soapenv:Body>" +
  "</soapenv:Envelope>";
  con.getOutputStream().write(s.getBytes());
  byte[] b = new byte[con.getInputStream().available()];
  con.getInputStream().read(b);
  System.out.println(new String(b));
  }
}
-----------------------------------------------------------------------------------------------------------------------------------------------------
Java Language (using WSDL):-
-----------------------------
package com.web;
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.List;
import javax.xml.ws.BindingProvider;
import com.sap.netweaver.pi.monitoring.ChannelAdminDescriptor;
import com.sap.netweaver.pi.monitoring.ChannelAdminStatus;
import com.sap.pi.monitoring.channel.ChannelAdminService;
import com.sap.pi.monitoring.channel.GetChannelAutomationStatusFault;
import com.sap.pi.monitoring.channel.IChannelAdmin;
public class MyMain {
  public static void main(String[] args) throws MalformedURLException, GetChannelAutomationStatusFault {
  IChannelAdmin ica = new ChannelAdminService().getChannelAdminPort();
  BindingProvider bp = (BindingProvider) ica;
  bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "UserId");
  bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "Password");
  ChannelAdminDescriptor cad = new ChannelAdminDescriptor();
  cad.setName("CC_File_Sender");
  cad.setService("BC_Test");
  cad.setParty("");
  List<ChannelAdminDescriptor> cadL = new ArrayList<ChannelAdminDescriptor>();
  cadL.add(cad);
  for (ChannelAdminDescriptor c : ica.getChannelAutomationStatus(cadL)) {
  System.out.println(c.getName());
  System.out.println(c.getService());
  List<ChannelAdminStatus> status = c.getStatus();
  System.out.println(status.get(0).getActivationState());
  }
  }
}
-----------------------------------------------------------------------------------------------------------------------------------------------------
Go Language:-
-----------------------------
package main
import (
  "bytes"
  "fmt"
  "io/ioutil"
  "net/http"
)
func main() {
  in := `<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:com:sap:netweaver:pi:monitoring">
   <soapenv:Header/>
   <soapenv:Body>
      <urn:getChannelAutomationStatus>
         <!--Zero or more repetitions:-->
         <channels name="CC_File_Sender" service="BC_Test" party="">
       
         </channels>
      </urn:getChannelAutomationStatus>
   </soapenv:Body>
</soapenv:Envelope>`
  req, _ := http.NewRequest("POST", "http://Server:50200/ChannelAdminService/ChannelAdmin", bytes.NewBufferString(in))
  req.SetBasicAuth("UserId", "Password")
  req.Header.Set("content-type", "text/xml")
  client := http.Client{}
  res, _ := client.Do(req)
  resB, _ := ioutil.ReadAll(res.Body)
  fmt.Println(string(resB))
}


Helpful Links: –

User roles required to perform above actions Assigning Permissions – SAP Library

How to use Integration Directory API

Web service navigator: – http://<host>:<port>/wsnavigator .

Single Service Administration: – http://<host>:<port>/nwa/ssadmin

Assigned Tags

      1 Comment
      You must be Logged on to comment or reply to a post.
      Author's profile photo p.bharat kharate
      p.bharat kharate

      Hello Raghu,

       

      I have followed the given steps and tried to execute the given program but It's giving me an error stating  "Exception in thread "main" java.lang.NoClassDefFoundError: com/sap/security/hardener/nw/facade/HardenerFacade". I tried to search for possible solution but I am not able to solve this issue. Please help me out with this issue.

      Refer the error thread snap attached below.

       It'll be really helpful if you provide your expertise to solve this issue.

       

      Thanks