Search in sources :

Example 1 with BraintreeComponent

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;
}
Also used : HashMap(java.util.HashMap) BraintreeComponent(org.apache.camel.component.braintree.BraintreeComponent) ConditionalOnClass(org.springframework.boot.autoconfigure.condition.ConditionalOnClass) HashMap(java.util.HashMap) Map(java.util.Map) Lazy(org.springframework.context.annotation.Lazy) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnClass(org.springframework.boot.autoconfigure.condition.ConditionalOnClass) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 2 with BraintreeComponent

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();
    }
}
Also used : DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) CamelContext(org.apache.camel.CamelContext) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) Customer(com.braintreegateway.Customer) BraintreeComponent(org.apache.camel.component.braintree.BraintreeComponent) CountDownLatch(java.util.concurrent.CountDownLatch) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) BraintreeConfiguration(org.apache.camel.component.braintree.BraintreeConfiguration) Exchange(org.apache.camel.Exchange) CustomerRequest(com.braintreegateway.CustomerRequest) Test(org.junit.Test)

Example 3 with BraintreeComponent

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();
    }
}
Also used : DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) CamelContext(org.apache.camel.CamelContext) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) BraintreeComponent(org.apache.camel.component.braintree.BraintreeComponent) CountDownLatch(java.util.concurrent.CountDownLatch) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) BraintreeConfiguration(org.apache.camel.component.braintree.BraintreeConfiguration) Exchange(org.apache.camel.Exchange) Test(org.junit.Test)

Example 4 with BraintreeComponent

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();
}
Also used : CamelContext(org.apache.camel.CamelContext) Transaction(com.braintreegateway.Transaction) TransactionGatewayApiMethod(org.apache.camel.component.braintree.internal.TransactionGatewayApiMethod) BraintreeComponent(org.apache.camel.component.braintree.BraintreeComponent) BraintreeGateway(com.braintreegateway.BraintreeGateway) JsonObjectBuilder(javax.json.JsonObjectBuilder) TransactionRequest(com.braintreegateway.TransactionRequest) BigDecimal(java.math.BigDecimal) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Example 5 with BraintreeComponent

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);
}
Also used : BraintreeComponent(org.apache.camel.component.braintree.BraintreeComponent) RuntimeValue(io.quarkus.runtime.RuntimeValue) BraintreeConfiguration(org.apache.camel.component.braintree.BraintreeConfiguration)

Aggregations

BraintreeComponent (org.apache.camel.component.braintree.BraintreeComponent)5 CamelContext (org.apache.camel.CamelContext)3 BraintreeConfiguration (org.apache.camel.component.braintree.BraintreeConfiguration)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 Exchange (org.apache.camel.Exchange)2 Processor (org.apache.camel.Processor)2 RouteBuilder (org.apache.camel.builder.RouteBuilder)2 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)2 Test (org.junit.Test)2 BraintreeGateway (com.braintreegateway.BraintreeGateway)1 Customer (com.braintreegateway.Customer)1 CustomerRequest (com.braintreegateway.CustomerRequest)1 Transaction (com.braintreegateway.Transaction)1 TransactionRequest (com.braintreegateway.TransactionRequest)1 RuntimeValue (io.quarkus.runtime.RuntimeValue)1 BigDecimal (java.math.BigDecimal)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 JsonObjectBuilder (javax.json.JsonObjectBuilder)1 POST (javax.ws.rs.POST)1