use of org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException in project carbon-apimgt by wso2.
the class APIPublisherImpl method updateAPIWSDL.
@Override
public String updateAPIWSDL(String apiId, InputStream inputStream) throws APIMgtDAOException, APIMgtWSDLException {
byte[] wsdlContent;
try {
wsdlContent = IOUtils.toByteArray(inputStream);
WSDLProcessor processor = WSDLProcessFactory.getInstance().getWSDLProcessor(wsdlContent);
if (!processor.canProcess()) {
throw new APIMgtWSDLException("Unable to process WSDL by the processor " + processor.getClass().getName(), ExceptionCodes.CANNOT_PROCESS_WSDL_CONTENT);
}
if (log.isDebugEnabled()) {
log.debug("Successfully validated the content of WSDL. API uuid: " + apiId);
}
getApiDAO().addOrUpdateWSDL(apiId, wsdlContent, getUsername());
if (log.isDebugEnabled()) {
log.debug("Successfully added WSDL to the DB. API uuid: " + apiId);
}
return new String(wsdlContent, APIMgtConstants.ENCODING_UTF_8);
} catch (IOException e) {
throw new APIMgtWSDLException("Error while updating WSDL of API " + apiId, e, ExceptionCodes.INTERNAL_WSDL_EXCEPTION);
}
}
use of org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException in project carbon-apimgt by wso2.
the class ApisApiServiceImplTestCase method testApisApiIdWsdlPutException.
@Test
public void testApisApiIdWsdlPutException() throws Exception {
printTestMethodName();
File file = new File(getClass().getClassLoader().getResource(WSDL_FILE_LOCATION).getFile());
FileInfo fileInfo = new FileInfo();
fileInfo.setFileName(WSDL_FILE);
InputStream inputStream = new FileInputStream(file);
ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
APIPublisher apiPublisher = powerMockDefaultAPIPublisher();
API api = SampleTestObjectCreator.createDefaultAPI().build();
Mockito.doThrow(new APIMgtWSDLException("Error while updating WSDL", ExceptionCodes.INTERNAL_WSDL_EXCEPTION)).when(apiPublisher).updateAPIWSDL(api.getId(), inputStream);
Response response = apisApiService.apisApiIdWsdlPut(api.getId(), inputStream, fileInfo, null, null, getRequest());
assertEquals(response.getStatus(), 500);
}
use of org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException in project carbon-apimgt by wso2.
the class AbstractWSDLProcessor method getSecuredParsedDocumentFromContent.
/**
* Returns an "XXE safe" built DOM XML object by reading the content from the byte array.
*
* @param content xml content
* @return an "XXE safe" built DOM XML object by reading the content from the byte array
* @throws APIMgtWSDLException When error occurred while reading from the byte array
*/
Document getSecuredParsedDocumentFromContent(byte[] content) throws APIMgtWSDLException {
InputStream inputStream = null;
try {
DocumentBuilderFactory factory = getSecuredDocumentBuilder();
DocumentBuilder builder = factory.newDocumentBuilder();
inputStream = new ByteArrayInputStream(content);
return builder.parse(inputStream);
} catch (ParserConfigurationException | SAXException | IOException e) {
throw new APIMgtWSDLException("Error while reading WSDL document", e);
} finally {
IOUtils.closeQuietly(inputStream);
}
}
use of org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException in project carbon-apimgt by wso2.
the class AbstractWSDLProcessor method getSecuredParsedDocumentFromPath.
/**
* Returns an "XXE safe" built DOM XML object by reading the content from the provided file path.
*
* @param path path to fetch the content
* @return an "XXE safe" built DOM XML object by reading the content from the provided file path
* @throws APIMgtWSDLException When error occurred while reading from file path
*/
Document getSecuredParsedDocumentFromPath(String path) throws APIMgtWSDLException {
InputStream inputStream = null;
try {
DocumentBuilderFactory factory = getSecuredDocumentBuilder();
DocumentBuilder builder = factory.newDocumentBuilder();
inputStream = new FileInputStream(new File(path));
return builder.parse(inputStream);
} catch (ParserConfigurationException | IOException | SAXException e) {
throw new APIMgtWSDLException("Error while reading WSDL document", e);
} finally {
IOUtils.closeQuietly(inputStream);
}
}
use of org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException in project carbon-apimgt by wso2.
the class WSDL11ProcessorImpl method updateEndpointsOfWSDLArchive.
/**
* Update the endpoint information of the WSDL (WSDL archive scenario) when an API and the environment details are
* provided
*
* @param api API
* @param environmentName name of the gateway environment
* @param environmentType type of the gateway environment
* @throws APIMgtWSDLException when error occurred while updating the endpoints
*/
private void updateEndpointsOfWSDLArchive(API api, String environmentName, String environmentType) throws APIMgtWSDLException {
for (Map.Entry<String, Definition> entry : pathToDefinitionMap.entrySet()) {
Definition definition = entry.getValue();
if (log.isDebugEnabled()) {
log.debug("Updating endpoints of WSDL: " + entry.getKey());
}
updateEndpointsOfSingleWSDL(api, environmentName, environmentType, definition);
if (log.isDebugEnabled()) {
log.debug("Successfully updated endpoints of WSDL: " + entry.getKey());
}
try (FileOutputStream wsdlFileOutputStream = new FileOutputStream(new File(entry.getKey()))) {
WSDLWriter writer = getWsdlFactoryInstance().newWSDLWriter();
writer.writeWSDL(definition, wsdlFileOutputStream);
} catch (IOException | WSDLException e) {
throw new APIMgtWSDLException("Failed to create WSDL archive for API:" + api.getId().getName() + ":" + api.getId().getVersion() + " for environment " + environmentName, e, ExceptionCodes.ERROR_WHILE_CREATING_WSDL_ARCHIVE);
}
}
}
Aggregations