Community Tip - You can change your system assigned username to something more personal in your community settings. X
Hello,
I am attempting to access a thing property from inside a service on a custom authenticator extension.
Inside a thingshape I am able to access the thing property like below with no issue
@ThingworxServiceDefinition(name = "Start", aspects = {"isAsync:false"})
@ThingworxServiceResult(name = "Result", baseType = "STRING")
public String Start() throws Exception {
Thing apiConfig = ThingUtilities.findThing("MESLite.Thing.APIConfig");
return apiConfig.getPropertyValue("BasePath").getStringValue();
}
When inside the Authenticator I get a null pointer exception on
apiConfig.getPropertyValue("BasePath").getStringValue();
Is it possible to access thing property inside the custom authenticator?
Solved! Go to Solution.
I was able to achieve what I needed using a configuration table.
@ThingworxConfigurationTableDefinitions(tables = {
@ThingworxConfigurationTableDefinition(name = "AuthenticatorRegex", description = "",
isMultiRow = false, ordinal = 0, dataShape = @ThingworxDataShapeDefinition(fields = {
@ThingworxFieldDefinition(name = "Regex", description = "", baseType = "STRING", ordinal
= 0)}))})
Then I can set the value inside TW and access it inside my authenticator using the code below:
String CONFIGURATION_TABLE = "AuthenticatorRegex";
String COLUMN_NAME = "Regex";
@ThingworxServiceDefinition(name = "GetAuthenticatorRegex", description = "", category = "",
isAllowOverride = false, aspects = {
"isAsync:false"})
@ThingworxServiceResult(name = "Result", description = "", baseType = "STRING", aspects = {})
public String GetAuthenticatorRegex() throws Exception {
return this.getConfigurationTable(CONFIGURATION_TABLE).getFirstRow()
.getStringValue(COLUMN_NAME);
}
Hi @jvisser.
Can you provide some additional information? Why do you need to access that property value? What does that property value hold? There may actually be an easier way of doing what you need to do, but we need a better understanding of your use case.
Regards.
--Sharon
I was able to achieve what I needed using a configuration table.
@ThingworxConfigurationTableDefinitions(tables = {
@ThingworxConfigurationTableDefinition(name = "AuthenticatorRegex", description = "",
isMultiRow = false, ordinal = 0, dataShape = @ThingworxDataShapeDefinition(fields = {
@ThingworxFieldDefinition(name = "Regex", description = "", baseType = "STRING", ordinal
= 0)}))})
Then I can set the value inside TW and access it inside my authenticator using the code below:
String CONFIGURATION_TABLE = "AuthenticatorRegex";
String COLUMN_NAME = "Regex";
@ThingworxServiceDefinition(name = "GetAuthenticatorRegex", description = "", category = "",
isAllowOverride = false, aspects = {
"isAsync:false"})
@ThingworxServiceResult(name = "Result", description = "", baseType = "STRING", aspects = {})
public String GetAuthenticatorRegex() throws Exception {
return this.getConfigurationTable(CONFIGURATION_TABLE).getFirstRow()
.getStringValue(COLUMN_NAME);
}