use of org.wso2.transport.http.netty.config.Parameter in project carbon-apimgt by wso2.
the class CommonThrottleMappingUtil method fromDTOToQueryParameterCondition.
/**
* Converts a Query Parameter Condition DTO object into a model object
*
* @param dto Query Parameter Condition DTO object
* @return Query Parameter Condition model object derived from Query Parameter Condition DTO
*/
public static QueryParameterCondition fromDTOToQueryParameterCondition(ThrottleConditionDTO dto) {
QueryParameterCondition queryParameterCondition = new QueryParameterCondition();
queryParameterCondition = updateFieldsFromDTOToCondition(dto, queryParameterCondition);
queryParameterCondition.setParameter(dto.getQueryParameterCondition().getParameterName());
queryParameterCondition.setValue(dto.getQueryParameterCondition().getParameterValue());
return queryParameterCondition;
}
use of org.wso2.transport.http.netty.config.Parameter in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method apisApiIdSdksLanguageGet.
/**
* Generates an SDK for a API with provided ID and language
*
* @param apiId API ID
* @param language SDK language
* @param request msf4j request object
* @return ZIP file for the generated SDK
* @throws NotFoundException if failed to find method implementation
*/
@Override
public Response apisApiIdSdksLanguageGet(String apiId, String language, Request request) throws NotFoundException {
if (StringUtils.isBlank(apiId) || StringUtils.isBlank(language)) {
String errorMessage = "API ID or language is not valid";
log.error(errorMessage);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(errorMessage, 400L, errorMessage);
return Response.status(Response.Status.BAD_REQUEST).entity(errorDTO).build();
}
String userName = RestApiUtil.getLoggedInUsername(request);
ApiStoreSdkGenerationManager sdkGenerationManager = new ApiStoreSdkGenerationManager();
if (!sdkGenerationManager.getSdkGenLanguages().containsKey(language)) {
String errorMessage = "Specified language parameter doesn't exist";
log.error(errorMessage);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(errorMessage, 400L, errorMessage);
return Response.status(Response.Status.BAD_REQUEST).entity(errorDTO).build();
}
String tempZipFilePath;
try {
tempZipFilePath = sdkGenerationManager.generateSdkForApi(apiId, language, userName);
} catch (ApiStoreSdkGenerationException e) {
String errorMessage = "Error while generating SDK for requested language";
HashMap<String, String> paramList = new HashMap<String, String>();
paramList.put(APIMgtConstants.ExceptionsConstants.API_ID, apiId);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
} catch (APIManagementException e) {
String errorMessage = "Error while retrieving API for SDK generation " + apiId;
HashMap<String, String> paramList = new HashMap<String, String>();
paramList.put(APIMgtConstants.ExceptionsConstants.API_ID, apiId);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
File sdkZipFile = new File(tempZipFilePath);
return Response.ok().entity(sdkZipFile).header("Content-Disposition", "attachment; filename=\"" + sdkZipFile.getName() + "\"").build();
}
use of org.wso2.transport.http.netty.config.Parameter in project carbon-apimgt by wso2.
the class LabelInfoApiServiceImpl method labelInfoGet.
/**
* Get label information for labels provided.
*
* @param labels List of labels
* @param ifNoneMatch If-None-Match header value
* @param ifModifiedSince If-Modified-Since header value
* @param request msf4j request object
* @return Label List
* @throws NotFoundException If failed to get the label values
*/
@Override
public Response labelInfoGet(String labels, String ifNoneMatch, String ifModifiedSince, Request request) throws NotFoundException {
String username = RestApiUtil.getLoggedInUsername(request);
LabelListDTO labelListDTO;
try {
APIStore apiStore = RestApiUtil.getConsumer(username);
if (labels != null) {
List<String> labelNames = Arrays.asList(labels.split(","));
List<Label> labelList = apiStore.getLabelInfo(labelNames, username);
labelListDTO = LabelMappingUtil.toLabelListDTO(labelList);
} else {
// mandatory parameters not provided
String errorMessage = "Labels parameter should be provided";
ErrorHandler errorHandler = ExceptionCodes.PARAMETER_NOT_PROVIDED;
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(errorHandler);
log.error(errorMessage);
return Response.status(errorHandler.getHttpStatusCode()).entity(errorDTO).build();
}
} catch (APIManagementException e) {
String errorMessage = "Error occurred while retrieving label information";
HashMap<String, String> paramList = new HashMap<String, String>();
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
return Response.ok().entity(labelListDTO).build();
}
use of org.wso2.transport.http.netty.config.Parameter in project carbon-apimgt by wso2.
the class ApplicationMappingUtil method fromApplicationsToDTO.
/**
* Converts an Application[] array into a corresponding ApplicationListDTO
*
* @param applications array of Application objects
* @param limit limit parameter
* @param offset starting index
* @return ApplicationListDTO object corresponding to Application[] array
*/
public static ApplicationListDTO fromApplicationsToDTO(List<Application> applications, int limit, int offset) {
ApplicationListDTO applicationListDTO = new ApplicationListDTO();
List<ApplicationInfoDTO> applicationInfoDTOs = applicationListDTO.getList();
if (applicationInfoDTOs == null) {
applicationInfoDTOs = new ArrayList<>();
applicationListDTO.setList(applicationInfoDTOs);
}
// identifying the proper start and end indexes
int start = offset < applications.size() && offset >= 0 ? offset : Integer.MAX_VALUE;
int end = offset + limit - 1 <= applications.size() - 1 ? offset + limit - 1 : applications.size() - 1;
for (int i = start; i <= end; i++) {
applicationInfoDTOs.add(fromApplicationToInfoDTO(applications.get(i)));
}
applicationListDTO.setCount(applicationInfoDTOs.size());
return applicationListDTO;
}
use of org.wso2.transport.http.netty.config.Parameter in project carbon-apimgt by wso2.
the class DefaultKeyManagerImpl method updateApplication.
@Override
public OAuthApplicationInfo updateApplication(OAuthApplicationInfo oAuthApplicationInfo) throws KeyManagementException {
if (log.isDebugEnabled()) {
log.debug("Updating OAuth2 application with : " + oAuthApplicationInfo.toString());
}
String applicationName = oAuthApplicationInfo.getClientName();
String keyType = (String) oAuthApplicationInfo.getParameter(KeyManagerConstants.APP_KEY_TYPE);
if (keyType != null) {
// Derive oauth2 app name based on key type and user input for app name
applicationName = applicationName + '_' + keyType;
}
DCRClientInfo dcrClientInfo = new DCRClientInfo();
dcrClientInfo.setClientName(applicationName);
dcrClientInfo.setClientId(oAuthApplicationInfo.getClientId());
dcrClientInfo.setClientSecret(oAuthApplicationInfo.getClientSecret());
dcrClientInfo.addCallbackUrl(oAuthApplicationInfo.getCallBackURL());
dcrClientInfo.setGrantTypes(oAuthApplicationInfo.getGrantTypes());
Response response = dcrmServiceStub.updateApplication(dcrClientInfo, dcrClientInfo.getClientId());
if (response == null) {
throw new KeyManagementException("Error occurred while updating DCR application. Response is null", ExceptionCodes.OAUTH2_APP_UPDATE_FAILED);
}
if (response.status() == APIMgtConstants.HTTPStatusCodes.SC_200_OK) {
// 200 - Success
try {
OAuthApplicationInfo oAuthApplicationInfoResponse = getOAuthApplicationInfo(response);
// setting original parameter list
oAuthApplicationInfoResponse.setParameters(oAuthApplicationInfo.getParameters());
if (log.isDebugEnabled()) {
log.debug("OAuth2 application updated: " + oAuthApplicationInfoResponse.toString());
}
return oAuthApplicationInfoResponse;
} catch (IOException e) {
throw new KeyManagementException("Error occurred while parsing the DCR application update response " + "message.", e, ExceptionCodes.OAUTH2_APP_UPDATE_FAILED);
}
} else if (response.status() == APIMgtConstants.HTTPStatusCodes.SC_400_BAD_REQUEST) {
// 400 - Known Error
try {
DCRError error = (DCRError) new GsonDecoder().decode(response, DCRError.class);
throw new KeyManagementException("Error occurred while updating DCR application. Error: " + error.getError() + ". Error Description: " + error.getErrorDescription() + ". Status Code: " + response.status(), ExceptionCodes.OAUTH2_APP_UPDATE_FAILED);
} catch (IOException e) {
throw new KeyManagementException("Error occurred while parsing the DCR error message.", e, ExceptionCodes.OAUTH2_APP_UPDATE_FAILED);
}
} else {
// Unknown Error
throw new KeyManagementException("Error occurred while updating DCR application. Error: " + response.body().toString() + " Status Code: " + response.status(), ExceptionCodes.OAUTH2_APP_UPDATE_FAILED);
}
}
Aggregations