Forums

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

Unable to initialise plugin settings factory?

Ashish Biswal April 16, 2019

I am unable to use the pluginsettingsfactory and unable to initialise the pluginsettingsfactory variable in the rest module.

1 answer

0 votes
Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 16, 2019

Hello,

Could you provide your code?

Ashish Biswal April 16, 2019

@Alexey Matveev 

MyRestResource.java

@Path("/message")
public class MyRestResource {
@GET @AnonymousAllowed
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@Path("/{value}/{name}")
public Response getMessage(@PathParam("value") String key, @PathParam("name") String name)
{

return Response.ok(new MyRestResourceModel( key,name)).build(); }

MyRestResourceModel.java

public class MyRestResourceModel {
static final String PLUGIN_STORAGE_KEY = "PLUGIN_KEY";
@ComponentImport final PluginSettingsFactory pluginSettingsFactory;
public MyRestResourceModel(PluginSettingsFactory factory)
{

this.pluginSettingsFactory = factory; }
public MyRestResourceModel(String message, String name)
{

this.message = message;
this.name = name;
PluginSettings settings = pluginSettingsFactory.createGlobalSettings();
String username = (String) settings.get( PLUGIN_STORAGE_KEY + ".name" );
String password = (String) settings.get( PLUGIN_STORAGE_KEY + ".age" );
}
}
Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 16, 2019
@Named
public
class MyRestResourceModel {
static final String PLUGIN_STORAGE_KEY = "PLUGIN_KEY";
@ComponentImport final PluginSettingsFactory pluginSettingsFactory;

@Inject
public MyRestResourceModel(PluginSettingsFactory factory)
{

this.pluginSettingsFactory = factory; }
public MyRestResourceModel(String message, String name)
{

this.message = message;
this.name = name;
PluginSettings settings = pluginSettingsFactory.createGlobalSettings();
String username = (String) settings.get( PLUGIN_STORAGE_KEY + ".name" );
String password = (String) settings.get( PLUGIN_STORAGE_KEY + ".age" );
}
}
Ashish Biswal April 16, 2019

@Alexey Matveev 

Tried the above but no luck.

Error :- variable pluginSettingsFactory might not have been initialized

Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 16, 2019

I just read your code. I do not understand what you mean by your code. Your code is broken. You assign to this.message but where is the variable defined? Why would you include constructor to constructor?

Ashish Biswal April 16, 2019

@Alexey Matveev 

I am trying to pass the values from the MyRestResource to the MyRestResourceModel

and as described in the tutorials I have made use of the first constructor for the plugin settings factory.

can you please help me get to the correct way?

Suggest an answer

Log in or Sign up to answer