Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OptionalParameters returned with curly braces in the link response #541

Open
navkmurthy opened this issue Feb 27, 2017 · 11 comments
Open

OptionalParameters returned with curly braces in the link response #541

navkmurthy opened this issue Feb 27, 2017 · 11 comments

Comments

@navkmurthy
Copy link

navkmurthy commented Feb 27, 2017

public TemplateVariables concat(Collection variables) {
...
}
Returns "{?view}" and as a result the link created contains {?view} appended in the end (with the extra curly braces).
I suspect that the value returned should not have curly braces.

Here "view" is an optional parameter in the restful controller
...
@RequestParam(value = "view", required = false) String viewString
..

Below mentioned is the snippet of the response with contains the optional parameters
.....
"_links": {
"self": {
"href": "http://localhost:8080/v1/school/00000000-0000-0000-0000-000000000000{?view}",
"templated": true
},
"members": {
"href": "http://localhost:8080/v1/school/00000000-0000-0000-0000-000000000000/members{?view}",
"templated": true
}
}
....

@odrotbohm
Copy link
Member

Depending on what your actual point is, that's correct. The template variable created for the link to that controller method expresses exactly, what the method expresses, that it takes an optional parameter named view. The fact that the href is a URI template and not a URI is also expressed by the template flag set to true.

If you want to create a canonical link, call expand() without any parameters and you'll get a link without any placeholders.

@navkmurthy
Copy link
Author

I have used linkTo and methodOn...Please let me know is the API's that I have used need to be modified

......

import static org.springframework.hateoas.core.DummyInvocationUtils.methodOn;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;

@RequestMapping
public ResponseEntity findAll(
@QuerydslPredicate(root = School.class) Predicate predicate,
@RequestParam(value = "view", required = false) String viewString,
Pageable pageable
) {
// Query resources
ResourcePage resources = getService().findAll(predicate, pageable);
// Add hateoas links
resources.forEach(resource -> {
resource.add(linkTo(methodOn(SchoolController.class).findOne(resource.getUuid(), viewString)).withSelfRel());
resource.add(linkTo(methodOn(SchoolMemberController.class).findAll(resource.getUuid(), null, null, null)).withRel("members"));
});
UriComponentsBuilder rootUri = linkTo(methodOn(SchoolController.class).findAll(predicate, viewString, pageable)).toUriComponentsBuilder();
resources.buildPageLinks(rootUri);
// Map view to response
MappedResource response = new MappedResource(resources, viewString, SchoolResource.View.class, SchoolResource.View.Default.class);
return ResponseEntity.ok(response);
}
....

@navkmurthy
Copy link
Author

The same code with the spring versions mentioned below returns without optional parameter

springBootVersion = "1.4.3.RELEASE"
springCloudVersion = "Camden.SR3"
Spring HATEOAS to 0.20.0.RELEASE
apply plugin: "spring-boot"
.....
"_links": {
"self": {
"href": "http://localhost:8080/v1/school/00000000-0000-0000-0000-000000000000",
"templated": true
},
"members": {
"href": "http://localhost:8080/v1/school/00000000-0000-0000-0000-000000000000/members",
"templated": true
}
}
....

and the version that is currently used is

springBootVersion = "1.5.1.RELEASE"
springCloudVersion = "Camden.SR5"
Spring HATEOAS to 0.23.0.RELEASE
apply plugin: "org.springframework.boot"

Hope this helps.

@Bert-R
Copy link

Bert-R commented Oct 7, 2017

I'm running into the same thing when upgrading from Spring Boot 1.4.7 to 1.5.7

Bert-R added a commit to yonadev/yona-server that referenced this issue Oct 7, 2017
* Upgrade Gradle from 3.3 to 4.2.1 and:
** Changed from testClassesDir to testClassesDirs, because the singular version is deprecated now
** Removed version_jackson from the project extension. Instead, we now automatically use the version number of Spring Boot. If we want, we can set that through jackson.version, like we do for thymeleaf.version
** Upgraded all plug-ins to the latest versions, also because of compatibility issues
** The new Spring Boot dependency management plug-in required upgrading Spring Boot, from 1.4.7 to 1.5.7
* Spring Boot 1.5.7 has a new health check for LDAP, which fails when the LDAP template is null. To resolve that, disabled the health check by setting management.health.ldap.enabled=false
* Spring Boot 1.5.7 has an issue with optional URL parameters, see spring-projects/spring-hateoas#541. To work around that, explicit "expand" calls are added. Did some deduplication in UserController along with this.
* Upgraded Bouncycastle from 1.56 to 1.58
aristotelos pushed a commit to yonadev/yona-server that referenced this issue Oct 13, 2017
* YD-489 Upgrade third party dependencies

