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

Strip context path correctly if deployed to the root context #731

Merged
merged 3 commits into from
Aug 28, 2014

Conversation

chkal
Copy link
Contributor

@chkal chkal commented Aug 5, 2014

VRaptor is currently not stripping the context path correctly if the app is deployed to the root context path.

For ordinary context paths like /myapp it works fine:

/myapp/somepage     ->     /somepath

But for the root context path / it is not correct:

/somepage     ->     somepath

This pull request fixes the problem. I hope I found all the relevant places. :)

@Turini
Copy link
Member

Turini commented Aug 5, 2014

Thks @chkal. It sounds good to me. What do you think @LucasC, @garcia-jj?

@garcia-jj
Copy link
Member

I use with root context and all paths works fine. Have you tested in which server?

return uri;
}
return uri.substring(getContextPath().length());
}
Copy link
Member

Choose a reason for hiding this comment

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

maybe we should have here a method, on VRaptorRequest/MutableRequest, returning the request uri without the context path, so we don't duplicate this logic here and on DefaultStaticContentHandler. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

But in that case we would need to cast that HttpServletRequest in DefaultStaticContentHandler, this could be problematic, right? But I agree that we should'nt duplicate this code, maybe we should create a component with this logic and inject it in both classes.

Copy link
Member

Choose a reason for hiding this comment

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

You're right, not a good solution =/

Copy link
Member

Choose a reason for hiding this comment

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

big enough for a component?

Copy link
Contributor

Choose a reason for hiding this comment

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

its kind of overkill :-\

maybe we should leave as it is? create a static method (urgh)?

Copy link
Member

Choose a reason for hiding this comment

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

I don't like the duplication =/ I prefer the static method.

Copy link
Contributor

Choose a reason for hiding this comment

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

Fine for me :D
@chkal, what do you think? do you want to refactor that code extracting a static method and reuse it in both classes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm on my phone and on vacation right now, so this will be short...

I had this issue with Undertow, which is the Servlet container of Wildfly.

And yeah, sure, I can refactor the patch. Creating a single static method
for this makes sense. I'll do this next week after returning from vacation.
Am 06.08.2014 21:17 schrieb "csokol" notifications@github.com:

In
vraptor-core/src/main/java/br/com/caelum/vraptor/http/VRaptorRequest.java:

    return uri.replaceFirst("(?i);jsessionid=.*$", "");
}
  • private String stripContextPath(String uri) {
  •   if ("/".equals(getContextPath())) {
    
  •       return uri;
    
  •   }
    
  •   return uri.substring(getContextPath().length());
    
  • }

Fine for me :D
@chkal https://github.com/chkal, what do you think? do you want to
refactor that code extracting a static method and reuse it in both classes?

Reply to this email directly or view it on GitHub
https://github.com/caelum/vraptor4/pull/731/files#r15896613.

Copy link
Member

Choose a reason for hiding this comment

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

I'll do this next week after returning from vacation.

thanks @chkal, enjoy your vacation's last week, we can wait for it :)

@Turini
Copy link
Member

Turini commented Aug 21, 2014

I use with root context and all paths works fine. Have you tested in which server?

@garcia-jj, adding this change will break something in your case?
If not, I'll merge this PR locally and extract the behaviour into a new classe.

@garcia-jj
Copy link
Member

I can test tonight.
On Aug 21, 2014 2:34 PM, "Rodrigo Turini" notifications@github.com wrote:

I use with root context and all paths works fine. Have you tested in which
server?

@garcia-jj https://github.com/garcia-jj, adding this change will break
something in your case?
If not, I'll merge this PR locally and extract the behaviour into a new
classe.


Reply to this email directly or view it on GitHub
#731 (comment).

@chkal
Copy link
Contributor Author

chkal commented Aug 28, 2014

I refactored the context path removal to a static method called VRaptorRequest.stripContextPath().

I'm not sure if this is the best place for the method. But as we actually would like to have something as VRaptorRequest.getRelativeRequestURI() (which would require ugly casting to use it), it IMHO makes sense to have it in VRaptorRequest.

Any thoughts on this?

@chkal
Copy link
Contributor Author

chkal commented Aug 28, 2014

Ups. Travis failed. Not sure if this is caused by my commit. I just merged the pull request with master locally and it builds fine.

@@ -63,10 +65,10 @@ public boolean requestingStaticFile(HttpServletRequest request) throws Malformed
}

private String uriRelativeToContextRoot(HttpServletRequest request) {
String uri = request.getRequestURI().substring(request.getContextPath().length());
String uri = VRaptorRequest.stripContextPath(request.getContextPath(), request.getRequestURI());
Copy link
Member

Choose a reason for hiding this comment

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

What do you think about changing to stripContextPath(request)?
So stripContextPath ask for contextPath and requestURI internally.

@Turini
Copy link
Member

Turini commented Aug 28, 2014

it IMHO makes sense to have it in VRaptorRequest.

I'm ok with method place too.

@chkal
Copy link
Contributor Author

chkal commented Aug 28, 2014

Hey @Turini,

yeah, I agree. That's much nicer. I also renamed the method to VRaptorRequest.getRelativeRequestURI(). I like that name as the method basically returns getRequestURI() but relative to the context path.

What do you think?

@garcia-jj
Copy link
Member

Sounds good. I like it.

@Turini
Copy link
Member

Turini commented Aug 28, 2014

great @chkal, thanks!

Turini added a commit that referenced this pull request Aug 28, 2014
Strip context path correctly if deployed to the root context
@Turini Turini merged commit e7b8c31 into caelum:master Aug 28, 2014
@chkal
Copy link
Contributor Author

chkal commented Aug 28, 2014

You're welcome. And thank YOU for this awesome framework. :)

@garcia-jj
Copy link
Member

@Turini, since we are getting some false warnings by Travis, can you run
test tasks on your machine? I'm unable to do this job because I'm on mobile
right now.

Thank you :)

@Turini
Copy link
Member

Turini commented Aug 28, 2014

@garcia-jj already done, its working (I'll restart Travis build).

@Turini
Copy link
Member

Turini commented Aug 28, 2014

all green now :)

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

Successfully merging this pull request may close these issues.

5 participants