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

Unable to Invoke Service AddStreamEntry

fmanniti
9-Granite

Unable to Invoke Service AddStreamEntry

Hi,

I am trying to add a new stream entry with a user who is not Administrator but I get this error:

Unable to Invoke Service AddStreamEntry on ErrorStream : null

 

In my Logs I have those two errors:

  • c.t.c.p.ReflectionProcessor

ErrorCode(3567b45a-99d2-488d-a832-f04463bb67a0), Cause(null), Reason(Access was attempted on a null reference variable.), Possible Resolutions(Remove the reference to the null variable within your extension code.)

 

  • c.t.w.BaseService

[context: com.thingworx.webservices.context.HttpExecutionContext@1e4b87eb][message: Unable to Invoke Service AddStreamEntry on ErrorStream : null]

I set my permissions on stream like this:

  • Visibility Everyone
  • Runtime: Users (Property Read, Service Execute)
    • Services
      • AddStreamEntry
1 ACCEPTED SOLUTION

Accepted Solutions
rnayak-2
5-Regular Member
(To:fmanniti)

Fabio, Form your error log, The null reference to the stream indicates that there is a visibility issue here. Although you have given visibility access to the stream, you may have missed giving access at the persistence provider level. Go to persistence provider and add the User org there and see if it resolves the issue. Rest everything seems normal from what you have told!

View solution in original post

17 REPLIES 17
supandey
19-Tanzanite
(To:fmanniti)

Hi Fabio, does it work when you attempt to log entry as an Admin user?

Yes, when I am Administrator it works fine.
If I'm a regular user, it doesn't

supandey
19-Tanzanite
(To:fmanniti)

Could you please enable the Stack Tracing in the Logging Subsystem and execute the service again, once done check for the error stack in the ErrorLog together with the ScriptLog and may be also share the stack here.

Thanks.

In application log

[context: com.thingworx.webservices.context.HttpExecutionContext@74ef3fad][message: Unable to Invoke Service AddStreamEntry on ErrorStream : null]

ErrorCode(fd3d2737-b8a0-4cf5-b0e6-ec8e898bc832), Cause(null), Reason(Access was attempted on a null reference variable.), Possible Resolutions(Remove the reference to the null variable within your extension code.)

in Script log no errors shown

(I forgot to say: I'm using TW version 8)

supandey
19-Tanzanite
(To:fmanniti)

Fabio, was there nothing in the ErrorLog after you enabled the StackTracing in LoggingSubsystem?

No, nothing

Hello, I still have this issue.
Does anyone have any suggestion?

Fabio,

You will need to create a Wrapper service that calls the AddStreamEntry  inside the wrapper.

Give the user runtime permission to execute the Wrapper and add System to the runtime permission


Does this make sense, If not can your provide more info

I did. I created a service named "AddItem"

The code is this:

var innerValues = me.CreateValues();

innerValues.Time = data.Time;

innerValues.Thing = data.Thing;

innerValues.Service = data.Service;

innerValues.Method = data.Method;

innerValues.Line = data.Line;

innerValues.ErrorMessage = data.ErrorMessage;

var newEntry = {

    sourceType: undefined,

    values: innerValues,

    location: undefined,

    source: undefined,

    timestamp: undefined,

    tags: undefined

};

me.AddStreamEntry(newEntry);

And my result is:

java.lang.NullPointerException: null

Visibility permission is Everyone.
Runtime is to all Users

I know the questions maybe simple but this helps in getting an understanding

Can you show the permissions on the Stream and where the service is. Also as I look more at the code

can you add more debugging - where is the data coming from - I assume input params

Stream (Thing template)

  • Visibility: Everyone
  • Visibility Instance: Everyone
  • Design Time: None
  • Design Time Istance: None
  • Run time: Users (Property read, Service Execute)
  • Run time Instance: Users (Property read, Service Execute)
    • AddStreamEntry (Users)

Where is data variable coming from?

This service is called in the catch of any service in case of error.

try{

    //code

}catch(err){

     Time = new Date();

     Thing = me.name;

     Service = "This service name";

     Method = data.Method;

     Line = err.lineNumber;

     ErrorMessage = err.message;

}

but I have the same problem also if I call the service from the composer

rnayak-2
5-Regular Member
(To:fmanniti)

Fabio, Form your error log, The null reference to the stream indicates that there is a visibility issue here. Although you have given visibility access to the stream, you may have missed giving access at the persistence provider level. Go to persistence provider and add the User org there and see if it resolves the issue. Rest everything seems normal from what you have told!

View solution in original post

Fabio,

Ragu is correct -  I simulated your issue and got the null pointer and was working the permissions and did not think about the visibility to the persistence provider. Version 8 by default takes visibility of everybody out of all collections

Below shows my configuration - Which I know you know - this just if anybody is reviewing the post

addItem service  permissions

Persistence Providers permission

You can also do a quick viability check via a test user using incognito

http://localhost/Thingworx/PersistenceProviders

That is a quick why to check visibility

Thanks! I've just done it.

It works.

Thank you

Announcements