Search in sources :

Example 11 with DefaultAnyValue

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);
    }
}
Also used : DefaultAnyValue(org.redkale.util.AnyValue.DefaultAnyValue)

Example 12 with DefaultAnyValue

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);
        }
    }
}
Also used : DefaultAnyValue(org.redkale.util.AnyValue.DefaultAnyValue)

Example 13 with DefaultAnyValue

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;
}
Also used : DefaultAnyValue(org.redkale.util.AnyValue.DefaultAnyValue)

Example 14 with DefaultAnyValue

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));
}
Also used : DefaultAnyValue(org.redkale.util.AnyValue.DefaultAnyValue)

Example 15 with DefaultAnyValue

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;
}
Also used : java.util.logging(java.util.logging) Convert(org.redkale.convert.Convert) java.util(java.util) SSLContext(javax.net.ssl.SSLContext) org.redkale.watch(org.redkale.watch) java.nio.channels(java.nio.channels) ByteBuffer(java.nio.ByteBuffer) javax.annotation(javax.annotation) java.net(java.net) org.redkale.net.http(org.redkale.net.http) org.redkale.net.sncp(org.redkale.net.sncp) HttpClient(java.net.http.HttpClient) org.redkale.mq(org.redkale.mq) Path(java.nio.file.Path) org.redkale.source(org.redkale.source) java.lang.reflect(java.lang.reflect) RedkaleClassLoader(org.redkale.util.RedkaleClassLoader) DATASOURCE_CONFPATH(org.redkale.source.DataSources.DATASOURCE_CONFPATH) java.util.concurrent(java.util.concurrent) org.redkale.net(org.redkale.net) java.util.concurrent.atomic(java.util.concurrent.atomic) Service(org.redkale.service.Service) StandardCharsets(java.nio.charset.StandardCharsets) org.redkale.convert.json(org.redkale.convert.json) org.redkale.util(org.redkale.util) java.io(java.io) TransportGroupInfo(org.redkale.net.TransportGroupInfo) DefaultAnyValue(org.redkale.util.AnyValue.DefaultAnyValue) ClusterAgent(org.redkale.cluster.ClusterAgent) BsonFactory(org.redkale.convert.bson.BsonFactory) org.redkale.cluster(org.redkale.cluster) FilterEntry(org.redkale.boot.ClassFilter.FilterEntry) DefaultAnyValue(org.redkale.util.AnyValue.DefaultAnyValue)

Aggregations

DefaultAnyValue (org.redkale.util.AnyValue.DefaultAnyValue)18 FilterEntry (org.redkale.boot.ClassFilter.FilterEntry)6 java.io (java.io)1 IOException (java.io.IOException)1 java.lang.reflect (java.lang.reflect)1 java.net (java.net)1 InetSocketAddress (java.net.InetSocketAddress)1 HttpClient (java.net.http.HttpClient)1 ByteBuffer (java.nio.ByteBuffer)1 java.nio.channels (java.nio.channels)1 AsynchronousSocketChannel (java.nio.channels.AsynchronousSocketChannel)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Path (java.nio.file.Path)1 java.util (java.util)1 java.util.concurrent (java.util.concurrent)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 java.util.concurrent.atomic (java.util.concurrent.atomic)1 java.util.logging (java.util.logging)1 javax.annotation (javax.annotation)1 SSLContext (javax.net.ssl.SSLContext)1