use of org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException 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.core.exception.APIMgtWSDLException 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.core.exception.APIMgtWSDLException 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;
}
use of org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException in project carbon-apimgt by wso2.
the class ApisApiServiceImplTestCase method testApisValidateDefinitionPostException.
@Test
public void testApisValidateDefinitionPostException() throws Exception {
printTestMethodName();
File file = new File(getClass().getClassLoader().getResource(WSDL_ZIP_LOCATION).getFile());
FileInputStream fis = new FileInputStream(file);
FileInfo fileInfo = new FileInfo();
fileInfo.setFileName(WSDL_ZIP);
ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
APIPublisher apiPublisher = powerMockDefaultAPIPublisher();
Mockito.doThrow(new APIMgtWSDLException("Error while validation", ExceptionCodes.INTERNAL_WSDL_EXCEPTION)).when(apiPublisher).extractAndValidateWSDLArchive(fis);
Response response = apisApiService.apisValidateDefinitionPost(WSDL, fis, fileInfo, null, getRequest());
fis.close();
assertEquals(response.getStatus(), 500);
}
use of org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException in project carbon-apimgt by wso2.
the class ApisApiServiceImplTestCase method testApisApiIdWsdlGetException.
@Test
public void testApisApiIdWsdlGetException() throws Exception {
printTestMethodName();
final String uuid = "11112222-3333-4444-5555-666677778888";
ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
APIStore apiStore = Mockito.mock(APIStoreImpl.class);
PowerMockito.mockStatic(RestApiUtil.class);
PowerMockito.when(RestApiUtil.getConsumer(USER)).thenReturn(apiStore);
Request request = getRequest();
PowerMockito.when(RestApiUtil.getLoggedInUsername(request)).thenReturn(USER);
Mockito.doReturn(true).when(apiStore).isWSDLExists(uuid);
Mockito.doReturn(false).when(apiStore).isWSDLArchiveExists(uuid);
Mockito.doThrow(new APIMgtWSDLException("Error while retrieving WSDL", ExceptionCodes.INTERNAL_WSDL_EXCEPTION)).when(apiStore).getAPIWSDL(uuid, "Sample");
Response response = apisApiService.apisApiIdWsdlGet(uuid, "Sample", null, null, request);
assertEquals(response.getStatus(), 500);
}
Aggregations