use of org.wso2.transport.http.netty.config.Parameter in project carbon-apimgt by wso2.
the class PolicyDAOImpl method setQueryParameterConditions.
/**
* Add Query parameter conditions of pipeline with pipeline Id: <code>pipelineId</code> to a
* provided {@link Condition} array
*
* @param pipelineId Id of the pipeline
* @param conditions condition array to populate
* @throws SQLException
*/
private void setQueryParameterConditions(int pipelineId, ArrayList<Condition> conditions, Connection connection) throws SQLException {
final String query = "SELECT " + "PARAMETER_NAME,PARAMETER_VALUE , IS_PARAM_MAPPING " + "FROM " + "AM_QUERY_PARAMETER_CONDITION " + "WHERE " + "CONDITION_GROUP_ID =?";
try (PreparedStatement preparedStatement = connection.prepareStatement(query)) {
preparedStatement.setInt(1, pipelineId);
try (ResultSet resultSet = preparedStatement.executeQuery()) {
while (resultSet.next()) {
QueryParameterCondition queryParameterCondition = new QueryParameterCondition();
queryParameterCondition.setParameter(resultSet.getString(APIMgtConstants.ThrottlePolicyConstants.COLUMN_PARAMETER_NAME));
queryParameterCondition.setValue(resultSet.getString(APIMgtConstants.ThrottlePolicyConstants.COLUMN_PARAMETER_VALUE));
queryParameterCondition.setInvertCondition(resultSet.getBoolean(APIMgtConstants.ThrottlePolicyConstants.COLUMN_IS_PARAM_MAPPING));
conditions.add(queryParameterCondition);
}
}
}
}
use of org.wso2.transport.http.netty.config.Parameter in project carbon-apimgt by wso2.
the class DefaultKeyManagerImpl method createApplication.
@Override
public OAuthApplicationInfo createApplication(OAuthAppRequest oauthAppRequest) throws KeyManagementException {
log.debug("Creating OAuth2 application:{}", oauthAppRequest.toString());
String applicationName = oauthAppRequest.getClientName();
String keyType = oauthAppRequest.getKeyType();
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.setGrantTypes(oauthAppRequest.getGrantTypes());
if (StringUtils.isNotEmpty(oauthAppRequest.getCallBackURL())) {
dcrClientInfo.addCallbackUrl(oauthAppRequest.getCallBackURL());
}
Response response = dcrmServiceStub.registerApplication(dcrClientInfo);
if (response == null) {
throw new KeyManagementException("Error occurred while DCR application creation. Response is null", ExceptionCodes.OAUTH2_APP_CREATION_FAILED);
}
if (response.status() == APIMgtConstants.HTTPStatusCodes.SC_201_CREATED) {
// 201 - Success
try {
OAuthApplicationInfo oAuthApplicationInfoResponse = getOAuthApplicationInfo(response);
// setting original parameter list
oAuthApplicationInfoResponse.setParameters(oauthAppRequest.getParameters());
log.debug("OAuth2 application created: {}", oAuthApplicationInfoResponse.toString());
return oAuthApplicationInfoResponse;
} catch (IOException e) {
throw new KeyManagementException("Error occurred while parsing the DCR application creation response " + "message.", e, ExceptionCodes.OAUTH2_APP_CREATION_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 DCR application creation. Error: " + error.getError() + ". Error Description: " + error.getErrorDescription() + ". Status Code: " + response.status(), ExceptionCodes.OAUTH2_APP_CREATION_FAILED);
} catch (IOException e) {
throw new KeyManagementException("Error occurred while parsing the DCR error message.", e, ExceptionCodes.OAUTH2_APP_CREATION_FAILED);
}
} else {
// Unknown Error
throw new KeyManagementException("Error occurred while DCR application creation. Error: " + response.body().toString() + " Status Code: " + response.status(), ExceptionCodes.OAUTH2_APP_CREATION_FAILED);
}
}
use of org.wso2.transport.http.netty.config.Parameter in project carbon-apimgt by wso2.
the class FunctionTriggerTestCase method testCaptureEvent.
@Test(description = "Test method for capturing event")
public void testCaptureEvent() throws APIManagementException, URISyntaxException {
FunctionDAO functionDAO = Mockito.mock(FunctionDAO.class);
RestCallUtil restCallUtil = Mockito.mock(RestCallUtil.class);
FunctionTrigger functionTrigger = new FunctionTrigger(functionDAO, restCallUtil);
URI testUri = new URI("http://testEndpointUri");
List<Function> functions = new ArrayList<>();
Function function = new Function(FUNCTION_NAME, testUri);
functions.add(function);
HttpResponse response = new HttpResponse();
response.setResponseCode(200);
Event event = Event.API_CREATION;
ZonedDateTime eventTime = ZonedDateTime.now();
Mockito.when(functionDAO.getUserFunctionsForEvent(USER_NAME, event)).thenReturn(functions);
Mockito.when(restCallUtil.postRequest(Mockito.eq(function.getEndpointURI()), Mockito.eq(null), Mockito.eq(null), Mockito.any(), Mockito.eq(MediaType.APPLICATION_JSON_TYPE), Mockito.eq(Collections.emptyMap()))).thenReturn(response);
functionTrigger.captureEvent(event, USER_NAME, eventTime, new HashMap<>());
// When the event parameter is null
try {
functionTrigger.captureEvent(null, USER_NAME, eventTime, new HashMap<>());
} catch (IllegalArgumentException e) {
Assert.assertEquals(e.getMessage(), "Event must not be null");
}
// When the username parameter is null
try {
functionTrigger.captureEvent(event, null, eventTime, new HashMap<>());
} catch (IllegalArgumentException e) {
Assert.assertEquals(e.getMessage(), "Username must not be null");
}
// When the eventTime parameter is null
try {
functionTrigger.captureEvent(event, USER_NAME, null, new HashMap<>());
} catch (IllegalArgumentException e) {
Assert.assertEquals(e.getMessage(), "Event_time must not be null");
}
// When the metadata parameter is null
try {
functionTrigger.captureEvent(event, USER_NAME, eventTime, null);
} catch (IllegalArgumentException e) {
Assert.assertEquals(e.getMessage(), "Payload must not be null");
}
}
use of org.wso2.transport.http.netty.config.Parameter in project carbon-apimgt by wso2.
the class RestApiUtil method getErrorDTO.
/**
* Return errorDTO object. This method accept APIMGTException as a parameter so we can set the e.getMessage
* directly to the errorDTO.
*
* @param errorHandler Error Handler object.
* @param paramList Parameter list
* @param e APIMGTException object.
* @return ErrorDTO Object.
*/
public static ErrorDTO getErrorDTO(ErrorHandler errorHandler, HashMap<String, String> paramList, APIManagementException e) {
ErrorDTO errorDTO = new ErrorDTO();
errorDTO.setCode(errorHandler.getErrorCode());
errorDTO.setMoreInfo(paramList);
if (e.getMessage() == null) {
errorDTO.setMessage(errorHandler.getErrorMessage());
} else {
errorDTO.setMessage(e.getMessage());
}
errorDTO.setDescription(errorHandler.getErrorDescription());
return errorDTO;
}
use of org.wso2.transport.http.netty.config.Parameter in project carbon-apimgt by wso2.
the class ThrottleStreamProcessor method init.
@Override
protected List<Attribute> init(AbstractDefinition abstractDefinition, ExpressionExecutor[] expressionExecutors, ConfigReader configReader, SiddhiAppContext siddhiAppContext) {
this.siddhiAppContext = siddhiAppContext;
if (attributeExpressionExecutors.length == 1) {
if (attributeExpressionExecutors[0] instanceof ConstantExpressionExecutor) {
if (attributeExpressionExecutors[0].getReturnType() == Attribute.Type.INT) {
timeInMilliSeconds = (Integer) ((ConstantExpressionExecutor) attributeExpressionExecutors[0]).getValue();
} else if (attributeExpressionExecutors[0].getReturnType() == Attribute.Type.LONG) {
timeInMilliSeconds = (Long) ((ConstantExpressionExecutor) attributeExpressionExecutors[0]).getValue();
} else {
throw new SiddhiAppValidationException("Throttle batch window's 1st parameter attribute should be " + "either int or long, but found " + attributeExpressionExecutors[0].getReturnType());
}
} else {
throw new SiddhiAppValidationException("Throttle batch window 1st parameter needs to be constant " + "parameter attribute but found a dynamic attribute " + attributeExpressionExecutors[0].getClass().getCanonicalName());
}
} else if (attributeExpressionExecutors.length == 2) {
if (attributeExpressionExecutors[0] instanceof ConstantExpressionExecutor) {
if (attributeExpressionExecutors[0].getReturnType() == Attribute.Type.INT) {
timeInMilliSeconds = (Integer) ((ConstantExpressionExecutor) attributeExpressionExecutors[0]).getValue();
} else if (attributeExpressionExecutors[0].getReturnType() == Attribute.Type.LONG) {
timeInMilliSeconds = (Long) ((ConstantExpressionExecutor) attributeExpressionExecutors[0]).getValue();
} else {
throw new SiddhiAppValidationException("Throttle batch window's 1st parameter attribute should be " + "either int or long, but found " + attributeExpressionExecutors[0].getReturnType());
}
} else {
throw new SiddhiAppValidationException("Throttle batch window 1st parameter needs to be constant " + "attribute but found a dynamic attribute " + attributeExpressionExecutors[0].getClass().getCanonicalName());
}
if (attributeExpressionExecutors[1].getReturnType() == Attribute.Type.INT) {
startTime = Integer.parseInt(String.valueOf(((ConstantExpressionExecutor) attributeExpressionExecutors[1]).getValue()));
} else if (attributeExpressionExecutors[1].getReturnType() == Attribute.Type.LONG) {
startTime = Long.parseLong(String.valueOf(((ConstantExpressionExecutor) attributeExpressionExecutors[1]).getValue()));
} else {
throw new SiddhiAppValidationException("Throttle batch window 2nd parameter needs to be a Long " + "or Int type but found a " + attributeExpressionExecutors[2].getReturnType());
}
} else {
throw new SiddhiAppValidationException("Throttle batch window should only have one/two parameter " + "(<int|long|time> windowTime (and <int|long> startTime), but found " + attributeExpressionExecutors.length + " input attributes");
}
List<Attribute> attributeList = new ArrayList<Attribute>();
attributeList.add(new Attribute(EXPIRY_TIME_STAMP, Attribute.Type.LONG));
return attributeList;
}
Aggregations