Search in sources :

Example 6 with ErrorItem

use of org.wso2.carbon.apimgt.api.ErrorItem in project carbon-apimgt by wso2.

the class WSDL20ProcessorImpl method init.

@Override
public boolean init(URL url) throws APIMgtWSDLException {
    setMode(Mode.SINGLE);
    WSDLReader reader;
    try {
        reader = WSDLFactory.newInstance().newWSDLReader();
    } catch (WSDLException e) {
        throw new APIMgtWSDLException("Error while initializing the WSDL reader", e);
    }
    reader.setFeature(WSDLReader.FEATURE_VALIDATION, false);
    Document document = getSecuredParsedDocumentFromURL(url);
    WSDLSource wsdlSource = getWSDLSourceFromDocument(document, reader);
    try {
        wsdlDescription = reader.readWSDL(wsdlSource);
    } catch (WSDLException e) {
        // This implementation class cannot process the WSDL.
        log.debug("Cannot process the WSDL by " + this.getClass().getName(), e);
        setError(new ErrorItem(ExceptionCodes.CANNOT_PROCESS_WSDL_CONTENT.getErrorMessage(), e.getMessage(), ExceptionCodes.CANNOT_PROCESS_WSDL_CONTENT.getErrorCode(), ExceptionCodes.CANNOT_PROCESS_WSDL_CONTENT.getHttpStatusCode()));
    }
    return !hasError;
}
Also used : APIMgtWSDLException(org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException) APIMgtWSDLException(org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException) WSDLException(org.apache.woden.WSDLException) ErrorItem(org.wso2.carbon.apimgt.api.ErrorItem) WSDLSource(org.apache.woden.WSDLSource) Document(org.w3c.dom.Document) WSDLReader(org.apache.woden.WSDLReader) APIMWSDLReader(org.wso2.carbon.apimgt.impl.utils.APIMWSDLReader)

Example 7 with ErrorItem

use of org.wso2.carbon.apimgt.api.ErrorItem in project carbon-apimgt by wso2.

the class WSDL20ProcessorImpl method init.

@Override
public boolean init(byte[] wsdlContent) throws APIMgtWSDLException {
    setMode(Mode.SINGLE);
    WSDLReader reader;
    try {
        reader = getWsdlFactoryInstance().newWSDLReader();
    } catch (WSDLException e) {
        throw new APIMgtWSDLException("Error while initializing the WSDL reader", e);
    }
    reader.setFeature(WSDLReader.FEATURE_VALIDATION, false);
    Document document = getSecuredParsedDocumentFromContent(wsdlContent);
    WSDLSource wsdlSource = getWSDLSourceFromDocument(document, reader);
    try {
        wsdlDescription = reader.readWSDL(wsdlSource);
        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);
        setError(new ErrorItem(ExceptionCodes.CANNOT_PROCESS_WSDL_CONTENT.getErrorMessage(), e.getMessage(), ExceptionCodes.CANNOT_PROCESS_WSDL_CONTENT.getErrorCode(), ExceptionCodes.CANNOT_PROCESS_WSDL_CONTENT.getHttpStatusCode()));
    }
    return !hasError;
}
Also used : APIMgtWSDLException(org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException) APIMgtWSDLException(org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException) WSDLException(org.apache.woden.WSDLException) ErrorItem(org.wso2.carbon.apimgt.api.ErrorItem) WSDLSource(org.apache.woden.WSDLSource) Document(org.w3c.dom.Document) WSDLReader(org.apache.woden.WSDLReader) APIMWSDLReader(org.wso2.carbon.apimgt.impl.utils.APIMWSDLReader)

Example 8 with ErrorItem

use of org.wso2.carbon.apimgt.api.ErrorItem in project carbon-apimgt by wso2.

the class APIProviderImpl method publishToExternalAPIStores.

/**
 * Publish API to external stores given by external store Ids
 *
 * @param api              API which need to published
 * @param externalStoreIds APIStore Ids which need to publish API
 * @throws APIManagementException If failed to publish to external stores
 */
