use of org.apache.camel.component.braintree.BraintreeComponent in project camel by apache.
the class BraintreeComponentAutoConfiguration method configureBraintreeComponent.
@Lazy
@Bean(name = "braintree-component")
@ConditionalOnClass(CamelContext.class)
@ConditionalOnMissingBean(BraintreeComponent.class)
public BraintreeComponent configureBraintreeComponent(CamelContext camelContext, BraintreeComponentConfiguration configuration) throws Exception {
BraintreeComponent component = new BraintreeComponent();
component.setCamelContext(camelContext);
Map<String, Object> parameters = new HashMap<>();
IntrospectionSupport.getProperties(configuration, parameters, null, false);
for (Map.Entry<String, Object> entry : parameters.entrySet()) {
Object value = entry.getValue();
Class<?> paramClass = value.getClass();
if (paramClass.getName().endsWith("NestedConfiguration")) {
Class nestedClass = null;
try {
nestedClass = (Class) paramClass.getDeclaredField("CAMEL_NESTED_CLASS").get(null);
HashMap<String, Object> nestedParameters = new HashMap<>();
IntrospectionSupport.getProperties(value, nestedParameters, null, false);
Object nestedProperty = nestedClass.newInstance();
IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), nestedProperty, nestedParameters);
entry.setValue(nestedProperty);
} catch (NoSuchFieldException e) {
}
}
}
IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), component, parameters);
return component;
}
use of org.apache.camel.component.braintree.BraintreeComponent in project wildfly-camel by wildfly-extras.
the class BraintreeIntegrationTest method testBraintreeCustomerGateway.
@Test
public void testBraintreeCustomerGateway() throws Exception {
Map<String, Object> braintreeOptions = createBraintreeOptions();
// Do nothing if the required credentials are not present
Assume.assumeTrue(braintreeOptions.size() == BraintreeOption.values().length);
final CountDownLatch latch = new CountDownLatch(2);
final CamelContext camelctx = new DefaultCamelContext();
final BraintreeConfiguration configuration = new BraintreeConfiguration();
IntrospectionSupport.setProperties(configuration, braintreeOptions);
// add BraintreeComponent to Camel context
final BraintreeComponent component = new BraintreeComponent(camelctx);
component.setConfiguration(configuration);
camelctx.addComponent("braintree", component);
camelctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:create").to("braintree:customer/create?inBody=request").process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
latch.countDown();
}
});
from("direct:delete").to("braintree:customer/delete?inBody=id").process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
latch.countDown();
}
});
}
});
camelctx.start();
// ****************************
// Create a customer
// ****************************
@SuppressWarnings("unchecked") Result<Customer> createResult = camelctx.createProducerTemplate().requestBody("direct:create", new CustomerRequest().firstName("user").lastName(UUID.randomUUID().toString()).company("Apache").email("user@braintree.camel").website("http://user.braintree.camel"), Result.class);
Assert.assertNotNull(createResult);
Assert.assertTrue(createResult.isSuccess());
Assert.assertNotNull(createResult.getTarget());
Assert.assertNotNull(createResult.getTarget().getId());
// ****************************
// Delete the customer
// ****************************
@SuppressWarnings("unchecked") Result<Customer> deleteResult = camelctx.createProducerTemplate().requestBody("direct:delete", createResult.getTarget().getId(), Result.class);
Assert.assertNotNull(deleteResult);
Assert.assertTrue(deleteResult.isSuccess());
Assert.assertNull(deleteResult.getTarget());
try {
Assert.assertTrue("Countdown reached zero", latch.await(5, TimeUnit.MINUTES));
} finally {
camelctx.close();
}
}
use of org.apache.camel.component.braintree.BraintreeComponent in project wildfly-camel by wildfly-extras.
the class BraintreeIntegrationTest method testBraintreeClientTokenGateway.
@Test
public void testBraintreeClientTokenGateway() throws Exception {
Map<String, Object> braintreeOptions = createBraintreeOptions();
Assume.assumeTrue("[#1679] Enable Braintree testing in Jenkins", braintreeOptions.size() == BraintreeOption.values().length);
final CountDownLatch latch = new CountDownLatch(1);
final CamelContext camelctx = new DefaultCamelContext();
final BraintreeConfiguration configuration = new BraintreeConfiguration();
configuration.setHttpLogLevel(Level.WARNING);
IntrospectionSupport.setProperties(configuration, braintreeOptions);
// add BraintreeComponent to Camel context
final BraintreeComponent component = new BraintreeComponent(camelctx);
component.setConfiguration(configuration);
camelctx.addComponent("braintree", component);
camelctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("timer://braintree?repeatCount=1").to("braintree:clientToken/generate").process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
latch.countDown();
}
}).to("mock:result");
}
});
camelctx.start();
try {
Assert.assertTrue("Countdown reached zero", latch.await(5, TimeUnit.MINUTES));
} finally {
camelctx.close();
}
}
use of org.apache.camel.component.braintree.BraintreeComponent in project camel-quarkus by apache.
the class BraintreeResource method sale.
@Path("/sale")
@POST
@Produces(MediaType.APPLICATION_JSON)
public Response sale() throws Exception {
String api = BraintreeApiCollection.getCollection().getApiName(TransactionGatewayApiMethod.class).getName();
TransactionRequest transaction = new TransactionRequest().amount(new BigDecimal("100.00")).paymentMethodNonce("fake-valid-nonce").options().submitForSettlement(true).done();
Result<Transaction> result = producerTemplate.requestBody("braintree:" + api + "/sale?inBody=request", transaction, Result.class);
CamelContext camelContext = producerTemplate.getCamelContext();
BraintreeComponent component = camelContext.getComponent("braintree", BraintreeComponent.class);
BraintreeGateway gateway = component.getGateway(component.getConfiguration());
gateway.testing().settle(result.getTarget().getId());
JsonObjectBuilder objectBuilder = Json.createObjectBuilder();
objectBuilder.add("success", result.isSuccess());
objectBuilder.add("transactionId", result.getTarget().getId());
return Response.status(Response.Status.OK).entity(objectBuilder.build()).build();
}
use of org.apache.camel.component.braintree.BraintreeComponent in project camel-quarkus by apache.
the class BraintreeRecorder method configureBraintreeComponent.
/**
* Always disable the {@link org.apache.camel.component.braintree.internal.BraintreeLogHandler}.
*
* It's not desirable to configure this where an existing JUL - SLF4J bridge exists on the classpath.
*/
public RuntimeValue<BraintreeComponent> configureBraintreeComponent() {
BraintreeComponent component = new BraintreeComponent();
BraintreeConfiguration configuration = new BraintreeConfiguration();
configuration.setLogHandlerEnabled(false);
component.setConfiguration(configuration);
return new RuntimeValue<>(component);
}
Aggregations