Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@khoubyari
khoubyari / gist:72f142f17d484b707b1f7ba4938d6f7f
Created May 11, 2017 22:17
How to configure the embedded Tomcat container in Spring Boot
//in Application.java
@Bean
public EmbeddedServletContainerFactory servletContainer() {
TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory();
tomcat.setProtocol("org.apache.coyote.http11.Http11Nio2Protocol");
tomcat.addContextCustomizers((context) -> {
StandardRoot standardRoot = new StandardRoot(context);
standardRoot.setCacheMaxSize(64 * 1024);
@khoubyari
khoubyari / gist:121ae53fa83e23c0424938290cf5483f
Created May 11, 2017 21:43
How to configure the Async executor in Spring Boot
// reference: http://www.baeldung.com/spring-async , http://javasampleapproach.com/java-integration/start-spring-async-spring-boot
...
//in ExecutorConfig.java
@Configuration
@EnableAsync
public class AsyncConfiguration {
@Bean(name = "myAsyncExecutor")
public Executor asyncExecutor() {
@khoubyari
khoubyari / boot_monitor.py
Created March 25, 2016 17:54
Python server plugin for monitoring a Spring Boot microservice health check
import os, sys, requests, json, argparse
if __name__=='__main__':
fileName = os.path.basename(__file__)
parser = argparse.ArgumentParser(description='Monitor a spring boot healthcheck.',
epilog='Examples: "' + fileName + ' -i localhost:8080 -s myService" OR "'+fileName+' -i myhost.example.com:8001"')
parser.add_argument('-i', '--host', help="The hostname or hostname:port portion of the service)", required=True)
parser.add_argument('-t', '--https', help="Turn on SSL (use HTTPS instead of HTTP)", action='store_true', default=False)
parser.add_argument('-s', '--service', help="The case-sensitive name of the service for including the service-specific section inside the health check response", required=False)
@khoubyari
khoubyari / gist:ed4c7e6935e469c6bc6b
Last active March 4, 2016 22:58
Configuring HAProxy 1.5.x to add Basic Auth and Health Check
#
#1. Add an ACL for the top level routes you need to proxy
#
acl routes_to_proxy path_beg -i /my/path /other-path
#
#2. Associate the routes with a backend
#
use_backend my_backend if routes_to_proxy
#
#3. Create a list of credentials (note: passwords are in clear text. this is bad security practice.)
@khoubyari
khoubyari / jackson-test
Created June 4, 2015 00:21
Jackson JSON (De)Serialization Test
public abstract class AbstractJackson2MarshallingTest {
protected ObjectMapper mapper;
@Before
public void setUp() {
mapper = new ObjectMapper();
mapper.enable(SerializationFeature.INDENT_OUTPUT);
}
@khoubyari
khoubyari / python-rest-json
Last active August 5, 2017 04:09
Python: Call REST API and access the JSON results (no authentication)
# tested with Python 2.7.5
import json
import urllib2
api_url = "http://jsonplaceholder.typicode.com/users"
# API below returns an array of complex JSON objects
jsonobj = json.load(urllib2.urlopen(api_url))
# index into the array and access a sub-attribute like this: