Skip to content

Commit

Permalink
Move parsing of credentials to info creator and also change info crea…
Browse files Browse the repository at this point in the history
…tor accept handling to depend on the 'solace-messaging' tag to follow Pivotal convention.
  • Loading branch information
mdspielman committed Aug 11, 2016
1 parent 210c3b4 commit cb462d5
Show file tree
Hide file tree
Showing 4 changed files with 212 additions and 197 deletions.
19 changes: 19 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
<!--
* 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.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package com.solace.labs.spring.cloud.cloudfoundry;

import java.util.List;
import java.util.Map;

import org.springframework.cloud.cloudfoundry.CloudFoundryServiceInfoCreator;
Expand All @@ -27,52 +28,118 @@

public class SolaceMessagingInfoCreator extends CloudFoundryServiceInfoCreator<SolaceMessagingInfo> {

//private static final Log trace = LogFactory.getLog(SolaceMessagingInfoCreator.class);
// This creator will accept and parse any credentials that have the matching tag or label.
// Therefore the default accept method is sufficient and doesn't need further specification.
static private String solaceMessagingTag = "solace-messaging";

String label = "solace-messaging";

public SolaceMessagingInfoCreator() {
super(new Tags("solace-messaging",
"solace",
"rest",
"mqtt",
"mq",
"queue",
"event-streaming",
"amqp",
"jms",
"messaging"));
super(new Tags(solaceMessagingTag));
}


// As a starting point, will only accept if the labels match.
public boolean accept(Map<String, Object> serviceData) {
String serviceLabel = (String) serviceData.get("label");

if (!super.accept(serviceData))
return false;

if (!this.label.equals(serviceLabel))
return false;

return true;
}


@SuppressWarnings("unchecked")
@Override
public SolaceMessagingInfo createServiceInfo(Map<String, Object> serviceData) {
String id = getId(serviceData);

String clientUsername = null;
String clientPassword = null;
String msgVpnName = null;
String smfUri = null;
String smfTlsUri = null;
String smfZipUri = null;
String webMessagingUri = null;
String jmsUri = null;
String jmsTlsUri = null;
List<String> restUris = null;
List<String> restTlsUris = null;
List<String> mqttUris = null;
List<String> mqttTlsUris = null;
List<String> mqttWsUris = null;
List<String> mqttWssUris = null;
List<String> managementHttpUris = null;
List<String> managementHttpsUris = null;
String managementPassword = null;
String managementUsername = null;

Map<String, Object> credentials = getCredentials(serviceData);

SolaceMessagingInfo solMessagingInfo = new SolaceMessagingInfo(id, credentials);

return solMessagingInfo;
}
if (credentials == null) {
throw new IllegalArgumentException("Received null credentials during object creation");
}

// These will come later from future version of Spring Cloud. For now clone
// methods here.
// Populate this the quick and dirty way for now. Can improve later as
// we harden. As a start, we'll be tolerant of missing attributes and
// just leave fields set to null.
for (Map.Entry<String, Object> entry : credentials.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();

@SuppressWarnings("unchecked")
protected Map<String, Object> getCredentials(Map<String, Object> serviceData) {
return (Map<String, Object>) serviceData.get("credentials");
switch (key) {
case "clientUsername":
clientUsername = (String) value;
break;
case "clientPassword":
clientPassword = (String) value;
break;
case "msgVpnName":
msgVpnName = (String) value;
break;
case "smfUri":
smfUri = (String) value;
break;
case "smfTlsUri":
smfTlsUri = (String) value;
break;
case "smfZipUri":
smfZipUri = (String) value;
break;
case "webMessagingUri":
webMessagingUri = (String) value;
break;
case "jmsUri":
jmsUri = (String) value;
break;
case "jmsTlsUri":
jmsTlsUri = (String) value;
break;
case "managementUsername":
managementUsername = (String) value;
break;
case "managementPassword":
managementPassword = (String) value;
break;
case "restUris":
restUris = (List<String>) value;
break;
case "restTlsUris":
restTlsUris = (List<String>) value;
break;
case "mqttUris":
mqttUris = (List<String>) value;
break;
case "mqttTlsUris":
mqttTlsUris = (List<String>) value;
break;
case "mqttWsUris":
mqttWsUris = (List<String>) value;
break;
case "mqttWssUris":
mqttWssUris = (List<String>) value;
break;
case "managementHttpUris":
managementHttpUris = (List<String>) value;
break;
case "managementHttpsUris":
managementHttpsUris = (List<String>) value;
break;
}
}

SolaceMessagingInfo solMessagingInfo = new SolaceMessagingInfo(id, clientUsername, clientPassword, msgVpnName,
smfUri, smfTlsUri, smfZipUri, webMessagingUri, jmsUri, jmsTlsUri, restUris, restTlsUris, mqttUris,
mqttTlsUris, mqttWsUris, mqttWssUris, managementHttpUris, managementHttpsUris, managementPassword,
managementUsername);

return solMessagingInfo;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package com.solace.labs.spring.cloud.core;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.springframework.cloud.service.BaseServiceInfo;
Expand Down Expand Up @@ -57,94 +56,39 @@ public class SolaceMessagingInfo extends BaseServiceInfo {
private String managementPassword;
private String managementUsername;

// Some details about the binding
private String plan;

// Default constructor to enable bean unit testing.
public SolaceMessagingInfo() {
super(null);
}

public SolaceMessagingInfo(String id) {

public SolaceMessagingInfo(String id, String clientUsername, String clientPassword, String msgVpnName,
String smfUri, String smfTlsUri, String smfZipUri, String webMessagingUri, String jmsUri, String jmsTlsUri,
List<String> restUris, List<String> restTlsUris, List<String> mqttUris, List<String> mqttTlsUris,
List<String> mqttWsUris, List<String> mqttWssUris, List<String> managementHttpUris,
List<String> managementHttpsUris, String managementPassword, String managementUsername) {
super(id);
this.clientUsername = clientUsername;
this.clientPassword = clientPassword;
this.msgVpnName = msgVpnName;
this.smfUri = smfUri;
this.smfTlsUri = smfTlsUri;
this.smfZipUri = smfZipUri;
this.webMessagingUri = webMessagingUri;
this.jmsUri = jmsUri;
this.jmsTlsUri = jmsTlsUri;
this.restUris = restUris;
this.restTlsUris = restTlsUris;
this.mqttUris = mqttUris;
this.mqttTlsUris = mqttTlsUris;
this.mqttWsUris = mqttWsUris;
this.mqttWssUris = mqttWssUris;
this.managementHttpUris = managementHttpUris;
this.managementHttpsUris = managementHttpsUris;
this.managementPassword = managementPassword;
this.managementUsername = managementUsername;
}

@SuppressWarnings("unchecked")
public SolaceMessagingInfo(String id, Map<String, Object> credentials) {
super(id);

if (credentials == null) {
throw new IllegalArgumentException("Received null credentials during object creation");
}

// Populate this the quick and dirty way for now. Can improve later as
// we harden. As a start, we'll be tolerant of missing attributes and
// just leave fields set to null.
for (Map.Entry<String, Object> entry : credentials.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();

switch (key) {
case "clientUsername":
clientUsername = (String) value;
break;
case "clientPassword":
clientPassword = (String) value;
break;
case "msgVpnName":
msgVpnName = (String) value;
break;
case "smfUri":
smfUri = (String) value;
break;
case "smfTlsUri":
smfTlsUri = (String) value;
break;
case "smfZipUri":
smfZipUri = (String) value;
break;
case "webMessagingUri":
webMessagingUri = (String) value;
break;
case "jmsUri":
jmsUri = (String) value;
break;
case "jmsTlsUri":
jmsTlsUri = (String) value;
break;
case "managementUsername":
managementUsername = (String) value;
break;
case "managementPassword":
managementPassword = (String) value;
break;
case "restUris":
restUris = (List<String>) value;
break;
case "restTlsUris":
restTlsUris = (List<String>) value;
break;
case "mqttUris":
mqttUris = (List<String>) value;
break;
case "mqttTlsUris":
mqttTlsUris = (List<String>) value;
break;
case "mqttWsUris":
mqttWsUris = (List<String>) value;
break;
case "mqttWssUris":
mqttWssUris = (List<String>) value;
break;
case "managementHttpUris":
managementHttpUris = (List<String>) value;
break;
case "managementHttpsUris":
managementHttpsUris = (List<String>) value;
break;
}
}

}


/**
* @return the clientUsername
Expand Down Expand Up @@ -337,7 +281,6 @@ public int hashCode() {
result = prime * result + ((smfUri == null) ? 0 : smfUri.hashCode());
result = prime * result + ((smfZipUri == null) ? 0 : smfZipUri.hashCode());
result = prime * result + ((webMessagingUri == null) ? 0 : webMessagingUri.hashCode());
result = prime * result + ((plan == null) ? 0 : plan.hashCode());
return result;
}

Expand Down Expand Up @@ -455,11 +398,6 @@ public boolean equals(Object obj) {
return false;
} else if (!webMessagingUri.equals(other.webMessagingUri))
return false;
if (plan == null) {
if (other.plan != null)
return false;
} else if (!plan.equals(other.plan))
return false;
return true;
}

Expand Down
Loading

0 comments on commit cb462d5

Please sign in to comment.