Mail Archives: djgpp/1996/06/24/00:33:31
Xref: | news2.mv.net comp.os.msdos.djgpp:5308
|
From: | root AT TeamInfinity DOT com (root)
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | CGI with JAVA on WinNT and -D arg passing limitations
|
Date: | 23 Jun 1996 22:03:13 -0400
|
Organization: | TEAM INFINITY P.O. BOX 952 Greenbelt, MD 20770 USA
|
Lines: | 226
|
Message-ID: | <4qkt11$hee@teaminfinity.com>
|
NNTP-Posting-Host: | dialin01.teaminfinity.com
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
First of, has anyone tried doing CGI with JAVA
on NT ? To get the environment in you need to
use java's -D switch and since CGI requires
a single command you need to invoke your
java application via a C execv for example.
We used Andrews jcgi.c compiled with djgpp lite
to do this. (See Source Code below)
In theory this all works and a prog called jcgi.c
does it all nicely, but under NT the args seemed to be
limited by something, not sure what, anyway onto the
questions...
Anyone know what affects the amount of command
line arguments a execv invocation of a command
can handle under Windows NT ?
This is related to a C program calling a java
program and passing via argv the parameters
necessary to pass the environment to the java
application.
Andrew, jcgi DOES work with NT, up to a point.
It can only pass about 3 of the -D environment
variables, after that, it will not work.
Must have something to do with length of command
limitations of NT and is further affected if
jcgi is part of a URL.
See if I execute the jcgi command from the command
prompt it works fine, but when executed via a URL
if more than about 3 environment vars are passed
it bombs.
I know you currently do not mess with NT, but if
you could get me in touch with someone who does
AND uses your jcgi, maybe I could share my NT/jcgi
experiences with them, and vice versa. It is
DEFINETLY viable under NT but SEVERLY limited by
hopefully a CONFIGURABLE NT limitation. That is
where I need help because I definetly have your
jcgi down.
By the way do you have any examples of jcgi calling
a java application which then calls your CGI class
to process say a simple html form ???
Thanks
Andrew, with luck and persistence we will make
you jcgi available to the NT world as well !
Eric Sean Webber
WebMeister AT TeamInfinity DOT com
/*
* Copyright (C) 1996 Andrew Scherpbier <andrew AT sdsu DOT edu>
*
* This file is part of the San Diego State University Java Library.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <memory.h>
#include <errno.h>
#define JAVA "c:\java\bin\java.exe"
#define MAX_ARGS 200
char **build_argv(char **envp, char **vars, char *programName);
char *make_arg(char *name, char *value);
char *vars[] =
{
"SERVER_SOFTWARE",
"SERVER_NAME",
"GATEWAY_INTERFACE",
"SERVER_PROTOCOL",
"SERVER_PORT",
"REQUEST_METHOD",
"PATH_INFO",
"PATH_TRANSLATED",
"SCRIPT_NAME",
"QUERY_STRING",
"REMOTE_HOST",
"REMOTE_ADDR",
"AUTH_TYPE",
"REMOTE_USER",
"REMOTE_IDENT",
"CONTENT_TYPE",
"CONTENT_LENGTH",
NULL
};
int
main(int ac, char **av, char **envp)
{
char **argv;
char *programName;
char *path = av[0];
char dir[1024];
char *p = strrchr(av[0], '/');
char *q = strrchr(av[0], '.');
/* Separate the path from the command */
if (q)
*q = '\0';
/* Get rid of any extension like .cgi that the program may have */
if (p)
{
programName = p + 1;
*p = '\0';
}
else
{
programName = av[0];
path = ".";
}
/* Go to the directory that contains the java program */
if (path)
{
if (chdir(path) != 0)
{
printf("Content-type: text/plain\r\n\r\n");
printf("Error code %s\n", errno);
perror(path);
exit(1);
}
}
if (ac > 1)
{
printf("Path: '%s'\n", path);
printf("Name: '%s'\n", programName);
}
argv = build_argv(envp, vars, programName);
execv(JAVA, argv);
printf("Content-type: text/plain\n\n");
printf("jcgi: unable to execute '%s'\n", JAVA);
}
char **
build_argv(char **envp, char **vars, char *programName)
{
char **argv = (char **) malloc(sizeof(char *) * MAX_ARGS);
int n = 0;
char *buffer;
int i;
char *p;
argv[n++] = "java";
argv[n++] = "-cs";
/*
* Add all the standard CGI variables
*/
for (i = 0; vars[i] && n < MAX_ARGS; i++)
{
if ((p = getenv(vars[i])))
{
argv[n++] = make_arg(vars[i], p);
}
}
/*
* Now add any variables that start with HTTP_
*/
for (; *envp && n < MAX_ARGS; envp++)
{
if (strncmp(*envp, "HTTP_", 5) == 0)
{
p = strchr(*envp, '=');
if (p)
{
*p++ = '\0';
argv[n++] = make_arg(*envp, p);
}
}
}
argv[n++] = programName;
argv[n] = NULL;
return argv;
}
char *
make_arg(char *name, char *value)
{
char *buffer = malloc(strlen(value) + strlen(name) + 4);
sprintf(buffer, "-D%s=%s", name, value);
return buffer;
}
- Raw text -