Search in sources :

Example 1 with NulsResourceConfig

use of io.nuls.rpc.resources.impl.NulsResourceConfig in project nuls by nuls-io.

the class RpcServerServiceImpl method startServer.

@Override
public void startServer(String ip, int port) {
    URI serverURI = UriBuilder.fromUri("http://" + ip).port(port).build();
    final Map<String, Object> initParams = new HashMap<>();
    initParams.put("jersey.config.server.provider.packages", RpcConstant.PACKAGES);
    initParams.put("load-on-startup", "1");
    NulsResourceConfig rc = new NulsResourceConfig();
    rc.addProperties(initParams);
    httpServer = GrizzlyHttpServerFactory.createHttpServer(serverURI, rc);
    try {
        httpServer.start();
        ClassLoader loader = this.getClass().getClassLoader();
        CLStaticHttpHandler docsHandler = new CLStaticHttpHandler(loader, "swagger-ui/");
        docsHandler.setFileCacheEnabled(false);
        ServerConfiguration cfg = httpServer.getServerConfiguration();
        cfg.addHttpHandler(docsHandler, "/docs/");
    } catch (IOException e) {
        Log.error(e);
    }
    Log.info("http restFul server is started!url is " + serverURI.toString());
}
Also used : CLStaticHttpHandler(org.glassfish.grizzly.http.server.CLStaticHttpHandler) NulsResourceConfig(io.nuls.rpc.resources.impl.NulsResourceConfig) HashMap(java.util.HashMap) ServerConfiguration(org.glassfish.grizzly.http.server.ServerConfiguration) IOException(java.io.IOException) URI(java.net.URI)

Aggregations

NulsResourceConfig (io.nuls.rpc.resources.impl.NulsResourceConfig)1 IOException (java.io.IOException)1 URI (java.net.URI)1 HashMap (java.util.HashMap)1 CLStaticHttpHandler (org.glassfish.grizzly.http.server.CLStaticHttpHandler)1 ServerConfiguration (org.glassfish.grizzly.http.server.ServerConfiguration)1