com.alibaba.dubbo.common.utils.ConfigUtils Java Examples
The following examples show how to use
com.alibaba.dubbo.common.utils.ConfigUtils.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ExtensionLoader.java From dubbo3 with Apache License 2.0 | 6 votes |
private boolean isActive(Activate activate, URL url) { String[] keys = activate.value(); if (keys.length == 0) { return true; } for (String key : keys) { for (Map.Entry<String, String> entry : url.getParameters().entrySet()) { String k = entry.getKey(); String v = entry.getValue(); if ((k.equals(key) || k.endsWith("." + key)) && ConfigUtils.isNotEmpty(v)) { return true; } } } return false; }
Example #2
Source File: AbstractInterfaceConfig.java From dubbox with Apache License 2.0 | 6 votes |
@SuppressWarnings("deprecation") protected void checkApplication() { // 兼容旧版本 if (application == null) { String applicationName = ConfigUtils.getProperty("dubbo.application.name"); if (applicationName != null && applicationName.length() > 0) { application = new ApplicationConfig(); } } if (application == null) { throw new IllegalStateException( "No such application config! Please add <dubbo:application name=\"...\" /> to your spring config."); } appendProperties(application); String wait = ConfigUtils.getProperty(Constants.SHUTDOWN_WAIT_KEY); if (wait != null && wait.trim().length() > 0) { System.setProperty(Constants.SHUTDOWN_WAIT_KEY, wait.trim()); } else { wait = ConfigUtils.getProperty(Constants.SHUTDOWN_WAIT_SECONDS_KEY); if (wait != null && wait.trim().length() > 0) { System.setProperty(Constants.SHUTDOWN_WAIT_SECONDS_KEY, wait.trim()); } } }
Example #3
Source File: ExtensionLoader.java From dubbo-2.6.5 with Apache License 2.0 | 6 votes |
private boolean isActive(Activate activate, URL url) { String[] keys = activate.value(); if (keys.length == 0) { return true; } for (String key : keys) { for (Map.Entry<String, String> entry : url.getParameters().entrySet()) { String k = entry.getKey(); String v = entry.getValue(); if ((k.equals(key) || k.endsWith("." + key)) && ConfigUtils.isNotEmpty(v)) { return true; } } } return false; }
Example #4
Source File: ThriftProtocol.java From dubbo-2.6.5 with Apache License 2.0 | 6 votes |
@Override public void destroy() { super.destroy(); for (String key : new ArrayList<String>(serverMap.keySet())) { ExchangeServer server = serverMap.remove(key); if (server != null) { try { if (logger.isInfoEnabled()) { logger.info("Close dubbo server: " + server.getLocalAddress()); } server.close(ConfigUtils.getServerShutdownTimeout()); } catch (Throwable t) { logger.warn(t.getMessage(), t); } } // ~ end of if ( server != null ) } // ~ end of loop serverMap }
Example #5
Source File: AbstractRegistry.java From dubbo-2.6.5 with Apache License 2.0 | 6 votes |
public AbstractRegistry(URL url) { setUrl(url); // Start file save timer 查询注册信息保存本地文件save.file syncSaveFile = url.getParameter(Constants.REGISTRY_FILESAVE_SYNC_KEY, false); // 默认文件名 /Users/jiangweifeng/.dubbo/dubbo-registry-dubbo-provider-192.168.50.251:2181.cache String filename = url.getParameter(Constants.FILE_KEY, System.getProperty("user.home") + "/.dubbo/dubbo-registry-" + url.getParameter(Constants.APPLICATION_KEY) + "-" + url.getAddress() + ".cache"); File file = null; if (ConfigUtils.isNotEmpty(filename)) { file = new File(filename); if (!file.exists() && file.getParentFile() != null && !file.getParentFile().exists()) { if (!file.getParentFile().mkdirs()) { throw new IllegalArgumentException("Invalid registry store file " + file + ", cause: Failed to create directory " + file.getParentFile() + "!"); } } } this.file = file; // 从配置文件中加载注册 loadProperties(); notify(url.getBackupUrls()); }
Example #6
Source File: AbstractInterfaceConfigTest.java From dubbo-2.6.5 with Apache License 2.0 | 6 votes |
@Test public void checkApplication1() throws Exception { try { ConfigUtils.setProperties(null); writeDubboProperties(Constants.SHUTDOWN_WAIT_KEY, "100"); System.setProperty("dubbo.application.name", "demo"); InterfaceConfig interfaceConfig = new InterfaceConfig(); interfaceConfig.checkApplication(); ApplicationConfig appConfig = interfaceConfig.getApplication(); TestCase.assertEquals("demo", appConfig.getName()); TestCase.assertEquals("100", System.getProperty(Constants.SHUTDOWN_WAIT_KEY)); System.clearProperty(Constants.SHUTDOWN_WAIT_KEY); ConfigUtils.setProperties(null); writeDubboProperties(Constants.SHUTDOWN_WAIT_SECONDS_KEY, "1000"); System.setProperty("dubbo.application.name", "demo"); interfaceConfig = new InterfaceConfig(); interfaceConfig.checkApplication(); TestCase.assertEquals("1000", System.getProperty(Constants.SHUTDOWN_WAIT_SECONDS_KEY)); } finally { ConfigUtils.setProperties(null); System.clearProperty("dubbo.application.name"); System.clearProperty(Constants.SHUTDOWN_WAIT_KEY); System.clearProperty(Constants.SHUTDOWN_WAIT_SECONDS_KEY); } }
Example #7
Source File: AbstractInterfaceConfig.java From dubbo3 with Apache License 2.0 | 6 votes |
@SuppressWarnings("deprecation") protected void checkApplication() { // 兼容旧版本 if (application == null) { String applicationName = ConfigUtils.getProperty("dubbo.application.name"); if (applicationName != null && applicationName.length() > 0) { application = new ApplicationConfig(); } } if (application == null) { throw new IllegalStateException( "No such application config! Please add <dubbo:application name=\"...\" /> to your spring config."); } appendProperties(application); String wait = ConfigUtils.getProperty(Constants.SHUTDOWN_WAIT_KEY); if (wait != null && wait.trim().length() > 0) { System.setProperty(Constants.SHUTDOWN_WAIT_KEY, wait.trim()); } else { wait = ConfigUtils.getProperty(Constants.SHUTDOWN_WAIT_SECONDS_KEY); if (wait != null && wait.trim().length() > 0) { System.setProperty(Constants.SHUTDOWN_WAIT_SECONDS_KEY, wait.trim()); } } }
Example #8
Source File: CacheFilter.java From dubbox with Apache License 2.0 | 6 votes |
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { if (cacheFactory != null && ConfigUtils.isNotEmpty(invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.CACHE_KEY))) { Cache cache = cacheFactory.getCache(invoker.getUrl().addParameter(Constants.METHOD_KEY, invocation.getMethodName())); if (cache != null) { String key = StringUtils.toArgumentString(invocation.getArguments()); if (cache != null && key != null) { Object value = cache.get(key); if (value != null) { return new RpcResult(value); } Result result = invoker.invoke(invocation); if (! result.hasException()) { cache.put(key, result.getValue()); } return result; } } } return invoker.invoke(invocation); }
Example #9
Source File: CacheFilter.java From dubbox with Apache License 2.0 | 6 votes |
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { if (cacheFactory != null && ConfigUtils.isNotEmpty(invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.CACHE_KEY))) { Cache cache = cacheFactory.getCache(invoker.getUrl().addParameter(Constants.METHOD_KEY, invocation.getMethodName())); if (cache != null) { String key = StringUtils.toArgumentString(invocation.getArguments()); if (cache != null && key != null) { Object value = cache.get(key); if (value != null) { return new RpcResult(value); } Result result = invoker.invoke(invocation); if (! result.hasException()) { cache.put(key, result.getValue()); } return result; } } } return invoker.invoke(invocation); }
Example #10
Source File: AbstractInterfaceConfig.java From dubbox with Apache License 2.0 | 6 votes |
@SuppressWarnings("deprecation") protected void checkApplication() { // 兼容旧版本 if (application == null) { String applicationName = ConfigUtils.getProperty("dubbo.application.name"); if (applicationName != null && applicationName.length() > 0) { application = new ApplicationConfig(); } } if (application == null) { throw new IllegalStateException( "No such application config! Please add <dubbo:application name=\"...\" /> to your spring config."); } appendProperties(application); String wait = ConfigUtils.getProperty(Constants.SHUTDOWN_WAIT_KEY); if (wait != null && wait.trim().length() > 0) { System.setProperty(Constants.SHUTDOWN_WAIT_KEY, wait.trim()); } else { wait = ConfigUtils.getProperty(Constants.SHUTDOWN_WAIT_SECONDS_KEY); if (wait != null && wait.trim().length() > 0) { System.setProperty(Constants.SHUTDOWN_WAIT_SECONDS_KEY, wait.trim()); } } }
Example #11
Source File: ExtensionLoader.java From dubbox with Apache License 2.0 | 6 votes |
private boolean isActive(Activate activate, URL url) { String[] keys = activate.value(); if (keys == null || keys.length == 0) { return true; } for (String key : keys) { for (Map.Entry<String, String> entry : url.getParameters().entrySet()) { String k = entry.getKey(); String v = entry.getValue(); if ((k.equals(key) || k.endsWith("." + key)) && ConfigUtils.isNotEmpty(v)) { return true; } } } return false; }
Example #12
Source File: CacheFilter.java From dubbo3 with Apache License 2.0 | 6 votes |
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { if (cacheFactory != null && ConfigUtils.isNotEmpty(invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.CACHE_KEY))) { Cache cache = cacheFactory.getCache(invoker.getUrl().addParameter(Constants.METHOD_KEY, invocation.getMethodName())); if (cache != null) { String key = StringUtils.toArgumentString(invocation.getArguments()); Object value = cache.get(key); if (value != null) { return new RpcResult(value); } Result result = invoker.invoke(invocation); if (! result.hasException()) { cache.put(key, result.getValue()); } return result; } } return invoker.invoke(invocation); }
Example #13
Source File: ValidationFilter.java From dubbo3 with Apache License 2.0 | 6 votes |
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { if (validation != null && ! invocation.getMethodName().startsWith("$") && ConfigUtils.isNotEmpty(invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.VALIDATION_KEY))) { try { Validator validator = validation.getValidator(invoker.getUrl()); if (validator != null) { validator.validate(invocation.getMethodName(), invocation.getParameterTypes(), invocation.getArguments()); } } catch (RpcException e) { throw e; } catch (Throwable t) { throw new RpcException(t.getMessage(), t); } } return invoker.invoke(invocation); }
Example #14
Source File: DefaultSyncTransfer.java From dubbo-plus with Apache License 2.0 | 6 votes |
@Override public void run() { while (!interrupted()) { try { Span first = queue.take(); cacheList.add(first); queue.drainTo(cacheList, flushSizeInner); if(cacheList.size()<=0){ continue; } if(!inited&&collector==null){ TracingCollectorFactory tracingCollectorFactory = ExtensionLoader .getExtensionLoader(TracingCollectorFactory.class) .getExtension(ConfigUtils.getProperty(DstConstants.TRACING_COLLECTOR ,DstConstants.DEFAULT_COLLECTOR_TYPE)); collector =tracingCollectorFactory.getTracingCollector(); inited=true; } collector.push(cacheList); cacheList.clear(); } catch (InterruptedException e) { logger.error("Dst-span-transfer-task-thread occur an error", e); } } }
Example #15
Source File: ValidationFilter.java From dubbox-hystrix with Apache License 2.0 | 6 votes |
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { if (validation != null && ! invocation.getMethodName().startsWith("$") && ConfigUtils.isNotEmpty(invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.VALIDATION_KEY))) { try { Validator validator = validation.getValidator(invoker.getUrl()); if (validator != null) { validator.validate(invocation.getMethodName(), invocation.getParameterTypes(), invocation.getArguments()); } } catch (RpcException e) { throw e; } catch (Throwable t) { throw new RpcException(t.getMessage(), t); } } return invoker.invoke(invocation); }
Example #16
Source File: CacheFilter.java From dubbox-hystrix with Apache License 2.0 | 6 votes |
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { if (cacheFactory != null && ConfigUtils.isNotEmpty(invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.CACHE_KEY))) { Cache cache = cacheFactory.getCache(invoker.getUrl().addParameter(Constants.METHOD_KEY, invocation.getMethodName())); if (cache != null) { String key = StringUtils.toArgumentString(invocation.getArguments()); if (cache != null && key != null) { Object value = cache.get(key); if (value != null) { return new RpcResult(value); } Result result = invoker.invoke(invocation); if (! result.hasException()) { cache.put(key, result.getValue()); } return result; } } } return invoker.invoke(invocation); }
Example #17
Source File: AbstractInterfaceConfig.java From dubbox-hystrix with Apache License 2.0 | 6 votes |
@SuppressWarnings("deprecation") protected void checkApplication() { // 兼容旧版本 if (application == null) { String applicationName = ConfigUtils.getProperty("dubbo.application.name"); if (applicationName != null && applicationName.length() > 0) { application = new ApplicationConfig(); } } if (application == null) { throw new IllegalStateException( "No such application config! Please add <dubbo:application name=\"...\" /> to your spring config."); } appendProperties(application); String wait = ConfigUtils.getProperty(Constants.SHUTDOWN_WAIT_KEY); if (wait != null && wait.trim().length() > 0) { System.setProperty(Constants.SHUTDOWN_WAIT_KEY, wait.trim()); } else { wait = ConfigUtils.getProperty(Constants.SHUTDOWN_WAIT_SECONDS_KEY); if (wait != null && wait.trim().length() > 0) { System.setProperty(Constants.SHUTDOWN_WAIT_SECONDS_KEY, wait.trim()); } } }
Example #18
Source File: ExtensionLoader.java From dubbox-hystrix with Apache License 2.0 | 6 votes |
private boolean isActive(Activate activate, URL url) { String[] keys = activate.value(); if (keys == null || keys.length == 0) { return true; } for (String key : keys) { for (Map.Entry<String, String> entry : url.getParameters().entrySet()) { String k = entry.getKey(); String v = entry.getValue(); if ((k.equals(key) || k.endsWith("." + key)) && ConfigUtils.isNotEmpty(v)) { return true; } } } return false; }
Example #19
Source File: ValidationFilter.java From dubbo-2.6.5 with Apache License 2.0 | 6 votes |
@Override public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { if (validation != null && !invocation.getMethodName().startsWith("$") && ConfigUtils.isNotEmpty(invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.VALIDATION_KEY))) { try { Validator validator = validation.getValidator(invoker.getUrl()); if (validator != null) { validator.validate(invocation.getMethodName(), invocation.getParameterTypes(), invocation.getArguments()); } } catch (RpcException e) { throw e; } catch (Throwable t) { return new RpcResult(t); } } return invoker.invoke(invocation); }
Example #20
Source File: JavaConfigContainer.java From dubbox with Apache License 2.0 | 5 votes |
public void start() { String configPath = ConfigUtils.getProperty(SPRING_JAVACONFIG); if (configPath == null || configPath.length() == 0) { configPath = DEFAULT_SPRING_JAVACONFIG; } context = new AnnotationConfigApplicationContext(configPath); context.start(); }
Example #21
Source File: SimpleMonitorService.java From dubbo3 with Apache License 2.0 | 5 votes |
public SimpleMonitorService() { queue = new LinkedBlockingQueue<>(Integer.parseInt(ConfigUtils.getProperty("dubbo.monitor.queue", "100000"))); writeThread = new Thread(() -> { while (running) { try { write(); // 记录统计日志 } catch (Throwable t) { // 防御性容错 logger.error("Unexpected error occur at write stat log, cause: " + t.getMessage(), t); try { Thread.sleep(5000); // 失败延迟 } catch (Throwable ignore) { } } } }); writeThread.setDaemon(true); writeThread.setName("DubboMonitorAsyncWriteLogThread"); writeThread.start(); chartFuture = scheduledExecutorService.scheduleWithFixedDelay(() -> { try { draw(); // 绘制图表 } catch (Throwable t) { // 防御性容错 logger.error("Unexpected error occur at draw stat chart, cause: " + t.getMessage(), t); } }, 1, 300, TimeUnit.SECONDS); INSTANCE = this; }
Example #22
Source File: RocketMqTracingCollector.java From dubbo-plus with Apache License 2.0 | 5 votes |
public RocketMqTracingCollector() { defaultMQProducer = new DefaultMQProducer(DstConstants.ROCKET_MQ_PRODUCER); defaultMQProducer.setNamesrvAddr(ConfigUtils.getProperty(DstConstants.ROCKET_MQ_NAME_SRV_ADD)); try { defaultMQProducer.start(); } catch (MQClientException e) { throw new IllegalArgumentException("fail to start rocketmq producer.",e); } }
Example #23
Source File: JavaConfigContainer.java From dubbox with Apache License 2.0 | 5 votes |
public void start() { String configPath = ConfigUtils.getProperty(SPRING_JAVACONFIG); if (configPath == null || configPath.length() == 0) { configPath = DEFAULT_SPRING_JAVACONFIG; } context = new AnnotationConfigApplicationContext(configPath); context.start(); }
Example #24
Source File: AbstractInterfaceConfig.java From dubbox-hystrix with Apache License 2.0 | 5 votes |
protected URL loadMonitor(URL registryURL) { if (monitor == null) { String monitorAddress = ConfigUtils.getProperty("dubbo.monitor.address"); String monitorProtocol = ConfigUtils.getProperty("dubbo.monitor.protocol"); if (monitorAddress != null && monitorAddress.length() > 0 || monitorProtocol != null && monitorProtocol.length() > 0) { monitor = new MonitorConfig(); } else { return null; } } appendProperties(monitor); Map<String, String> map = new HashMap<String, String>(); map.put(Constants.INTERFACE_KEY, MonitorService.class.getName()); map.put("dubbo", Version.getVersion()); map.put(Constants.TIMESTAMP_KEY, String.valueOf(System.currentTimeMillis())); if (ConfigUtils.getPid() > 0) { map.put(Constants.PID_KEY, String.valueOf(ConfigUtils.getPid())); } appendParameters(map, monitor); String address = monitor.getAddress(); String sysaddress = System.getProperty("dubbo.monitor.address"); if (sysaddress != null && sysaddress.length() > 0) { address = sysaddress; } if (ConfigUtils.isNotEmpty(address)) { if (! map.containsKey(Constants.PROTOCOL_KEY)) { if (ExtensionLoader.getExtensionLoader(MonitorFactory.class).hasExtension("logstat")) { map.put(Constants.PROTOCOL_KEY, "logstat"); } else { map.put(Constants.PROTOCOL_KEY, "dubbo"); } } return UrlUtils.parseURL(address, map); } else if (Constants.REGISTRY_PROTOCOL.equals(monitor.getProtocol()) && registryURL != null) { return registryURL.setProtocol("dubbo").addParameter(Constants.PROTOCOL_KEY, "registry").addParameterAndEncoded(Constants.REFER_KEY, StringUtils.toQueryString(map)); } return null; }
Example #25
Source File: AbstractInterfaceConfig.java From dubbox with Apache License 2.0 | 5 votes |
protected URL loadMonitor(URL registryURL) { if (monitor == null) { String monitorAddress = ConfigUtils.getProperty("dubbo.monitor.address"); String monitorProtocol = ConfigUtils.getProperty("dubbo.monitor.protocol"); if (monitorAddress != null && monitorAddress.length() > 0 || monitorProtocol != null && monitorProtocol.length() > 0) { monitor = new MonitorConfig(); } else { return null; } } appendProperties(monitor); Map<String, String> map = new HashMap<String, String>(); map.put(Constants.INTERFACE_KEY, MonitorService.class.getName()); map.put("dubbo", Version.getVersion()); map.put(Constants.TIMESTAMP_KEY, String.valueOf(System.currentTimeMillis())); if (ConfigUtils.getPid() > 0) { map.put(Constants.PID_KEY, String.valueOf(ConfigUtils.getPid())); } appendParameters(map, monitor); String address = monitor.getAddress(); String sysaddress = System.getProperty("dubbo.monitor.address"); if (sysaddress != null && sysaddress.length() > 0) { address = sysaddress; } if (ConfigUtils.isNotEmpty(address)) { if (! map.containsKey(Constants.PROTOCOL_KEY)) { if (ExtensionLoader.getExtensionLoader(MonitorFactory.class).hasExtension("logstat")) { map.put(Constants.PROTOCOL_KEY, "logstat"); } else { map.put(Constants.PROTOCOL_KEY, "dubbo"); } } return UrlUtils.parseURL(address, map); } else if (Constants.REGISTRY_PROTOCOL.equals(monitor.getProtocol()) && registryURL != null) { return registryURL.setProtocol("dubbo").addParameter(Constants.PROTOCOL_KEY, "registry").addParameterAndEncoded(Constants.REFER_KEY, StringUtils.toQueryString(map)); } return null; }
Example #26
Source File: JettyContainer.java From dubbox with Apache License 2.0 | 5 votes |
public void start() { String serverPort = ConfigUtils.getProperty(JETTY_PORT); int port; if (serverPort == null || serverPort.length() == 0) { port = DEFAULT_JETTY_PORT; } else { port = Integer.parseInt(serverPort); } connector = new SelectChannelConnector(); connector.setPort(port); ServletHandler handler = new ServletHandler(); String resources = ConfigUtils.getProperty(JETTY_DIRECTORY); if (resources != null && resources.length() > 0) { FilterHolder resourceHolder = handler.addFilterWithMapping(ResourceFilter.class, "/*", Handler.DEFAULT); resourceHolder.setInitParameter("resources", resources); } ServletHolder pageHolder = handler.addServletWithMapping(PageServlet.class, "/*"); pageHolder.setInitParameter("pages", ConfigUtils.getProperty(JETTY_PAGES)); pageHolder.setInitOrder(2); Server server = new Server(); server.addConnector(connector); server.addHandler(handler); try { server.start(); } catch (Exception e) { throw new IllegalStateException("Failed to start jetty server on " + NetUtils.getLocalHost() + ":" + port + ", cause: " + e.getMessage(), e); } }
Example #27
Source File: TokenFilter.java From dubbox-hystrix with Apache License 2.0 | 5 votes |
public Result invoke(Invoker<?> invoker, Invocation inv) throws RpcException { String token = invoker.getUrl().getParameter(Constants.TOKEN_KEY); if (ConfigUtils.isNotEmpty(token)) { Class<?> serviceType = invoker.getInterface(); Map<String, String> attachments = inv.getAttachments(); String remoteToken = attachments == null ? null : attachments.get(Constants.TOKEN_KEY); if (! token.equals(remoteToken)) { throw new RpcException("Invalid token! Forbid invoke remote service " + serviceType + " method " + inv.getMethodName() + "() from consumer " + RpcContext.getContext().getRemoteHost() + " to provider " + RpcContext.getContext().getLocalHost()); } } return invoker.invoke(inv); }
Example #28
Source File: MockInvoker.java From dubbox-hystrix with Apache License 2.0 | 5 votes |
private String normallizeMock(String mock) { if (mock == null || mock.trim().length() ==0){ return mock; } else if (ConfigUtils.isDefault(mock) || "fail".equalsIgnoreCase(mock.trim()) || "force".equalsIgnoreCase(mock.trim())){ mock = url.getServiceInterface()+"Mock"; } if (mock.startsWith(Constants.FAIL_PREFIX)) { mock = mock.substring(Constants.FAIL_PREFIX.length()).trim(); } else if (mock.startsWith(Constants.FORCE_PREFIX)) { mock = mock.substring(Constants.FORCE_PREFIX.length()).trim(); } return mock; }
Example #29
Source File: DubboProviderMain.java From castle-example with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws Exception { StaticConfigSupplier.append("config.properties"); String[] customArgs = new String[] { "javaconfig" }; Properties properties = new Properties(); properties.setProperty(JavaConfigContainer.SPRING_JAVACONFIG, "com.whenling"); ConfigUtils.setProperties(properties); com.alibaba.dubbo.container.Main.main(customArgs); }
Example #30
Source File: JettyContainer.java From dubbox with Apache License 2.0 | 5 votes |
public void start() { String serverPort = ConfigUtils.getProperty(JETTY_PORT); int port; if (serverPort == null || serverPort.length() == 0) { port = DEFAULT_JETTY_PORT; } else { port = Integer.parseInt(serverPort); } connector = new SelectChannelConnector(); connector.setPort(port); ServletHandler handler = new ServletHandler(); String resources = ConfigUtils.getProperty(JETTY_DIRECTORY); if (resources != null && resources.length() > 0) { FilterHolder resourceHolder = handler.addFilterWithMapping(ResourceFilter.class, "/*", Handler.DEFAULT); resourceHolder.setInitParameter("resources", resources); } ServletHolder pageHolder = handler.addServletWithMapping(PageServlet.class, "/*"); pageHolder.setInitParameter("pages", ConfigUtils.getProperty(JETTY_PAGES)); pageHolder.setInitOrder(2); Server server = new Server(); server.addConnector(connector); server.addHandler(handler); try { server.start(); } catch (Exception e) { throw new IllegalStateException("Failed to start jetty server on " + NetUtils.getLocalHost() + ":" + port + ", cause: " + e.getMessage(), e); } }