Search in sources :

Example 1 with WSDLValidationResponseDTO

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;
}
Also used : APIDefinitionValidationResponse_wsdlInfo_endpointsDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.APIDefinitionValidationResponse_wsdlInfo_endpointsDTO) APIDefinitionValidationResponse_wsdlInfoDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.APIDefinitionValidationResponse_wsdlInfoDTO) APIDefinitionValidationResponseDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.APIDefinitionValidationResponseDTO) APIDefinitionValidationResponse_wsdlInfo_bindingInfoDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.APIDefinitionValidationResponse_wsdlInfo_bindingInfoDTO)

Example 2 with 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();
}
Also used : WSDLValidationResponseDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.WSDLValidationResponseDTO) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap)

Example 3 with WSDLValidationResponseDTO

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;
}
Also used : MalformedURLException(java.net.MalformedURLException) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) WSDLValidationResponse(org.wso2.carbon.apimgt.impl.wsdl.model.WSDLValidationResponse) WSDLValidationResponseDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.WSDLValidationResponseDTO) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) URL(java.net.URL)

Example 4 with WSDLValidationResponseDTO

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;
}
Also used : WSDLInfo(org.wso2.carbon.apimgt.impl.wsdl.model.WSDLInfo) WSDLValidationResponseDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.WSDLValidationResponseDTO) WSDLValidationResponseWsdlInfoEndpointsDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.WSDLValidationResponseWsdlInfoEndpointsDTO) WSDLValidationResponseWsdlInfoDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.WSDLValidationResponseWsdlInfoDTO)

Aggregations

WSDLValidationResponseDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.WSDLValidationResponseDTO)3 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)1 WSDLInfo (org.wso2.carbon.apimgt.impl.wsdl.model.WSDLInfo)1 WSDLValidationResponse (org.wso2.carbon.apimgt.impl.wsdl.model.WSDLValidationResponse)1 APIDefinitionValidationResponseDTO (org.wso2.carbon.apimgt.rest.api.publisher.dto.APIDefinitionValidationResponseDTO)1 APIDefinitionValidationResponse_wsdlInfoDTO (org.wso2.carbon.apimgt.rest.api.publisher.dto.APIDefinitionValidationResponse_wsdlInfoDTO)1 APIDefinitionValidationResponse_wsdlInfo_bindingInfoDTO (org.wso2.carbon.apimgt.rest.api.publisher.dto.APIDefinitionValidationResponse_wsdlInfo_bindingInfoDTO)1 APIDefinitionValidationResponse_wsdlInfo_endpointsDTO (org.wso2.carbon.apimgt.rest.api.publisher.dto.APIDefinitionValidationResponse_wsdlInfo_endpointsDTO)1 WSDLValidationResponseWsdlInfoDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.WSDLValidationResponseWsdlInfoDTO)1 WSDLValidationResponseWsdlInfoEndpointsDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.WSDLValidationResponseWsdlInfoEndpointsDTO)1