List of usage examples for org.springframework.util ReflectionUtils rethrowRuntimeException
public static void rethrowRuntimeException(Throwable ex)
From source file:org.springframework.cloud.etcd.discovery.EtcdDiscoveryProperties.java
public static InetAddress getIpAddress() { try {// ww w.j a va2s . co m for (Enumeration<NetworkInterface> enumNic = NetworkInterface.getNetworkInterfaces(); enumNic .hasMoreElements();) { NetworkInterface ifc = enumNic.nextElement(); if (ifc.isUp()) { for (Enumeration<InetAddress> enumAddr = ifc.getInetAddresses(); enumAddr.hasMoreElements();) { InetAddress address = enumAddr.nextElement(); if (address instanceof Inet4Address && !address.isLoopbackAddress()) { return address; } } } } return InetAddress.getLocalHost(); } catch (UnknownHostException e) { ReflectionUtils.rethrowRuntimeException(e); return null; } catch (IOException e) { log.warn("Unable to find non-loopback address", e); return null; } }
From source file:org.springframework.cloud.etcd.discovery.EtcdLifecycle.java
protected void register(Service service) { try {/*from ww w . j ava2 s . c om*/ log.info("Registering service with etcd: " + service); String key = getServiceKey(service.appName, service.getId()); //TODO: what should be serialized about the service? String value = props.getHostname() + ":" + service.getPort(); etcd.put(key, value).ttl(props.getTtl()).send().get(); } catch (IOException | TimeoutException | EtcdException e) { ReflectionUtils.rethrowRuntimeException(e); } }
From source file:org.springframework.cloud.etcd.discovery.EtcdLifecycle.java
private void deregister(String appName, String serviceId) { try {//from ww w .j ava 2 s. co m etcd.delete(getServiceKey(appName, serviceId)).send(); } catch (IOException e) { ReflectionUtils.rethrowRuntimeException(e); } }
From source file:org.springframework.cloud.etcd.discovery.EtcdServerList.java
private List<EtcdServer> getServers() { List<EtcdServer> servers = null; try {//w w w . j ava2s.c o m if (etcd == null) { return Collections.emptyList(); } EtcdKeysResponse response = etcd.getDir(props.getDiscoveryPrefix() + "/" + serviceId).send().get(); if (response.node.nodes == null || response.node.nodes.isEmpty()) { return Collections.emptyList(); } servers = new ArrayList<>(); for (EtcdNode node : response.node.nodes) { String[] appInfo = getAppInfo(node.key); String[] strings = node.value.split(":"); EtcdServer server = new EtcdServer(appInfo[0], appInfo[1], strings[0], strings[1]); servers.add(server); } } catch (IOException | TimeoutException | EtcdException e) { ReflectionUtils.rethrowRuntimeException(e); } return servers; }
From source file:org.springframework.cloud.netflix.zuul.filters.post.SendErrorFilter.java
@Override public Object run() { try {/*from ww w. j ava 2s. c o m*/ RequestContext ctx = RequestContext.getCurrentContext(); ZuulException exception = findZuulException(ctx.getThrowable()); HttpServletRequest request = ctx.getRequest(); request.setAttribute("javax.servlet.error.status_code", exception.nStatusCode); log.warn("Error during filtering", exception); request.setAttribute("javax.servlet.error.exception", exception); if (StringUtils.hasText(exception.errorCause)) { request.setAttribute("javax.servlet.error.message", exception.errorCause); } RequestDispatcher dispatcher = request.getRequestDispatcher(this.errorPath); if (dispatcher != null) { ctx.set(SEND_ERROR_FILTER_RAN, true); if (!ctx.getResponse().isCommitted()) { dispatcher.forward(request, ctx.getResponse()); } } } catch (Exception ex) { ReflectionUtils.rethrowRuntimeException(ex); } return null; }
From source file:org.springframework.cloud.zookeeper.config.ZookeeperPropertySource.java
private byte[] getPropertyBytes(String fullPath) { try {/*from w ww . ja va 2s . c o m*/ byte[] bytes = null; try { bytes = this.getSource().getData().forPath(fullPath); } catch (KeeperException e) { if (e.code() != KeeperException.Code.NONODE) { // not found throw e; } } return bytes; } catch (Exception exception) { ReflectionUtils.rethrowRuntimeException(exception); } return null; }
From source file:org.springframework.cloud.zookeeper.config.ZookeeperPropertySource.java
private void findProperties(String path) { try {//from w ww . j a va2 s . com log.trace("entering findProperties for path: " + path); List<String> children = null; try { children = this.getSource().getChildren().forPath(path); } catch (KeeperException e) { if (e.code() != KeeperException.Code.NONODE) { // not found throw e; } } if (children == null || children.isEmpty()) { return; } for (String child : children) { String childPath = path + "/" + child; byte[] bytes = getPropertyBytes(childPath); if (bytes == null || bytes.length == 0) { findProperties(childPath); } else { String key = sanitizeKey(childPath); this.properties.put(key, new String(bytes, Charset.forName("UTF-8"))); } } log.trace("leaving findProperties for path: " + path); } catch (Exception exception) { ReflectionUtils.rethrowRuntimeException(exception); } }
From source file:org.springframework.cloud.zookeeper.config.ZookeeperPropertySourceLocator.java
@Override public PropertySource<?> locate(Environment environment) { if (environment instanceof ConfigurableEnvironment) { ConfigurableEnvironment env = (ConfigurableEnvironment) environment; String appName = env.getProperty("spring.application.name"); List<String> profiles = Arrays.asList(env.getActiveProfiles()); String root = this.properties.getRoot(); this.contexts = new ArrayList<>(); String defaultContext = root + "/" + this.properties.getDefaultContext(); this.contexts.add(defaultContext); addProfiles(this.contexts, defaultContext, profiles); StringBuilder baseContext = new StringBuilder(root); if (!appName.startsWith("/")) { baseContext.append("/"); }/*from ww w . j a v a2 s . co m*/ baseContext.append(appName); this.contexts.add(baseContext.toString()); addProfiles(this.contexts, baseContext.toString(), profiles); CompositePropertySource composite = new CompositePropertySource("zookeeper"); Collections.reverse(this.contexts); for (String propertySourceContext : this.contexts) { try { PropertySource propertySource = create(propertySourceContext); composite.addPropertySource(propertySource); // TODO: howto call close when /refresh } catch (Exception e) { if (this.properties.isFailFast()) { ReflectionUtils.rethrowRuntimeException(e); } else { log.warn("Unable to load zookeeper config from " + propertySourceContext, e); } } } return composite; } return null; }
From source file:org.springframework.cloud.zookeeper.discovery.ZookeeperDiscoveryClient.java
@Override public List<org.springframework.cloud.client.ServiceInstance> getInstances(final String serviceId) { try {/*from w w w . j av a 2s . c om*/ String serviceIdToQuery = getServiceIdToQuery(serviceId); Collection<ServiceInstance<ZookeeperInstance>> zkInstances = this.serviceDiscovery.getServiceDiscovery() .queryForInstances(serviceIdToQuery); List<org.springframework.cloud.client.ServiceInstance> instances = new ArrayList<>(); for (ServiceInstance<ZookeeperInstance> instance : zkInstances) { instances.add(createServiceInstance(serviceIdToQuery, instance)); } return instances; } catch (Exception exception) { ReflectionUtils.rethrowRuntimeException(exception); } return new ArrayList<>(); }
From source file:org.springframework.cloud.zookeeper.discovery.ZookeeperLifecycle.java
@Override protected void register() { if (!this.properties.isRegister()) { log.debug("Registration disabled."); return;//from w w w. j a va 2s.com } try { this.serviceDiscovery.getServiceDiscovery().start(); } catch (Exception e) { ReflectionUtils.rethrowRuntimeException(e); } }