Javaaxis calls phpwebservevice php webservice
Here, wsdl is used.
" http://192.168.1.12/ "); // This uri is the ip address of the your SERVER. // Register the function // $ soap-> addFunction (SOAP_FUNCTIONS_ALL); $ soap-> addFunction ('Get _ cpu_rate '); $ soap-> handle (); function get_cpu_rate ($ host_ip, $ cpu_limit_max, $ cpu_limit_min) {$ bandwidth = $ cpu_limit_max * 100; // $ bandwidth = $ cpu_limit_min * 100; $ conn = mysql_connect ("localhost ", "admin", "admin") or die ("cocould not connect :". mysql_error ()); Mysql_select_db ('mydb', $ conn); $ SQL = "select status from host where hostname = '". $ host_ip. "'"; $ query = mysql_query ($ SQL); $ host_msg = mysql_fetch_array ($ query); if ($ host_msg ['status'] = 3) {$ host_status = "online"; $ res = array (); $ sh = '/var/www/snmp_exec '. $ host_ip; exec ($ sh, $ res, $ rc); if ($ rc = 0) {$ cpu_util = $ res [4];} if ($ cpu_util >=$ cpu_limit_max_per) {// return $ cpu_util-$ cpu_limit_min_per; return "CPU used ". $ Cpu_util. "% is bigger ". $ cpu_limit_max;} if ($ cpu_util <= $ cpu_limit_min_per) {// return $ cpu_util-$ cpu_limit_min_per; return "CPU used ". $ cpu_util. "% is smaller ". $ cpu_limit_min;} return $ cpu_util. '%';} else {$ host_status = "deprecate"; return "down" ;}mysql_close ($ conn) ;}?>
The java end uses axis for calling.
package com.fei;import java.net.MalformedURLException; import java.rmi.RemoteException; import javax.xml.rpc.ServiceException; import org.apache.axis.client.Call; import org.apache.axis.client.Service;public class javasoapclient { public static void main(String[] args) throws ServiceException, MalformedURLException, RemoteException { String serviceUrl = "http://192.168.1.12/serverSoap.php"; Service service = new Service(); Call call = (Call) service.createCall(); call.setTargetEndpointAddress(new java.net.URL(serviceUrl)); call.setOperationName("get_cpu_rate"); String ip = "192.168.1.10"; double cpu_limit_max = 0.50; double cpu_limit_min = 0.01; String reVal = call.invoke(new Object[] {ip,cpu_limit_max,cpu_limit_min}).toString(); System.out.println(reVal); }}
Possible java packages
Axis-ant.jar
Axis. jar
Commons-discovery-0.2.jar
Commons-logging-1.0.4.jar
Jaxrpc. jar
Log4j-1.2.8.jar
Saaj. jar
Wsdl4j-1.5.1.jar
Axis: http://www.apache.org/dist/ws/axis/1_4/