Skip to content

Commit 9847ee5

Browse files
author
pangpang@hi-nginx.com
committed
update:remove java-javasrcipt support
1 parent 43c49b8 commit 9847ee5

File tree

6 files changed

+33
-385
lines changed

6 files changed

+33
-385
lines changed

README.md

Lines changed: 1 addition & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Features
22
- All features of nginx(latest release) are inherited, i.e., it is 100% compatible with nginx.
3-
- Web development using python, c++, lua, php7, java , javascript and jsr-223 JVM language
3+
- Web development using python, c++, lua, php7, java , quickjs
44

55
# Dependency
66
- linux
@@ -137,13 +137,6 @@ public class jhello implements hi.servlet {
137137

138138
```
139139

140-
### java compile
141-
142-
```
143-
${JAVA_HOME}/bin/javac -classpath .:${NGINX_INSTALL_DIR}/java/hi-nginx-java.jar hi/jhello.java
144-
145-
```
146-
147140

148141
## php servlet class
149142

@@ -176,30 +169,7 @@ class index implements \hi\servlet {
176169

177170
```
178171

179-
## javascript hello world
180172

181-
```javascript
182-
183-
if (typeof (Mustache) == 'undefined') {
184-
load('https://cdn.bootcss.com/mustache.js/2.3.0/mustache.min.js')
185-
}
186-
187-
188-
var list = java.util.Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
189-
var template = "{{#list}}* {{.}}\n{{/list}}"
190-
var key = 'test', output
191-
if (hi_req.cache.containsKey(key)) {
192-
output = hi_req.cache.get(key)
193-
} else {
194-
output = Mustache.render(template, {'list': JSON.parse(list.toString())})
195-
hi_res.cache.put(key, output)
196-
}
197-
hi_res.headers.get('Content-Type').set(0, 'text/plain;charset=UTF-8')
198-
hi_res.content = output
199-
hi_res.status = 200;
200-
201-
202-
```
203173

204174
## quickjs
205175

@@ -559,79 +529,6 @@ hi_java_servlet_cache_size 10;
559529
hi_java_version 8;
560530
561531
562-
```
563-
564-
565-
- directives : content: loc,if in loc
566-
- **hi_javascript_lang**,default:javascript
567-
568-
example:
569-
570-
```nginx
571-
572-
hi_javascript_lang javascript;
573-
574-
575-
```
576-
577-
578-
- directives : content: loc,if in loc
579-
- **hi_javascript_extension**,default:js
580-
581-
example:
582-
583-
```nginx
584-
585-
hi_javascript_extension js;
586-
587-
588-
```
589-
590-
591-
592-
- directives : content: loc,if in loc
593-
- **hi_javascript_content**,default:""
594-
595-
example:
596-
597-
```nginx
598-
599-
hi_javascript_content "hi_res.content='hello,world';hi_res.status=200;";
600-
601-
602-
```
603-
604-
- directives : content: loc,if in loc
605-
- **hi_javascript_script**,default:""
606-
607-
example:
608-
609-
```nginx
610-
611-
hi_javascript_script javascript/index.js;
612-
613-
614-
```
615-
616-
or
617-
618-
```nginx
619-
620-
621-
hi_javascript_script javascript;
622-
623-
624-
```
625-
626-
- directives : content: http,srv,loc,if in loc ,if in srv
627-
- **hi_javascript_compiledscript_expires**,default:300s
628-
629-
example:
630-
631-
```nginx
632-
633-
hi_javascript_compiledscript_expires 300s;
634-
635532
```
636533

637534
- directives : content: loc,if in loc

module/ngx_http_hi_module/application_t.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ enum application_t
1111
#endif
1212
#ifdef HTTP_HI_JAVA
1313
__java__,
14-
__javascript__,
1514
#endif
1615
#ifdef HTTP_HI_PHP
1716
__php__,

module/ngx_http_hi_module/config

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ if test $HTTP_HI_CPP = YES ; then
5959
else
6060
NGX_LD_OPT="$NGX_LD_OPT -L${JAVA_HOME}/lib/server/ -L${JAVA_HOME}/lib/amd64/server/ -ljvm"
6161
fi
62+
if test -n ${CLASSPATH} ; then
63+
CXXFLAGS="$CXXFLAGS -DCLASSPATH=\\\"${CLASSPATH}\\\""
64+
else
65+
CXXFLAGS="$CXXFLAGS -DCLASSPATH=\\\".\\\""
66+
fi;
6267
fi
6368

6469
if test $HTTP_HI_PHP = YES ; then

module/ngx_http_hi_module/java_handler.hpp

Lines changed: 0 additions & 198 deletions
Original file line numberDiff line numberDiff line change
@@ -277,39 +277,6 @@ namespace hi
277277
JAVA->env->DeleteLocalRef(content);
278278
}
279279

280-
static bool javascript_engine_init_handler(ngx_http_hi_loc_conf_t *conf)
281-
{
282-
bool result = false;
283-
if (conf->javascript_engine_index == NGX_CONF_UNSET)
284-
{
285-
std::pair<jobject, jobject> engine{NULL, NULL};
286-
jstring engine_name = JAVA->env->NewStringUTF((char *)conf->javascript_lang.data);
287-
engine.first = (jobject)JAVA->env->CallObjectMethod(JAVA->script_manager_instance, JAVA->script_manager_get_engine_by_name, engine_name);
288-
JAVA->env->ReleaseStringUTFChars(engine_name, 0);
289-
JAVA->env->DeleteLocalRef(engine_name);
290-
if (engine.first != NULL)
291-
{
292-
if (JAVA->env->IsInstanceOf(engine.first, JAVA->compilable) == JNI_TRUE)
293-
{
294-
engine.second = (jobject)engine.first;
295-
}
296-
else
297-
{
298-
engine.second = NULL;
299-
}
300-
JAVA->engines.push_back(engine);
301-
conf->javascript_engine_index = JAVA->engines.size() - 1;
302-
result = true;
303-
}
304-
}
305-
else
306-
{
307-
308-
result = true;
309-
}
310-
return result;
311-
}
312-
313280
static void ngx_http_hi_java_handler(ngx_http_request_t *r, ngx_http_hi_loc_conf_t *conf, hi::request &req, hi::response &res)
314281
{
315282
if (java_init_handler(conf))
@@ -364,169 +331,4 @@ namespace hi
364331
JAVA->env->DeleteLocalRef(response_instance);
365332
}
366333
}
367-
368-
static void ngx_http_hi_javascript_handler(ngx_http_request_t *r, ngx_http_hi_loc_conf_t *conf, hi::request &req, hi::response &res)
369-
{
370-
if (java_init_handler(conf) && javascript_engine_init_handler(conf))
371-
{
372-
373-
std::pair<jobject, jobject> &engine = JAVA->engines[conf->javascript_engine_index];
374-
375-
if (engine.first == NULL)
376-
{
377-
return;
378-
}
379-
380-
jobject request_instance, response_instance;
381-
382-
request_instance = JAVA->env->NewObject(JAVA->request, JAVA->request_ctor);
383-
response_instance = JAVA->env->NewObject(JAVA->response, JAVA->response_ctor);
384-
385-
java_input_handler(conf, req, res, request_instance, response_instance);
386-
387-
jstring jhi_req = JAVA->env->NewStringUTF("hi_req");
388-
jstring jhi_res = JAVA->env->NewStringUTF("hi_res");
389-
390-
JAVA->env->CallVoidMethod(engine.first, JAVA->script_engine_put, jhi_req, request_instance);
391-
JAVA->env->CallVoidMethod(engine.first, JAVA->script_engine_put, jhi_res, response_instance);
392-
393-
if (conf->javascript_script.len > 0)
394-
{
395-
std::string script_path = std::move(std::string((char *)conf->javascript_script.data, conf->javascript_script.len));
396-
auto c = script_path.find_last_of('.');
397-
if (c == std::string::npos || script_path.substr(c + 1) != (char *)conf->javascript_extension.data)
398-
{
399-
script_path.append(req.uri);
400-
}
401-
402-
if (is_file(script_path))
403-
{
404-
std::string md5key = std::move(md5(script_path));
405-
if (conf->need_kvdb == 1)
406-
{
407-
if (JAVA->compiledscript_instances.find(md5key) != JAVA->compiledscript_instances.end())
408-
{
409-
time_t now(0);
410-
const std::pair<time_t, jobject> &compiledscript_pair = JAVA->compiledscript_instances[md5key];
411-
if (difftime(now, compiledscript_pair.first) > conf->javascript_compiledscript_expires)
412-
{
413-
JAVA->env->DeleteLocalRef(compiledscript_pair.second);
414-
JAVA->compiledscript_instances.erase(md5key);
415-
goto update_string_compiledscript_instance;
416-
}
417-
if (compiledscript_pair.second != NULL)
418-
{
419-
JAVA->env->CallObjectMethod(compiledscript_pair.second, JAVA->compiledscript_eval_void);
420-
}
421-
}
422-
else
423-
{
424-
update_string_compiledscript_instance:
425-
jstring script_content = NULL;
426-
std::pair<char *, struct stat> script_mmap;
427-
if (JAVA->script_mmap.get(script_path, script_mmap))
428-
{
429-
script_content = JAVA->env->NewStringUTF(script_mmap.first);
430-
}
431-
if (engine.second != NULL)
432-
{
433-
jobject compiledscript_instance = (jobject)JAVA->env->CallObjectMethod(engine.second, JAVA->compile_string, script_content);
434-
if (compiledscript_instance != NULL)
435-
{
436-
JAVA->compiledscript_instances[md5key] = std::make_pair(time(0), compiledscript_instance);
437-
JAVA->env->CallObjectMethod(compiledscript_instance, JAVA->compiledscript_eval_void);
438-
}
439-
}
440-
else
441-
{
442-
JAVA->env->CallObjectMethod(engine.first, JAVA->script_engine_eval_string, script_content);
443-
}
444-
445-
if (script_content != NULL)
446-
{
447-
JAVA->env->ReleaseStringUTFChars(script_content, 0);
448-
JAVA->env->DeleteLocalRef(script_content);
449-
}
450-
}
451-
}
452-
else
453-
{
454-
if (JAVA->compiledscript_instances.find(md5key) != JAVA->compiledscript_instances.end())
455-
{
456-
time_t now(NULL);
457-
const std::pair<time_t, jobject> &compiledscript_pair = JAVA->compiledscript_instances[md5key];
458-
if (difftime(now, compiledscript_pair.first) > conf->javascript_compiledscript_expires)
459-
{
460-
JAVA->env->DeleteLocalRef(compiledscript_pair.second);
461-
JAVA->compiledscript_instances.erase(md5key);
462-
goto update_file_compiledscript_instance;
463-
}
464-
if (compiledscript_pair.second != NULL)
465-
{
466-
JAVA->env->CallObjectMethod(compiledscript_pair.second, JAVA->compiledscript_eval_void);
467-
}
468-
}
469-
else
470-
{
471-
update_file_compiledscript_instance:
472-
jstring javascript_path = JAVA->env->NewStringUTF(script_path.c_str());
473-
jobject filereader_instance = (jobject)JAVA->env->NewObject(JAVA->filereader, JAVA->filereader_ctor, javascript_path);
474-
475-
if (engine.second != NULL)
476-
{
477-
jobject compiledscript_instance = (jobject)JAVA->env->CallObjectMethod(engine.second, JAVA->compile_filereader, filereader_instance);
478-
if (compiledscript_instance != NULL)
479-
{
480-
JAVA->compiledscript_instances[md5key] = std::make_pair(time(0), compiledscript_instance);
481-
JAVA->env->CallObjectMethod(compiledscript_instance, JAVA->compiledscript_eval_void);
482-
}
483-
}
484-
else
485-
{
486-
JAVA->env->CallObjectMethod(engine.first, JAVA->script_engine_eval_filereader, filereader_instance);
487-
}
488-
JAVA->env->DeleteLocalRef(filereader_instance);
489-
JAVA->env->ReleaseStringUTFChars(javascript_path, 0);
490-
JAVA->env->DeleteLocalRef(javascript_path);
491-
}
492-
}
493-
}
494-
}
495-
else if (conf->javascript_content.len > 0)
496-
{
497-
498-
jstring script_content = JAVA->env->NewStringUTF((char *)conf->javascript_content.data);
499-
500-
if (engine.second != NULL)
501-
{
502-
jobject compiledscript_instance = (jobject)JAVA->env->CallObjectMethod(engine.second, JAVA->compile_string, script_content);
503-
if (compiledscript_instance != NULL)
504-
{
505-
JAVA->env->CallObjectMethod(compiledscript_instance, JAVA->compiledscript_eval_void);
506-
JAVA->env->DeleteLocalRef(compiledscript_instance);
507-
}
508-
}
509-
else
510-
{
511-
512-
JAVA->env->CallObjectMethod(engine.first, JAVA->script_engine_eval_string, script_content);
513-
}
514-
515-
JAVA->env->ReleaseStringUTFChars(script_content, 0);
516-
JAVA->env->DeleteLocalRef(script_content);
517-
}
518-
519-
java_output_handler(conf, req, res, request_instance, response_instance);
520-
521-
JAVA->env->DeleteLocalRef(request_instance);
522-
JAVA->env->DeleteLocalRef(response_instance);
523-
524-
JAVA->env->ReleaseStringUTFChars(jhi_req, 0);
525-
JAVA->env->DeleteLocalRef(jhi_req);
526-
JAVA->env->ReleaseStringUTFChars(jhi_res, 0);
527-
JAVA->env->DeleteLocalRef(jhi_res);
528-
}
529-
}
530334
} // namespace hi
531-
532-

0 commit comments

Comments
 (0)