Hi all,

I'm using RESTlet API in my tomcat application using ServletConverter.

Our servlet creates in his init method a router. In the constructor of this
router, it attaches some uri patterns to others routers.

Our application can be called for many clients in the same time, when we
have many calls in the beginning of servlet life circle we are having the
following problem:

During the compilation of uri template it thinks that a pattern variable was
used before and it adds to the regexp to: "\\" + (varIndex + 1)

I think the problem is in getRegexPattern method (
org.restlet.util.Template.java). In our case it can be called many times for
the same Template object instance. This method can be interrupted by other
call before it sets regexPattern variable and it may case that
regexVariables tried to add the same pattern variable two times.

To solve this issue the method getRegexPattern should be done in the
constructor of Template or the method getRegexPattern should be
synchronized. getRegexPattern method only parses this.regexPattern if it is
null and in our case it is null for more than one thread.

Following I will show a part of my code:

public class TestServlet extends HttpServlet {
     private ServletConverter converter;
     public void init() throws ServletException {
         super.init();
         this.converter = new ServletConverter(getServletContext());
         Router router = new MainTestRouter(converter.getContext());
         this.converter.setTarget(router);
     }

     protected void service(HttpServletRequest req, HttpServletResponse res)
             throws ServletException, IOException {
         this.converter.service(req, res);
     }
}

public class MainTestRouter extends Router {

      public MainTestRouter (Context context) {
            super(context);
            attach("/uri1/{version}", new Router1(getContext()));
            attach("/uri2/{version}", new Router1(getContext()));
            attach("/uri3/{version}", new Router1(getContext()));
            attach("/uri4/{version}", new Router1(getContext()));
            attach("/uri5/{version}", new Router1(getContext()));
     }

      // This method can be called concurrently and it will iterate in the
same rotes.
      public void handle(Request request, Response response) {
            super.handle(request, response);
      }
}

Do you think it is a bug? Am I using it correctly?

Thanks in advanced,
Paulo

Reply via email to