-
Notifications
You must be signed in to change notification settings - Fork 2
/
ApiRegister.java
32 lines (27 loc) · 1014 Bytes
/
ApiRegister.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package com.x.server;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import spark.Request;
import spark.Response;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
public class ApiRegister {
private static final Logger LOGGER = LoggerFactory.getLogger(ApiRegister.class);
private Request request;
private Response response;
public ApiRegister(Request request, Response response) {
this.request = request;
this.response = response;
}
public String process(Method method) {
try {
Class<?> runtimeClass = Class.forName(method.getDeclaringClass().getName());
Constructor<?> constructor = runtimeClass.getConstructor(Request.class, Response.class);
Object runtimeObject = constructor.newInstance(request, response);
return (String) method.invoke(runtimeObject);
} catch (Exception e) {
LOGGER.error("registerEndpoints", e);
return null;
}
}
}