wsdl4jwrapper.java
来自「开源的axis2框架的源码。用于开发WEBSERVER」· Java 代码 · 共 503 行 · 第 1/2 页
JAVA
503 行
}
private static WSDLReader getWSDLReader() throws WSDLException {
// Keep this method private
WSDLReader reader;
try {
reader = (WSDLReader)AccessController.doPrivileged(
new PrivilegedExceptionAction() {
public Object run() throws WSDLException {
WSDLFactory factory = WSDLFactory.newInstance();
return factory.newWSDLReader();
}
});
} catch (PrivilegedActionException e) {
throw (WSDLException)e.getException();
}
return reader;
}
public WSDL4JWrapper(URL wsdlURL, Definition wsdlDefinition) throws WSDLException {
super();
this.wsdlURL = wsdlURL;
this.wsdlDefinition = wsdlDefinition;
}
//TODO: Perform validations for each method to check for null parameters on QName.
public Definition getDefinition() {
return wsdlDefinition;
}
public Binding getFirstPortBinding(QName serviceQname) {
// TODO Auto-generated method stub
Service service = getService(serviceQname);
if (service == null) {
return null;
}
Map map = getService(serviceQname).getPorts();
if (map == null || map.isEmpty()) {
return null;
}
for (Object listObject : map.values()) {
Port wsdlPort = (Port)listObject;
return wsdlPort.getBinding();
}
return null;
}
public String getOperationName(QName serviceQname, QName portQname) {
Port port = getPort(serviceQname, portQname);
Binding binding = port.getBinding();
if (binding == null) {
return null;
}
List operations = binding.getBindingOperations();
for (Object opObj : operations) {
BindingOperation operation = (BindingOperation)opObj;
return operation.getName();
}
return null;
}
private Port getPort(QName serviceQname, QName eprQname) {
Service service = getService(serviceQname);
if (service == null) {
return null;
}
return service.getPort(eprQname.getLocalPart());
}
public ArrayList getPortBinding(QName serviceQname) {
// TODO Auto-generated method stub
Map map = this.getService(serviceQname).getPorts();
if (map == null || map.isEmpty()) {
return null;
}
ArrayList<Binding> portBindings = new ArrayList<Binding>();
for (Object listObject : map.values()) {
Port wsdlPort = (Port)listObject;
Binding binding = wsdlPort.getBinding();
if (binding != null) {
portBindings.add(binding);
}
}
return portBindings;
}
public String getPortBinding(QName serviceQname, QName portQname) {
Port port = getPort(serviceQname, portQname);
if (port == null) {
return null;
}
Binding binding = port.getBinding();
return binding.getQName().getLocalPart();
}
public String[] getPorts(QName serviceQname) {
String[] portNames = null;
Service service = this.getService(serviceQname);
if (service == null) {
return null;
}
Map map = service.getPorts();
if (map == null || map.isEmpty()) {
return null;
}
portNames = new String[map.values().size()];
Iterator iter = map.values().iterator();
for (int i = 0; iter.hasNext(); i++) {
Port wsdlPort = (Port)iter.next();
if (wsdlPort != null) {
portNames[i] = wsdlPort.getName();
}
}
return portNames;
}
public Service getService(QName serviceQname) {
// TODO Auto-generated method stub
if (serviceQname == null) {
return null;
}
return wsdlDefinition.getService(serviceQname);
}
public String getSOAPAction(QName serviceQname) {
// TODO Auto-generated method stub
Binding binding = getFirstPortBinding(serviceQname);
if (binding == null) {
return null;
}
List operations = binding.getBindingOperations();
for (Object opObj : operations) {
BindingOperation operation = (BindingOperation)opObj;
List exElements = operation.getExtensibilityElements();
for (Object elObj : exElements) {
ExtensibilityElement exElement = (ExtensibilityElement)elObj;
if (isSoapOperation(exElement)) {
SOAPOperation soapOperation = (SOAPOperation)exElement;
return soapOperation.getSoapActionURI();
}
}
}
return null;
}
public String getSOAPAction(QName serviceQname, QName portQname) {
// TODO Auto-generated method stub
Port port = getPort(serviceQname, portQname);
if (port == null) {
return null;
}
Binding binding = port.getBinding();
if (binding == null) {
return null;
}
List operations = binding.getBindingOperations();
for (Object opObj : operations) {
BindingOperation operation = (BindingOperation)opObj;
List exElements = operation.getExtensibilityElements();
for (Object elObj : exElements) {
ExtensibilityElement exElement = (ExtensibilityElement)elObj;
if (isSoapOperation(exElement)) {
SOAPOperation soapOperation = (SOAPOperation)exElement;
return soapOperation.getSoapActionURI();
}
}
}
return null;
}
public String getSOAPAction(QName serviceQname, QName portQname, QName operationQname) {
Port port = getPort(serviceQname, portQname);
if (port == null) {
return null;
}
Binding binding = port.getBinding();
if (binding == null) {
return null;
}
List operations = binding.getBindingOperations();
if (operations == null) {
return null;
}
BindingOperation operation = null;
for (Object opObj : operations) {
operation = (BindingOperation)opObj;
}
List exElements = operation.getExtensibilityElements();
for (Object elObj : exElements) {
ExtensibilityElement exElement = (ExtensibilityElement)elObj;
if (isSoapOperation(exElement)) {
SOAPOperation soapOperation = (SOAPOperation)exElement;
if (soapOperation.getElementType().equals(operationQname)) {
return soapOperation.getSoapActionURI();
}
}
}
return null;
}
public URL getWSDLLocation() {
// TODO Auto-generated method stub
return this.wsdlURL;
}
private boolean isSoapOperation(ExtensibilityElement exElement) {
return WSDLWrapper.SOAP_11_OPERATION.equals(exElement.getElementType());
//TODO: Add Soap12 support later
// || WSDLWrapper.SOAP_12_OPERATION.equals(exElement.getElementType());
}
public String getTargetNamespace() {
// TODO Auto-generated method stub
return wsdlDefinition.getTargetNamespace();
}
/**
* This method provides a Java2 Security compliant way to obtain the InputStream
* for a given URLConnection object. This is needed as a given URLConnection object
* may be an instance of a FileURLConnection object which would require access
* permissions if Java2 Security was enabled.
*/
private InputStream getInputStream(URLConnection urlCon) throws Exception {
final URLConnection finalURLCon = urlCon;
InputStream is = null;
try {
is = (InputStream) AccessController.doPrivileged(
new PrivilegedExceptionAction() {
public Object run() throws IOException {
return finalURLCon.getInputStream();
}
});
}
catch(PrivilegedActionException e) {
throw e.getException();
}
return is;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?