Search in sources :

Example 96 with Parameter

use of org.wso2.transport.http.netty.config.Parameter in project carbon-apimgt by wso2.

the class InboundWebsocketProcessorUtil method getBadRequestFrameErrorDTO.

/**
 * Get bad request (error code 4010) error frame DTO for error message. The closeConnection parameter is false.
 *
 * @param errorMessage Error message
 * @return InboundProcessorResponseDTO
 */
public static InboundProcessorResponseDTO getBadRequestFrameErrorDTO(String errorMessage) {
    InboundProcessorResponseDTO inboundProcessorResponseDTO = new InboundProcessorResponseDTO();
    inboundProcessorResponseDTO.setError(true);
    inboundProcessorResponseDTO.setErrorCode(WebSocketApiConstants.FrameErrorConstants.BAD_REQUEST);
    inboundProcessorResponseDTO.setErrorMessage(errorMessage);
    return inboundProcessorResponseDTO;
}
Also used : InboundProcessorResponseDTO(org.wso2.carbon.apimgt.gateway.inbound.websocket.InboundProcessorResponseDTO)

Example 97 with Parameter

use of org.wso2.transport.http.netty.config.Parameter in project carbon-apimgt by wso2.

the class InboundWebsocketProcessorUtil method getHandshakeErrorDTO.

/**
 * Get handshake error DTO for error code and message. The closeConnection parameter is false.
 *
 * @param errorCode    Error code
 * @param errorMessage Error message
 * @return InboundProcessorResponseDTO
 */
public static InboundProcessorResponseDTO getHandshakeErrorDTO(int errorCode, String errorMessage) {
    InboundProcessorResponseDTO inboundProcessorResponseDTO = new InboundProcessorResponseDTO();
    inboundProcessorResponseDTO.setError(true);
    inboundProcessorResponseDTO.setErrorCode(errorCode);
    inboundProcessorResponseDTO.setErrorMessage(errorMessage);
    return inboundProcessorResponseDTO;
}
Also used : InboundProcessorResponseDTO(org.wso2.carbon.apimgt.gateway.inbound.websocket.InboundProcessorResponseDTO)

Example 98 with Parameter

use of org.wso2.transport.http.netty.config.Parameter in project carbon-apimgt by wso2.

the class ApisApiServiceImpl method importAPI.

/**
 * Import an API by uploading an archive file. All relevant API data will be included upon the creation of
 * the API. Depending on the choice of the user, provider of the imported API will be preserved or modified.
 *
 * @param fileInputStream  Input stream from the REST request
 * @param fileDetail       File details as Attachment
 * @param preserveProvider User choice to keep or replace the API provider
 * @param overwrite        Whether to update the API or not. This is used when updating already existing APIs.
 * @return API import response
 * @throws APIManagementException when error occurred while trying to import the API
 */
@Override
public Response importAPI(InputStream fileInputStream, Attachment fileDetail, Boolean preserveProvider, Boolean rotateRevision, Boolean overwrite, MessageContext messageContext) throws APIManagementException {
    // Check whether to update. If not specified, default value is false.
    overwrite = overwrite == null ? false : overwrite;
    // Check if the URL parameter value is specified, otherwise the default value is true.
    preserveProvider = preserveProvider == null || preserveProvider;
    String organization = RestApiUtil.getValidatedOrganization(messageContext);
    String[] tokenScopes = (String[]) PhaseInterceptorChain.getCurrentMessage().getExchange().get(RestApiConstants.USER_REST_API_SCOPES);
    ImportExportAPI importExportAPI = APIImportExportUtil.getImportExportAPI();
    importExportAPI.importAPI(fileInputStream, preserveProvider, rotateRevision, overwrite, tokenScopes, organization);
    return Response.status(Response.Status.OK).entity("API imported successfully.").build();
}
Also used : ImportExportAPI(org.wso2.carbon.apimgt.impl.importexport.ImportExportAPI)

Example 99 with Parameter

use of org.wso2.transport.http.netty.config.Parameter in project carbon-apimgt by wso2.

the class ApisApiServiceImpl method importServiceFromCatalog.

