src/server/plugins/java/javasrc/webserver/ServerPlugin.java

Thu, 20 Jan 2022 16:04:32 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Thu, 20 Jan 2022 16:04:32 +0100
branch
webdav
changeset 267
4ded424f4a5f
parent 84
afd57ce39ec9
permissions
-rw-r--r--

update configure script / fix configure on freebsd

84
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2013 Olaf Wintermann. All rights reserved.
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28 package webserver;
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 import java.io.File;
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31 import java.lang.reflect.InvocationTargetException;
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32 import java.lang.reflect.Method;
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 import java.net.MalformedURLException;
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34 import java.net.URL;
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35 import java.net.URLClassLoader;
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36 import java.util.ArrayList;
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37 import java.util.logging.Level;
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38 import java.util.logging.Logger;
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39 import webserver.nsapi.Module;
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40 import webserver.nsapi.PBlock;
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41 import webserver.nsapi.Request;
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42 import webserver.nsapi.SAF;
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43 import webserver.nsapi.Session;
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45 class ServerPlugin {
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46 private ArrayList<ServerFunction> registeredFunctions = new ArrayList<>(32);
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48 public ServerPlugin() {
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50 }
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52 public native void addMethod(String name, int safIndex);
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54 static {
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55 System.loadLibrary("nsapi_jni");
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56 }
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
58 public int loadModule(String jar, String classes) {
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59 System.out.println("load-jmodule jar=\""+jar+"\" classes=\""+classes+"\"");
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61 File jarFile = new File(jar);
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62 if(!jarFile.exists()) {
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63 System.err.println("jar file does not exist");
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
64 return -1;
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65 }
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66 try {
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67 URL[] urls = new URL[]{jarFile.toURI().toURL()};
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
68 URLClassLoader cl = new URLClassLoader(urls, this.getClass().getClassLoader());
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
69
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70 for(String className : classes.split(",")) {
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71 Class moduleClass = Class.forName(className, true, cl);
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72 loadClass(moduleClass);
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
73 }
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
74 } catch (MalformedURLException e) {
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
75 System.err.println("ServerPlugin.loadModule: "+e);
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
76 return -1;
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
77 } catch (ClassNotFoundException e) {
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
78 System.err.println("Java Module Class not found: "+e);
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79 return -1;
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
80 } catch (InstantiationException e) {
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
81 System.err.println("ServerPlugin.loadModule: "+e);
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
82 return -1;
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
83 } catch (IllegalAccessException e) {
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
84 System.err.println("ServerPlugin.loadModule: "+e);
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
85 return -1;
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
86 }
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
87
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
88 System.out.println("Java Module loaded");
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
89 return 0;
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
90 }
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
91
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
92 public void loadClass(Class cl) throws InstantiationException, IllegalAccessException {
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
93 Module module = (Module)cl.getAnnotation(Module.class);
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
94 if(module == null) {
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
95 System.err.println("Missing Module annotation for class: "+cl.getCanonicalName());
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
96 return;
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
97 }
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
98
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
99 Object moduleInstance = cl.newInstance();
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
100 for(Method m : cl.getMethods()) {
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
101 if(isSAF(m)) {
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
102 SAF saf = m.getAnnotation(SAF.class);
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
103 if(saf.init()) {
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
104
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
105 }
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
106 if(saf.name().length() > 0) {
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
107 ServerFunction f = new ServerFunction();
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
108 f.module = moduleInstance;
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
109 f.method = m;
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
110
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
111 String safName = module.name() + "." + saf.name();
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
112 registeredFunctions.add(f);
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
113 int index = registeredFunctions.lastIndexOf(f);
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
114 addMethod(safName, index);
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
115 }
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
116 }
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
117 }
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
118 }
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
119
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
120 private boolean isSAF(Method m) {
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
121 SAF saf = m.getAnnotation(SAF.class);
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
122 if(saf != null) {
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
123 // check method signature
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
124 if(m.getReturnType() != int.class) {
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
125 System.err.println("wrong return type for SAF: "+m.getName());
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
126 return false;
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
127 }
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
128 Class paramTypes[] = m.getParameterTypes();
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
129 if(paramTypes.length != 3) {
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
130 System.err.println("wrong number of parameters for SAF: "+m.getName());
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
131 return false;
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
132 }
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
133 if(paramTypes[0] != PBlock.class) {
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
134 System.err.println("wrong method signature for SAF: "+m.getName());
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
135 return false;
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
136 }
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
137 if(paramTypes[1] != Session.class) {
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
138 System.err.println("wrong method signature for SAF: "+m.getName());
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
139 return false;
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
140 }
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
141 if(paramTypes[2] != Request.class) {
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
142 System.err.println("wrong method signature for SAF: "+m.getName());
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
143 return false;
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
144 }
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
145 return true;
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
146 }
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
147 return false;
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
148 }
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
149
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
150 public int exec(int safIndex) {
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
151 System.out.println("(Java) exec: "+safIndex);
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
152 ServerFunction saf = registeredFunctions.get(safIndex);
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
153 if(saf == null) {
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
154 return -1;
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
155 }
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
156 Integer ret = new Integer(-1);
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
157 try {
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
158 ret = (Integer)saf.method.invoke(saf.module, null, null, null);
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
159 } catch (IllegalAccessException e) {
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
160 e.printStackTrace();
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
161 } catch (IllegalArgumentException e) {
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
162 e.printStackTrace();
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
163 } catch (InvocationTargetException e) {
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
164 e.printStackTrace();
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
165 }
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
166 return ret.intValue();
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
167 }
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
168 }

mercurial