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