use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.WSDLValidationResponseDTO in project carbon-apimgt by wso2.
the class MappingUtil method toWSDLValidationResponseDTO.
/**
* Map WSDLInfo to APIDefinitionValidationResponseDTO
*
* @param info WSDLInfo object
* @return {@link APIDefinitionValidationResponseDTO} based on provided {@link WSDLInfo} object
*/
public static APIDefinitionValidationResponseDTO toWSDLValidationResponseDTO(WSDLInfo info) {
APIDefinitionValidationResponseDTO wsdlValidationResponseDTO = new APIDefinitionValidationResponseDTO();
wsdlValidationResponseDTO.setIsValid(info.getVersion() != null);
APIDefinitionValidationResponse_wsdlInfoDTO infoDTO = new APIDefinitionValidationResponse_wsdlInfoDTO();
infoDTO.setVersion(info.getVersion());
APIDefinitionValidationResponse_wsdlInfo_endpointsDTO endpointsDTO;
if (info.getEndpoints() != null) {
for (String endpointName : info.getEndpoints().keySet()) {
endpointsDTO = new APIDefinitionValidationResponse_wsdlInfo_endpointsDTO();
endpointsDTO.setName(endpointName);
endpointsDTO.setLocation(info.getEndpoints().get(endpointName));
infoDTO.addEndpointsItem(endpointsDTO);
}
}
// currently operations are supported only in WSDL 1.1
if (APIMgtConstants.WSDLConstants.WSDL_VERSION_11.equals(info.getVersion())) {
APIDefinitionValidationResponse_wsdlInfo_bindingInfoDTO bindingInfoDTO = new APIDefinitionValidationResponse_wsdlInfo_bindingInfoDTO();
bindingInfoDTO.setHasHttpBinding(info.hasHttpBindingOperations());
bindingInfoDTO.setHasSoapBinding(info.hasSoapBindingOperations());
infoDTO.setBindingInfo(bindingInfoDTO);
}
wsdlValidationResponseDTO.setWsdlInfo(infoDTO);
return wsdlValidationResponseDTO;
}
use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.WSDLValidationResponseDTO in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method validateWSDLDefinition.
/**
* Validate a provided WSDL definition via a URL or a file/zip
*
* @param url WSDL URL
* @param fileInputStream file/zip input stream
* @param fileDetail file/zip details
* @param messageContext messageContext object
* @return WSDL validation response
* @throws APIManagementException when error occurred during validation
*/
@Override
public Response validateWSDLDefinition(String url, InputStream fileInputStream, Attachment fileDetail, MessageContext messageContext) throws APIManagementException {
Map validationResponseMap = validateWSDL(url, fileInputStream, fileDetail, false);
WSDLValidationResponseDTO validationResponseDTO = (WSDLValidationResponseDTO) validationResponseMap.get(RestApiConstants.RETURN_DTO);
return Response.ok().entity(validationResponseDTO).build();
}
use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.WSDLValidationResponseDTO in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method validateWSDL.
/**
* Validate the provided input parameters and returns the validation response DTO (for REST API)
* and the intermediate model as a Map
*
* @param url WSDL url
* @param fileInputStream file data stream
* @param fileDetail file details
* @param isServiceAPI is service api condition
* @return the validation response DTO (for REST API) and the intermediate model as a Map
* @throws APIManagementException if error occurred during validation of the WSDL
*/
private Map validateWSDL(String url, InputStream fileInputStream, Attachment fileDetail, Boolean isServiceAPI) throws APIManagementException {
handleInvalidParams(fileInputStream, fileDetail, url, null, isServiceAPI);
WSDLValidationResponseDTO responseDTO;
WSDLValidationResponse validationResponse = new WSDLValidationResponse();
if (url != null) {
try {
URL wsdlUrl = new URL(url);
validationResponse = APIMWSDLReader.validateWSDLUrl(wsdlUrl);
} catch (MalformedURLException e) {
RestApiUtil.handleBadRequest("Invalid/Malformed URL : " + url, log);
}
} else if (fileInputStream != null && !isServiceAPI) {
String filename = fileDetail.getContentDisposition().getFilename();
try {
if (filename.endsWith(".zip")) {
validationResponse = APIMWSDLReader.extractAndValidateWSDLArchive(fileInputStream);
} else if (filename.endsWith(".wsdl")) {
validationResponse = APIMWSDLReader.validateWSDLFile(fileInputStream);
} else {
RestApiUtil.handleBadRequest("Unsupported extension type of file: " + filename, log);
}
} catch (APIManagementException e) {
String errorMessage = "Internal error while validating the WSDL from file:" + filename;
RestApiUtil.handleInternalServerError(errorMessage, e, log);
}
} else if (fileInputStream != null) {
try {
validationResponse = APIMWSDLReader.validateWSDLFile(fileInputStream);
} catch (APIManagementException e) {
String errorMessage = "Internal error while validating the WSDL definition input stream";
RestApiUtil.handleInternalServerError(errorMessage, e, log);
}
}
responseDTO = APIMappingUtil.fromWSDLValidationResponseToDTO(validationResponse);
Map response = new HashMap();
response.put(RestApiConstants.RETURN_MODEL, validationResponse);
response.put(RestApiConstants.RETURN_DTO, responseDTO);
return response;
}
use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.WSDLValidationResponseDTO in project carbon-apimgt by wso2.
the class APIMappingUtil method fromWSDLValidationResponseToDTO.
/**
* Converts a WSDL validation response model to DTO.
*
* @param validationResponse validation response model
* @return Converted WSDL validation response model to DTO
*/
public static WSDLValidationResponseDTO fromWSDLValidationResponseToDTO(WSDLValidationResponse validationResponse) {
WSDLValidationResponseDTO wsdlValidationResponseDTO = new WSDLValidationResponseDTO();
WSDLInfo wsdlInfo;
if (validationResponse.isValid()) {
wsdlValidationResponseDTO.setIsValid(true);
wsdlInfo = validationResponse.getWsdlInfo();
WSDLValidationResponseWsdlInfoDTO wsdlInfoDTO = new WSDLValidationResponseWsdlInfoDTO();
wsdlInfoDTO.setVersion(wsdlInfo.getVersion());
List<WSDLValidationResponseWsdlInfoEndpointsDTO> endpointsDTOList = fromEndpointsMapToWSDLValidationResponseEndpointsDTO(wsdlInfo.getEndpoints());
wsdlInfoDTO.setEndpoints(endpointsDTOList);
wsdlValidationResponseDTO.setWsdlInfo(wsdlInfoDTO);
} else {
wsdlValidationResponseDTO.setIsValid(false);
wsdlValidationResponseDTO.setErrors(getErrorListItemsDTOsFromErrorHandler(validationResponse.getError()));
}
return wsdlValidationResponseDTO;
}
Aggregations