Search in sources :

Example 1 with WSDLInfo

use of org.wso2.carbon.apimgt.core.models.WSDLInfo 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 WSDLInfo

use of org.wso2.carbon.apimgt.core.models.WSDLInfo in project carbon-apimgt by wso2.

the class ApisApiServiceImplTestCase method testApisValidateDefinitionPostWSDLArchive.

@Test
public void testApisValidateDefinitionPostWSDLArchive() throws Exception {
    printTestMethodName();
    File file = new File(getClass().getClassLoader().getResource(WSDL_ZIP_LOCATION).getFile());
    FileInputStream fis = new FileInputStream(file);
    FileInfo fileInfo = new FileInfo();
    fileInfo.setFileName(WSDL_ZIP);
    ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
    APIPublisher apiPublisher = powerMockDefaultAPIPublisher();
    WSDLArchiveInfo archiveInfo = new WSDLArchiveInfo("/tmp", "sample.zip");
    WSDLInfo wsdlInfo = new WSDLInfo();
    wsdlInfo.setVersion("1.1");
    archiveInfo.setWsdlInfo(wsdlInfo);
    Mockito.doReturn(archiveInfo).doThrow(new IllegalArgumentException()).when(apiPublisher).extractAndValidateWSDLArchive(fis);
    Response response = apisApiService.apisValidateDefinitionPost(WSDL, fis, fileInfo, null, getRequest());
    fis.close();
    assertEquals(response.getStatus(), 200);
    assertTrue(response.getEntity() instanceof APIDefinitionValidationResponseDTO);
    assertTrue(((APIDefinitionValidationResponseDTO) response.getEntity()).getIsValid());
}
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) WSDLInfo(org.wso2.carbon.apimgt.core.models.WSDLInfo) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher) WSDLArchiveInfo(org.wso2.carbon.apimgt.core.models.WSDLArchiveInfo) File(java.io.File) FileInputStream(java.io.FileInputStream) APIDefinitionValidationResponseDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.APIDefinitionValidationResponseDTO) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with WSDLInfo

use of org.wso2.carbon.apimgt.core.models.WSDLInfo in project carbon-apimgt by wso2.

the class ApisApiServiceImpl method apisValidateDefinitionPost.

/**
 * Validates a provided API definition
 *
 * @param type            API definition type (SWAGGER or WSDL)
 * @param fileInputStream file content stream
 * @param fileDetail      file details
 * @param url             URL of the definition
 * @param request         msf4j request
 * @return API definition validation information
 * @throws NotFoundException
 */
@Override
public Response apisValidateDefinitionPost(String type, InputStream fileInputStream, FileInfo fileDetail, String url, Request request) throws NotFoundException {
    String errorMessage = "Error while validating the definition";
    String username = RestApiUtil.getLoggedInUsername(request);
    try {
        APIPublisher apiPublisher = RestAPIPublisherUtil.getApiPublisher(username);
        if (StringUtils.isBlank(type)) {
            type = APIDefinitionValidationResponseDTO.DefinitionTypeEnum.SWAGGER.toString();
        }
        Response responseIfParamsInvalid = buildResponseIfParamsInvalid(type, fileInputStream, url);
        if (responseIfParamsInvalid != null) {
            return responseIfParamsInvalid;
        }
        if (APIDefinitionValidationResponseDTO.DefinitionTypeEnum.SWAGGER.toString().equals(type)) {
            if (log.isDebugEnabled()) {
                log.debug("Validating a swagger file.");
            }
            // TODO implement swagger validation
            return Response.noContent().build();
        } else {
            // WSDL type
            WSDLProcessor processor = null;
            WSDLInfo info = null;
            if (!StringUtils.isBlank(url)) {
                processor = WSDLProcessFactory.getInstance().getWSDLProcessor(url);
                info = processor.getWsdlInfo();
                if (log.isDebugEnabled()) {
                    log.debug("Successfully validated WSDL URL " + url);
                }
            } else {
                if (fileDetail.getFileName().endsWith(".zip")) {
                    WSDLArchiveInfo archiveInfo = apiPublisher.extractAndValidateWSDLArchive(fileInputStream);
                    info = archiveInfo.getWsdlInfo();
                    if (log.isDebugEnabled()) {
                        log.debug("Successfully validated WSDL archive " + fileDetail.getFileName());
                    }
                } else if (fileDetail.getFileName().endsWith(".wsdl")) {
                    byte[] wsdlContent = IOUtils.toByteArray(fileInputStream);
                    processor = WSDLProcessFactory.getInstance().getWSDLProcessor(wsdlContent);
                    info = processor.getWsdlInfo();
                    if (log.isDebugEnabled()) {
                        log.debug("Successfully validated WSDL file " + fileDetail.getFileName());
                    }
                } else {
                    String msg = "Unsupported extension type of file: " + fileDetail.getFileName();
                    log.error(msg);
                    ErrorDTO errorDTO = RestApiUtil.getErrorDTO(msg, 900700L, msg);
                    return Response.status(Response.Status.BAD_REQUEST).entity(errorDTO).build();
                }
            }
            if (info != null) {
                APIDefinitionValidationResponseDTO responseDTO = MappingUtil.toWSDLValidationResponseDTO(info);
                return Response.ok(responseDTO).build();
            }
            APIDefinitionValidationResponseDTO responseDTO = new APIDefinitionValidationResponseDTO();
            responseDTO.isValid(false);
            return Response.ok().entity(responseDTO).build();
        }
    } catch (APIManagementException e) {
        ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler());
        log.error(errorMessage, e);
        return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
    } catch (IOException e) {
        ErrorDTO errorDTO = RestApiUtil.getErrorDTO(errorMessage, 900313L, errorMessage);
        log.error(errorMessage, e);
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorDTO).build();
    }
}
Also used : WorkflowResponse(org.wso2.carbon.apimgt.core.api.WorkflowResponse) GeneralWorkflowResponse(org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse) Response(javax.ws.rs.core.Response) WSDLProcessor(org.wso2.carbon.apimgt.core.api.WSDLProcessor) WSDLInfo(org.wso2.carbon.apimgt.core.models.WSDLInfo) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) ErrorDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher) WSDLArchiveInfo(org.wso2.carbon.apimgt.core.models.WSDLArchiveInfo) IOException(java.io.IOException) APIDefinitionValidationResponseDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.APIDefinitionValidationResponseDTO)

