Skip to content

Migrate from legacy RestClient to ThingsboardClient#32

Open
ViacheslavKlimov wants to merge 2 commits intodevelop/4.4from
feature/new-tb-client
Open

Migrate from legacy RestClient to ThingsboardClient#32
ViacheslavKlimov wants to merge 2 commits intodevelop/4.4from
feature/new-tb-client

Conversation

@ViacheslavKlimov
Copy link
Copy Markdown
Member

Summary

Replace the hand-written RestClient with the auto-generated ThingsboardClient from thingsboard-java-client. The new client provides type-safe OpenAPI-generated methods with built-in auth management and rate-limit retry.

Key changes:

  • Remove org.thingsboard.common:data, util, java-jwt, spring-web deps
  • Add thingsboard-pe-client as sole TB dependency (uses ${thingsboard.version})
  • Rewrite RestClientService to use ThingsboardClient builder with auto token refresh
  • Delete RestClient.java and RestJsonConverter.java
  • Create JsonUtils helper to replace JacksonUtil from removed util dep
  • Migrate all 11 tool classes to use string IDs and flat pagination params
  • Migrate all 10 test files to mock ThingsboardClient instead of RestClient
  • All 175 tests pass

Type of change

  • Bug fix
  • Feature / new MCP tool
  • Refactor / tech debt
  • Docs only

Checklist

  • Code builds on Java 17 / Maven 3.6+
  • Unit tests added/updated (where applicable)
  • Docs updated (README, examples, env var notes)
  • No breaking API changes (or documented under “Breaking changes”)
  • Docker path tested (STDIO and/or SSE as relevant)
  • Security considerations reviewed (no secrets in code/logs)

Breaking changes (if any)

Replace the hand-written RestClient (~5200 lines) with the auto-generated
ThingsboardClient from thingsboard-java-client. The new client provides
type-safe OpenAPI-generated methods with built-in auth management and
rate-limit retry.

Key changes:
- Remove org.thingsboard.common:data, util, java-jwt, spring-web deps
- Add thingsboard-pe-client as sole TB dependency (uses ${thingsboard.version})
- Rewrite RestClientService to use ThingsboardClient builder with auto token refresh
- Delete RestClient.java and RestJsonConverter.java
- Create JsonUtils helper to replace JacksonUtil from removed util dep
- Migrate all 11 tool classes to use string IDs and flat pagination params
- Migrate all 10 test files to mock ThingsboardClient instead of RestClient
- All 175 tests pass
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

public class JsonUtils {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename to JacksonUtil

Copy link
Copy Markdown
Member Author

@ViacheslavKlimov ViacheslavKlimov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review summary

Reviewed 30 changed files in Migrate from legacy RestClient to ThingsboardClient. Left 5 comment(s) inline.

Clean migration overall — the move from hand-rolled RestClient + JacksonUtil to the generated ThingsboardClient simplifies the codebase significantly. The CeOnly variable rename fix in EditionAwareToolProvider is a nice catch. A few inconsistencies in the pagination parameter handling across PE-only methods stood out.

Additional findings

These observations are about existing code outside the PR's diff — spotted while reading surrounding context.

  • src/main/java/org/thingsboard/ai/mcp/server/tools/ota/OtaTools.java:255rest.replace("/", "\\\\") replaces each / with two literal backslash characters (\\) instead of one. The first path separator uses a single backslash (":\\":\), so the result is inconsistent (e.g., C:\Users\\foo\\file.bin). Should be rest.replace("/", "\\") for single backslashes. Windows APIs tolerate this, but it's a latent bug.

This review was auto-generated by Claude. Findings may contain errors — please verify before applying changes.

Comment thread pom.xml
Comment thread src/main/java/org/thingsboard/ai/mcp/server/tools/user/UserTools.java Outdated
- Rename JsonUtils to JacksonUtil per reviewer request
- Add null guard in RestClientService.initClient() to fail fast when
  no credentials are configured instead of NPE in detectEdition()
- Add comments explaining why PE-only API methods use String pagination
  params while CE methods use Integer (generated client inconsistency)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant