You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Steffen Heil (Mailinglisten)" <li...@steffen-heil.de> on 2015/08/20 17:58:26 UTC

URI Templates

Hi


I have several servlets with mappings such as
  /a/*
  /b/*
  /c/*
And so on.

One of these mappings was for the old Tomcat 7.0.27 websocket implementation:
  /ws/*

That worked.

Now, with the new JSR version in Tomcat 8, I cannot get this to work.
The problem is, that all of the following paths shall match:

/ws/a/b
/ws/a/c
/ws/d/e

While these would work using /ws/{one}/{two}, the folloing won't:

/ws/a/b/c
/ws/x/Y/z/a

And I cannot know in advance, how many slashed there are.
(This is for a framework, not a specific application.)

Is there any way to match those? Or to add a usual servlet mapping instead of an URI Template?
(Prefered prorgrammatically, not per web.xml, not per annotations.)

While I would prefer a clean solution, I am also fine with one that works in tomcat only (using tomcat private functions).


Best regards,
   Steffen


Re: URI Templates

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Steffen,

On 8/20/15 11:58 AM, Steffen Heil (Mailinglisten) wrote:
> I have several servlets with mappings such as /a/* /b/* /c/* And so
> on.
> 
> One of these mappings was for the old Tomcat 7.0.27 websocket
> implementation: /ws/*
> 
> That worked.
> 
> Now, with the new JSR version in Tomcat 8, I cannot get this to
> work. The problem is, that all of the following paths shall match:
> 
> /ws/a/b /ws/a/c /ws/d/e
> 
> While these would work using /ws/{one}/{two}, the folloing won't:
> 
> /ws/a/b/c /ws/x/Y/z/a

So you have a servlet mapping for the uri-pattern of "/a/*", and the
context path is "/ws"?

I'm not sure why it would have worked in the past but not now. Can you
be very clear about what used to work and is no longer working?

> And I cannot know in advance, how many slashed there are. (This is
> for a framework, not a specific application.)
> 
> Is there any way to match those? Or to add a usual servlet mapping
> instead of an URI Template? (Preferred programmatically, not per
> web.xml, not per annotations.)

I think you have two possibilities:

1. Manually set-up the uri-patterns so that they do not overlap
2. Write a Servlet (or Filter) that inspects the URL and makes its own
decisions
3. Use something like url-rewrite as a config-only alternative for #2

I think due to your "not in web.xml" requirement, #1 cannot be done.

> While I would prefer a clean solution, I am also fine with one
> that works in tomcat only (using tomcat private functions).

I'm still not sure I understand the use case. There should be a way to
achieve what you want... I just don't yet understand the requirements.

- -chris
-----BEGIN PGP SIGNATURE-----
Comment: GPGTools - http://gpgtools.org

iQIcBAEBCAAGBQJV1kcMAAoJEBzwKT+lPKRYSaYP/0AhpDeSPCzk6dCPgYhrOzxU
GUpM3vBz7w64Scy0gDqln74QJjCRadVvVNkw25i/HrIEv/85wFj6RlKskoizjoan
m8XiS1MsVNmQQqAMcWV39Qu7vaq/X84uJ9T0EDxksLg1yo6BfRAmfdCciSr8mGQn
JuI4smp9PV7S/MkJdn9p/ZbXVH9aOWqk/gcbV4/hvNLzqaL1hbR3KSE+DhAjDkDD
WuVKKsO350jTfNue5xPRtPmAHrm9cIBCx+RPIUmICkbEAN9L3hT/nIOWxCA2ncaq
EMuNO4d/YLXZ7X3/Bcp9fzzgdPjtwrNYJ3lJJ5vV6q1X5MldkjRhyVfiYcLsSLQO
Fn8XBlnGEpMU94LHt6xGLDXwXE/3gAU7wePbX9X72GNVNLry1iMdd2Hqu3NzZ7gF
hWj9IMJWGgcKV6K+YzKJJJSc9LzGw/jiRwBO3xPb22yHv47TDxecDkbS+Z1AuUKb
5k1gnsdPa/5Eh9TCrFBYGGXBjvLkCnZOQKtfAjoG2pFxvYIZZ1+6p0And/C5lNao
QucJtiAxVt8vr7zHWuyDKi5BHqIwvD/DqMd/AfctiALJd766QKxol/8aDAOEdLN1
leGWvOgpn/Tl0flN16J6ZHsq3hcfgqzfWA66+uODhTVR6yxb0N/XpjNt3I1x6ZeV
/9CdBewDPIC+aaH9RrO1
=1p52
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: URI Templates

Posted by Mark Thomas <ma...@apache.org>.
On 20/08/2015 16:58, Steffen Heil (Mailinglisten) wrote:
> Hi
> 
> 
> I have several servlets with mappings such as
>   /a/*
>   /b/*
>   /c/*
> And so on.
> 
> One of these mappings was for the old Tomcat 7.0.27 websocket implementation:
>   /ws/*
> 
> That worked.
> 
> Now, with the new JSR version in Tomcat 8, I cannot get this to work.
> The problem is, that all of the following paths shall match:
> 
> /ws/a/b
> /ws/a/c
> /ws/d/e
> 
> While these would work using /ws/{one}/{two}, the folloing won't:
> 
> /ws/a/b/c
> /ws/x/Y/z/a
> 
> And I cannot know in advance, how many slashed there are.
> (This is for a framework, not a specific application.)
> 
> Is there any way to match those? Or to add a usual servlet mapping instead of an URI Template?
> (Prefered prorgrammatically, not per web.xml, not per annotations.)
> 
> While I would prefer a clean solution, I am also fine with one that works in tomcat only (using tomcat private functions).

I see three options.

Option 1

Using ServerContainer.addEndpoint to add the same endpoint multiple
times with different configurations mapped to:
/ws
/ws/{a}
/ws/{a}/{b}
/ws/{a}/{b}/{c}

etc.

If there is a maximum depth that should work. If there isn't then it
will break at the maximum depth you configure +1.


Option 2

Look at the WsFilter implementation [1] and write an alternative filter
of your own that does custom mapping to endpoints and calls
UpgradeUtil.doUpgrade with the right parameters


Option 3
Write a filter that looks at the request and if it should use web socket
redirects to the correct URL and converts the additional pathInfo into
query parameters, puts the values into the session, or something else
along those lines.

HTH,

Mark


[1]
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/server/WsFilter.java?view=annotate


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org