Bilk File Upload

i am using Content Service for bulk file upload
i have to use upload method to fetch the 'ContentOutputStream' for file uploading to Knowledge Center
and the upload method is called as
ContentOutputStream outStream = cs.upload(doc, arg1);
//here cs is instance of ContentService

which is created as

ContentService cs = ServiceLocator.getContentService(sc);
//here sc is ServiceContext which is created as

ServiceContext sc = ServiceLocator.getAdministratorServiceContext();

//* these lines of codes are provided #forum.appian.com/.../


But i am getting an error as "Could not initialize class com.appiancorp.suiteapi.common.ServiceLocator"

can some1 help

//log file attached

OriginalPostID-238850


log.txt

  Discussion posts and replies are publicly visible

Parents
  • In addition to the suggestions given by Stefan, I would like to add these:
    1. Never instantiate any *Service using a ServiceLocator. In smart services and custom expression function plugins, the Services are injected automatically. In case of Smart Services, you can access the injected smart service by adding parameters in the Constructor. Then you can use them in your run() method. This will avoid the need for ServiceLocator().
    The solution given by @samiullahm is also not an ideal one.
    Check this link for details: forum.appian.com/.../Custom_Smart_Service_Plug-ins.html
    2. Avoid using the Administrator context(not considered a good practice). If you decide to submit your plugin to the Forum for Cloud Approval, it won't be approved. You can get the context of the user by username. If you still want to use the admin context in the custom plugins, I suggest the following approach: Create a new third party credentials in the Admin console. Add a key called "username" in it. Then in the plugin code, get the context of the user like this:
    String username = null;
                        try {
                                  Map<String, String> securedValues = scs.getSystemSecuredValues(EXTERNAL_KEY) ;
                                  username = securedValues.get(USERNAME_FIELD);
                                  LOG.debug("The username is "+username);
                        } catch (InsufficientPrivilegesException | ObjectNotFoundException e) {
                                  LOG.error("Could not get the Secure credentials key");
                                  e.printStackTrace();
                        }
                        ServiceContext sc_userContext = ServiceContextFactory.getServiceContext(username);
Reply
  • In addition to the suggestions given by Stefan, I would like to add these:
    1. Never instantiate any *Service using a ServiceLocator. In smart services and custom expression function plugins, the Services are injected automatically. In case of Smart Services, you can access the injected smart service by adding parameters in the Constructor. Then you can use them in your run() method. This will avoid the need for ServiceLocator().
    The solution given by @samiullahm is also not an ideal one.
    Check this link for details: forum.appian.com/.../Custom_Smart_Service_Plug-ins.html
    2. Avoid using the Administrator context(not considered a good practice). If you decide to submit your plugin to the Forum for Cloud Approval, it won't be approved. You can get the context of the user by username. If you still want to use the admin context in the custom plugins, I suggest the following approach: Create a new third party credentials in the Admin console. Add a key called "username" in it. Then in the plugin code, get the context of the user like this:
    String username = null;
                        try {
                                  Map<String, String> securedValues = scs.getSystemSecuredValues(EXTERNAL_KEY) ;
                                  username = securedValues.get(USERNAME_FIELD);
                                  LOG.debug("The username is "+username);
                        } catch (InsufficientPrivilegesException | ObjectNotFoundException e) {
                                  LOG.error("Could not get the Secure credentials key");
                                  e.printStackTrace();
                        }
                        ServiceContext sc_userContext = ServiceContextFactory.getServiceContext(username);
Children
No Data