Example 4 with WSDLInfo

use of org.wso2.carbon.apimgt.core.models.WSDLInfo in project carbon-apimgt by wso2.

the class WSDL11SOAPOperationExtractor method getWsdlInfo.

public WSDLInfo getWsdlInfo() throws APIMgtWSDLException {
    WSDLInfo wsdlInfo = new WSDLInfo();
    if (wsdlDefinition != null) {
        Set<WSDLSOAPOperation> soapOperations = getSoapBindingOperations(wsdlDefinition);
        wsdlInfo.setVersion(WSDL_VERSION_11);
        if (!soapOperations.isEmpty()) {
            wsdlInfo.setHasSoapBindingOperations(true);
            wsdlInfo.setSoapBindingOperations(soapOperations);
        } else {
            wsdlInfo.setHasSoapBindingOperations(false);
        }
        wsdlInfo.setHasSoapBindingOperations(hasSoapBindingOperations());
        wsdlInfo.setHasSoap12BindingOperations(hasSoap12BindingOperations());
        if (parameterModelMap.size() > 0) {
            wsdlInfo.setParameterModelMap(parameterModelMap);
        }
    } else {
        throw new APIMgtWSDLException("WSDL Definition is not initialized.");
    }
    return wsdlInfo;
}
Also used : WSDLInfo(org.wso2.carbon.apimgt.impl.wsdl.model.WSDLInfo) APIMgtWSDLException(org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException) WSDLSOAPOperation(org.wso2.carbon.apimgt.impl.wsdl.model.WSDLSOAPOperation)

Example 5 with WSDLInfo

use of org.wso2.carbon.apimgt.core.models.WSDLInfo in project carbon-apimgt by wso2.

the class SOAPOperationBindingUtils method getSoapOperationMapping.

/**
 * Gets soap operations to rest resources mapping for a wsdl byte content
 *
 * @param wsdlContent WSDL byte content
 * @return swagger json string with the soap operation mapping
 * @throws APIManagementException if an error occurs when generating swagger
 */
public static String getSoapOperationMapping(byte[] wsdlContent) throws APIManagementException {
    WSDL11SOAPOperationExtractor processor = APIMWSDLReader.getWSDLSOAPOperationExtractor(wsdlContent);
    WSDLInfo wsdlInfo = processor.getWsdlInfo();
    return getGeneratedSwaggerFromWSDL(wsdlInfo);
}
Also used : WSDLInfo(org.wso2.carbon.apimgt.impl.wsdl.model.WSDLInfo) WSDL11SOAPOperationExtractor(org.wso2.carbon.apimgt.impl.wsdl.WSDL11SOAPOperationExtractor)

Aggregations

WSDLInfo (org.wso2.carbon.apimgt.impl.wsdl.model.WSDLInfo)8 WSDLInfo (org.wso2.carbon.apimgt.core.models.WSDLInfo)4 WSDL11SOAPOperationExtractor (org.wso2.carbon.apimgt.impl.wsdl.WSDL11SOAPOperationExtractor)3 APIDefinitionValidationResponseDTO (org.wso2.carbon.apimgt.rest.api.publisher.dto.APIDefinitionValidationResponseDTO)3 Response (javax.ws.rs.core.Response)2 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)2 WorkflowResponse (org.wso2.carbon.apimgt.core.api.WorkflowResponse)2 WSDLArchiveInfo (org.wso2.carbon.apimgt.core.models.WSDLArchiveInfo)2 GeneralWorkflowResponse (org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse)2 APIMgtWSDLException (org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException)2 WSDLSOAPOperation (org.wso2.carbon.apimgt.impl.wsdl.model.WSDLSOAPOperation)2 Info (io.swagger.models.Info)1 ModelImpl (io.swagger.models.ModelImpl)1 Operation (io.swagger.models.Operation)1 Path (io.swagger.models.Path)1 RefModel (io.swagger.models.RefModel)1 Response (io.swagger.models.Response)1 Swagger (io.swagger.models.Swagger)1 BodyParameter (io.swagger.models.parameters.BodyParameter)1 QueryParameter (io.swagger.models.parameters.QueryParameter)1