braintree / braintree_java

Braintree Java library
https://developer.paypal.com/braintree/docs/start/overview
MIT License
158 stars 98 forks source link

Support for configuring connection timeout #56

Closed vinaiarun closed 6 years ago

vinaiarun commented 6 years ago

Support for configuring connection timeout

Braintree does not currently set a connection timeout in its Java SDK

Braintree Java SDK currently sets only request timeout value. We would like to set the connection timeout value as well.

Below is the email thread related to the above request

Dustin (Braintree) Dec 18, 12:49 PM CST 

Vinai,

Thanks for the clarification.  

Currently, Braintree does not currently set a connection timeout in our SDK.  The only timeout that is set is the read timeout, as previously mentioned.

I apologize for the inconvenience, but feel free to open a feature request if this is something that is causing an issue on your end.Cheers,Dustin

⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼

Kari (Braintree) Dec 17, 4:39 PM CST

Hey Vinai,

Thanks for writing back in.

I reached out to a specialized team here at Braintree in order to see what options we could offer you. For clarification, I'd like to ensure that we understand your goal. Are you looking to adjust the timeframe of incoming data sent to your website or are you looking to adjust the time where outgoing data is being sent to Braintree from your website? Once they've gotten the chance to review your request, they'll reach out to you with any relevant information they might find.

Kindest Regards,

Kari Braintree

⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼

Arunachalam, Vinai Dec 15, 1:06 PM CST

Hi Casey,

Thanks for the details. I was able to find the read timeout details and the recommendation to not set the read timeout myself.

My question is not about read timeout. I would like to know how the connect timeout value is set and how to configure it. By looking into the Java SDK I found that Braintree is using URLConnection. But I couldn’t find how the connect timeout value is set in the code for the URLConnection.

The timeout value that we set in the configuration is used only to set the read timeout value. I see the below code in com.braintreegateway.util.Http connection.setReadTimeout(configuration.getTimeout());

I am looking for something like connection.setConnectTimeout….

I tried my best to explain my question in a better way. Please let me know if it is still not clear or if you need more details.

Thank you. Vinai

⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼

Casey C. (Braintree) Dec 15, 3:57 AM CST

Hi Vinai,

Thanks for reaching out to us. Happy to help out here.

The article that you linked me contains the code needed to set the timeout. In the article linked, it contains this code: private static BraintreeGateway gateway = new BraintreeGateway( Environment.SANDBOX, "your_merchant_id", "your_public_key", "your_private_key" );

gateway.configuration.setTimeout(10000);

This will timeout your API requests in 10000ms. I've tested this code and it does work successfully, throwing the timeout error.

The default timeout is 60 seconds. To be frank, however, I do not recommend setting a custom timeout. The timeout is thrown on your server's side, but Braintree will still process the API request. For example, if you set your timeout for 10 seconds and then issue a Braintree_Transaction::sale() API request, but the transaction takes more than 10 seconds to process, the transaction will still be completed. Your server will not receive the successful response, as the function already closes with a timeOutError.

I hope this clarifies everything! If you have any other questions, don't hesitate to reach back out!

Warmest Regards,

Casey C. Braintree ⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼

Arunachalam, Vinai Dec 14, 5:28 PM CST Name: Vinai Arunachalam Business Email: viarunachalam@paypal.com Business Name: Xoom Message: Hi, I would like to know how to configure the connection timeout. We are using the braintree Java SDK. The link below explains only about the read timeout https://developers.braintreepayments.com/reference/general/best-practices/java#timeouts We would like to how to set the connection timeout value. Right it looks like the connection timeout value is around 120 seconds. But I couldn't find where this value was set in the Java SDK and don't know how to change it. A code snippet that explains how to set this connection timeout value or any link to documents that explain this in detail would be very helpful. Thank you. Vinai Environment: Sandbox Referrer: https://developers.braintreepayments.com/reference/general/best-practices/java

crookedneighbor commented 6 years ago

Thanks for opening this issue, we'll look into the feasibility of this.

crookedneighbor commented 6 years ago

This will go out in the next release. I'll update here when it does.

crookedneighbor commented 6 years ago

The configuration object now has a setConnectTimeout method in the latest release.

private static BraintreeGateway gateway = new BraintreeGateway(
  Environment.SANDBOX,
  "your_merchant_id",
  "your_public_key",
  "your_private_key"
);

gateway.configuration.setConnectTimeout(your_int_value);