use of org.wso2.carbon.apimgt.api.model.Wsdl in project carbon-apimgt by wso2.
the class WSDL11ProcessorImpl method getHttpBindingOperations.
/**
* Retrieves all the operations defined in the provided Binding.
*
* @param binding WSDL binding
* @return a set of {@link WSDLOperation} defined in the provided Binding
*/
private Set<WSDLOperation> getHttpBindingOperations(Binding binding) {
Set<WSDLOperation> allBindingOperations = new HashSet<>();
if (binding.getExtensibilityElements() != null && binding.getExtensibilityElements().size() > 0) {
if (binding.getExtensibilityElements().get(0) instanceof HTTPBinding) {
HTTPBinding httpBinding = (HTTPBinding) binding.getExtensibilityElements().get(0);
String verb = httpBinding.getVerb();
for (Object opObj : binding.getBindingOperations()) {
if (opObj instanceof BindingOperation) {
BindingOperation bindingOperation = (BindingOperation) opObj;
WSDLOperation wsdlOperation = getOperation(bindingOperation, verb);
if (wsdlOperation != null) {
allBindingOperations.add(wsdlOperation);
}
}
}
}
}
return allBindingOperations;
}
use of org.wso2.carbon.apimgt.api.model.Wsdl in project carbon-apimgt by wso2.
the class WSDL11ProcessorImpl method getHttpBindingOperations.
/**
* Retrieves all the operations defined in the provided WSDL definition.
*
* @param definition WSDL Definition
* @return a set of {@link WSDLOperation} defined in the provided WSDL definition
*/
private Set<WSDLOperation> getHttpBindingOperations(Definition definition) {
Set<WSDLOperation> allOperations = new HashSet<>();
for (Object bindingObj : definition.getAllBindings().values()) {
if (bindingObj instanceof Binding) {
Binding binding = (Binding) bindingObj;
Set<WSDLOperation> operations = getHttpBindingOperations(binding);
allOperations.addAll(operations);
}
}
return allOperations;
}
use of org.wso2.carbon.apimgt.api.model.Wsdl in project carbon-apimgt by wso2.
the class WSDL11ProcessorImpl method init.
/**
* {@inheritDoc}
* Will return true if the provided WSDL is of 1.1 and can be successfully parsed by WSDL4J.
*/
@Override
public boolean init(byte[] wsdlContent) throws APIMgtWSDLException {
WSDLReader wsdlReader = getWsdlFactoryInstance().newWSDLReader();
// switch off the verbose mode
wsdlReader.setFeature(JAVAX_WSDL_VERBOSE_MODE, false);
wsdlReader.setFeature(JAVAX_WSDL_IMPORT_DOCUMENTS, false);
try {
wsdlDefinition = wsdlReader.readWSDL(null, new InputSource(new ByteArrayInputStream(wsdlContent)));
canProcess = true;
if (log.isDebugEnabled()) {
log.debug("Successfully initialized an instance of " + this.getClass().getSimpleName() + " with a single WSDL.");
}
} catch (WSDLException e) {
// This implementation class cannot process the WSDL.
log.debug("Cannot process the WSDL by " + this.getClass().getName(), e);
canProcess = false;
}
return canProcess;
}
use of org.wso2.carbon.apimgt.api.model.Wsdl in project carbon-apimgt by wso2.
the class APIMWSDLUtils method getWSDL.
/**
* Retrieves the WSDL located in the provided URI ({@code wsdlUrl}
*
* @param wsdlUrl URL of the WSDL file
* @return Content bytes of the WSDL file
* @throws APIMgtWSDLException If an error occurred while retrieving the WSDL file
*/
public static byte[] getWSDL(String wsdlUrl) throws APIMgtWSDLException {
ByteArrayOutputStream outputStream = null;
InputStream inputStream = null;
URLConnection conn;
try {
URL url = new URL(wsdlUrl);
conn = url.openConnection();
conn.setConnectTimeout(CONNECTION_TIMEOUT);
conn.setReadTimeout(READ_TIMEOUT);
conn.connect();
outputStream = new ByteArrayOutputStream();
inputStream = conn.getInputStream();
IOUtils.copy(inputStream, outputStream);
return outputStream.toByteArray();
} catch (IOException e) {
throw new APIMgtWSDLException("Error while reading content from " + wsdlUrl, e, ExceptionCodes.INVALID_WSDL_URL_EXCEPTION);
} finally {
if (outputStream != null) {
IOUtils.closeQuietly(outputStream);
}
if (inputStream != null) {
IOUtils.closeQuietly(inputStream);
}
}
}
use of org.wso2.carbon.apimgt.api.model.Wsdl in project carbon-apimgt by wso2.
the class WSDL20ProcessorImpl method init.
/**
* {@inheritDoc}
* Will return true if the provided WSDL is of 2.0 and can be successfully parsed by woden library.
*/
@Override
public boolean init(byte[] wsdlContent) throws APIMgtWSDLException {
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
factory.setNamespaceAware(true);
DocumentBuilder builder = factory.newDocumentBuilder();
WSDLReader reader = getWsdlFactoryInstance().newWSDLReader();
reader.setFeature(WSDLReader.FEATURE_VALIDATION, false);
Document dom = builder.parse(new ByteArrayInputStream(wsdlContent));
Element domElement = dom.getDocumentElement();
WSDLSource wsdlSource = reader.createWSDLSource();
wsdlSource.setSource(domElement);
wsdlDescription = reader.readWSDL(wsdlSource);
canProcess = true;
if (log.isDebugEnabled()) {
log.debug("Successfully initialized an instance of " + this.getClass().getSimpleName() + " with a single WSDL.");
}
} catch (WSDLException | ParserConfigurationException | SAXException | IOException e) {
// This implementation class cannot process the WSDL.
log.debug("Cannot process the WSDL by " + this.getClass().getName(), e);
canProcess = false;
}
return canProcess;
}
Aggregations