servlet filter in jython
Question: Based on [this java example](http://stackoverflow.com/questions/12652957/how-
to-change-the-requesturl-using-filter-or-servlet), I made the following
servlet filter in jython (exact code):

    
    
    from javax.servlet import Filter
    from javax.servlet.http import HttpServletRequest
    
    class HttpServletRequestWrapper(HttpServletRequest):
        def init(self, request):
            self.originalURL = self.getRequestURL()
            pathi = self.originalURL.find('/', 10) # find start of path
            qsi = self.originalURL.find('?', pathi) # find start of qs if any
            qs = self.originalURL[qsi:] if qsi > -1 else ''
            self.newURL = self.originalURL[:pathi] + '/ccc/jope.py' + qs
    
        def getRequestURL(self):
            return self.newURL
    
    class Route2Jope(Filter):
        def init(self, config):
            pass
    
        def doFilter(self, request, response, chain):
            wrapped = HttpServletRequestWrapper(request)
            chain.doFilter(wrapped, response)
    

However, I am getting the error message:

    
    
    Traceback (most recent call last):
      File "c:\CCC\webapps\ccc\WEB-INF\pyfilter\Route2Jope.py", line 24, in doFilter
        wrapped = HttpServletRequestWrapper(request)
    TypeError: org.python.proxies.__main__$HttpServletRequestWrapper$2(): expected 0 args; got 1
    
        org.python.core.Py.TypeError(Py.java:259)
        org.python.core.PyReflectedFunction.throwError(PyReflectedFunction.java:209)
        org.python.core.PyReflectedFunction.throwArgCountError(PyReflectedFunction.java:262)
        org.python.core.PyReflectedFunction.throwError(PyReflectedFunction.java:319)
        org.python.core.PyReflectedConstructor.__call__(PyReflectedConstructor.java:177)
        org.python.core.PyObject.__call__(PyObject.java:419)
        org.python.core.PyMethod.instancemethod___call__(PyMethod.java:237)
        org.python.core.PyMethod.__call__(PyMethod.java:228)
        org.python.core.PyMethod.__call__(PyMethod.java:223)
        org.python.core.Deriveds.dispatch__init__(Deriveds.java:19)
        org.python.core.PyObjectDerived.dispatch__init__(PyObjectDerived.java:1112)
        org.python.core.PyType.type___call__(PyType.java:1713)
        org.python.core.PyType.__call__(PyType.java:1696)
        org.python.core.PyObject.__call__(PyObject.java:461)
        org.python.core.PyObject.__call__(PyObject.java:465)
        org.python.pycode._pyx1.doFilter$6(c:\CCC\webapps\ccc\WEB-INF\pyfilter\Route2Jope.py:25)
        org.python.pycode._pyx1.call_function(c:\CCC\webapps\ccc\WEB-INF\pyfilter\Route2Jope.py)
        org.python.core.PyTableCode.call(PyTableCode.java:167)
        org.python.core.PyBaseCode.call(PyBaseCode.java:307)
        org.python.core.PyBaseCode.call(PyBaseCode.java:198)
        org.python.core.PyFunction.__call__(PyFunction.java:482)
        org.python.core.PyMethod.instancemethod___call__(PyMethod.java:237)
        org.python.core.PyMethod.__call__(PyMethod.java:228)
        org.python.core.PyMethod.__call__(PyMethod.java:218)
        org.python.core.PyMethod.__call__(PyMethod.java:213)
        org.python.core.PyObject._jcallexc(PyObject.java:3626)
        org.python.proxies.__main__$Route2Jope$3.doFilter(Unknown Source)
        org.python.util.PyFilter.doFilter(PyFilter.java:80)
    

I think it's telling me I should not pass the parameter 'request', but it does
not make sense to me. Maybe I am overlooking some mapping issue between python
ad java classes? Suggestions?


Answer: The name of your constructor must be `__init__`, not `init`. :)

