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

Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X

Not authorized for PropertyWrite

振霍
1-Visitor

Not authorized for PropertyWrite

I used kafka, but when I assign a value to a property, there's an error:com.thingworx.common.exceptions.InvalidRequestException: Not authorized for PropertyWrite on strvalue in TestReceiver

 

@ThingworxPropertyDefinitions(properties = {

@ThingworxPropertyDefinition(name = "strvalue", description = "", category = "", baseType = "STRING", aspects = {"isReadOnly:false","isPersistent:true"}) })

 

setPropertyValue("strvalue", new StringPrimitive(results));

 

Please help me solve this problem.

 

 

 

 

7 REPLIES 7
PaiChung
22-Sapphire I
(To:振霍)

For the User that is doing the Write, did you verify permissions for Runtime Property Write in the platform?

振霍
1-Visitor
(To:PaiChung)

My user is Administrator

PaiChung
22-Sapphire I
(To:振霍)

When you look in the Application Log in Thingworx, does it show that same error and Administrator as the user?

振霍
1-Visitor
(To:PaiChung)

The user of the log is Administrator.

The exception was thrown to Tomcat.

PaiChung
22-Sapphire I
(To:振霍)

That doesn't make sense that you don't see that in the application log.

How are you doing the auth definition in your kafka code?

振霍
1-Visitor
(To:PaiChung)

I wrote a timer in kafka's code to send a heartbeat to the producer.






@ThingworxServiceDefinition(name = "ReceiverStringMessage", description = "Receiver a string message to the specified Kafka")

@ThingworxServiceResult(name = "result", description = "", baseType = "STRING")

public String ReceiverStringMessage() throws Exception {

//String results = this.utils.ReceiverStringMessage(entity,strMap);

String msg = "";

//String state = "0";

    try {

    logger.info("开始接收数据:" + entity.getGetServerAddress() + "=====" + entity.getTopic() + "===" + entity.getZookeeperSyncTimeMs() + "===" + entity.getReceiveTimeout() + "===" + entity.getAutoCommitInterval()+"==="+entity.getFetch());

    consumer.subscribe(Collections.singletonList(entity.getTopic()));

    logger.info("consumer 订阅成功");

    //ConsumerRecords<String, String> records = consumer.poll(entity.getPollTimeout());

    logger.info("consumer 提取成功");

    //executor = new ScheduledThreadPoolExecutor(1);

    //Task5 task5 = new Task5();

    //mapMsg = new HashMap<String,String>();

    try{

    if(!atomic.get()){

    timer = new Timer();

    timer.scheduleAtFixedRate(new TimerTask() {

//KafkaReceiverThing kafkathing;

@Override

public void run() {

String message = "";

try{

     ConsumerRecords<String, String> records = consumer.poll(entity.getPollTimeout());

     logger.info("consumer 提取成功");

     for (ConsumerRecord<String, String> record : records) {

     if(record.value() != null && record.value() != "" ){

     message += record.value() + ";";

     }

     }

     if(message != null && message != "" ){

     logger.info("数据获取成功111111:" + message);

     }

    

     json = new JSONObject();

    

     if(message != null && message != "" ){

     json.put("state", state);

     json.put("msg", message);

     logger.info("收到的消息:"+json.toString());

     strMap.put("mapmsg2", json.toString());

     logger.info("map value:"+strMap.get("mapmsg2"));

     results = strMap.get("mapmsg2");

     logger.info("收到的数据有值:"+results);

     //logger.info("property value:"+GetPropertyDefinition("strvalue"));

     //logger.info("property value:"+GetPropertyDefinition("strvalue").getFirstRow().getStringValue("value"));

     //String msg = getPropertyValue("strvalue").toString();

     //logger.info("property value:"+msg);

     setPropertyValue("strvalue", new StringPrimitive(results));

     //logger.info("property length:"+GetPropertyDefinition("strvalue").getLength());

     }else{

     json.put("state", state);

     json.put("msg", message);

     strMap.put("mapmsg2", json.toString());

     results = strMap.get("mapmsg2");

     logger.info("收到的数据为空:"+results);

     }

     } catch (JSONException e) {

     e.printStackTrace();

     } catch (Exception e) {

// 添加kafkathing.GetPropertyDefinition("strvalue").getReturnValue()方法后抛出的异常

e.printStackTrace();

}

}

}, 0, 10000);

   

    }

    } catch (WakeupException e){

    if (!atomic.get()) throw e;

    }

   

    } catch (Exception e) {

    state = "1";

    msg = "获取数据失败";

    logger.info("获取数据失败222222:" + e.getLocalizedMessage());

    }

logger.info("接收到的数据为:"+strMap.get("mapmsg2"));

return results;

}

振霍
1-Visitor
(To:PaiChung)

You can now display the same errors and administrators as the user.

Announcements


Top Tags