question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Path param can NOT be resolved in register method of Service

See original GitHub issue

Environment Details

  • Helidon Version: 0.10.0
  • Helidon SE
  • JDK version: java version “1.8.0_181”
  • OS: Windows 10
  • Docker version (if applicable):

Problem Description

Currently the Service provides a update method to define routine rules, but it can not provides concept like Jaxrs Resource and sub resource, the path params can NOT be resolved in register method.

Steps to reproduce

Imagine the following case.

I want to build comments api under a certain post, I could design APIs like this.

/posts/post-id/comments

I would like register it in the PostService like this:

@Override
    public void update(Routing.Rules rules) {
        rules.get("/", this::getAllPosts)
            .post("/", this::savePost)
            .get("/{id}", this::getPostById)
            .put("/{id}", this::updatePost)
            .delete("/{id}", this::deletePostById);
            .register("/{id}/comments", new CommentService());
    }

And in the CommentService:

    @Override
    public void update(Routing.Rules rules) {
        rules.get("/", this::getAllComments)
            .post("/", Handler.of(JsonObject.class, this::saveComment, this::errorHandler));
    } 

All uri path in CommentService should be appended /{id}/comments, and all path params should be resolved in CommentService, eg post id in the path.

post id in /{id}/comments is null, check my sample, https://github.com/hantsy/helidon-sample/blob/master/quickstart-se/src/main/java/io/helidon/examples/quickstart/se/CommentService.java#L37.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
barchettacommented, Sep 22, 2018

@romain-grecourt and I dug into this and it looks like a bug. Proposed fix (needs a bit more verification):

diff --git a/webserver/webserver/src/main/java/io/helidon/webserver/Request.java b/webserver/webserver/src/main/java/io/helidon/webserver/Request.java
index 3437928..a30cd1d 100644
--- a/webserver/webserver/src/main/java/io/helidon/webserver/Request.java
+++ b/webserver/webserver/src/main/java/io/helidon/webserver/Request.java
@@ -441,13 +441,13 @@ abstract class Request implements ServerRequest {
                 HashMap<String, String> map = new HashMap<>(this.params.size() + params.size());
                 map.putAll(this.params);
                 map.putAll(params);
-                return new Path(path, params, new Path(this.path, map, null));
+                return new Path(path, map, new Path(this.path, map, null));
             } else {
                 HashMap<String, String> map = new HashMap<>(this.params.size() + params.size() + absolutePath.params.size());
                 map.putAll(absolutePath.params);
                 map.putAll(this.params);
                 map.putAll(params);
-                return new Path(path, params, new Path(absolutePath.path, map, null));
+                return new Path(path, map, new Path(absolutePath.path, map, null));
             }
         }
     }
1reaction
spericascommented, Sep 24, 2018

@barchetta @romain-grecourt Could we add a test for that as part of the PR?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Path param can NOT be resolved in register method of Service
Currently the Service provides a update method to define routine rules, but it can not provides concept like Jaxrs Resource and sub resource, ......
Read more >
Cannot handle request by requestMapping - Stack Overflow
You can handle it using PathVariable and RequestParam annotation. In below code name is thisisname part and city is query param city value....
Read more >
Passing Parameters to Resolve — Autofac 6.0.0 documentation
ResolvedParameter can be used as a way to supply values dynamically retrieved from the container, e.g. by resolving a service by name. Parameters...
Read more >
PathParam Interface | Microsoft Learn
A parameter that is annotated with PathParam will be ignored if the "uri template" does not contain a path segment variable with name...
Read more >
Path (Java Platform SE 7 ) - Oracle Help Center
Registers the file located by this path with a watch service. ... This method does not access the file system; the path or...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found