Javaaxis calls phpwebservevice

Source: Internet
Author: User
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/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.