JAVA如何调用SAP PI PO 发布的Web Services接口
请使用 SoapUI 在沙盒中测试这些 Web 服务,因为这些 Web 服务的 SAP 文档很少。SAP甚至可能在未来添加更多的Web服务。
SAP PO Web Services
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());
}
}
}
有用的链接:
Web 服务导航器:http://<host>:<port>/wsnavigator
单一服务管理:http://<host>:<port>/nwa/ssadmin
post SAP-Garson
原文链接:https://blog.csdn.net/dwjnhkbc123/article/details/125923285文章来自于网络,如果侵犯了您的权益,请联系站长删除!