Skip to content
This repository was archived by the owner on May 16, 2024. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
848f42b
Updating samples so it refers to the new 'shared' service plan, so it…
dickeyf Sep 28, 2016
efeeead
Merge pull request #1 from dickeyf/master
dickeyf Oct 6, 2016
a215c9d
Merge branch 'master' of https://github.com/SolaceDev/solace-samples-…
benhaig Oct 6, 2016
6512204
Update "Common Setup"
benhaig Oct 7, 2016
a70436a
Improve deployment instructions
benhaig Oct 7, 2016
83a7513
Fixed links to tutorials
benhaig Oct 7, 2016
b6d62ef
Update VCAP_SERVICES example
benhaig Oct 7, 2016
f37c8af
Updated service instance name to match sample code
benhaig Oct 7, 2016
ca68c2b
Merge branch 'master' of https://github.com/SolaceSamples/solace-samp…
MichaelDavisSolace Nov 22, 2016
6ff051b
Added tls support
MichaelDavisSolace Nov 22, 2016
dd5e7de
Merge branch 'master' of https://github.com/SolaceSamples/solace-samp…
MichaelDavisSolace Nov 30, 2016
5b3905d
java-tls work in progress.
MichaelDavisSolace Dec 2, 2016
fba5ff4
Added secure-app, the TLS tutorial
MichaelDavisSolace Dec 9, 2016
7a7df8e
minor improvements to the secure-sessions tutorial.
MichaelDavisSolace Dec 9, 2016
f347576
Editorial changes from review
mdspielman Dec 9, 2016
02bb150
Added build dir to gitignore
MichaelDavisSolace Dec 13, 2016
320dbc7
Merge remote-tracking branch 'origin/mdspielman-patch-1' into tls-sup…
MichaelDavisSolace Dec 13, 2016
89cb009
Merge remote-tracking branch 'public/master'
MichaelDavisSolace Dec 13, 2016
77bca79
Merge branch 'master' into tls-support
MichaelDavisSolace Dec 13, 2016
9590cc9
Improvements to the secure-session tutorial based on Mark Spielman's …
MichaelDavisSolace Dec 14, 2016
c23db37
Improved secure-session tutorial based on the third review.
MichaelDavisSolace Dec 19, 2016
07c0748
Revert "Added tls support"
MichaelDavisSolace Dec 19, 2016
3375643
Fixed wrong variable name in the secure-session tutorial text. Improv…
MichaelDavisSolace Dec 20, 2016
61a163e
Merged changes from SolaceSamples
MichaelDavisSolace Dec 20, 2016
2ddecce
Fixed conflicts in secure-session.md
MichaelDavisSolace Dec 20, 2016
b3558d8
Fixed links to tutorials
benhaig Oct 7, 2016
797c095
Added tls support
MichaelDavisSolace Nov 22, 2016
19c4293
java-tls work in progress.
MichaelDavisSolace Dec 2, 2016
0e6569c
Added secure-app, the TLS tutorial
MichaelDavisSolace Dec 9, 2016
90ada31
minor improvements to the secure-sessions tutorial.
MichaelDavisSolace Dec 9, 2016
d010d4b
Editorial changes from review
mdspielman Dec 9, 2016
041af53
Improvements to the secure-session tutorial based on Mark Spielman's …
MichaelDavisSolace Dec 14, 2016
1fbd779
Improved secure-session tutorial based on the third review.
MichaelDavisSolace Dec 19, 2016
fd2e485
Revert "Added tls support"
MichaelDavisSolace Dec 19, 2016
0029972
Fixed wrong variable name in the secure-session tutorial text. Improv…
MichaelDavisSolace Dec 20, 2016
0cdfc00
Fixed conflicts in secure-session.md
MichaelDavisSolace Dec 20, 2016
3e0c12e
Upgraded to version 1.0.0 of the Solace cloud connector, added discus…
MichaelDavisSolace Mar 14, 2017
a864fb6
Reworded description of JCSMPTransportException.
MichaelDavisSolace Mar 14, 2017
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
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ For more details and example usage, see the walk through tutorial here:

