Installing Java CGI - how to
Installing Java CGI - how to
am 19.11.2007 23:00:55 von myalog
Hi
On a 2003 we need to install java.exe that will be run by calling:
http://www.mysite.com/cgi-bin/iTuens?destination=ssss
The file iTunes that does not have extension has in it one line
java iTunes.class
So far everything we try end up with 404 page not found.
- What is the right way to setup IIS 6.0 so java.exe can be run
- How can we set filter for files with no extension
- Any idea why we actually getting 404
Thanks in advance
Moshe
Re: Installing Java CGI - how to
am 20.11.2007 04:58:18 von David Wang
On Nov 19, 2:00 pm, myalo wrote:
> Hi
> On a 2003 we need to install java.exe that will be run by calling:http://www.mysite.com/cgi-bin/iTuens?destination=sss s
> The file iTunes that does not have extension has in it one line
> java iTunes.class
> So far everything we try end up with 404 page not found.
> - What is the right way to setup IIS 6.0 so java.exe can be run
> - How can we set filter for files with no extension
Create Wildcard Application Mapping to java.exe for vdir named /cgi-
bin/iTuens
Add Web Service Extension for java.exe and enable it
> - Any idea why we actually getting 404
Without knowing what you configured nor IIS log entry for the request,
it is not possible to figure out why you get 404.
>
> Thanks in advance
> Moshe
However, this is going to run really badly because it will start up
java for every single request. You will want to use something like a
JSP framework to more efficiently run Java -- like Apache Tomcat or
JRUN. Java and Windows is really hasslesome because of Sun's lawsuit
against Microsoft, which makes Java a real pain to integrate and run
on Windows vs .Net.
//David
http://w3-4u.blogspot.com
http://blogs.msdn.com/David.Wang
//
Re: Installing Java CGI - how to
am 20.11.2007 19:11:28 von myalog
On Nov 19, 7:58 pm, David Wang wrote:
> Create Wildcard Application Mapping to java.exe for vdir named /cgi-
> bin/iTuens
> Add Web Service Extension for java.exe and enable it
I am confused. The call will be made by Appple as follows
https://www.mysite.edu/cgi-bin/iTunesU?destination=mysite. In the cgi-
bin folder I have a file "iTunesU" with no extension that in it there
is one line "jave iTunes.class". iTunes.class is a compiled java class
that creates encrypted tokens to be sent back to Apple website so the
user get access to the university iTunesU site. Doesn't iTunesU needs
to be a file and not vdir?
If it can be a vdir, I understand that java.exe will be executed
before a Web file is processed regardless of the file name extension
but then how java.exe knows what to process?
> Without knowing what you configured nor IIS log entry for the request,
> it is not possible to figure out why you get 404.
>
I followed the steps and created a new web service and it is allowed
to "C:\Program Files\Java\jre1.6.0_03\lib". Now I am getting a new
error CGI Error The specified CGI application misbehaved by not
returning a complete set of HTTP headers. I looked up this error and
created a simple jave class that returns the two essintial header
lines as follows:
System.out.println("HTTP/1.0 200 OK\n");
System.out.println("Content-Type: text/html\n\n\n");
but it still returning the same error = CGI error....
Here is the real link http://testing1.ajula.edu/cgi/test (I am using
cgi instead of cgi-bin as the vdir but that should not make any
difference.
I am sure I still do something wrong here. Can you help?
Thanks
Re: Installing Java CGI - how to
am 21.11.2007 04:34:38 von David Wang
On Nov 20, 10:11 am, myalo wrote:
> On Nov 19, 7:58 pm, David Wang wrote:> Create Wildcard Application Mapping to java.exe for vdir named /cgi-
> > bin/iTuens
> > Add Web Service Extension for java.exe and enable it
>
> I am confused. The call will be made by Appple as followshttps://www.mysite.edu/cgi-bin/iTunesU?destination=my site. In the cgi-
> bin folder I have a file "iTunesU" with no extension that in it there
> is one line "jave iTunes.class". iTunes.class is a compiled java class
> that creates encrypted tokens to be sent back to Apple website so the
> user get access to the university iTunesU site. Doesn't iTunesU needs
> to be a file and not vdir?
> If it can be a vdir, I understand that java.exe will be executed
> before a Web file is processed regardless of the file name extension
> but then how java.exe knows what to process?
The client is making a request to a URL RESOURCE and not file or
virtual directory. Client doesn't know whether the resource is a file
or directory. So, don't get confused byfiles or directories or
thinking that /iTunesU has to be a file or directory. It can be, but
it doesn't have to be either. Just focus on how to execute "java
iTunes.class" when the client makes a request to the URL "/cgi-bin/
iTunesU"
There are two ways to accomplish the above task:
1. Have a IIsWebFile named iTunesU and configure its
ApplicationMapping (which determines how to execute the file
extension) to launch "java iTunes.class"
2. Have a virtual directory named iTunes and configure its
WildcardApplicationMapping (which executes before any file extension
determination) to launch "java iTunes.class". This approach needs a
DefaultDocument as well so that IIS is happy, but the basic idea
remains the same
I suggested #2 because you have a very hard-coded requirement that
cannot be accomplished from the UI. You can search my MSDN blog on how
to do this. I have a blog entry showing how to have requests to "/cgi-
bin" execute a perl script with Perl.exe -- which is not very
different than your situation where you need a request to "/cgi-bin/
iTunesU" to execute iTunes.class with Java.exe.
> I followed the steps and created a new web service and it is allowed
> to "C:\Program Files\Java\jre1.6.0_03\lib". Now I am getting a new
> error CGI Error The specified CGI application misbehaved by not
> returning a complete set of HTTP headers. I looked up this error and
> created a simple jave class that returns the two essintial header
> lines as follows:
> System.out.println("HTTP/1.0 200 OK\n");
> System.out.println("Content-Type: text/html\n\n\n");
> but it still returning the same error = CGI error....
The Java class does not return a proper HTTP response where lines are
separated by \r\n. It also terminates the request header with three
\n, so one of them can be interpreted as entity body, yet you did not
send a Content-Length or any other entity length specifier. Please fix
your code to return proper HTTP.
I suspect that the iTunes.class is not returning proper HTTP response,
either, so the code will need to be fixed as well.
//David
http://w3-4u.blogspot.com
http://blogs.msdn.com/David.Wang
//
Re: Installing Java CGI - how to
am 21.11.2007 19:18:26 von myalog
On Nov 20, 7:34 pm, David Wang wrote:
> On Nov 20, 10:11 am, myalo wrote:
>
> > On Nov 19, 7:58 pm, David Wang wrote:> Create Wildcard Application Mapping tojava.exe for vdir named /cgi-
> The client is making a request to a URL RESOURCE and not file or
> virtual directory. Client doesn't know whether the resource is a file
> or directory. So, don't get confused byfiles or directories or
> thinking that /iTunesU has to be a file or directory. It can be, but
> it doesn't have to be either. Just focus on how to execute "java
> iTunes.class" when the client makes a request to the URL "/cgi-bin/
> iTunesU"
>
> There are two ways to accomplish the above task:
> 1. Have a IIsWebFile named iTunesU and configure its
> ApplicationMapping (which determines how to execute the file
> extension) to launch "javaiTunes.class"
> 2. Have a virtual directory named iTunes and configure its
> WildcardApplicationMapping (which executes before any file extension
> determination) to launch "javaiTunes.class". This approach needs a
> DefaultDocument as well so that IIS is happy, but the basic idea
> remains the same
>
> I suggested #2 because you have a very hard-coded requirement that
> cannot be accomplished from the UI. You can search my MSDN blog on how
> to do this. I have a blog entry showing how to have requests to "/cgi-
> bin" execute a perl script with Perl.exe -- which is not very
> different than your situation where you need a request to "/cgi-bin/
> iTunesU" to execute iTunes.class withJava.exe.
>
If we go with #2, can the parameter - ?destination=something be
forwarded to the class?
>
> TheJavaclass does not return a proper HTTP response where lines are
> separated by \r\n. It also terminates the request header with three
> \n, so one of them can be interpreted as entity body, yet you did not
> send a Content-Length or any other entity length specifier. Please fix
> your code to return proper HTTP.
>
> I suspect that the iTunes.class is not returning proper HTTP response,
> either, so the code will need to be fixed as well.
>
The actual iTunes.class is expected to send a proper HTTP response.
How do I know? I did run the command "java iTunes.class" on the server
command window and redirected the results to a file > a.html. Then I
used the a.html it did go to the right place on Apple iTunesU
university area with the correct credential.
Is it possible that the error is related to something else? I will of
course change my test class and make sure it does proper HTTP
response. If it still fails that it might be something else
Thank you very much
Moshe
Re: Installing Java CGI - how to
am 22.11.2007 06:10:20 von David Wang
On Nov 21, 10:18 am, myalo wrote:
> On Nov 20, 7:34 pm, David Wang wrote:
>
>
>
>
>
> > On Nov 20, 10:11 am, myalo wrote:
>
> > > On Nov 19, 7:58 pm, David Wang wrote:> Create Wildcard Application Mapping tojava.exe for vdir named /cgi-
> > The client is making a request to a URL RESOURCE and not file or
> > virtual directory. Client doesn't know whether the resource is a file
> > or directory. So, don't get confused byfiles or directories or
> > thinking that /iTunesU has to be a file or directory. It can be, but
> > it doesn't have to be either. Just focus on how to execute "java
> > iTunes.class" when the client makes a request to the URL "/cgi-bin/
> > iTunesU"
>
> > There are two ways to accomplish the above task:
> > 1. Have a IIsWebFile named iTunesU and configure its
> > ApplicationMapping (which determines how to execute the file
> > extension) to launch "javaiTunes.class"
> > 2. Have a virtual directory named iTunes and configure its
> > WildcardApplicationMapping (which executes before any file extension
> > determination) to launch "javaiTunes.class". This approach needs a
> > DefaultDocument as well so that IIS is happy, but the basic idea
> > remains the same
>
> > I suggested #2 because you have a very hard-coded requirement that
> > cannot be accomplished from the UI. You can search my MSDN blog on how
> > to do this. I have a blog entry showing how to have requests to "/cgi-
> > bin" execute a perl script with Perl.exe -- which is not very
> > different than your situation where you need a request to "/cgi-bin/
> > iTunesU" to execute iTunes.class withJava.exe.
>
> If we go with #2, can the parameter - ?destination=something be
> forwarded to the class?
>
You are running it like a CGI, meaning those parameters will be
available as environment variables that your Java class will need to
read. Such as PATH_INFO, QUERY_STRING, etc. Enumerate the process
environment of your Java class to see what are available to your CGI.
>
>
> > TheJavaclass does not return a proper HTTP response where lines are
> > separated by \r\n. It also terminates the request header with three
> > \n, so one of them can be interpreted as entity body, yet you did not
> > send a Content-Length or any other entity length specifier. Please fix
> > your code to return proper HTTP.
>
> > I suspect that the iTunes.class is not returning proper HTTP response,
> > either, so the code will need to be fixed as well.
>
> The actual iTunes.class is expected to send a proper HTTP response.
> How do I know? I did run the command "java iTunes.class" on the server
> command window and redirected the results to a file > a.html. Then I
> used the a.html it did go to the right place on Apple iTunesU
> university area with the correct credential.
Your approach is flawed. Just because a web browser can interpret your
a.html output does NOT mean it is correct HTML nor proper HTTP, nor
does it say that the server allows it. It is well known that the web
browser allows both broken and improper HTTP and HTML. So, you have
only shown that the client accepts bad data, which we already knew. It
says nothing about the server allowing bad data, and I can tell you
that your code snippet produces invalid HTTP response that will be
rejected by IIS6. Your only choice is to make your Java class produce
proper HTTP response.
> Is it possible that the error is related to something else? I will of
> course change my test class and make sure it does proper HTTP
> response. If it still fails that it might be something else
> Thank you very much
> Moshe- Hide quoted text -
>
> - Show quoted text -
The error you observe is completely due to your Java class producing
invalid output.
I'm pretty certain that IIS6 will accomplish what you want (I've done
similar things before using Perl.exe instead of Java.exe and Perl
script instead of Java class), so your problems are most likely due to
your misconfiguration or Java class producing improper output.
//David
http://w3-4u.blogspot.com
http://blogs.msdn.com/David.Wang
//
Re: Installing Java CGI - how to
am 28.11.2007 03:13:54 von myalog
David,
As for the first error, I change the code of the java class and it
outputs a proper response.
Now I am getting 404 when doing http://www.mysite.com/cgi/
In the IIS log it shows 404 2 1260.
I found a message you have replied explaining what is behind this
error. I also read other resouces about this error.
What I understand is that web extension is not "allowed". I have
checked many times and it is allowed. I know I am doing something
wrong but cannot get what it is.
Here is exactly the setup in IIS:
Default website: No wildcard mapping
CGI virtual directory: Has a wildcard application mapping to
"C:\Program Files\Java\jre1.6.0_03\bin\java.exe" with the quotes and
Verfiy file exists is checked
In Web Service Extensions I have the following entry:
Name: JavaJRE
File Name: C:\Program Files\Java\jre1.6.0_03\bin\java.exe (without the
quotes) and status is Allowed
What am I doing wrong???
Thanks in Advance
Re: Installing Java CGI - how to
am 28.11.2007 08:38:29 von David Wang
On Nov 27, 6:13 pm, myalo wrote:
> David,
> As for the first error, I change the code of the java class and it
> outputs a proper response.
> Now I am getting 404 when doinghttp://www.mysite.com/cgi/
> In the IIS log it shows 404 2 1260.
> I found a message you have replied explaining what is behind this
> error. I also read other resouces about this error.
> What I understand is that web extension is not "allowed". I have
> checked many times and it is allowed. I know I am doing something
> wrong but cannot get what it is.
> Here is exactly the setup in IIS:
> Default website: No wildcard mapping
> CGI virtual directory: Has a wildcard application mapping to
> "C:\Program Files\Java\jre1.6.0_03\bin\java.exe" with the quotes and
> Verfiy file exists is checked
> In Web Service Extensions I have the following entry:
> Name: JavaJRE
> File Name: C:\Program Files\Java\jre1.6.0_03\bin\java.exe (without the
> quotes) and status is Allowed
> What am I doing wrong???
>
> Thanks in Advance
Look into adding quotes to the Web Service Extensions, even though the
UI won't let you do it. See this blog entry on the details:
http://blogs.msdn.com/david.wang/archive/2005/04/20/IIS6-CGI -Web-Service-Extension.aspx
//David
http://w3-4u.blogspot.com
http://blogs.msdn.com/David.Wang
//
Re: Installing Java CGI - how to
am 28.11.2007 19:04:45 von myalog
Hi David - I sent you an email directly. This is in case it will not
reach you.
I am very frustrated. I read your last link and did the following:
Removed the web service extension for the java.exe and used iisext.vbs
and did the following:
C:\>iisext.vbs /addfile "C:\Program Files\Java\jre1.6.0_03\bin
\java.exe %s" 1 java 1 java
Connecting to server ...Done.
Adding extension file complete. I hope I understood your comment about
the quotes. I left the wildcard mapping unchaged: "C:\Program Files
\Java\jre1.6.0_03\bin\java.exe" %s
Now when I call http://www.mysite.com/cgi/ with our without ?test
(which is a name of a class) I am getting again the 502.2 The
specified CGI application misbehaved by not returning a complete set
of HTTP headers. As I believe that my test.java is returning proper
HTTP header, there is still something wrong with my setup.
David, I realy need your help on this. Can you contact me to my email?
Thanks
Moshe
Re: Installing Java CGI - how to
am 28.11.2007 23:47:06 von David Wang
Use this to setup the "...\bin\java.exe java.class" Application
Mapping:
http://blogs.msdn.com/david.wang/archive/2005/09/14/HOWTO-Us e-IIsWebFile-to-Securely-Run-CGI-in-cgi-bin-from-the-root-di rectory-.aspx
Use this to setup the Web Service Extension for java.exe:
http://blogs.msdn.com/david.wang/archive/2005/04/20/IIS6-CGI -Web-Service-Extension.aspx
What you are doing is not accessible via any IIS Manager UI because it
is the ~20% IIS functionality which IIS is able to do but not main-
stream enough to be in the UI.
//David
http://w3-4u.blogspot.com
http://blogs.msdn.com/David.Wang
//
On Nov 28, 10:04 am, myalo wrote:
> Hi David - I sent you an email directly. This is in case it will not
> reach you.
> I am very frustrated. I read your last link and did the following:
> Removed the web service extension for the java.exe and used iisext.vbs
> and did the following:
> C:\>iisext.vbs /addfile "C:\Program Files\Java\jre1.6.0_03\bin
> \java.exe %s" 1 java 1 java
> Connecting to server ...Done.
> Adding extension file complete. I hope I understood your comment about
> the quotes. I left the wildcard mapping unchaged: "C:\Program Files
> \Java\jre1.6.0_03\bin\java.exe" %s
> Now when I callhttp://www.mysite.com/cgi/with our without ?test
> (which is a name of a class) I am getting again the 502.2 The
> specified CGI application misbehaved by not returning a complete set
> of HTTP headers. As I believe that my test.java is returning proper
> HTTP header, there is still something wrong with my setup.
> David, I realy need your help on this. Can you contact me to my email?
>
> Thanks
> Moshe