Skip to content

Remove reflection-based registry lookup in favor of Camel's public API#5

Closed
Copilot wants to merge 3 commits intocodex/add-a2a-supportfrom
copilot/sub-pr-1-yet-again
Closed

Remove reflection-based registry lookup in favor of Camel's public API#5
Copilot wants to merge 3 commits intocodex/add-a2a-supportfrom
copilot/sub-pr-1-yet-again

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 17, 2026

SampleAdminMcpBindings was using reflection to access the protected registry field on org.apache.camel.main.Main, which is brittle across Camel versions and can trigger illegal-access warnings/errors. Camel's Main already exposes a public lookup(String, Class) method backed by the same registry.

Changes

  • Removed lookupFromRegistry(Main, String) and import java.lang.reflect.Field
  • Replaced all 6 call sites with main.lookup(name, Object.class)
  • Simplified bindIfMissing, lookup, and required — the redundant dual-lookup (registry + main.lookup) collapses to a single call

Before:

private static Object lookupFromRegistry(Main main, String name) {
    try {
        Field registryField = Main.class.getDeclaredField("registry");
        registryField.setAccessible(true);
        Object registry = registryField.get(main);
        return registry.getClass().getMethod("lookupByName", String.class).invoke(registry, name);
    } catch (Exception ignored) {
        return null;
    }
}

After:

private static Object lookup(Main main, String name) {
    Object value = main.lookup(name, Object.class);
    return value != null ? value : new ObjectMapper();
}

📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.

Copilot AI and others added 2 commits March 17, 2026 20:48
…lookup() API

Co-authored-by: rdobrik <8812511+rdobrik@users.noreply.github.com>
Co-authored-by: rdobrik <8812511+rdobrik@users.noreply.github.com>
Copilot AI changed the title [WIP] [WIP] Address feedback on A2A runtime integration pull request Remove reflection-based registry lookup in favor of Camel's public API Mar 17, 2026
Copilot AI requested a review from rdobrik March 17, 2026 20:49
@rdobrik rdobrik marked this pull request as ready for review March 18, 2026 16:07
Copilot AI review requested due to automatic review settings March 18, 2026 16:07
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Removes brittle reflection-based access to Camel Main’s internal registry in the sample admin MCP bindings by switching to Camel’s public Main.lookup(...) API, and also removes custom Maven launcher scripts.

Changes:

  • Replace reflection-based registry lookups with Main.lookup(name, Object.class) in SampleAdminMcpBindings.
  • Delete root mvnw / mvnw.cmd helper scripts.
  • Update .gitignore to ignore compiled .class files and Maven wrapper-related paths.

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated no comments.

File Description
samples/agent-support-service/src/main/java/io/dscope/camel/agent/samples/SampleAdminMcpBindings.java Switches registry lookups from reflection to Camel’s public Main.lookup(...) and simplifies related helper methods.
mvnw.cmd Removes root Windows Maven launcher script.
mvnw Removes root Unix Maven launcher script.
.gitignore Adds ignore rules for .class files and Maven wrapper-related paths.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@rdobrik rdobrik closed this Mar 18, 2026
@rdobrik rdobrik deleted the copilot/sub-pr-1-yet-again branch March 18, 2026 16:28
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.

3 participants