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;
}
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;
}
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);
}
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;
}
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;
}
Aggregations