Im trying to set up a cgi script for my RMI webserver, but it is giving me an HTTP 500 all the time.
My CGI script look like this.
# This class will support a QUERY_STRING of the form "forward=<port>"
# with a REQUEST_METHOD "POST". The body of the request will be
# forwarded (as another POST request) to the server listening on the
# specified port (must be >= 1024). The response from this forwarded
# request will be the response to the original request.
#
# CONFIGURATION:
#
# Fill in correct absolute path to Java interpreter below. For example,
# the "PATH=" line might be changed to the follow if the JDK is installed
# at the path "/home/peter/java":
#
# PATH=/home/peter/java/bin:$PATH
#
PATH=/usr/lib/jvm/java-7-openjdk-amd64/bin:$PATH
exec java \
-DAUTH_TYPE="$AUTH_TYPE" \
-DCONTENT_LENGTH="$CONTENT_LENGTH" \
-DCONTENT_TYPE="$CONTENT_TYPE" \
-DGATEWAY_INTERFACE="$GATEWAY_INTERFACE" \
-DHTTP_ACCEPT="$HTTP_ACCEPT" \
-DPATH_INFO="$PATH_INFO" \
-DPATH_TRANSLATED="$PATH_TRANSLATED" \
-DQUERY_STRING="$QUERY_STRING" \
-DREMOTE_ADDR="$REMOTE_ADDR" \
-DREMOTE_HOST="$REMOTE_HOST" \
-DREMOTE_IDENT="$REMOTE_IDENT" \
-DREMOTE_USER="$REMOTE_USER" \
-DREQUEST_METHOD="$REQUEST_METHOD" \
-DSCRIPT_NAME="$SCRIPT_NAME" \
-DSERVER_NAME="$SERVER_NAME" \
-DSERVER_PORT="$SERVER_PORT" \
-DSERVER_PROTOCOL="$SERVER_PROTOCOL" \
-DSERVER_SOFTWARE="$SERVER_SOFTWARE" \
sun.rmi.transport.proxy.CGIHandler
In my access.log it says:
"POST /cgi-bin/java-rmi.cgi?forward=1099 HTTP/1.1" 500 415 "-" "Java/1.7.0"
In my error.log it says:
(104)Connection reset by peer: ap_content_length_filter: apr_bucket_read() failed
I am using RMISocketFactory.setSocketFactory(new sun.rmi.transport.proxy.RMIHttpToCGISocketFactory());
to force Http-to-cgi.
I can't figure out what i'm doing wrong..
I have put my java-rmi.cgi file in /usr/lib/cgi-bin/
Am i suppose to add something else to the script?
The java error i get is:
java.rmi.UnmarshalException: Error unmarshaling return header; nested exception is:
java.io.IOException: HTTP request failed
EDIT: Visiting my cgi script as a website it give me(maybe you can't do that):
Java RMI Client Error
invalid command.
I traced this into the CGICommandHandler.java and it returns invalid command when the handler is null.
This is the debug output when i run bash -x:
+ PATH=/usr/lib/jvm/java-7-openjdk-amd64/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
+ exec java -DAUTH_TYPE= -DCONTENT_LENGTH= -DCONTENT_TYPE= -DGATEWAY_INTERFACE= -DHTTP_ACCEPT= -DPATH_INFO= -DPATH_TRANSLATED= -DQUERY_STRING= -DREM OTE_ADDR= -DREMOTE_HOST= -DREMOTE_IDENT= -DREMOTE_USER= -DREQUEST_METHOD= -DSCRIPT_NAME= -DSERVER_NAME= -DSERVER_PORT= -DSERVER_PROTOCOL= -DSERVER_S OFTWARE= sun.rmi.transport.proxy.CGIHandler
Status: 400 Bad Request: invalid command.
Content-type: text/html
<HTML><HEAD><TITLE>Java RMI Client Error</TITLE></HEAD><BODY>
<H1>Java RMI Client Error</H1>
invalid command.
</BODY></HTML>
And if i echo out my cgi i file i get this:
AUTH_TYPE=
CONTENT_LENGTH=
CONTENT_TYPE=
GATEWAY_INTERFACE=CGI/1.1 HTTP_ACCEPT=text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8 PATH_INFO=
PATH_TRANSLATED=
QUERY_STRING=
REMOTE_ADDR=xx.xxx.x.xx
REMOTE_HOST=
REMOTE_IDENT=
REMOTE_IDENT REMOTE_USER=
REQUEST_METHOD=GET SCRIPT_NAME=/cgi-bin/java-rmi.cgi.sh
SERVER_NAME=xx.xxx.xxx.xxx
SERVER_PORT=80 SERVER_PROTOCOL=HTTP/1.1
SERVER_SOFTWARE=Apache/2.2.22 (Ubuntu) Status: 400 Bad Request: invalid command. Content-type: text/html
As you can see my many strings are empty...
EDIT 2: Now my acess log brings me this:
"POST http://xx.xxx.xxx.xxx/cgi-bin/java-rmi.cgi?forward=1099 HTTP/1.1" 500 415 "-" "Java/1.7.0"
Still HTTP 500, my error log gives my the same as before..
EDIT 3:
I now tried to implement the servlet of java-rmi.cgi and it's giving me errors.
My http.conf lookes like this:
LoadModule proxy_module /usr/lib/apache2/modules/mod_proxy.so
LoadModule proxy_ajp_module /usr/lib/apache2/modules/mod_proxy_ajp.so
<Location /cgi-bin/java-rmi.cgi>
ProxyPass ajp://localhost:8009/rmi/ServletHandler
</Location>
What should be the port and adress? In the guide it says localhost:8009(https://forums.oracle.com/message/4804030).
This is where i've placed ServletHandler.class:
/var/lib/tomcat7/webapps/rmi/WEB_INF/classes
My web.xml(inside WEB_INF) looks like this:
<servlet>
<servlet-name>ServletHandler</servlet-name>
<servlet-class>ServletHandler</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ServletHandler</servlet-name>
<url-pattern>/ServletHandler</url-pattern>
</servlet-mapping>
I've installed tomcat 7 properly.
My access log gives me the same but my error log now gives me(with localhost:8009 set in httpd.conf):
[Fri Nov 15 08:16:26 2013] [error] [client 127.0.0.1] Invalid method in request \x124\x01\xb2\x02\x02
[Fri Nov 15 08:16:26 2013] [error] ajp_check_msg_header() got bad signature 3c21
[Fri Nov 15 08:16:26 2013] [error] ajp_ilink_receive() received bad header
[Fri Nov 15 08:16:26 2013] [error] ajp_read_header: ajp_ilink_receive failed
[Fri Nov 15 08:16:26 2013] [error] (120007)APR does not understand this error code: proxy: read response failed from (null) (localhost)
Error log when setting my global ip and port 80 in http.conf:
[Fri Nov 15 08:13:26 2013] [error] [client xx.xxx.xxx.xxx] Invalid method in request \x124\x01\xb2\x02\x02
[Fri Nov 15 08:13:26 2013] [error] ajp_check_msg_header() got bad signature 3c21
[Fri Nov 15 08:13:26 2013] [error] ajp_ilink_receive() received bad header
[Fri Nov 15 08:13:26 2013] [error] ajp_read_header: ajp_ilink_receive failed
[Fri Nov 15 08:13:26 2013] [error] (120007)APR does not understand this error code: proxy: read response failed from (null) (xx.xxx.xxx.xxx)
EDIT 4:
Now it lookes like this:
web.xml:
<servlet>
<servlet-name>ServletHandler</servlet-name>
<servlet-class>rmiservlethandler.ServletHandler</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>ServletHandler</servlet-name>
<url-pattern>/ServletHandler</url-pattern>
</servlet-mapping>
httpd.conf:
LoadModule proxy_module /usr/lib/apache2/modules/mod_proxy.so
LoadModule proxy_ajp_module /usr/lib/apache2/modules/mod_proxy_ajp.so
<Location /cgi-bin/java-rmi.cgi>
ProxyPass ajp://xx.xxx.xxx.xxx:8009/rmi/ServletHandler
</Location>
I tried localhost:8009 but that gives me error, entering my servers global adress makes my webserver to halt, HTTP 503. Stop responding.
My error log for localhost:
[Fri Nov 15 12:20:53 2013] [error] (111)Connection refused: proxy: AJP: attempt to connect to 127.0.0.1:8009 (localhost) failed
[Fri Nov 15 12:20:53 2013] [error] ap_proxy_connect_backend disabling worker for (localhost)
[Fri Nov 15 12:20:53 2013] [error] proxy: AJP: failed to make connection to backend: localhost
error log for global ip:
[Fri Nov 15 12:37:23 2013] [error] (110)Connection timed out: proxy: AJP: attempt to connect to xx.xxx.xxx.xxx:8009 (xx.xxx.xxx.xxx) failed
[Fri Nov 15 12:37:23 2013] [error] ap_proxy_connect_backend disabling worker for (xx.xxx.xxx.xxx)
[Fri Nov 15 12:37:23 2013] [error] proxy: AJP: failed to make connection to backend: xx.xxx.xxx.xxx
Tomcatlog gives me this:
My tomcatlog gives me this:
xx.xxx.x.xx - - [15/Nov/2013:13:32:14 +0000] "POST /rmi/ServletHandler?forward=1099 HTTP/1.1" 404 987
EDIT 5.
Didn't work, i get 404 for /rmi/ServletHandler.
Here is my httpd.conf(taking away .cgi):
<Location /cgi-bin/java-rmi> ProxyPass ajp://localhost:8009/rmi/ServletHandler </Location>
This is web.xml:
<?xml version="1.0" encoding="UTF-8"?> <web-app> <servlet>
<servlet-name>ServletHandler</servlet-name>
<servlet-class>rmiservlethandler.ServletHandler</servlet-class>
<load-on-startup>1</load-on-startup> </servlet>
<servlet-mapping> <servlet-name>ServletHandler</servlet-name>
<url-pattern>/ServletHandler</url-pattern>
</servlet-mapping>
</web-app>
The folder setup is now:
/var/lib/tomcat7/webapps/rmi/WEB_INF.
WEB_INF contains web.xml and classes/rmiservlethandler/ where rmiservlethandler is where all my class files are(package structure).
Why isn't this working?
My /usr/lib/cgi-bin/ is empty that is should be right?
My servlet dosen't run... Thanks!