JavaXT
|
|
Web ServicesThe javaxt.webservices package is used to parse WSDLs and dynamically execute web methods using SOAP over HTTP. This is a really nice alternative to creating proxy classes which tend to clutter up your code.WSDL ParserHere's a simple example of how to iterate through all the web methods found in a WSDL.//Parse WSDL String url = "http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso?WSDL"; javaxt.webservices.WSDL wsdl = new javaxt.webservices.WSDL(url); //Iterate Through the Services for (javaxt.webservices.Service service : wsdl.getServices()){ //Print service name System.out.println("------------------------"); System.out.println(service.getName() + " Service"); System.out.println("------------------------"); //Print web methods for (javaxt.webservices.Method method : service.getMethods()){ System.out.println(" + " + method.getName()); //Print parameters javaxt.webservices.Parameters parameters = method.getParameters(); if (parameters!=null){ for (javaxt.webservices.Parameter parameter : parameters.getArray()){ System.out.println(" - " + parameter.getName() + " (" + parameter.getType() + ")"); } } } } Dynamically Execute Web MethodsHere's a simple example of how to execute a web method. Note that there are no proxy classes or autogenerated code required to execute this web service request. //Parse WSDL String url = "http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso?WSDL"; javaxt.webservices.WSDL wsdl = new javaxt.webservices.WSDL(url); //Set Parameters javaxt.webservices.Service service = wsdl.getServices()[0]; javaxt.webservices.Method method = service.getMethod("CountryName"); javaxt.webservices.Parameters parameters = method.getParameters(); parameters.setValue("sCountryISOCode", "US"); //Execute Web Method and Print Response javaxt.webservices.SoapRequest soap = new javaxt.webservices.SoapRequest(service, method, parameters); try{ String countryName = soap.getResponse().toString(); System.out.println(countryName); } catch(Exception e){ e.printStackTrace(); } |