Skip to content

Commit ec59f73

Browse files
committed
nginx-jersey can use Jersey Application
1 parent 0bfbbc0 commit ec59f73

File tree

2 files changed

+38
-14
lines changed

2 files changed

+38
-14
lines changed

nginx-jersey/README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,12 @@ in nginx.conf
3939
##aplication path usually it is the same with nginx location
4040
content_handler_property jersey.app.path '/jersey';
4141
42-
##application resources which can be either of JAX-RS resources, providers
42+
## jersey application class
43+
content_handler_property jersey.app.Appclass 'org.glassfish.jersey.examples.MyApplication';
44+
45+
## If we have no jersey application class we can define JAX-RS resources, providers here
46+
## If jersey.app.Appclass is defined jersey.app.resources will be ignored.
47+
## application resources which can be either of JAX-RS resources, providers
4348
content_handler_property jersey.app.resources '
4449
org.glassfish.jersey.examples.jackson.EmptyArrayResource,
4550
org.glassfish.jersey.examples.jackson.NonJaxbBeanResource,

nginx-jersey/src/java/nginx/clojure/jersey/NginxJerseyContainer.java

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import javax.ws.rs.GET;
2323
import javax.ws.rs.Path;
2424
import javax.ws.rs.Produces;
25+
import javax.ws.rs.core.Application;
2526
import javax.ws.rs.core.MultivaluedMap;
2627
import javax.ws.rs.core.SecurityContext;
2728

@@ -56,23 +57,41 @@ public void boot(Map<String, String> properties, ClassLoader loader) {
5657
if (appPath == null) {
5758
appPath = "";
5859
}
59-
String res = properties.get("jersey.app.resources");
60-
List<Class> clzList = new ArrayList<Class>();
61-
if (res != null) {
62-
for (String clz : res.split(",") ) {
63-
try {
64-
clzList.add(loader.loadClass(clz.trim()));
65-
} catch (Throwable e) {
66-
NginxClojureRT.log.warn("can not load resource %s, skiping", clz, e);
60+
61+
String application = properties.get("jersey.app.Appclass");
62+
if (application != null) {
63+
Class appClz = null;
64+
try {
65+
appClz = loader.loadClass(application.trim());
66+
} catch (ClassNotFoundException e) {
67+
NginxClojureRT.log.warn("can not load jersey.app.Appclass %s", application, e);
68+
throw new RuntimeException("can not load jersey.app.Appclass " + e.getMessage(), e);
69+
}
70+
try {
71+
appHandler = new ApplicationHandler((Class<? extends Application>) appClz.newInstance());
72+
} catch (Exception e) {
73+
throw new RuntimeException("can not create jersey.app.Appclass" + e.getMessage(), e);
74+
}
75+
}else {
76+
String res = properties.get("jersey.app.resources");
77+
List<Class> clzList = new ArrayList<Class>();
78+
if (res != null) {
79+
for (String clz : res.split(",") ) {
80+
try {
81+
clzList.add(loader.loadClass(clz.trim()));
82+
} catch (Throwable e) {
83+
NginxClojureRT.log.warn("can not load resource %s, skiping", clz, e);
84+
}
6785
}
86+
appResources = clzList.toArray(new Class[clzList.size()]);
87+
}
88+
89+
if (appResources == null || appResources.length == 0){
90+
NginxClojureRT.log.warn("no resource defined, property %s is null", "jersey.app.resources");
6891
}
69-
appResources = clzList.toArray(new Class[clzList.size()]);
92+
appHandler = new ApplicationHandler(configure());
7093
}
7194

72-
if (appResources == null || appResources.length == 0){
73-
NginxClojureRT.log.warn("no resource defined, property %s is null", "jersey.app.resources");
74-
}
75-
appHandler = new ApplicationHandler(configure());
7695
}
7796

7897
@Override

0 commit comments

Comments
 (0)