* Upgrade Gradle from 3.3 to 4.2.1 and:
** Changed from testClassesDir to testClassesDirs, because the singular version is deprecated now
** Removed version_jackson from the project extension. Instead, we now automatically use the version number of Spring Boot. If we want, we can set that through jackson.version, like we do for thymeleaf.version
** Upgraded all plug-ins to the latest versions, also because of compatibility issues
** The new Spring Boot dependency management plug-in required upgrading Spring Boot, from 1.4.7 to 1.5.7
* Spring Boot 1.5.7 has a new health check for LDAP, which fails when the LDAP template is null. To resolve that, disabled the health check by setting management.health.ldap.enabled=false
* Spring Boot 1.5.7 has an issue with optional URL parameters, see spring-hateoas#541. To work around that, explicit "expand" calls are added. Did some deduplication in UserController along with this.
* Upgraded Bouncycastle from 1.56 to 1.58

* YD-489 Upgrade third party dependencies

* Upgrade Gradle from 3.3 to 4.2.1 and:
** Changed from testClassesDir to testClassesDirs, because the singular version is deprecated now
** Removed version_jackson from the project extension. Instead, we now automatically use the version number of Spring Boot. If we want, we can set that through jackson.version, like we do for thymeleaf.version
** Upgraded all plug-ins to the latest versions, also because of compatibility issues
** The new Spring Boot dependency management plug-in required upgrading Spring Boot, from 1.4.7 to 1.5.7
* Spring Boot 1.5.7 has a new health check for LDAP, which fails when the LDAP template is null. To resolve that, disabled the health check by setting management.health.ldap.enabled=false
* Spring Boot 1.5.7 has an issue with optional URL parameters, see spring-projects/spring-hateoas#541. To work around that, explicit "expand" calls are added. Did some deduplication in UserController along with this.
* Upgraded Bouncycastle from 1.56 to 1.58

* YD-489 Use @ConditionalOnProperty

Originally, we used to return null from the bean initialization method for the LDAP template, but this was wrong. With Spring Boot 1.4.7, this was tolerated but with 1.5.7, it fails in Actuator. On spring-projects/spring-boot#10558, @philwebb pointed out the mistake and provided the right solution: use @ConditionalOnProperty("yona.ldap.enabled")
@aayoustic
Copy link

aayoustic commented Mar 6, 2020

Hi @odrotbohm ,
I'm trying to use the expand method, but doesn't work properly it does remove the extra optional parameters but malformed the other query param values.

The url goes like-

https://faloola.com//v1/hello-world?firstParam=abcd&secondParam=Hello%20world{&thirdParam}

After using expand-
https://faloola.com//v1/hello-world?firstParam=abcd&secondParam=Hello%252520world

Do focus on the value of the secondParam

I think it encoded it twice, by using build method and then new Link again.
Can you please look into this?

@odrotbohm
Copy link
Member

@aayoustic – Which version are you using? We just recently fixed a couple of double encoding issues.

@aayoustic
Copy link

aayoustic commented Mar 6, 2020

Hey @odrotbohm,
We're using 0.25.0.RELEASE.

@gregturn
Copy link
Contributor

gregturn commented Mar 6, 2020

0.25.0.RELEASE was released in the middle of 2018. 0.25.2.RELEASE is the latest stable version of 0.25.x.

That being said, the odds of the double encoding solution @odrotbohm is referencing getting backported are close to zero.

My recommendation is to try migrating to the latest stable 1.1 version version (using our migration script) and seeing if that fixes your problem.

@aayoustic
Copy link

@gregturn -
Did you mean 1.0.1.RELEASE?

@gregturn
Copy link
Contributor

gregturn commented Mar 6, 2020

Actually, it appears Ollie backported that to the 1.0 branch through #1131, so indeed you can pick the latest version 1.0.3.RELEASE) and give it a spin.

@aayoustic
Copy link

Sure thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants