Results 1 to 5 of 5

Thread: EndPoints/Interceptors - thread Safe

  1. #1
    Join Date
    Feb 2011
    Posts
    19

    Default EndPoints/Interceptors - thread Safe

    Hi,

    I have an endpoint class & a number of interceptors, one of which is a security interceptor.
    This security interceptor set a static value in the endpoint class.

    Is this setup thread safe? I'm unsure!

    Is there a better way for interceptors to set values that the endpoint class needs?

    thanks in advance,
    Kevin

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,695

    Default

    No it isn't... First the endpoint is a singleton so setting variables is always a no-go next you are setting a static variable which is class loader wide as it is attached to the class and not the instance, so basically even worse.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Feb 2011
    Posts
    19

    Default

    Quote Originally Posted by Marten Deinum View Post
    No it isn't... First the endpoint is a singleton so setting variables is always a no-go next you are setting a static variable which is class loader wide as it is attached to the class and not the instance, so basically even worse.
    Thank Marten, I only wrote this awful code as right now I see no other "solution" to a problem.

    My endpoint needs access to security info in the soap header - namely the username.

    The only place where I know I can get access to security info is in my security interceptor. (Unfortunately spring SoapHeader does not give access to this info). In the interceptor I set the static "userName" in the endpoint. The framework passes control to the endpoint once the interceptor is finished doing its work - therefore the endpoint point has access to username.

    Is there a proper way of doing what I'm attempting?

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,695

    Default

    If you can get access to it in the interceptor you can get access to it in the endpoint.

    A work around could be instead of setting it in the endpoint to store it in a thread local (like Spring Security does) and use that to retrieve the current credentials, that way it is thread safe.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  5. #5
    Join Date
    Feb 2011
    Posts
    19

    Default

    Quote Originally Posted by Marten Deinum View Post
    If you can get access to it in the interceptor you can get access to it in the endpoint.

    A work around could be instead of setting it in the endpoint to store it in a thread local (like Spring Security does) and use that to retrieve the current credentials, that way it is thread safe.
    Thanks Marten, I'll do that. As you say its a workaround.
    In the meantime I'll keep looking to solve the "real" problem - why I haven't access to the authorized user name in the endpoint.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •