cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - You can change your system assigned username to something more personal in your community settings. X

Access Thing property inside custom Authenticator

jvisser
12-Amethyst

Access Thing property inside custom Authenticator

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?

ACCEPTED SOLUTION

Accepted Solutions
jvisser
12-Amethyst
(To:jvisser)

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);
}

 

View solution in original post

3 REPLIES 3
slangley
23-Emerald II
(To:jvisser)

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

slangley
23-Emerald II
(To:slangley)

Hi @jvisser.

 

Glad to hear you found a solution!

 

Regards.

 

--Sharon

jvisser
12-Amethyst
(To:jvisser)

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);
}

 

Announcements


Top Tags