use of org.wso2.carbon.bpel.ui.bpel2svg.Link in project carbon-apimgt by wso2.
the class FunctionTrigger method captureEvent.
/**
* Used to observe all the {@link org.wso2.carbon.apimgt.core.models.Event} occurrences
* in an {@link org.wso2.carbon.apimgt.core.api.APIMObservable} object and trigger corresponding function that is
* mapped to the particular {@link org.wso2.carbon.apimgt.core.models.Event} occurred.
* <p>
* This is a specific implementation for
* {@link org.wso2.carbon.apimgt.core.api.EventObserver#captureEvent(Event, String, ZonedDateTime, Map)} method,
* provided by {@link org.wso2.carbon.apimgt.core.impl.FunctionTrigger} which implements
* {@link org.wso2.carbon.apimgt.core.api.EventObserver} interface.
* <p>
* {@inheritDoc}
*
* @see org.wso2.carbon.apimgt.core.impl.EventLogger#captureEvent(Event, String, ZonedDateTime, Map)
*/
@Override
public void captureEvent(Event event, String username, ZonedDateTime eventTime, Map<String, String> metadata) {
List<Function> functions = null;
String jsonPayload = null;
if (event == null) {
throw new IllegalArgumentException("Event must not be null");
}
if (username == null) {
throw new IllegalArgumentException("Username must not be null");
}
if (eventTime == null) {
throw new IllegalArgumentException("Event_time must not be null");
}
if (metadata == null) {
throw new IllegalArgumentException("Payload must not be null");
}
// Add general attributes to payload
metadata.put(APIMgtConstants.FunctionsConstants.EVENT, event.getEventAsString());
metadata.put(APIMgtConstants.FunctionsConstants.COMPONENT, event.getComponent().getComponentAsString());
metadata.put(APIMgtConstants.FunctionsConstants.USERNAME, username);
metadata.put(APIMgtConstants.FunctionsConstants.EVENT_TIME, eventTime.toString());
try {
functions = functionDAO.getUserFunctionsForEvent(username, event);
jsonPayload = new Gson().toJson(metadata);
} catch (APIMgtDAOException e) {
String message = "Error loading functions for event from DB: -event: " + event + " -Username: " + username;
log.error(message, new APIManagementException("Problem invoking 'getUserFunctionsForEvent' method in " + "'FunctionDAO' ", e, ExceptionCodes.APIMGT_DAO_EXCEPTION));
}
if (functions != null && !functions.isEmpty()) {
for (Function function : functions) {
HttpResponse response = null;
try {
response = restCallUtil.postRequest(function.getEndpointURI(), null, null, Entity.json(jsonPayload), MediaType.APPLICATION_JSON_TYPE, Collections.EMPTY_MAP);
} catch (APIManagementException e) {
log.error("Failed to make http request: -function: " + function.getName() + " -endpoint URI: " + function.getEndpointURI() + " -event: " + event + " -Username: " + username, e);
}
if (response != null) {
int responseStatusCode = response.getResponseCode();
// Benefit of integer division used to ensure all possible success response codes covered
if (responseStatusCode / 100 == 2) {
log.info("Function successfully invoked: " + function.getName() + " -event: " + event + " -Username: " + username + " -Response code: " + responseStatusCode);
} else {
log.error("Problem invoking function: " + function.getName() + " -event: " + event + " -Username: " + username + " -Response code: " + responseStatusCode);
}
}
}
}
}
use of org.wso2.carbon.bpel.ui.bpel2svg.Link in project carbon-apimgt by wso2.
the class TestUtil method subscribeToAPI.
/**
* Subscribe an application to given API
*
* @param api API to be subscribed to
* @param application Application to subscribe to the API
* @return {@link Subscription} object
* @throws APIManagementException If failed to add subscription.
*/
public static Subscription subscribeToAPI(API api, Application application) throws APIManagementException {
APISubscriptionDAO subscriptionDAO = DAOFactory.getAPISubscriptionDAO();
String subscriptionId = UUID.randomUUID().toString();
subscriptionDAO.addAPISubscription(subscriptionId, api.getId(), application.getId(), api.getPolicies().iterator().next().getUuid(), APIMgtConstants.SubscriptionStatus.ACTIVE);
return subscriptionDAO.getAPISubscription(subscriptionId);
}
use of org.wso2.carbon.bpel.ui.bpel2svg.Link in project carbon-apimgt by wso2.
the class MappingUtil method convertToApplicationDtoList.
/**
* convert {@link ApplicationDTO} to {@link Application}
*
* @param applicationList List of {@link Application}
* @return ApplicationEvent list
*/
public static List<ApplicationDTO> convertToApplicationDtoList(List<Application> applicationList) {
List<ApplicationDTO> applicationDTOList = new ArrayList<>();
for (Application application : applicationList) {
ApplicationDTO applicationDTO = new ApplicationDTO();
applicationDTO.setName(application.getName());
applicationDTO.setApplicationId(application.getId());
applicationDTO.setThrottlingTier(application.getPolicy().getUuid());
applicationDTO.setSubscriber(application.getCreatedUser());
applicationDTOList.add(applicationDTO);
}
return applicationDTOList;
}
use of org.wso2.carbon.bpel.ui.bpel2svg.Link in project carbon-apimgt by wso2.
the class MappingUtil method toEndpointListDto.
/**
* Converts {@link Endpoint} list to {@link EndPointDTO} list
*
* @param endpointList {@link Endpoint} list
* @return EndPointDTO list
*/
public static List<EndPointDTO> toEndpointListDto(List<Endpoint> endpointList) {
List<EndPointDTO> endPointDTOList = new ArrayList<>();
endpointList.forEach(endpoint -> endPointDTOList.add(new EndPointDTO().endpointConfig(endpoint.getEndpointConfig()).id(endpoint.getId()).type(endpoint.getType()).name(endpoint.getName()).security(endpoint.getSecurity())));
return endPointDTOList;
}
use of org.wso2.carbon.bpel.ui.bpel2svg.Link in project wso2-synapse by wso2.
the class VFSTransportListenerTest method testVFSTransportListenerBasics.
/**
* Testcase to test basic functionality of {@link VFSTransportListener}
* @throws Exception
*/
public void testVFSTransportListenerBasics() throws Exception {
MockFileHolder.getInstance().clear();
String fileUri = "test1:///foo/bar/test-" + System.currentTimeMillis() + "/DIR/IN/";
String moveAfterFailure = "test1:///foo/bar/test-" + System.currentTimeMillis() + "/DIR/FAIL/";
AxisService axisService = new AxisService("testVFSService");
axisService.addParameter(new Parameter(VFSConstants.TRANSPORT_FILE_FILE_URI, fileUri));
axisService.addParameter(new Parameter(VFSConstants.TRANSPORT_FILE_CONTENT_TYPE, "text/xml"));
axisService.addParameter(new Parameter(VFSConstants.TRANSPORT_FILE_FILE_NAME_PATTERN, ".*\\.txt"));
axisService.addParameter(new Parameter(VFSConstants.TRANSPORT_FILE_ACTION_AFTER_PROCESS, VFSTransportListener.MOVE));
axisService.addParameter(new Parameter(VFSConstants.TRANSPORT_FILE_ACTION_AFTER_FAILURE, VFSTransportListener.MOVE));
axisService.addParameter(new Parameter(VFSConstants.TRANSPORT_FILE_MOVE_AFTER_FAILURE, moveAfterFailure));
axisService.addParameter(new Parameter(VFSConstants.TRANSPORT_FILE_MOVE_AFTER_FAILED_MOVE, moveAfterFailure));
axisService.addParameter(new Parameter(VFSConstants.STREAMING, "false"));
axisService.addParameter(new Parameter(VFSConstants.TRANSPORT_FILE_LOCKING, VFSConstants.TRANSPORT_FILE_LOCKING_ENABLED));
axisService.addParameter(new Parameter(VFSConstants.TRANSPORT_FILE_INTERVAL, "1000"));
axisService.addParameter(new Parameter(VFSConstants.TRANSPORT_FILE_COUNT, "1"));
axisService.addParameter(new Parameter(VFSConstants.TRANSPORT_AUTO_LOCK_RELEASE, "true"));
axisService.addParameter(new Parameter(VFSConstants.TRANSPORT_AUTO_LOCK_RELEASE_INTERVAL, "20000"));
axisService.addParameter(new Parameter(VFSConstants.TRANSPORT_AUTO_LOCK_RELEASE_SAME_NODE, "true"));
axisService.addParameter(new Parameter(VFSConstants.TRANSPORT_DISTRIBUTED_LOCK, "true"));
axisService.addParameter(new Parameter(VFSConstants.TRANSPORT_DISTRIBUTED_LOCK_TIMEOUT, "20000"));
axisService.addParameter(new Parameter(VFSConstants.FILE_SORT_PARAM, VFSConstants.FILE_SORT_VALUE_NAME));
axisService.addParameter(new Parameter(VFSConstants.FILE_SORT_ORDER, "true"));
TransportDescriptionFactory transportDescriptionFactory = new VFSTransportDescriptionFactory();
TransportInDescription transportInDescription = null;
try {
transportInDescription = transportDescriptionFactory.createTransportInDescription();
} catch (Exception e) {
Assert.fail("Error occurred while creating transport in description");
}
VFSTransportListener vfsTransportListener = getListener(transportInDescription);
// initialize listener
vfsTransportListener.init(new ConfigurationContext(new AxisConfiguration()), transportInDescription);
// Initialize VFSTransportListener
vfsTransportListener.doInit();
// Start listener
vfsTransportListener.start();
// Create poll entry
PollTableEntry pollTableEntry = vfsTransportListener.createEndpoint();
Assert.assertTrue("Global file locking not applied to created poll entry", pollTableEntry.isFileLockingEnabled());
// Load configuration of poll entry
pollTableEntry.loadConfiguration(axisService);
populatePollTableEntry(pollTableEntry, axisService, vfsTransportListener);
vfsTransportListener.poll(pollTableEntry);
MockFile targetDir = MockFileHolder.getInstance().getFile(fileUri);
Assert.assertNotNull("Failed target directory creation", targetDir);
Assert.assertEquals("Created target directory is not Folder type", targetDir.getName().getType(), FileType.FOLDER);
MockFile failDir = MockFileHolder.getInstance().getFile(moveAfterFailure);
Assert.assertNotNull("Fail to create expected directory to move files when failure", failDir);
MockFileHolder.getInstance().clear();
}
Aggregations