use of org.wso2.broker.amqp.Server in project ballerina by ballerina-lang.
the class Register method startServerConnector.
private void startServerConnector(Struct serviceEndpoint, HTTPServicesRegistry httpServicesRegistry, WebSocketServicesRegistry webSocketServicesRegistry) {
ServerConnector serverConnector = getServerConnector(serviceEndpoint);
ServerConnectorFuture serverConnectorFuture = serverConnector.start();
HashSet<FilterHolder> filterHolder = getFilters(serviceEndpoint);
serverConnectorFuture.setHttpConnectorListener(new BallerinaHTTPConnectorListener(httpServicesRegistry, filterHolder));
serverConnectorFuture.setWSConnectorListener(new WebSocketServerConnectorListener(webSocketServicesRegistry));
serverConnectorFuture.setPortBindingEventListener(new HttpConnectorPortBindingListener());
try {
serverConnectorFuture.sync();
} catch (Throwable ex) {
throw new BallerinaException("failed to start server connector '" + serverConnector.getConnectorID() + "': " + ex.getMessage(), ex);
}
serviceEndpoint.addNativeData(HttpConstants.CONNECTOR_STARTED, true);
}
use of org.wso2.broker.amqp.Server in project charon by wso2.
the class UserResourceManager method listWithPOST.
/*
* this facilitates the querying using HTTP POST
* @param resourceString
* @param usermanager
* @return
*/
public SCIMResponse listWithPOST(String resourceString, UserManager userManager) {
JSONEncoder encoder = null;
JSONDecoder decoder = null;
try {
// obtain the json encoder
encoder = getEncoder();
// obtain the json decoder
decoder = getDecoder();
// unless configured returns core-user schema or else returns extended user schema)
SCIMResourceTypeSchema schema = SCIMResourceSchemaManager.getInstance().getUserResourceSchema();
// create the search request object
SearchRequest searchRequest = decoder.decodeSearchRequestBody(resourceString, schema);
searchRequest.setCount(ResourceManagerUtil.processCount(searchRequest.getCountStr()));
searchRequest.setStartIndex(ResourceManagerUtil.processCount(searchRequest.getStartIndexStr()));
// check whether provided sortOrder is valid or not
if (searchRequest.getSortOder() != null) {
if (!(searchRequest.getSortOder().equalsIgnoreCase(SCIMConstants.OperationalConstants.ASCENDING) || searchRequest.getSortOder().equalsIgnoreCase(SCIMConstants.OperationalConstants.DESCENDING))) {
String error = " Invalid sortOrder value is specified";
throw new BadRequestException(error, ResponseCodeConstants.INVALID_VALUE);
}
}
// ascending.
if (searchRequest.getSortOder() == null && searchRequest.getSortBy() != null) {
searchRequest.setSortOder(SCIMConstants.OperationalConstants.ASCENDING);
}
// get the URIs of required attributes which must be given a value
Map<String, Boolean> requiredAttributes = ResourceManagerUtil.getOnlyRequiredAttributesURIs((SCIMResourceTypeSchema) CopyUtil.deepCopy(schema), searchRequest.getAttributesAsString(), searchRequest.getExcludedAttributesAsString());
List<Object> returnedUsers;
int totalResults = 0;
// API user should pass a usermanager usermanager to UserResourceEndpoint.
if (userManager != null) {
List<Object> tempList = userManager.listUsersWithPost(searchRequest, requiredAttributes);
totalResults = (int) tempList.get(0);
tempList.remove(0);
returnedUsers = tempList;
for (Object user : returnedUsers) {
// perform service provider side validation.
ServerSideValidator.validateRetrievedSCIMObjectInList((User) user, schema, searchRequest.getAttributesAsString(), searchRequest.getExcludedAttributesAsString());
}
// create a listed resource object out of the returned users list.
ListedResource listedResource = createListedResource(returnedUsers, searchRequest.getStartIndex(), totalResults);
// convert the listed resource into specific format.
String encodedListedResource = encoder.encodeSCIMObject(listedResource);
// if there are any http headers to be added in the response header.
Map<String, String> responseHeaders = new HashMap<String, String>();
responseHeaders.put(SCIMConstants.CONTENT_TYPE_HEADER, SCIMConstants.APPLICATION_JSON);
return new SCIMResponse(ResponseCodeConstants.CODE_OK, encodedListedResource, responseHeaders);
} else {
String error = "Provided user manager handler is null.";
// throw internal server error.
throw new InternalErrorException(error);
}
} catch (CharonException e) {
return AbstractResourceManager.encodeSCIMException(e);
} catch (NotFoundException e) {
return AbstractResourceManager.encodeSCIMException(e);
} catch (InternalErrorException e) {
return AbstractResourceManager.encodeSCIMException(e);
} catch (BadRequestException e) {
return AbstractResourceManager.encodeSCIMException(e);
} catch (NotImplementedException e) {
return AbstractResourceManager.encodeSCIMException(e);
}
}
use of org.wso2.broker.amqp.Server in project charon by wso2.
the class UserResourceManager method listWithGET.
/*
* To list all the resources of resource endpoint.
*
* @param usermanager
* @param filter
* @param startIndex
* @param count
* @param sortBy
* @param sortOrder
* @param attributes
* @param excludeAttributes
* @return
*/
public SCIMResponse listWithGET(UserManager userManager, String filter, int startIndex, int count, String sortBy, String sortOrder, String attributes, String excludeAttributes) {
FilterTreeManager filterTreeManager = null;
Node rootNode = null;
JSONEncoder encoder = null;
try {
// According to SCIM 2.0 spec minus values will be considered as 0
if (count < 0) {
count = 0;
}
// According to SCIM 2.0 spec minus values will be considered as 1
if (startIndex < 1) {
startIndex = 1;
}
if (sortOrder != null) {
if (!(sortOrder.equalsIgnoreCase(SCIMConstants.OperationalConstants.ASCENDING) || sortOrder.equalsIgnoreCase(SCIMConstants.OperationalConstants.DESCENDING))) {
String error = " Invalid sortOrder value is specified";
throw new BadRequestException(error, ResponseCodeConstants.INVALID_VALUE);
}
}
// ascending.
if (sortOrder == null && sortBy != null) {
sortOrder = SCIMConstants.OperationalConstants.ASCENDING;
}
// unless configured returns core-user schema or else returns extended user schema)
SCIMResourceTypeSchema schema = SCIMResourceSchemaManager.getInstance().getUserResourceSchema();
if (filter != null) {
filterTreeManager = new FilterTreeManager(filter, schema);
rootNode = filterTreeManager.buildTree();
}
// obtain the json encoder
encoder = getEncoder();
// get the URIs of required attributes which must be given a value
Map<String, Boolean> requiredAttributes = ResourceManagerUtil.getOnlyRequiredAttributesURIs((SCIMResourceTypeSchema) CopyUtil.deepCopy(schema), attributes, excludeAttributes);
List<Object> returnedUsers;
int totalResults = 0;
// API user should pass a usermanager usermanager to UserResourceEndpoint.
if (userManager != null) {
List<Object> tempList = userManager.listUsersWithGET(rootNode, startIndex, count, sortBy, sortOrder, requiredAttributes);
totalResults = (int) tempList.get(0);
tempList.remove(0);
returnedUsers = tempList;
for (Object user : returnedUsers) {
// perform service provider side validation.
ServerSideValidator.validateRetrievedSCIMObjectInList((User) user, schema, attributes, excludeAttributes);
}
// create a listed resource object out of the returned users list.
ListedResource listedResource = createListedResource(returnedUsers, startIndex, totalResults);
// convert the listed resource into specific format.
String encodedListedResource = encoder.encodeSCIMObject(listedResource);
// if there are any http headers to be added in the response header.
Map<String, String> responseHeaders = new HashMap<String, String>();
responseHeaders.put(SCIMConstants.CONTENT_TYPE_HEADER, SCIMConstants.APPLICATION_JSON);
return new SCIMResponse(ResponseCodeConstants.CODE_OK, encodedListedResource, responseHeaders);
} else {
String error = "Provided user manager handler is null.";
// throw internal server error.
throw new InternalErrorException(error);
}
} catch (CharonException e) {
return AbstractResourceManager.encodeSCIMException(e);
} catch (NotFoundException e) {
return AbstractResourceManager.encodeSCIMException(e);
} catch (InternalErrorException e) {
return AbstractResourceManager.encodeSCIMException(e);
} catch (BadRequestException e) {
return AbstractResourceManager.encodeSCIMException(e);
} catch (NotImplementedException e) {
return AbstractResourceManager.encodeSCIMException(e);
} catch (IOException e) {
String error = "Error in tokenization of the input filter";
CharonException charonException = new CharonException(error);
return AbstractResourceManager.encodeSCIMException(charonException);
}
}
use of org.wso2.broker.amqp.Server in project jaggery by wso2.
the class TomcatJaggeryWebappsDeployer method handleWebappDeployment.
/**
* Deployment procedure of Jaggery apps
*
* @param webappFile The Jaggery app file to be deployed
* @param contextStr jaggery app context string
* @param webContextParams context-params for this Jaggery app
* @param applicationEventListeners Application event listeners
* @throws CarbonException If a deployment error occurs
*/
protected void handleWebappDeployment(File webappFile, String contextStr, List<WebContextParameter> webContextParams, List<Object> applicationEventListeners) throws CarbonException {
String filename = webappFile.getName();
ArrayList<Object> listeners = new ArrayList<Object>(1);
// listeners.add(new CarbonServletRequestListener());
SecurityConstraint securityConstraint = new SecurityConstraint();
securityConstraint.setAuthConstraint(true);
SecurityCollection securityCollection = new SecurityCollection();
securityCollection.setName("ConfigDir");
securityCollection.setDescription("Jaggery Configuration Dir");
securityCollection.addPattern("/" + JaggeryCoreConstants.JAGGERY_CONF_FILE);
securityConstraint.addCollection(securityCollection);
WebApplicationsHolder webApplicationsHolder = WebAppUtils.getWebappHolder(webappFile.getAbsolutePath(), configurationContext);
try {
JSONObject jaggeryConfigObj = readJaggeryConfig(webappFile);
Tomcat tomcat = DataHolder.getCarbonTomcatService().getTomcat();
Context context = DataHolder.getCarbonTomcatService().addWebApp(contextStr, webappFile.getAbsolutePath(), new JaggeryDeployerManager.JaggeryConfListener(jaggeryConfigObj, securityConstraint));
// deploying web app for url mapping inside virtual host
if (DataHolder.getHotUpdateService() != null) {
List<String> hostNames = DataHolder.getHotUpdateService().getMappigsPerWebapp(contextStr);
for (String hostName : hostNames) {
Host host = DataHolder.getHotUpdateService().addHost(hostName);
/* ApplicationContext.getCurrentApplicationContext().putUrlMappingForApplication(hostName, contextStr);
*/
Context contextForHost = DataHolder.getCarbonTomcatService().addWebApp(host, "/", webappFile.getAbsolutePath(), new JaggeryDeployerManager.JaggeryConfListener(jaggeryConfigObj, securityConstraint));
log.info("Deployed JaggeryApp on host: " + contextForHost);
}
}
Manager manager = context.getManager();
if (isDistributable(context, jaggeryConfigObj)) {
// Clusterable manager implementation as DeltaManager
context.setDistributable(true);
// Using clusterable manager
CarbonTomcatClusterableSessionManager sessionManager;
if (manager instanceof CarbonTomcatClusterableSessionManager) {
sessionManager = (CarbonTomcatClusterableSessionManager) manager;
sessionManager.setOwnerTenantId(tenantId);
} else {
sessionManager = new CarbonTomcatClusterableSessionManager(tenantId);
context.setManager(sessionManager);
}
Object alreadyinsertedSMMap = configurationContext.getProperty(CarbonConstants.TOMCAT_SESSION_MANAGER_MAP);
if (alreadyinsertedSMMap != null) {
((Map<String, CarbonTomcatClusterableSessionManager>) alreadyinsertedSMMap).put(context.getName(), sessionManager);
} else {
sessionManagerMap.put(context.getName(), sessionManager);
configurationContext.setProperty(CarbonConstants.TOMCAT_SESSION_MANAGER_MAP, sessionManagerMap);
}
} else {
if (manager instanceof CarbonTomcatSessionManager) {
((CarbonTomcatSessionManager) manager).setOwnerTenantId(tenantId);
} else if (manager instanceof CarbonTomcatSessionPersistentManager) {
((CarbonTomcatSessionPersistentManager) manager).setOwnerTenantId(tenantId);
log.debug(manager.getInfo() + " enabled Tomcat HTTP Session Persistent mode using " + ((CarbonTomcatSessionPersistentManager) manager).getStore().getInfo());
} else {
context.setManager(new CarbonTomcatSessionManager(tenantId));
}
}
context.setReloadable(false);
JaggeryApplication webapp = new JaggeryApplication(this, context, webappFile);
webapp.setServletContextParameters(webContextParams);
webapp.setState("Started");
webApplicationsHolder.getStartedWebapps().put(filename, webapp);
webApplicationsHolder.getFaultyWebapps().remove(filename);
registerApplicationEventListeners(applicationEventListeners, context);
log.info("Deployed webapp: " + webapp);
} catch (Throwable e) {
// catching a Throwable here to avoid web-apps crashing the server during startup
StandardContext context = new StandardContext();
context.setName(webappFile.getName());
context.addParameter(WebappsConstants.FAULTY_WEBAPP, "true");
JaggeryApplication webapp = new JaggeryApplication(this, context, webappFile);
webapp.setProperty(WebappsConstants.WEBAPP_FILTER, JaggeryConstants.JAGGERY_WEBAPP_FILTER_PROP);
String msg = "Error while deploying webapp: " + webapp;
log.error(msg, e);
webapp.setFaultReason(new Exception(msg, e));
webApplicationsHolder.getFaultyWebapps().put(filename, webapp);
webApplicationsHolder.getStartedWebapps().remove(filename);
throw new CarbonException(msg, e);
}
}
use of org.wso2.broker.amqp.Server in project carbon-apimgt by wso2.
the class BrokerManager method start.
/**
* Starting the broker
*/
public static void start() {
try {
StartupContext startupContext = new StartupContext();
initConfigProvider(startupContext);
BrokerConfigProvider service = startupContext.getService(BrokerConfigProvider.class);
BrokerConfiguration brokerConfiguration = service.getConfigurationObject(BrokerConfiguration.NAMESPACE, BrokerConfiguration.class);
DataSource dataSource = getDataSource(brokerConfiguration.getDataSource());
startupContext.registerService(DataSource.class, dataSource);
restServer = new BrokerRestServer(startupContext);
broker = new Broker(startupContext);
broker.startMessageDelivery();
amqpServer = new Server(startupContext);
amqpServer.start();
restServer.start();
loadUsers();
} catch (Exception e) {
log.error("Error while starting broker", e);
}
}
Aggregations