Search in sources :

Example 41 with APIMgtWSDLException

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);
    }
}
Also used : WSDLProcessor(org.wso2.carbon.apimgt.core.api.WSDLProcessor) APIMgtWSDLException(org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException) IOException(java.io.IOException)

Example 42 with APIMgtWSDLException

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);
}
Also used : WorkflowResponse(org.wso2.carbon.apimgt.core.api.WorkflowResponse) GeneralWorkflowResponse(org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse) Response(javax.ws.rs.core.Response) FileInfo(org.wso2.msf4j.formparam.FileInfo) APIMgtWSDLException(org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher) API(org.wso2.carbon.apimgt.core.models.API) File(java.io.File) FileInputStream(java.io.FileInputStream) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 43 with APIMgtWSDLException

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);
    }
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) APIMgtWSDLException(org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException)

Example 44 with APIMgtWSDLException

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);
    }
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) APIMgtWSDLException(org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream) SAXException(org.xml.sax.SAXException)

Example 45 with APIMgtWSDLException

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);
        }
    }
}
Also used : APIMgtWSDLException(org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException) APIMgtWSDLException(org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException) WSDLException(javax.wsdl.WSDLException) FileOutputStream(java.io.FileOutputStream) Definition(javax.wsdl.Definition) WSDLWriter(javax.wsdl.xml.WSDLWriter) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map) File(java.io.File)

Aggregations

APIMgtWSDLException (org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException)24 APIMgtWSDLException (org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException)22 IOException (java.io.IOException)15 File (java.io.File)12 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)10 ByteArrayInputStream (java.io.ByteArrayInputStream)9 HashMap (java.util.HashMap)9 Map (java.util.Map)9 WSDLException (javax.wsdl.WSDLException)9 WSDLException (org.apache.woden.WSDLException)9 InputStream (java.io.InputStream)8 WSDLProcessor (org.wso2.carbon.apimgt.core.api.WSDLProcessor)8 FileInputStream (java.io.FileInputStream)7 WSDLSOAPOperation (org.wso2.carbon.apimgt.impl.wsdl.model.WSDLSOAPOperation)7 WSDLReader (javax.wsdl.xml.WSDLReader)5 ErrorItem (org.wso2.carbon.apimgt.api.ErrorItem)5 APIMWSDLReader (org.wso2.carbon.apimgt.impl.utils.APIMWSDLReader)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 FileOutputStream (java.io.FileOutputStream)4 ArrayList (java.util.ArrayList)4