@Override
public Response importServiceFromCatalog(String serviceKey, APIDTO apiDto, MessageContext messageContext) {
    if (StringUtils.isEmpty(serviceKey)) {
        RestApiUtil.handleBadRequest("Required parameter serviceKey is missing", log);
    }
    try {
        ServiceCatalogImpl serviceCatalog = new ServiceCatalogImpl();
        String username = RestApiCommonUtil.getLoggedInUsername();
        int tenantId = APIUtil.getTenantId(username);
        ServiceEntry service = serviceCatalog.getServiceByKey(serviceKey, tenantId);
        if (service == null) {
            RestApiUtil.handleResourceNotFoundError("Service", serviceKey, log);
        }
        APIDTO createdApiDTO = null;
        String organization = RestApiUtil.getValidatedOrganization(messageContext);
        if (ServiceEntry.DefinitionType.OAS2.equals(service.getDefinitionType()) || ServiceEntry.DefinitionType.OAS3.equals(service.getDefinitionType())) {
            createdApiDTO = importOpenAPIDefinition(service.getEndpointDef(), null, null, apiDto, null, service, organization);
        } else if (ServiceEntry.DefinitionType.ASYNC_API.equals(service.getDefinitionType())) {
            createdApiDTO = importAsyncAPISpecification(service.getEndpointDef(), null, apiDto, null, service, organization);
        } else if (ServiceEntry.DefinitionType.WSDL1.equals(service.getDefinitionType())) {
            apiDto.setProvider(RestApiCommonUtil.getLoggedInUsername());
            apiDto.setType(APIDTO.TypeEnum.fromValue("SOAP"));
            API apiToAdd = PublisherCommonUtils.prepareToCreateAPIByDTO(apiDto, RestApiCommonUtil.getLoggedInUserProvider(), username, organization);
            apiToAdd.setServiceInfo("key", service.getKey());
            apiToAdd.setServiceInfo("md5", service.getMd5());
            apiToAdd.setEndpointConfig(PublisherCommonUtils.constructEndpointConfigForService(service.getServiceUrl(), null));
            API api = importSOAPAPI(service.getEndpointDef(), null, null, apiToAdd, organization, service);
            createdApiDTO = APIMappingUtil.fromAPItoDTO(api);
        }
        if (createdApiDTO != null) {
            URI createdApiUri = new URI(RestApiConstants.RESOURCE_PATH_APIS + "/" + createdApiDTO.getId());
            return Response.created(createdApiUri).entity(createdApiDTO).build();
        } else {
            RestApiUtil.handleBadRequest("Unsupported definition type provided. Cannot create API " + "using the service type " + service.getDefinitionType().name(), log);
        }
    } catch (APIManagementException e) {
        if (RestApiUtil.isDueToResourceNotFound(e)) {
            RestApiUtil.handleResourceNotFoundError("Service", serviceKey, e, log);
        } else {
            String errorMessage = "Error while creating API using Service with Id : " + serviceKey + " from Service Catalog";
            RestApiUtil.handleInternalServerError(errorMessage, e, log);
        }
    } catch (URISyntaxException e) {
        String errorMessage = "Error while retrieving API location : " + apiDto.getName() + "-" + apiDto.getVersion();
        RestApiUtil.handleInternalServerError(errorMessage, e, log);
    }
    return null;
}
Also used : APIDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIDTO) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) ServiceCatalogImpl(org.wso2.carbon.apimgt.impl.ServiceCatalogImpl) API(org.wso2.carbon.apimgt.api.model.API) ImportExportAPI(org.wso2.carbon.apimgt.impl.importexport.ImportExportAPI) SubscribedAPI(org.wso2.carbon.apimgt.api.model.SubscribedAPI) URISyntaxException(java.net.URISyntaxException) ServiceEntry(org.wso2.carbon.apimgt.api.model.ServiceEntry) URI(java.net.URI)

Example 100 with Parameter

use of org.wso2.transport.http.netty.config.Parameter in project carbon-apimgt by wso2.

the class SystemApplicationDAO method getClientCredentialsForApplication.

/**
 * Method to retrieve client credentials for a given application name
 *
 * @param appName required parameter
 * @return SystemApplicationDTO which hold the retrieved client credentials
 * @throws APIMgtDAOException
 */
public SystemApplicationDTO getClientCredentialsForApplication(String appName, String tenantDomain) throws APIMgtDAOException {
    Connection connection = null;
    PreparedStatement preparedStatement = null;
    ResultSet resultSet = null;
    SystemApplicationDTO systemApplicationDTO = null;
    String getCredentialsQuery = SQLConstants.SystemApplicationConstants.GET_CLIENT_CREDENTIALS_FOR_APPLICATION;
    try {
        connection = APIMgtDBUtil.getConnection();
        connection.setAutoCommit(false);
        connection.commit();
        preparedStatement = connection.prepareStatement(getCredentialsQuery);
        preparedStatement.setString(1, appName);
        preparedStatement.setString(2, tenantDomain);
        resultSet = preparedStatement.executeQuery();
        while (resultSet.next()) {
            systemApplicationDTO = new SystemApplicationDTO();
            systemApplicationDTO.setConsumerKey(resultSet.getString("CONSUMER_KEY"));
            systemApplicationDTO.setConsumerSecret(resultSet.getString("CONSUMER_SECRET"));
        }
    } catch (SQLException e) {
        if (log.isDebugEnabled()) {
            log.debug("Error while retrieving client credentials for application: " + appName);
        }
        handleException("Error while retrieving client credentials for application: " + appName, e);
    } finally {
        APIMgtDBUtil.closeAllConnections(preparedStatement, connection, resultSet);
    }
    return systemApplicationDTO;
}
Also used : SQLException(java.sql.SQLException) SystemApplicationDTO(org.wso2.carbon.apimgt.impl.dto.SystemApplicationDTO) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Aggregations

HashMap (java.util.HashMap)35 ArrayList (java.util.ArrayList)32 Parameter (org.apache.axis2.description.Parameter)14 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)14 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)13 JSONDecoder (org.wso2.charon3.core.encoder.JSONDecoder)11 BadRequestException (org.wso2.charon3.core.exceptions.BadRequestException)11 CharonException (org.wso2.charon3.core.exceptions.CharonException)11 InternalErrorException (org.wso2.charon3.core.exceptions.InternalErrorException)11 NotFoundException (org.wso2.charon3.core.exceptions.NotFoundException)11 SCIMResponse (org.wso2.charon3.core.protocol.SCIMResponse)11 SCIMResourceTypeSchema (org.wso2.charon3.core.schema.SCIMResourceTypeSchema)11 List (java.util.List)10 Map (java.util.Map)10 ConstantExpressionExecutor (org.wso2.siddhi.core.executor.ConstantExpressionExecutor)9 IOException (java.io.IOException)8 PreparedStatement (java.sql.PreparedStatement)8 ResultSet (java.sql.ResultSet)8 Test (org.testng.annotations.Test)8 BInvokableSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol)8