use of org.apache.camel.Component in project camel by apache.
the class DefaultConnectorComponent method getVerifier.
@SuppressWarnings("unchecked")
@Override
public ComponentVerifier getVerifier() {
final String scheme = model.getBaseScheme();
final Component component = getCamelContext().getComponent(scheme);
if (component instanceof VerifiableComponent) {
return (scope, map) -> {
Map<String, Object> options;
try {
// A little nasty hack required as verifier uses Map<String, Object>
// to be compatible with all the methods in CamelContext whereas
// catalog deals with Map<String, String>
options = (Map) buildEndpointOptions(null, map);
} catch (URISyntaxException e) {
// and stop the validation step.
return ResultBuilder.withStatusAndScope(ComponentVerifier.Result.Status.OK, scope).error(ResultErrorBuilder.withException(e).build()).build();
}
return ((VerifiableComponent) component).getVerifier().verify(scope, options);
};
} else {
return (scope, map) -> {
return ResultBuilder.withStatusAndScope(ComponentVerifier.Result.Status.UNSUPPORTED, scope).error(ResultErrorBuilder.withCode("unsupported").attribute("camel.connector.name", getConnectorName()).attribute("camel.component.name", getComponentName()).build()).build();
};
}
}
use of org.apache.camel.Component in project camel by apache.
the class SalesforceComponentConfigurationIntegrationTest method testEndpointCompletion.
@Test
public void testEndpointCompletion() throws Exception {
Component component = context().getComponent(componentName);
ComponentConfiguration configuration = component.createComponentConfiguration();
// get operation names
assertCompletionOptions(configuration.completeEndpointPath(""), "getVersions", "getResources", "getGlobalObjects", "getBasicInfo", "getDescription", "getSObject", "createSObject", "updateSObject", "deleteSObject", "getSObjectWithId", "upsertSObject", "deleteSObjectWithId", "getBlobField", "query", "queryMore", "queryAll", "search", "apexCall", "recent", "createJob", "getJob", "closeJob", "abortJob", "createBatch", "getBatch", "getAllBatches", "getRequest", "getResults", "createBatchQuery", "getQueryResultIds", "getQueryResult", "getRecentReports", "getReportDescription", "executeSyncReport", "executeAsyncReport", "getReportInstances", "getReportResults", "limits", "approval", "approvals", "composite-batch", "composite-tree", "[PushTopicName]");
// get filtered operation names
assertCompletionOptions(configuration.completeEndpointPath("get"), "getVersions", "getResources", "getGlobalObjects", "getBasicInfo", "getDescription", "getSObject", "getSObjectWithId", "getBlobField", "getJob", "getBatch", "getAllBatches", "getRequest", "getResults", "getQueryResultIds", "getQueryResult", "getRecentReports", "getReportDescription", "getReportInstances", "getReportResults");
/* TODO support parameter completion
// get ALL REST operation parameters
// TODO support operation specific parameter completion
assertCompletionOptions(configuration.completeEndpointPath("getSObject?"),
"apiVersion", "httpClient", "format", "sObjectName", "sObjectId", "sObjectFields",
"sObjectIdName", "sObjectIdValue", "sObjectBlobFieldName", "sObjectClass", "sObjectQuery", "sObjectSearch");
// get filtered REST parameters
assertCompletionOptions(configuration.completeEndpointPath("getSObject?format=XML&"),
"apiVersion", "httpClient", "sObjectName", "sObjectId", "sObjectFields",
"sObjectIdName", "sObjectIdValue", "sObjectBlobFieldName", "sObjectClass", "sObjectQuery", "sObjectSearch");
// get ALL Bulk operation parameters
// TODO support operation specific parameter completion
assertCompletionOptions(configuration.completeEndpointPath("createJob?"),
"apiVersion", "httpClient", "sObjectQuery", "contentType", "jobId", "batchId", "resultId");
// get filtered Bulk operation parameters
assertCompletionOptions(configuration.completeEndpointPath("createJob?contentType=XML&"),
"apiVersion", "httpClient", "sObjectQuery", "jobId", "batchId", "resultId");
// get ALL topic parameters for consumers
assertCompletionOptions(configuration.completeEndpointPath("myTopic?"),
"apiVersion", "httpClient", "updateTopic", "notifyForFields", "notifyForOperations");
// get filtered topic parameters for consumers
assertCompletionOptions(configuration.completeEndpointPath("myTopic?updateTopic=true&"),
"apiVersion", "httpClient", "notifyForFields", "notifyForOperations");
// get parameters from partial name
assertCompletionOptions(configuration.completeEndpointPath("getSObject?sObject"),
"sObjectName", "sObjectId", "sObjectFields",
"sObjectIdName", "sObjectIdValue", "sObjectBlobFieldName", "sObjectClass", "sObjectQuery", "sObjectSearch");
*/
// get sObjectName values, from scanned DTO packages
assertCompletionOptions(configuration.completeEndpointPath("getSObject?sObjectName="), "Account", "Asset", "Contact", "Task", "Line_Item__c", "Merchandise__c", "Document", "MSPTest");
// get sObjectFields values, from scanned DTO
assertCompletionOptions(configuration.completeEndpointPath("getSObject?sObjectName=Merchandise__c&sObjectFields="), "Description__c", "Price__c", "Total_Inventory__c", "attributes", "Id", "OwnerId", "IsDeleted", "Name", "CreatedDate", "CreatedById", "LastModifiedDate", "LastModifiedById", "SystemModstamp", "LastActivityDate", "LastViewedDate", "LastReferencedDate");
// get sObjectClass values, from scanned DTO packages
assertCompletionOptions(configuration.completeEndpointPath("getSObject?sObjectClass="), Account.class.getName(), Asset.class.getName(), Contact.class.getName(), Task.class.getName(), Line_Item__c.class.getName(), Merchandise__c.class.getName(), Document.class.getName(), MSPTest.class.getName(), QueryRecordsLine_Item__c.class.getName());
}
use of org.apache.camel.Component in project camel by apache.
the class DefaultConnectorComponent method createNewBaseComponent.
// ***************************************
// Helpers
// ***************************************
private Component createNewBaseComponent(String scheme) throws Exception {
String baseClassName = model.getBaseJavaType();
if (baseClassName != null) {
// create a new instance of this base component
Class<?> type = Class.forName(baseClassName);
Constructor ctr = getPublicDefaultConstructor(type);
if (ctr != null) {
// call default no-arg constructor
Object base = ctr.newInstance();
// the connector may have default values for the component level also
// and if so we need to prepare these values and set on this component before we can start
Map<String, String> defaultOptions = model.getDefaultComponentOptions();
if (!defaultOptions.isEmpty()) {
Map<String, Object> copy = new LinkedHashMap<>();
for (Map.Entry<String, String> entry : defaultOptions.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
if (value != null) {
// also support {{ }} placeholders so resolve those first
value = getCamelContext().resolvePropertyPlaceholders(value);
log.debug("Using component option: {}={}", key, value);
copy.put(key, value);
}
}
IntrospectionSupport.setProperties(getCamelContext(), getCamelContext().getTypeConverter(), base, copy);
}
// configure component with extra options
if (componentOptions != null && !componentOptions.isEmpty()) {
Map<String, Object> copy = new LinkedHashMap<>(componentOptions);
IntrospectionSupport.setProperties(getCamelContext(), getCamelContext().getTypeConverter(), base, copy);
}
if (base instanceof Component) {
getCamelContext().removeComponent(scheme);
// ensure component is started and stopped when Camel shutdown
getCamelContext().addService(base, true, true);
getCamelContext().addComponent(scheme, (Component) base);
return (Component) base;
}
}
}
return null;
}
use of org.apache.camel.Component in project camel by apache.
the class AbstractFeatureTest method testComponent.
protected void testComponent(String mainFeature, String component) throws Exception {
LOG.info("Looking up CamelContext(myCamel) in OSGi Service Registry");
installCamelFeature(mainFeature);
CamelContext camelContext = getOsgiService(bundleContext, CamelContext.class, "(camel.context.name=myCamel)", SERVICE_TIMEOUT);
assertNotNull("Cannot find CamelContext with name myCamel", camelContext);
LOG.info("Getting Camel component: {}", component);
// do not auto start the component as it may not have been configured properly and fail in its start method
Component comp = camelContext.getComponent(component, true, false);
assertNotNull("Cannot get component with name: " + component, comp);
LOG.info("Found Camel component: {} instance: {} with className: {}", component, comp, comp.getClass());
}
use of org.apache.camel.Component in project camel by apache.
the class SalesforceComponentConfigurationIntegrationTest method testConfiguration.
@Test
public void testConfiguration() throws Exception {
Component component = context().getComponent(componentName);
ComponentConfiguration configuration = component.createComponentConfiguration();
SortedMap<String, ParameterConfiguration> parameterConfigurationMap = configuration.getParameterConfigurationMap();
if (verbose) {
Set<Map.Entry<String, ParameterConfiguration>> entries = parameterConfigurationMap.entrySet();
for (Map.Entry<String, ParameterConfiguration> entry : entries) {
String name = entry.getKey();
ParameterConfiguration config = entry.getValue();
LOG.info("Has name: {} with type {}", name, config.getParameterType().getName());
}
}
assertParameterConfig(configuration, "format", PayloadFormat.class);
assertParameterConfig(configuration, "sObjectName", String.class);
assertParameterConfig(configuration, "sObjectFields", String.class);
assertParameterConfig(configuration, "updateTopic", boolean.class);
configuration.setParameter("format", PayloadFormat.XML);
configuration.setParameter("sObjectName", "Merchandise__c");
configuration.setParameter("sObjectFields", "Description__c,Total_Inventory__c");
configuration.setParameter("updateTopic", false);
// operation name is base uri
configuration.setBaseUri(componentName + ":getSObject");
SalesforceEndpoint endpoint = assertIsInstanceOf(SalesforceEndpoint.class, configuration.createEndpoint());
final SalesforceEndpointConfig endpointConfig = endpoint.getConfiguration();
assertEquals("endpoint.format", PayloadFormat.XML, endpointConfig.getFormat());
assertEquals("endpoint.sObjectName", "Merchandise__c", endpointConfig.getSObjectName());
assertEquals("endpoint.sObjectFields", "Description__c,Total_Inventory__c", endpointConfig.getSObjectFields());
assertEquals("endpoint.updateTopic", false, endpointConfig.isUpdateTopic());
}
Aggregations