Skip to content

Commit

Permalink
Update documentation for Spring Config class
Browse files Browse the repository at this point in the history
  • Loading branch information
trungie committed Apr 18, 2017
1 parent 3b85c52 commit 2e0e004
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
31 changes: 29 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ We have a build.sbt file defined in the root.


### Configure
The Xero Java SDK depends on an external JSON file to configure values unique to your Application.
The Xero Java SDK is easily configured using an external JSON file to configure values unique to your Application. This is the default configuration method, however you can implement the `Config` interface and pass it to the `XeroClient`.

We include an Example App (in this repo) built using Eclipse. We started with a Maven Project and selected the maven-archetype-webapp with the setup Wizard. This created a web application structure good for use with Servlets & JSPs. By default a src/main/resources directory is added to the project. **Place the config.json file you create in the resources directory**.

The Xero Java SDK - Config.java class parses the JSON file from the resources directory using the following bit of code.
The Xero Java SDK JsonConfig.java class parses the JSON file from the resources directory using the following bit of code.

```java
final ClassLoader loader = Config.class.getClassLoader();
Expand Down Expand Up @@ -97,6 +97,33 @@ In a text editor, create a file called config.json (examples are below) Refer t
* AuthenticateUrl: path for redirect to authorize *default is /oauth/RequestToken*
* AccessTokenPath: path for Access Token *default is https://api.xero.com/oauth/Authorize*

### Spring Framework based Config

An alternative method of configuring the Xero Java SDK can be found in the `example/src/main/java` folder named `SpringConfig.java`.

This class reads the configuration from the spring `Environment` backed by the `application.properties`. This handy way of configuring the SDK
allows spring profiles to control your production and development environments.

```java
@Bean
public XeroClient xeroClient(Environment environment) {
SpringConfig config = new SpringConfig("xero.", environment);
XeroClient client = new XeroClient(config);
client.setOAuthToken(config.getConsumerKey(), config.getConsumerSecret());
return client;
}
```

Application.properties
```
xero.AppType=PRIVATE
xero.UserAgent=Your App Name
xero.ConsumerKey=FA6UXXXXXXXXXXXXXXXXXXXXXXRC7
xero.ConsumerSecret=7FMXXXXXXXXXXXXXXXXXXXXXXXXXCSA
xero.PrivateKeyCert=certs/public_privatekey.pfx
xero.PrivateKeyPassword=
```

### Example App
This repo includes an Example App mentioned above. The file structure mirrors that of an Eclipse Maven Project with the maven-archetype-webapp

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/xero/api/XeroClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ public class XeroClient {
protected static final Pattern MESSAGE_PATTERN = Pattern.compile("<Message>(.*)</Message>");
protected final ObjectFactory objFactory = new ObjectFactory();

public XeroClient() {
this.config = JsonConfig.getInstance();
}

public XeroClient(Config config) {
this.config = config;
}
Expand Down

0 comments on commit 2e0e004

Please sign in to comment.