forked from atomikos/transactions-essentials
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
https://github.com/atomikos/transactions-essentials/issues/213
Builder for Rest Client of remote-transactions
- Loading branch information
1 parent
115834e
commit f7990c2
Showing
6 changed files
with
123 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
...sactions-remoting/src/main/java/com/atomikos/remoting/twopc/DefaultRestClientBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.atomikos.remoting.twopc; | ||
|
||
import static javax.ws.rs.client.ClientBuilder.newClient; | ||
|
||
import javax.ws.rs.client.Client; | ||
|
||
/** | ||
* Default provider for standard Jaxrs Client without connection pool | ||
*/ | ||
public class DefaultRestClientBuilder extends RestClientBuilder { | ||
|
||
public Client build() { | ||
Client client = newClient(); | ||
client.property("jersey.config.client.suppressHttpComplianceValidation", true); | ||
client.register(ParticipantsProvider.class); | ||
return client; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...ic/transactions-remoting/src/main/java/com/atomikos/remoting/twopc/RestClientBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.atomikos.remoting.twopc; | ||
|
||
import javax.ws.rs.client.Client; | ||
|
||
/** | ||
* Abstract Builder for creation of Rest Client | ||
* | ||
* You can create a sublcass if you need some special handling like connection polling, timeouts, ... | ||
* Implementation is defined by the property com.atomikos.remoting.rest_client_builder | ||
* Default in transaction-default.properties is | ||
* com.atomikos.remoting.rest_client_builder=com.atomikos.remoting.twopc.DefaultRestClientBuilder | ||
* | ||
* Here some example: | ||
* <pre> | ||
* | ||
* public class PooledRestClientBuilder extends RestClientBuilder { | ||
@Override | ||
public Client build() { | ||
ResteasyClientBuilder builder = new ResteasyClientBuilder(); | ||
ConfigProperties configProperties = Configuration.getConfigProperties(); | ||
String connectionPoolSizeProperty = configProperties.getProperty("com.atomikos.remoting.twopc.ParticipantAdapter.connectionPoolSize"); | ||
int connectionPoolSize = 20; | ||
if (connectionPoolSizeProperty != null) | ||
connectionPoolSize = Integer.valueOf(connectionPoolSizeProperty); | ||
String connectTimeoutProperty = configProperties.getProperty("com.atomikos.remoting.twopc.ParticipantAdapter.connectTimeout"); | ||
int connectTimeout = 10; | ||
if (connectTimeoutProperty != null) | ||
connectTimeout = Integer.valueOf(connectTimeoutProperty); | ||
String readTimeoutProperty = configProperties.getProperty("com.atomikos.remoting.twopc.ParticipantAdapter.readTimeout"); | ||
int readTimeout = 60; | ||
if (readTimeoutProperty != null) | ||
readTimeout = Integer.valueOf(readTimeoutProperty); | ||
builder.connectTimeout(connectTimeout, TimeUnit.SECONDS); | ||
builder.readTimeout(readTimeout, TimeUnit.SECONDS); | ||
Client c = builder.connectionPoolSize(connectionPoolSize).build(); | ||
c.property("jersey.config.client.suppressHttpComplianceValidation", true); | ||
c.register(ParticipantsProvider.class); | ||
return c; | ||
} | ||
} | ||
* | ||
* </pre> | ||
*/ | ||
public abstract class RestClientBuilder { | ||
|
||
public abstract Client build(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters