package com.landtool.lanbase.modules.res.controller;
|
|
import java.util.Iterator;
|
import java.util.Map;
|
|
import javax.wsdl.Binding;
|
import javax.wsdl.Definition;
|
import javax.wsdl.Service;
|
import javax.wsdl.WSDLException;
|
import javax.wsdl.factory.WSDLFactory;
|
import javax.wsdl.xml.WSDLReader;
|
|
import org.springframework.stereotype.Controller;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
@Controller
|
@RequestMapping("res/webservice")
|
public class WebServiceController {
|
|
@RequestMapping("/getWebServiceInfo")
|
@ResponseBody
|
public String getWebServiceInfo(String webServiceUrl){
|
String result = "";
|
if(webServiceUrl == null || webServiceUrl.equals("")){
|
return result;
|
}
|
if(webServiceUrl.indexOf("wsdl") == -1) {
|
webServiceUrl += (webServiceUrl.indexOf("?") != -1 ? "&wsdl" : "?wsdl");
|
}
|
try {
|
WSDLFactory factory = WSDLFactory.newInstance();
|
WSDLReader reader = factory.newWSDLReader();
|
reader.setFeature("javax.wsdl.verbose", true);
|
reader.setFeature("javax.wsdl.importDocuments", true);
|
Definition def = reader.readWSDL(webServiceUrl);
|
Map services = def.getServices();
|
Iterator<Map.Entry> siterator = services.entrySet().iterator();
|
String servcename = ((Service) siterator.next().getValue()).getQName().getLocalPart().toString();
|
String namespaceURI = def.getTargetNamespace();
|
Map bindings = def.getBindings();
|
Iterator<Map.Entry> biterator = bindings.entrySet().iterator();
|
String wsports = "";
|
while (biterator.hasNext()) {
|
Binding binding = (Binding) biterator.next().getValue();
|
if (binding != null) {
|
if (wsports != "") wsports += ",";
|
wsports += binding.getQName().getLocalPart();
|
}
|
}
|
result = "{wsports:'" + wsports + "',servicename:'" + servcename + "',tns:'" + namespaceURI + "'}";
|
} catch (WSDLException e) {
|
e.printStackTrace();
|
}
|
return result;
|
}
|
}
|