* [Online Tutorial](https://solacesamples.github.io/solace-samples-cloudfoundry-java/spring-cloud/)


## Secure Session

application name: `solace-sample-secure-session`
Expand All @@ -94,6 +93,15 @@ Transport Level Security (TLS) between the Java application and the Solace Messa

* [Online Tutorial](https://solacesamples.github.io/solace-samples-cloudfoundry-java/secure-session/)

## Secure Session

application name: `solace-sample-secure-session`

This application is based on the Spring Cloud Connector described above, but shows how to use
Transport Level Security (TLS) between the Java application and the Messaging Service.

* [Online Tutorial](https://solacesamples.github.io/solace-samples-cloudfoundry-java/secure-session/)

## Try out the Applications

The sample applications have a simple REST interface that allows you to subscribe, send and receive Solace messages. You can try the applications out using command like the following.
Expand Down
1 change: 1 addition & 0 deletions docs/_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ links-pubsub-tutorial: http://dev.solace.com/get-started/java-tutorials/publish-
links-tls-client: http://docs.solace.com/Solace-Messaging-APIs/Creating-Secure-Sessions.htm
links-tls-server: https://docs.pivotal.io/solace-messaging/installing.html#configure
links-vcap: http://docs.pivotal.io/solace-messaging/credentials.html
links-best-practices: http://docs.solace.com/Solace-Messaging-APIs/Best-Practices.htm
#----------------------------------------------------
# Generally don't modify items below this point
url: "solacesamples.github.io" # the base hostname & protocol for your site
Expand Down
7 changes: 7 additions & 0 deletions docs/_includes/intro.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,19 @@ <h2 class="nolineheading">{{ site.title }}</h2>

<p>Solace Messaging is available in a number of network and deployment environments including Public/Private PaaS, Public/Private IaaS, LAN, WAN, Web, and Wireless ensuring your applications will have Solace Messaging available to them wherever they are deployed.</p>

<p>Solace Messaging supports High Availability configurations, where each message router is assigned backup that takes over in case of failures. Details about how to use this are in the Java Application tutorial.
Be sure to read the
<a href="http://docs.solace.com/Solace-Messaging-APIs/Best-Practices.htm" target="_top">Best Practices</a>
document, particularly the section on Replication.
</p>

<p>Here are a few links you might find interesting if you are new to Solace Messaging in Pivotal Cloud Foundry:</p>
<ol>
<li><a href="https://github.com/SolaceSamples/solace-samples-cloudfoundry-java" target="_top">GitHub code for the Getting Started samples</a></li>
<li><a href="https://network.pivotal.io/products/solace-messaging" target="_top">How to download Solace Messaging for PCF</a></li>
<li><a href="http://docs.pivotal.io/solace-messaging/" target="_top">The Solace Messaging in PCF Documentation</a></li>
<li><a href="https://github.com/SolaceLabs/sl-cf-solace-messaging-demo" target="_top">A demo application using Solace Messaging for PCF</a></li>
<li><a href="http://docs.solace.com/Solace-Messaging-APIs/Best-Practices.htm" target="_top">Best Practices for developing applications that use Solace Messaging</a></li>
</ol>
</div>
</div>
Expand Down
52 changes: 49 additions & 3 deletions docs/_tutorials/java-app.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ The Pivotal Cloud Foundry environment exposes any bound Service Instances in a J
"clientPassword": "bb90fcb0-6c83-4a10-bafa-3ec225bbfc08",
"msgVpnName": "v005",
(...)
"smfHost": "tcp://192.168.132.14:7000",
"smfHosts": [ "tcp://192.168.132.14:7000" ],
(...)
}
}
Expand Down Expand Up @@ -153,8 +153,14 @@ logger.info("Solace client initializing and using Credentials: " + solaceCredent
Once the credentials are extracted, you can create and then connect the Solace Session in the conventional way as outlined in the [Publish/Subscribe tutorial]({{ site.links-pubsub-tutorial }}){:target="_top"}. You set the JCSMP properties and then use the `JCSMPFactory` to create a `Session`:

```java

// The host property is in a json array. Two hosts are provided in a High Availability
// environment, one for the primary router and one for the backup.
JSONArray hostsArray = solaceCredentials.getJSONArray("smfHosts");
String host = hostsArray.getString(0);

final JCSMPProperties properties = new JCSMPProperties();
properties.setProperty(JCSMPProperties.HOST, solaceCredentials.getString("smfHost"));
properties.setProperty(JCSMPProperties.HOST, host);
properties.setProperty(JCSMPProperties.VPN_NAME, solaceCredentials.getString("msgVpnName"));
properties.setProperty(JCSMPProperties.USERNAME, solaceCredentials.getString("clientUsername"));
properties.setProperty(JCSMPProperties.PASSWORD, solaceCredentials.getString("clientPassword"));
Expand Down Expand Up @@ -291,7 +297,7 @@ export APP_URL=`cf apps | grep $APP_NAME | grep started | awk '{ print $6}'`
echo "The application URL is: ${APP_URL}"
```

To demonstrate the application we will make the application send a message to itself. Then we will read the message back to confirm the successful delivery of the message :
To demonstrate the application we will make the application send a message to itself. Then we will read the message back to confirm the successful delivery of the message:

```
# Subscribes the application to the topic "test"
Expand All @@ -303,3 +309,43 @@ curl -X POST -H "Content-Type: application/json;charset=UTF-8" -d '{"topic": "te
# The message should have been asynchronously received by the application. Check that the message was indeed received:
curl -X GET http://$APP_URL/message
```
## High Availability

Solace provides the option to set up High Availability configurations, where each message router has a backup. To use this in Cloud Foundry you need to create a service of type medium-ha or large-ha, for example:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Point us to an architectural overview of HA in the PCF Tile docs with picture.

```
cf create-service solace-messaging medium-ha solace-messaging-sample-instance
```

The Solace Java API automatically switches to the backup connection if it loses the connection to the primary router.

When using a High Availability service, the environment provided to the applications contains two connection urls rather than one. The first is the primary router and the second is the backup, for example:

```
"smfHosts": [ "tcp://192.168.101.16:7000", "tcp://192.168.101.17:7000" ]
```

In order to provide both hosts to the Solace Java API, you need to create a string containing a comma-separated list of the two hosts:

```
// The host property is in a json array. Two hosts are provided in a High Availability
// environment, one for the primary router and one for the backup.
JSONArray hostsArray = solaceCredentials.getJSONArray("smfHosts");
String primary = hostsArray.getString(0);
String backup = hostsArray.getString(1);
String hosts = String.join(",", primary, backup);
properties.setProperty(JCSMPProperties.HOST, hosts);
```
When you do the Spring Cloud tutorial, you will see that the Solace Spring Cloud Connector takes care of this for you.

Please consult the [Best Practices]({{ site.links-best-practices }}){:target="_top"} page, particularly the section named Replication Best Practices.

As described in that document, when using High Availability it is recommended to set the following configuration:

```
JCSMPProperties properties = new JCSMPProperties();
JCSMPChannelProperties cp = (JCSMPChannelProperties) properties
.getProperty(JCSMPProperties.CLIENT_CHANNEL_PROPERTIES);
cp.setReconnectRetries(-1); // try reconnecting forever
```

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use best practice recommendations here and not forever.


6 changes: 2 additions & 4 deletions docs/_tutorials/secure-session.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,6 @@ curl -X GET http://$APP_URL/message

## Common Problems

### JCSMPTransportException

If you see:

```
Expand All @@ -178,14 +176,14 @@ JCSMPTransportException: Error communicating with the router, ConnectException:

this can happen if a TLS server certificate was not configured in the Solace Messaging for PCF tile in which case the Solace Message Router will reject incoming TLS connections.

### CertificateException
>>>>>>> 2ddecceb096c1c345139b6b2f2bfb47b3348e923

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merge issue. Please fix.

If you see:
```
CertificateException: Path does not chain with any of the trust anchors
```

it is because the application could not validate the certificate it received from the Solace Message Router. This can happen when you install a self-signed certificate on the Solace Message Router, but didn't package it with the app, or didn't set INSTALL_CERTIFICATE to true in the sample.
it is because the application could not validate the certificate it received from the server. This can happen when you install a self-signed certificate on the router, but didn't package it with the app, or didn't set INSTALL_CERTIFICATE to true.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have reverted some text here which is not correct.




6 changes: 5 additions & 1 deletion docs/_tutorials/spring-cloud.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ The Pivotal Cloud Foundry environment exposes any bound Service Instances in a J
"clientPassword": "bb90fcb0-6c83-4a10-bafa-3ec225bbfc08",
"msgVpnName": "v005",
(...)
"smfHost": "tcp://192.168.132.14:7000",
"smfHosts": [ "tcp://192.168.132.14:7000" ],
(...)
}
}
Expand Down Expand Up @@ -140,6 +140,10 @@ try {
return;
}
```
Note that the VCAP_SERVICES environment variable contains a json array named smfHosts.
In a High Availability environment this will contain two hosts, the primary router and the backup.
The Spring Cloud connector automatically combines these into a single comma-separated string exposed
as the smfHost property, which is what the JCSMP library expects.

With the Solace session connected. The remainder of this tutorial is exactly the same as the [Java App]({{ site.baseurl }}/java-app) tutorial. The details are repeated here for convenience.

Expand Down
1 change: 1 addition & 0 deletions java-app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jar {

repositories {
mavenCentral()
mavenLocal()
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,26 @@ public void init() {

logger.info("Solace client initializing and using Credentials: " + solaceCredentials.toString(2));


// The host property is in a json array. Two hosts are provided in a High Availability environment,
// one for the primary router and one for the backup.
JSONArray hostsArray = solaceCredentials.getJSONArray("smfHosts");
String host = hostsArray.getString(0);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks broken for HA.

// If using high availability, uncomment these lines - the JCSMP library accepts a comma-separated list of 2 hosts:
//String backup = hostsArray.getString(1);
//host = String.join(",", host, backup);

final JCSMPProperties properties = new JCSMPProperties();
properties.setProperty(JCSMPProperties.HOST, solaceCredentials.getString("smfHost"));
properties.setProperty(JCSMPProperties.HOST, host);
properties.setProperty(JCSMPProperties.VPN_NAME, solaceCredentials.getString("msgVpnName"));
properties.setProperty(JCSMPProperties.USERNAME, solaceCredentials.getString("clientUsername"));
properties.setProperty(JCSMPProperties.PASSWORD, solaceCredentials.getString("clientPassword"));

// If using High Availability, uncomment these lines:
// JCSMPChannelProperties channelProperties = (JCSMPChannelProperties) properties
// .getProperty(JCSMPProperties.CLIENT_CHANNEL_PROPERTIES);
// channelProperties.setReconnectRetries(-1);

try {
session = JCSMPFactory.onlyInstance().createSession(properties);
Expand Down
6 changes: 5 additions & 1 deletion secure-session/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ buildscript {
springBootVersion = '1.3.3.RELEASE'
springCloudVersion = '1.2.3.RELEASE'
solaceJCSMPVersion = '10.+'
solaceCloudVersion = '0.+'
solaceCloudVersion = '1.0.+'
}
repositories {
mavenCentral()
Expand All @@ -25,6 +25,10 @@ jar {

repositories {
mavenCentral()
mavenLocal()
// maven {
// url "http://apps-jenkins:9090/nexus/content/repositories/snapshots/"
// }
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,20 @@ public void init() {
logger.info("Solace client initializing and using SolaceMessagingInfo: " + solaceMessagingServiceInfo);

final JCSMPProperties properties = new JCSMPProperties();
properties.setProperty(JCSMPProperties.HOST, solaceMessagingServiceInfo.getSmfTlsHost());
properties.setProperty(JCSMPProperties.HOST, solaceMessagingServiceInfo.getSmfHost());
properties.setProperty(JCSMPProperties.VPN_NAME, solaceMessagingServiceInfo.getMsgVpnName());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks broken for TLS.

properties.setProperty(JCSMPProperties.USERNAME, solaceMessagingServiceInfo.getClientUsername());
properties.setProperty(JCSMPProperties.PASSWORD, solaceMessagingServiceInfo.getClientPassword());

properties.setProperty(JCSMPProperties.SSL_VALIDATE_CERTIFICATE, true);
properties.setProperty(JCSMPProperties.SSL_VALIDATE_CERTIFICATE_DATE, true);
properties.setProperty(JCSMPProperties.SSL_TRUST_STORE, TRUST_STORE);
properties.setProperty(JCSMPProperties.SSL_TRUST_STORE_PASSWORD, TRUST_STORE_PASSWORD);

// If using High Availability, uncomment these lines:
// JCSMPChannelProperties channelProperties = (JCSMPChannelProperties) properties
// .getProperty(JCSMPProperties.CLIENT_CHANNEL_PROPERTIES);
// channelProperties.setReconnectRetries(-1);
try {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix so this follows best practices for reconnecting in an HA environment.

session = JCSMPFactory.onlyInstance().createSession(properties);
session.connect();
Expand Down Expand Up @@ -331,6 +335,7 @@ private static void importCertificate() throws Exception {
DataInputStream dis = new DataInputStream(fis);
byte[] bytes = new byte[dis.available()];
dis.readFully(bytes);
dis.close();
ByteArrayInputStream certstream = new ByteArrayInputStream(bytes);

// This takes that Byte Array and creates a certificate out of it.
Expand Down
7 changes: 6 additions & 1 deletion spring-cloud/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ buildscript {
springBootVersion = '1.3.3.RELEASE'
springCloudVersion = '1.2.3.RELEASE'
solaceJCSMPVersion = '10.+'
solaceCloudVersion = '0.+'
solaceCloudVersion = '1.0.+'
}
repositories {
mavenCentral()
mavenLocal()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
Expand All @@ -25,6 +26,10 @@ jar {

repositories {
mavenCentral()
mavenLocal()
// maven {
// url "http://apps-jenkins:9090/nexus/content/repositories/snapshots/"
// }
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ public void init() {
properties.setProperty(JCSMPProperties.USERNAME, solaceMessagingServiceInfo.getClientUsername());
properties.setProperty(JCSMPProperties.PASSWORD, solaceMessagingServiceInfo.getClientPassword());

// If using High Availability, uncomment these lines:
// JCSMPChannelProperties channelProperties = (JCSMPChannelProperties) properties
// .getProperty(JCSMPProperties.CLIENT_CHANNEL_PROPERTIES);
// channelProperties.setReconnectRetries(-1);

try {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please follow HA best practices.

session = JCSMPFactory.onlyInstance().createSession(properties);
session.connect();
Expand Down