Spring Boot 3 - JUnitTest

Let's chat here.


Post Reply
superstef1005
Posts: 4

Hi there,

I would like to write a SpringBoot3 application to control a device. I have properly registered and set up my device that I want to control in the Tuya cloud, and everything is working so far.
I have now checked out the tuya-sdk, the tuya-connector and the connector project from Github and integrated them into my project, so far so good. Everything is compilable, everything is wonderful.

I have also written a JUnit test to log in with my credentials, which was successful.

However, I now have a problem accessing my device.
I have executed all the instructions in the readme file of the tuya-connector project. But I still get this error (see below)
Can someone explain to me what else I might have to do to successfully run my test and finally get access to my device?

I work with SpringToolSuite 4.21, use Lombok version 1.18.30, Java version 17.
Somehow I have the suspicion that the two specified "add-opens"
--add-opens java.base/java.lang.reflect=ALL-UNNAMED
--add-opens java.base/java.lang=ALL-UNNAMED
from the readme file are not effective (I have specified them in the springtoolsuite.ini). Do I have to specify these two things somewhere else?

11:15:35.560 DEBUG [main] c.t.c.api.core.delegate.DelegateFactory.forRetrofit 28 : Finish create retrofit delegate for connector[de.stefan.tuya.connector.ITuyaDeviceConnector] costs : 327 ms
11:15:35.567 ERROR [main] c.t.c.a.error.ErrorProcessorInterceptor.intercept 48 : Error invoke connector[de.stefan.tuya.connector.ITuyaDeviceConnector.getById(java.lang.String), args: (bfcv54cd4b4a6712sef6qm)]
11:15:35.573 WARN [main] c.t.c.api.context.ContextInterceptor.intercept 32 : content intercept error: Error create retrofit delegate for connector : de.stefan.tuya.connector.ITuyaDeviceConnector.
Cause: java.lang.reflect.InaccessibleObjectException: Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain) throws java.lang.ClassFormatError accessible: module java.base does not "opens java.lang" to unnamed module @2145433b

qiufeng.yu
Posts: 12

Re: Spring Boot 3 - JUnitTest

Well, you can configure the "--add-opens" startup option in SpringToolSuite4 as follows:

  1. Click the start button in the top left corner to open Run Configurations option.
  2. Switch to the 'Arguments' tab, add "--add-opens java.base/java.lang.reflect=ALL-UNNAMED
    --add-opens java.base/java.lang=ALL-UNNAMED", and then click apply.
  3. Finally, start the project.

Image

superstef1005
Posts: 4

Re: Spring Boot 3 - JUnitTest

Thx for your reply!
So far so good... Now I get a permission denied when I call the getById-method.
I am wondering because I also see some 200 states, so..
By the way: If I call the "commands"-method, I can control my device...

11:24:35.486 INFO [main] c.t.c.api.logging.HttpLoggingFactory.intercept 169 : --> GET https://openapi.tuyaeu.com/v1.0/token?grant_type=1
11:24:35.487 INFO [main] c.t.c.o.api.header.TuyaHeaderProcessor.isWithToken 161 : URL PATH: /v1.0/token
11:24:36.022 INFO [main] c.t.c.api.logging.HttpLoggingFactory.intercept 233 : <-- 200 https://openapi.tuyaeu.com/v1.0/token?grant_type=1 (534ms, 235-byte body)
11:24:36.030 INFO [main] c.t.c.open.api.token.TuyaTokenManager.getToken 57 : Get token success, token: TuyaToken(access_token=7d7c137b38550f9f95ebfbc7016563a8, expire_time=6674, refresh_token=c98d7e152de09a1f8d99ac1ebaaee308, uid=bay1702393307711YOdR, expire_at=null)
11:24:36.094 INFO [main] c.t.c.api.logging.HttpLoggingFactory.intercept 233 : <-- 200 https://openapi.tuyaeu.com/v1.0/iot-03/ ... 712ef6qmvs (650ms, 112-byte body)
11:24:36.096 WARN [main] c.t.c.a.core.delegate.RetrofitDelegate.execute 115 : Result(code=1106,msg=permission deny,t=1703759074810) is not successful for requeset: de.stefan.tuya.connector.ITuyaDeviceConnector.getById(java.lang.String), args: (bfc54cd4b4a6712ef6qmvs)
11:24:36.104 INFO [main] c.t.c.a.error.ErrorProcessorInterceptor.intercept 43 : No error processor found for errorCode:1106
11:24:36.106 ERROR [main] c.t.c.a.error.ErrorProcessorInterceptor.intercept 44 : Error invoke connector[de.stefan.tuya.connector.ITuyaDeviceConnector.getById(java.lang.String), args: (bfc54cd4b4a6712ef6qmvs)]
11:24:36.108 WARN [main] c.t.c.api.context.ContextInterceptor.intercept 32 : content intercept error: error code : 1106, error msg : permission deny t : 1703759074810

qiufeng.yu
Posts: 12

Re: Spring Boot 3 - JUnitTest

Hello, the "1106 permission deny" indicates that you currently do not have the permission to call the API. Please check under the cloud development module of the IOT platform whether the corresponding cloud service has been opened, and that the opened cloud service has been authorized to the corresponding cloud project.
Please refer to the document:https://developer.tuya.com/en/docs/iot/ ... wsvmgoj3et

e.g The method "getById" may correspond to the "Industry Basic Service" cloud service
Image
Image

Post Reply