Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,15 @@ for this component:


// component options: START
The Braintree component supports 4 options, which are listed below.
The Braintree component supports 5 options, which are listed below.



[width="100%",cols="2,5,^1,2",options="header"]
|===
| Name | Description | Default | Type
| *configuration* (common) | To use the shared configuration | | BraintreeConfiguration
| *logHandlerEnabled* (logging) | Sets whether to enable the BraintreeLogHandler. It may be desirable to set this to 'false' where an existing JUL - SLF4J logger bridge is on the classpath. | true | boolean
| *basicPropertyBinding* (advanced) | Whether the component should use basic property binding (Camel 2.x) or the newer property binding with additional capabilities | false | boolean
| *lazyStartProducer* (producer) | Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel's routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | boolean
| *bridgeErrorHandler* (consumer) | Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | boolean
Expand Down Expand Up @@ -78,7 +79,7 @@ with the following path and query parameters:
|===


=== Query Parameters (32 parameters):
=== Query Parameters (33 parameters):


[width="100%",cols="2,5,^1,2",options="header"]
Expand All @@ -100,6 +101,7 @@ with the following path and query parameters:
| *httpReadTimeout* (advanced) | Set read timeout for http calls. | | Integer
| *synchronous* (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean
| *httpLogLevel* (logging) | Set logging level for http calls, see java.util.logging.Level | | String
| *logHandlerEnabled* (logging) | Sets whether to enable the BraintreeLogHandler. It may be desirable to set this to 'false' where an existing JUL - SLF4J logger bridge is on the classpath. This option can also be configured globally on the BraintreeComponent. | true | boolean
| *backoffErrorThreshold* (scheduler) | The number of subsequent error polls (failed due some error) that should happen before the backoffMultipler should kick-in. | | int
| *backoffIdleThreshold* (scheduler) | The number of subsequent idle polls that should happen before the backoffMultipler should kick-in. | | int
| *backoffMultiplier* (scheduler) | To let the scheduled polling consumer backoff if there has been a number of subsequent idles/errors in a row. The multiplier is then the number of polls that will be skipped before the next actual attempt is happening again. When this option is in use then backoffIdleThreshold and/or backoffErrorThreshold must also be configured. | | int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.camel.Endpoint;
import org.apache.camel.component.braintree.internal.BraintreeApiCollection;
import org.apache.camel.component.braintree.internal.BraintreeApiName;
import org.apache.camel.spi.Metadata;
import org.apache.camel.spi.annotations.Component;
import org.apache.camel.support.component.AbstractApiComponent;

Expand All @@ -32,6 +33,10 @@
*/
@Component("braintree")
public class BraintreeComponent extends AbstractApiComponent<BraintreeApiName, BraintreeConfiguration, BraintreeApiCollection> {

@Metadata(label = "advanced,logging", defaultValue = "true")
private boolean logHandlerEnabled = true;

private final Map<String, BraintreeGateway> gateways;

public BraintreeComponent() {
Expand All @@ -53,6 +58,7 @@ protected BraintreeApiName getApiName(String apiNameStr) throws IllegalArgumentE
protected Endpoint createEndpoint(String uri, String methodName, BraintreeApiName apiName, BraintreeConfiguration endpointConfiguration) {
endpointConfiguration.setApiName(apiName);
endpointConfiguration.setMethodName(methodName);
endpointConfiguration.setLogHandlerEnabled(logHandlerEnabled);
return new BraintreeEndpoint(uri, this, apiName, methodName, endpointConfiguration);
}

Expand All @@ -69,6 +75,18 @@ public BraintreeConfiguration getConfiguration() {
return super.getConfiguration();
}

/**
* Sets whether to enable the BraintreeLogHandler. It may be desirable to set this to
* 'false' where an existing JUL - SLF4J logger bridge is on the classpath.
*/
public void setLogHandlerEnabled(boolean logHandlerEnabled) {
this.logHandlerEnabled = logHandlerEnabled;
}

public boolean isLogHandlerEnabled() {
return logHandlerEnabled;
}

public synchronized BraintreeGateway getGateway(BraintreeConfiguration configuration) {
BraintreeGateway gateway;
if (configuration.getAccessToken() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ public class BraintreeConfiguration {
@Metadata(label = "advanced,logging")
private String httpLogName;

@UriParam(defaultValue = "true")
@Metadata(label = "advanced,logging")
private boolean logHandlerEnabled = true;

@UriParam
@Metadata(label = "advanced")
private Integer httpReadTimeout;
Expand Down Expand Up @@ -215,6 +219,20 @@ public Integer getHttpReadTimeout() {
return httpReadTimeout;
}

/**
* Sets whether to enable the BraintreeLogHandler. It may be desirable to set this to
* 'false' where an existing JUL - SLF4J logger bridge is on the classpath.
*
* This option can also be configured globally on the BraintreeComponent.
*/
public void setLogHandlerEnabled(boolean logHandlerEnabled) {
this.logHandlerEnabled = logHandlerEnabled;
}

public boolean isLogHandlerEnabled() {
return logHandlerEnabled;
}

/**
* Set read timeout for http calls.
*/
Expand Down Expand Up @@ -280,7 +298,9 @@ synchronized BraintreeGateway newBraintreeGateway() {
logger.removeHandler(handler);
}

logger.addHandler(new BraintreeLogHandler());
if (isLogHandlerEnabled()) {
logger.addHandler(new BraintreeLogHandler());
}

if (httpLogLevel != null) {
logger.setLevel(httpLogLevel);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.component.braintree;

import java.util.logging.Level;
import java.util.logging.Logger;

import com.braintreegateway.BraintreeGateway;
import org.apache.camel.component.braintree.internal.BraintreeApiName;
import org.apache.camel.component.braintree.internal.BraintreeLogHandler;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

public class BraintreeComponentTest {

@Test
public void testLoggerConfiguration() {
BraintreeConfiguration configuration = createBraintreeConfiguration();
configuration.setHttpLogLevel(Level.WARNING);

BraintreeComponent component = new BraintreeComponent();
component.createEndpoint("braintree:clientToken", "generate", BraintreeApiName.CLIENTTOKEN, configuration);

BraintreeGateway braintreeGateway = component.getGateway(configuration);
Logger logger = braintreeGateway.getConfiguration().getLogger();
assertEquals(Level.WARNING, logger.getLevel());
assertEquals(1, logger.getHandlers().length);
assertTrue(logger.getHandlers()[0] instanceof BraintreeLogHandler);
}

@Test
public void testBraintreeLogHandlerDisabled() {
BraintreeConfiguration configuration = createBraintreeConfiguration();

BraintreeComponent component = new BraintreeComponent();
component.setLogHandlerEnabled(false);
component.createEndpoint("", "", BraintreeApiName.CLIENTTOKEN, configuration);

BraintreeGateway braintreeGateway = component.getGateway(configuration);
Logger logger = braintreeGateway.getConfiguration().getLogger();
assertEquals(0, logger.getHandlers().length);
}

private BraintreeConfiguration createBraintreeConfiguration() {
BraintreeConfiguration configuration = new BraintreeConfiguration();
configuration.setEnvironment("SANDBOX");
configuration.setMerchantId("dummy-merchant-id");
configuration.setPublicKey("dummy-public-key");
configuration.setPrivateKey("dummy-private-key");
return configuration;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.component.braintree;

import java.util.logging.Level;
import java.util.logging.Logger;

import com.braintreegateway.BraintreeGateway;
import org.apache.camel.component.braintree.internal.BraintreeLogHandler;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

public class BraintreeConfigurationTest {

@Test
public void testLoggerConfiguration() {
BraintreeConfiguration configuration = createBraintreeConfiguration();
configuration.setHttpLogLevel(Level.WARNING);

BraintreeGateway braintreeGateway = configuration.newBraintreeGateway();
Logger logger = braintreeGateway.getConfiguration().getLogger();
assertEquals(Level.WARNING, logger.getLevel());
assertEquals(1, logger.getHandlers().length);
assertTrue(logger.getHandlers()[0] instanceof BraintreeLogHandler);
}

@Test
public void testBraintreeLogHandlerDisabled() {
BraintreeConfiguration configuration = createBraintreeConfiguration();
configuration.setLogHandlerEnabled(false);

BraintreeGateway braintreeGateway = configuration.newBraintreeGateway();
Logger logger = braintreeGateway.getConfiguration().getLogger();
assertEquals(0, logger.getHandlers().length);
}

private BraintreeConfiguration createBraintreeConfiguration() {
BraintreeConfiguration configuration = new BraintreeConfiguration();
configuration.setEnvironment("SANDBOX");
configuration.setMerchantId("dummy-merchant-id");
configuration.setPublicKey("dummy-public-key");
configuration.setPrivateKey("dummy-private-key");
return configuration;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,38 @@ default AdvancedBraintreeEndpointConsumerBuilder httpLogLevel(
doSetProperty("httpLogLevel", httpLogLevel);
return this;
}
/**
* Sets whether to enable the BraintreeLogHandler. It may be desirable
* to set this to 'false' where an existing JUL - SLF4J logger bridge is
* on the classpath. This option can also be configured globally on the
* BraintreeComponent.
*
* The option is a: <code>boolean</code> type.
*
* Default: true
* Group: logging
*/
default AdvancedBraintreeEndpointConsumerBuilder logHandlerEnabled(
boolean logHandlerEnabled) {
doSetProperty("logHandlerEnabled", logHandlerEnabled);
return this;
}
/**
* Sets whether to enable the BraintreeLogHandler. It may be desirable
* to set this to 'false' where an existing JUL - SLF4J logger bridge is
* on the classpath. This option can also be configured globally on the
* BraintreeComponent.
*
* The option will be converted to a <code>boolean</code> type.
*
* Default: true
* Group: logging
*/
default AdvancedBraintreeEndpointConsumerBuilder logHandlerEnabled(
String logHandlerEnabled) {
doSetProperty("logHandlerEnabled", logHandlerEnabled);
return this;
}
}

/**
Expand Down Expand Up @@ -1073,6 +1105,38 @@ default AdvancedBraintreeEndpointProducerBuilder httpLogLevel(
doSetProperty("httpLogLevel", httpLogLevel);
return this;
}
/**
* Sets whether to enable the BraintreeLogHandler. It may be desirable
* to set this to 'false' where an existing JUL - SLF4J logger bridge is
* on the classpath. This option can also be configured globally on the
* BraintreeComponent.
*
* The option is a: <code>boolean</code> type.
*
* Default: true
* Group: logging
*/
default AdvancedBraintreeEndpointProducerBuilder logHandlerEnabled(
boolean logHandlerEnabled) {
doSetProperty("logHandlerEnabled", logHandlerEnabled);
return this;
}
/**
* Sets whether to enable the BraintreeLogHandler. It may be desirable
* to set this to 'false' where an existing JUL - SLF4J logger bridge is
* on the classpath. This option can also be configured globally on the
* BraintreeComponent.
*
* The option will be converted to a <code>boolean</code> type.
*
* Default: true
* Group: logging
*/
default AdvancedBraintreeEndpointProducerBuilder logHandlerEnabled(
String logHandlerEnabled) {
doSetProperty("logHandlerEnabled", logHandlerEnabled);
return this;
}
}

/**
Expand Down Expand Up @@ -1300,6 +1364,38 @@ default AdvancedBraintreeEndpointBuilder httpLogLevel(
doSetProperty("httpLogLevel", httpLogLevel);
return this;
}
/**
* Sets whether to enable the BraintreeLogHandler. It may be desirable
* to set this to 'false' where an existing JUL - SLF4J logger bridge is
* on the classpath. This option can also be configured globally on the
* BraintreeComponent.
*
* The option is a: <code>boolean</code> type.
*
* Default: true
* Group: logging
*/
default AdvancedBraintreeEndpointBuilder logHandlerEnabled(
boolean logHandlerEnabled) {
doSetProperty("logHandlerEnabled", logHandlerEnabled);
return this;
}
/**
* Sets whether to enable the BraintreeLogHandler. It may be desirable
* to set this to 'false' where an existing JUL - SLF4J logger bridge is
* on the classpath. This option can also be configured globally on the
* BraintreeComponent.
*
* The option will be converted to a <code>boolean</code> type.
*
* Default: true
* Group: logging
*/
default AdvancedBraintreeEndpointBuilder logHandlerEnabled(
String logHandlerEnabled) {
doSetProperty("logHandlerEnabled", logHandlerEnabled);
return this;
}
}
/**
* Braintree (camel-braintree)
Expand Down
Loading