Skip to content

Instantly share code, notes, and snippets.

@moqimoqidea
Forked from ankushs92/SomeInterceptor.java
Created March 11, 2021 08:33
Show Gist options
  • Save moqimoqidea/dd0c78949bdaad4d1337d83e42a719d8 to your computer and use it in GitHub Desktop.
Save moqimoqidea/dd0c78949bdaad4d1337d83e42a719d8 to your computer and use it in GitHub Desktop.

Revisions

  1. @ankushs92 ankushs92 revised this gist Dec 22, 2015. 1 changed file with 6 additions and 6 deletions.
    12 changes: 6 additions & 6 deletions SomeInterceptor.java
    Original file line number Diff line number Diff line change
    @@ -3,15 +3,15 @@ public class SomeInterceptor extends HandlerInterceptorAdapter{
    public boolean preHandle(final HttpServletRequest request,final HttpServletResponse response,final Object handler)
    throws Exception
    {
    /*Assume the URI is user/{userId}/post/{postId} and our interceptor is registered for this URI.
    * This map would then be a map of two elements,with keys 'userId' and 'postId'
    */
    /*Assume the URI is user/{userId}/post/{postId} and our interceptor is registered for this URI.
    * This map would then be a map of two elements,with keys 'userId' and 'postId'
    */
    final Map<String, String> pathVariables = (Map<String, String>) request
    .getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);

    //You'll have to convert the String to Long or Integer or any other type manually. For instance..
    //final Integer userId = Integer.valueOf(pathVariables.get("userId"));
    //final Long postId = Long.valueOf(pathVariables.get("postId"));
    //You'll have to convert the String to Long or Integer or any other type manually. For instance..
    //final Integer userId = Integer.valueOf(pathVariables.get("userId"));
    //final Long postId = Long.valueOf(pathVariables.get("postId"));

    }
    }
  2. @ankushs92 ankushs92 revised this gist Dec 22, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion SomeInterceptor.java
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,7 @@ public boolean preHandle(final HttpServletRequest request,final HttpServletRespo
    /*Assume the URI is user/{userId}/post/{postId} and our interceptor is registered for this URI.
    * This map would then be a map of two elements,with keys 'userId' and 'postId'
    */
    final Map<String, String> pathVariables = (Map<String, String>) request
    final Map<String, String> pathVariables = (Map<String, String>) request
    .getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);

    //You'll have to convert the String to Long or Integer or any other type manually. For instance..
  3. @ankushs92 ankushs92 revised this gist Dec 22, 2015. No changes.
  4. @ankushs92 ankushs92 revised this gist Dec 22, 2015. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions SomeInterceptor.java
    Original file line number Diff line number Diff line change
    @@ -3,11 +3,11 @@ public class SomeInterceptor extends HandlerInterceptorAdapter{
    public boolean preHandle(final HttpServletRequest request,final HttpServletResponse response,final Object handler)
    throws Exception
    {
    /*Assume the URI is user/{userId}/post/{postId} and our interceptor is registered for this URI.
    * This map would then be a map of two elements,with keys 'userId' and 'postId'
    */
    final Map<String, String> pathVariables = (Map<String, String>) request
    .getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
    /*Assume the URI is user/{userId}/post/{postId} and our interceptor is registered for this URI.
    * This map would then be a map of two elements,with keys 'userId' and 'postId'
    */
    final Map<String, String> pathVariables = (Map<String, String>) request
    .getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);

    //You'll have to convert the String to Long or Integer or any other type manually. For instance..
    //final Integer userId = Integer.valueOf(pathVariables.get("userId"));
  5. @ankushs92 ankushs92 created this gist Dec 22, 2015.
    18 changes: 18 additions & 0 deletions SomeInterceptor.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    public class SomeInterceptor extends HandlerInterceptorAdapter{
    @Override
    public boolean preHandle(final HttpServletRequest request,final HttpServletResponse response,final Object handler)
    throws Exception
    {
    /*Assume the URI is user/{userId}/post/{postId} and our interceptor is registered for this URI.
    * This map would then be a map of two elements,with keys 'userId' and 'postId'
    */
    final Map<String, String> pathVariables = (Map<String, String>) request
    .getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);

    //You'll have to convert the String to Long or Integer or any other type manually. For instance..
    //final Integer userId = Integer.valueOf(pathVariables.get("userId"));
    //final Long postId = Long.valueOf(pathVariables.get("postId"));

    }
    }