--
You received this message because you are subscribed to the Google Groups "django-jython-dev" group.
To post to this group, send email to django-j...@googlegroups.com.
To unsubscribe from this group, send email to django-jython-...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-jython-dev?hl=en.
Also on Windows or on other OSs?
Deploying on top of Tomcat works fine for me on Mac OS X and Linux
(haven't tested on Linux the last month or so though) with Tomcat 6.
--
Leo Soto M.
http://blog.leosoto.com
-Frank
Crap, so it's a Windows-related issue (probably on Jython itself?).
I won't be able to look at it this weekend but hopefully next weekend
should be able to get a VM running to help with the problem. Any
progress you folks can do on the meantime would be really appreciated,
of course.
This might be related: http://bugs.jython.org/issue1489
-Frank
My 2 cents: I bet you are right. The bug linked by Frank tends to
manifest itself as a "maximum recursion depth" exception. I'd rather
continue debugging it from the Django side but sure it help to have
this other bug in mind in case we find something that looks like
related to it.
> I doubt I will be all that helpful with this issue since I know very little
> about the Jython internals, but I'm still going to poke around the code and
> see what I can do.
I can help with the Jython internals. Hopefully you will be able to
advance a lot (and probably find the actual bug) just poking at the
Python level.
Couple of things.
1. That definition of create_py_file (in modjy_wsgi.py) i.e.
try:
from org.python.core.util import FileUtil
create_py_file = FileUtil.wrap
except ImportError:
from org.python.core import PyFile
create_py_file = PyFile
was put in because PyFile creation changed in revision 5514
http://fisheye3.atlassian.com/changelog/jython/trunk/?cs=5514
Since FileUtil.wrap was introduced, the old method of creating a
PyFile from a java.io.InputStream, i.e. the
PyFile(java.io.InputStream) constructor, is no longer valid. So, since
revision 5514, the above definition should really be replaced by
create_py_file = FileUtil.wrap
The old definition given above was so that the same code would work
pre and post revision 5514.
Looking closer at the source for
org.apache.catalina.connector.CoyoteInputStream, I see the following
code in the read method.
if (SecurityUtil.isPackageProtectionEnabled()){
try{
Integer result =
(Integer)AccessController.doPrivileged(
new PrivilegedExceptionAction(){
public Object run() throws IOException{
Integer integer =
new Integer(ib.read(b, off, len));
return integer;
}
});
return result.intValue();
The definition of Security.isPackageProtectionEnabled depends (in
part) on the definition of two system properties, package.definition
and package.access. These are set in catalina.properties file in
$TOMCAT_HOME/conf. Their meaning can be read here
http://tomcat.apache.org/tomcat-6.0-doc/security-manager-howto.html
So, what I'd like for you to try is to set the package.definition and
package.access properties to null, and restarting your container. You
can do this by simply commenting out the two properties in the
catalina.properties file, like so
# package.access=sun.,org.apache.catalina.,org.apache.coyote.,org.apache.tomcat.,org.apache.jasper.,sun.beans.
# package.definition=sun.,java.,org.apache.catalina.,org.apache.coyote.,org.apache.tomcat.,org.apache.jasper.
If that changes the behaviour you're seeing, then we might be onto something.
Regards,
Alan.
OK.
Another suggestion: try reading the java ServletInputStream directly,
by accessing it through environ['j2ee.request'].getInputStream()
The return value should be a ServletInputStream
http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/ServletInputStream.html
Try using the methods of that directly to see if you get any data.
If you succeed in getting data from it, then we're looking at a jython
problem with wrapping ServletInputStream in a PyFile.
Alan.
OK, so both environ['wsgi.input'] and
environ['j2ee.request'].getInputStream() both return the same data.
So wsgi.input correctly provides the data, i.e. if you call
environ['wsgi.input'].read(), then wsgi.input is working correctly.
> So now I'm not sure what to do. It seems that the data is there and it can
> be read using Java methods, but somehow the Python isn't able to read it.
But that doesn't agree with what you've seen, except maybe if Django
is reading the post data in some peculiar way.
What code does Django use to to read wsgi.input?
Alan.
Well done, Jacob, for narrowing this one down.
So this looks like a simple line-endings translation problem. So
> I think there are three possible points that could be causing failure:
> 1. The Windows version of the servlet container is passing the wrong data
I don't think this is it. I expect that if you look at the data you
read from the java ServletInputStream, the correct "\r\n\r\n" will be
there.
> 2. modjy.py is ignoring the \r characters
This is not the case, since modjy does no processing of the wsgi.input data.
> 3. jython is ignoring the \r character
I think this is the most likely.
> There's also a small possibility that there is some obscure line of Django
> code that is supposed to do add in those extra \r characters, but I think
> that is unlikely.
I also think this is unlikely.
> I think this means Django is not compliant with RFC 2616 since it will only accept CRLF.
> Is this something I should file as a ticket with them?
Strictly speaking, I think your interpretration of RFC 2616 is
correct, and if django is not accepting "\n\n" as a separator, then it
is *strictly* not compliant. This clause was put in the spec for
precisely the reason of varying line-ending representation between
windows( "\r\n"), *nix ("\n") and mac ("\r").
But I think that you'll find it extremely rare, in the wild, for
"\n\n" to appear as a separator in POST data: that's why the django
code has been working correctly in pretty much every scenario in
existence, except this one. I wouldn't be surprised if the django
folks reject your bug report.
I'll be looking into this one today: more later.
Alan.
> I think there are three possible points that could be causing failure:I don't think this is it. I expect that if you look at the data you
> 1. The Windows version of the servlet container is passing the wrong data
read from the java ServletInputStream, the correct "\r\n\r\n" will be
there.
> 3. jython is ignoring the \r characterI think this is the most likely.
> I think this means Django is not compliant with RFC 2616 since it will only accept CRLF.
> Is this something I should file as a ticket with them?
I wouldn't be surprised if the django
folks reject your bug report.
If you mean the Python language parser, then not. This problem
shouldn't have anything to do with the parser.
But there may be something wrong when translating Java strings to
Python strings on Windows. Maybe you could try invoking a simple Java
method returning CRLF and seeing if Jython translates it as just LF on
the Python side?
Regards,
Create foo/Foo.java:
package foo;
public class Foo {
public static String crlf() {
return "\r\n";
}
}
Compile it:
> javac foo/Foo.java
and then fire up Jython (staying on the same directory) and invoke the
Java method:
>>> from foo import Foo
>>> Foo.crlf()
u'\r\n'
Problem reported on the jython bug tracker.
Wrapping an InputStream with a PyFile wrongly carries out line-ending
translation.
http://bugs.jython.org/issue1549
Alan.
--
Glad to hear it.
> It's only a few lines of code to change, how can we get these changes into
> trunk?
Attach your patches to the bug I reported.
Regards,
Alan.
Alan.