@Override
public boolean publishToExternalAPIStores(API api, List<String> externalStoreIds) throws APIManagementException {
    Set<APIStore> inputStores = new HashSet<>();
    boolean apiOlderVersionExist = false;
    APIIdentifier apiIdentifier = api.getId();
    for (String store : externalStoreIds) {
        if (StringUtils.isNotEmpty(store)) {
            APIStore inputStore = APIUtil.getExternalAPIStore(store, APIUtil.getTenantIdFromTenantDomain(tenantDomain));
            if (inputStore == null) {
                String errorMessage = "Error while publishing to external stores. Invalid External Store Id: " + store;
                log.error(errorMessage);
                ExceptionCodes exceptionCode = ExceptionCodes.EXTERNAL_STORE_ID_NOT_FOUND;
                throw new APIManagementException(errorMessage, new ErrorItem(exceptionCode.getErrorMessage(), errorMessage, exceptionCode.getErrorCode(), exceptionCode.getHttpStatusCode()));
            }
            inputStores.add(inputStore);
        }
    }
    Set<String> versions = getAPIVersions(apiIdentifier.getProviderName(), apiIdentifier.getName(), api.getOrganization());
    APIVersionStringComparator comparator = new APIVersionStringComparator();
    for (String tempVersion : versions) {
        if (comparator.compare(tempVersion, apiIdentifier.getVersion()) < 0) {
            apiOlderVersionExist = true;
            break;
        }
    }
    return updateAPIsInExternalAPIStores(api, inputStores, apiOlderVersionExist);
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier) ErrorItem(org.wso2.carbon.apimgt.api.ErrorItem) APIVersionStringComparator(org.wso2.carbon.apimgt.impl.utils.APIVersionStringComparator) ExceptionCodes(org.wso2.carbon.apimgt.api.ExceptionCodes) APIStore(org.wso2.carbon.apimgt.api.model.APIStore) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 9 with ErrorItem

use of org.wso2.carbon.apimgt.api.ErrorItem in project carbon-apimgt by wso2.

the class OASParserUtil method addErrorToValidationResponse.

/**
 * Add error item with the provided message to the provided validation response object
 *
 * @param validationResponse APIDefinitionValidationResponse object
 * @param errMessage         error message
 * @return added ErrorItem object
 */
public static ErrorItem addErrorToValidationResponse(APIDefinitionValidationResponse validationResponse, String errMessage) {
    ErrorItem errorItem = new ErrorItem();
    errorItem.setErrorCode(ExceptionCodes.OPENAPI_PARSE_EXCEPTION.getErrorCode());
    errorItem.setMessage(ExceptionCodes.OPENAPI_PARSE_EXCEPTION.getErrorMessage());
    errorItem.setDescription(errMessage);
    validationResponse.getErrorItems().add(errorItem);
    return errorItem;
}
Also used : ErrorItem(org.wso2.carbon.apimgt.api.ErrorItem)

Example 10 with ErrorItem

use of org.wso2.carbon.apimgt.api.ErrorItem in project carbon-apimgt by wso2.

the class WSDL11ProcessorImpl method init.

@Override
public boolean init(URL url) throws APIMgtWSDLException {
    setMode(Mode.SINGLE);
    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(url.toString(), getSecuredParsedDocumentFromURL(url));
        if (log.isDebugEnabled()) {
            log.debug("Successfully initialized an instance of " + this.getClass().getSimpleName() + " with a single WSDL.");
        }
    } catch (WSDLException | APIManagementException e) {
        // This implementation class cannot process the WSDL.
        log.debug("Cannot process the WSDL by " + this.getClass().getName(), e);
        setError(new ErrorItem(ExceptionCodes.CANNOT_PROCESS_WSDL_CONTENT.getErrorMessage(), e.getMessage(), ExceptionCodes.CANNOT_PROCESS_WSDL_CONTENT.getErrorCode(), ExceptionCodes.CANNOT_PROCESS_WSDL_CONTENT.getHttpStatusCode()));
    }
    return !hasError;
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) APIMgtWSDLException(org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException) WSDLException(javax.wsdl.WSDLException) ErrorItem(org.wso2.carbon.apimgt.api.ErrorItem) WSDLReader(javax.wsdl.xml.WSDLReader) APIMWSDLReader(org.wso2.carbon.apimgt.impl.utils.APIMWSDLReader)

Aggregations

ErrorItem (org.wso2.carbon.apimgt.api.ErrorItem)10 APIMWSDLReader (org.wso2.carbon.apimgt.impl.utils.APIMWSDLReader)6 APIMgtWSDLException (org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException)6 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)5 WSDLException (javax.wsdl.WSDLException)3 WSDLReader (javax.wsdl.xml.WSDLReader)3 WSDLException (org.apache.woden.WSDLException)3 WSDLReader (org.apache.woden.WSDLReader)3 WSDLSource (org.apache.woden.WSDLSource)3 Document (org.w3c.dom.Document)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 File (java.io.File)2 APIDefinitionValidationResponse (org.wso2.carbon.apimgt.api.APIDefinitionValidationResponse)2 Info (io.swagger.models.Info)1 Swagger (io.swagger.models.Swagger)1 SwaggerParser (io.swagger.parser.SwaggerParser)1 SwaggerDeserializationResult (io.swagger.parser.util.SwaggerDeserializationResult)1 OpenAPI (io.swagger.v3.oas.models.OpenAPI)1 Info (io.swagger.v3.oas.models.info.Info)1 OpenAPIV3Parser (io.swagger.v3.parser.OpenAPIV3Parser)1