Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix for Grails10425 #403

Open
wants to merge 1 commit into from

3 participants

Sukrit Khera graemerocher Lari Hotari
Sukrit Khera

Fix for Grails10425.Removed contextPath from uri. The existing tests pass , however need a strategy to set context path for testing.

graemerocher

We'll need a better fix, as we can't depend on WebRequest within the renderers

Sukrit Khera

One possible way is to expose a method in RenderContext that can give the original request URL. Let me know if that works and I may be able to resubmit the PR.

graemerocher
Owner

Yes you can provide things through the render context, but directly referencing the servlet API specific stuff is a no no

Lari Hotari lhotari closed this
Lari Hotari lhotari reopened this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
6 grails-plugin-rest/src/main/groovy/grails/rest/render/hal/HalJsonRenderer.groovy
View
@@ -24,6 +24,7 @@ import groovy.transform.CompileStatic
import org.codehaus.groovy.grails.web.binding.bindingsource.DataBindingSourceRegistry
import org.codehaus.groovy.grails.web.binding.bindingsource.HalJsonDataBindingSourceCreator
import org.codehaus.groovy.grails.web.mime.MimeType
+import org.codehaus.groovy.grails.web.util.WebUtils
import org.grails.datastore.mapping.model.PersistentEntity
import org.grails.datastore.mapping.model.types.Association
import org.grails.datastore.mapping.model.types.ToOne
@@ -164,7 +165,10 @@ class HalJsonRenderer<T> extends AbstractLinkingRenderer<T> {
}
protected void writeLinkForCurrentPath(RenderContext context, MimeType mimeType, JsonWriter writer) {
- final href = linkGenerator.link(uri: context.resourcePath, method: HttpMethod.GET.toString(), absolute: absoluteLinks)
+ final uriWithoutContext = context.resourcePath.substring(
+ WebUtils.retrieveGrailsWebRequest().contextPath.length())
+ final href = linkGenerator.link(uri: uriWithoutContext, method: HttpMethod.GET.toString(),
+ absolute: absoluteLinks)
final resourceRef = href
final locale = context.locale
def link = new Link(RELATIONSHIP_SELF, href)
Something went wrong with that request. Please try again.