use of org.redkale.util.AnyValue.DefaultAnyValue in project redkale by redkale.
the class Application method load.
private static void load(final DefaultAnyValue any, final Node root) {
final String home = System.getProperty(RESNAME_APP_HOME);
NamedNodeMap nodes = root.getAttributes();
if (nodes == null)
return;
for (int i = 0; i < nodes.getLength(); i++) {
Node node = nodes.item(i);
any.addValue(node.getNodeName(), node.getNodeValue().replace("${APP_HOME}", home));
}
NodeList children = root.getChildNodes();
if (children == null)
return;
for (int i = 0; i < children.getLength(); i++) {
Node node = children.item(i);
if (node.getNodeType() != Node.ELEMENT_NODE)
continue;
DefaultAnyValue sub = new DefaultAnyValue();
load(sub, node);
any.addValue(node.getNodeName(), sub);
}
}
use of org.redkale.util.AnyValue.DefaultAnyValue in project redkale by redkale.
the class ClassFilter method filter.
/**
* 过滤指定的class
*
* @param property application.xml中对应class节点下的property属性项
* @param clazzname class名称
* @param autoscan 为true表示自动扫描的, false表示显著调用filter, AutoLoad的注解将被忽略
*/
public final void filter(AnyValue property, String clazzname, boolean autoscan) {
boolean r = accept0(property, clazzname);
ClassFilter cf = r ? this : null;
if (r && ands != null) {
for (ClassFilter filter : ands) {
if (!filter.accept(property, clazzname))
return;
}
}
if (!r && ors != null) {
for (ClassFilter filter : ors) {
if (filter.accept(property, clazzname)) {
cf = filter;
break;
}
}
}
if (cf == null || clazzname.startsWith("sun."))
return;
try {
Class clazz = classLoader.loadClass(clazzname);
if (!cf.accept(property, clazz, autoscan))
return;
if (cf.conf != null) {
if (property == null) {
property = cf.conf;
} else if (property instanceof DefaultAnyValue) {
((DefaultAnyValue) property).addAll(cf.conf);
} else {
DefaultAnyValue dav = new DefaultAnyValue();
dav.addAll(property);
dav.addAll(cf.conf);
property = dav;
}
}
AutoLoad auto = (AutoLoad) clazz.getAnnotation(AutoLoad.class);
if (autoscan && auto != null && !auto.value()) {
// 自动扫描且被标记为@AutoLoad(false)的
expectEntrys.add(new FilterEntry(clazz, autoscan, true, property));
} else {
entrys.add(new FilterEntry(clazz, autoscan, false, property));
}
} catch (Throwable cfe) {
if (finer && !clazzname.startsWith("sun.") && !clazzname.startsWith("javax.") && !clazzname.startsWith("com.sun.") && !clazzname.startsWith("jdk.")) {
logger.log(Level.FINEST, ClassFilter.class.getSimpleName() + " filter error", cfe);
}
}
}
use of org.redkale.util.AnyValue.DefaultAnyValue in project redkale by redkale.
the class XmlReader method read.
public AnyValue read() {
DefaultAnyValue root = DefaultAnyValue.create();
char ch;
lineNumber++;
ByteArray array = new ByteArray(128);
while ((ch = nextGoodChar()) > 0) {
if (ch == '<') {
char ch2 = nextChar();
if (ch2 == '!') {
char ch3 = nextChar();
if (ch3 == '-') {
readComment();
} else if (ch3 == '[') {
readCDSect(root, array);
} else if (ch3 == 'D') {
readDocdecl(root, array);
} else {
throw newException("unexpected character in markup " + ch3);
}
} else if (ch2 == '?') {
readXmlDecl(root, array);
} else if (ch2 == '/') {
// 节点结束
String tag = readEndTag();
if (tags.isEmpty())
throw newException("unexpected end tag " + tag);
if (!tags.getFirst().tag.equals(tag))
throw newException("expected end tag " + tags.getFirst().tag + " but " + tag);
tags.removeFirst();
if (tags.isEmpty())
break;
} else {
// 节点开始
readStartTag(root);
}
} else {
int start = this.position;
for (; ; ) {
ch = nextChar();
if (ch == '<') {
backChar(ch);
break;
}
}
String content = escape(new String(this.text, start, this.position + 1 - start));
if (tags.isEmpty()) {
root.addValue(AnyValue.XML_TEXT_NODE_NAME, content);
} else {
tags.getFirst().config.addValue(AnyValue.XML_TEXT_NODE_NAME, content);
}
}
}
return root;
}
use of org.redkale.util.AnyValue.DefaultAnyValue in project redkale by redkale.
the class _DynHelloRestServlet1 method main.
public static void main(String[] args) throws Throwable {
final int port = 8888;
HelloService service = new HelloService();
HttpServer server = new HttpServer();
System.out.println(server.addRestServlet(null, service, null, SimpleRestServlet.class, "/pipes"));
System.out.println(server.addRestServlet(null, new HelloService(3), null, SimpleRestServlet.class, "/pipes"));
DefaultAnyValue conf = DefaultAnyValue.create("port", "" + port);
server.init(conf);
server.start();
Thread.sleep(100);
HelloEntity entity = new HelloEntity();
entity.setHelloname("my name");
Map<String, String> headers = new HashMap<>();
headers.put("hello-res", "my res");
// headers.put(Rest.REST_HEADER_RESOURCE_NAME, "my-res");
String url = "http://127.0.0.1:" + port + "/pipes/hello/update?entity={}&bean2={}";
System.out.println(Utility.postHttpContent(url, headers, null));
url = "http://127.0.0.1:" + port + "/pipes/hello/update2?entity={}&bean2={}";
System.out.println(Utility.postHttpContent(url, headers, null));
url = "http://127.0.0.1:" + port + "/pipes/hello/asyncfind/1234";
System.out.println("异步查找: " + Utility.postHttpContent(url, headers, null));
url = "http://127.0.0.1:" + port + "/pipes/hello/listmap?map={'a':5}";
System.out.println("listmap: " + Utility.postHttpContent(url, headers, null));
url = "http://127.0.0.1:" + port + "/pipes/hello/create?entity={}";
System.out.println("增加记录: " + Utility.postHttpContent(url, headers, "{'a':2,'b':3}"));
url = "http://127.0.0.1:" + port + "/pipes/hello/asyncfind/111111";
System.out.println("listmap: " + Utility.postHttpContent(url, headers, null));
url = "http://127.0.0.1:" + port + "/pipes/hello/asyncfind2/22222";
System.out.println("listmap: " + Utility.postHttpContent(url, headers, null));
url = "http://127.0.0.1:" + port + "/pipes/hello/asyncfind3/333333";
System.out.println("listmap: " + Utility.postHttpContent(url, headers, null));
}
use of org.redkale.util.AnyValue.DefaultAnyValue in project redkale by redkale.
the class Application method loadAppConfig.
static AnyValue loadAppConfig() throws IOException {
final String home = new File(System.getProperty(RESNAME_APP_HOME, "")).getCanonicalPath().replace('\\', '/');
System.setProperty(RESNAME_APP_HOME, home);
String confDir = System.getProperty(RESNAME_APP_CONF, "conf");
URI appConfFile;
boolean fromcache = false;
if (confDir.contains("://")) {
appConfFile = URI.create(confDir + (confDir.endsWith("/") ? "" : "/") + "application.xml");
} else if (confDir.charAt(0) == '/' || confDir.indexOf(':') > 0) {
File f = new File(confDir, "application.xml");
if (f.isFile() && f.canRead()) {
appConfFile = f.toURI();
confDir = f.getParentFile().getCanonicalPath();
} else {
// 不能传confDir
appConfFile = RedkaleClassLoader.getConfResourceAsURI(null, "application.xml");
confDir = appConfFile.toString().replace("/application.xml", "");
fromcache = true;
}
} else {
File f = new File(new File(home, confDir), "application.xml");
if (f.isFile() && f.canRead()) {
appConfFile = f.toURI();
confDir = f.getParentFile().getCanonicalPath();
} else {
// 不能传confDir
appConfFile = RedkaleClassLoader.getConfResourceAsURI(null, "application.xml");
confDir = appConfFile.toString().replace("/application.xml", "");
fromcache = true;
}
}
System.setProperty(RESNAME_APP_CONF, confDir);
AnyValue conf = AnyValue.loadFromXml(appConfFile.toURL().openStream(), StandardCharsets.UTF_8, (k, v) -> v.replace("${APP_HOME}", home)).getAnyValue("application");
if (fromcache)
((DefaultAnyValue) conf).addValue("[config-from-cache]", "true");
return conf;
}
Aggregations