Skip to content

Instantly share code, notes, and snippets.

@omidp
omidp / GatewayContext.java
Last active February 27, 2022 16:55
scg-body-cache
import org.springframework.util.MultiValueMap;
public class GatewayContext {
public static final String CACHE_GATEWAY_CONTEXT = "cacheGatewayContext";
/**
* cache json body
@omidp
omidp / pidmonitor
Created February 15, 2022 07:20
monitor cpu and mem for a pid
vi pdmonitor.sh
###########
#!/bin/sh
while true
do
date
ps -p [PID] -o %cpu,%mem
sleep 5
@omidp
omidp / ClientHttpPoolConfiguration.java
Created January 23, 2022 07:54 — forked from soverby/ClientHttpPoolConfiguration.java
RestTemplate backed by Apache HttpClient Connection Pool. Addresses RestTemplate HttpConnection exhaustion. Note this implementation is not route tunable and should be expanded when tuning by route is required. Example error: I/O error on POST request for "https://someendpoint": Timeout waiting for connection from pool; nested exception is org.a…
import org.apache.http.client.config.RequestConfig;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class ClientHttpPoolConfiguration {
@omidp
omidp / check active connection netstat
Created December 29, 2021 11:28
check active connection netstat
netstat -anp | grep :80 | grep ESTABLISHED | wc -l
netstat -anp | grep :80 | grep WAITED | wc -l
@omidp
omidp / ab on windows
Created December 17, 2021 06:52
ab on windows
https://www.cedric-dumont.com/2017/02/01/install-apache-benchmarking-tool-ab-on-windows/
https://www.apachelounge.com/download/
ab -n 100 -c 10 http://yourserver/yourapi
# content.json contains the json you want to post
# -p means to POST it
# -H adds an Auth header (could be Basic or Token)
# -T sets the Content-Type
@omidp
omidp / httpmethodgatewayfilter
Created December 12, 2021 10:06
spring cloud gateway http method filter
package com.cloud.gateway.app;
import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.setResponseStatus;
import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
import org.springframework.cloud.gateway.support.HttpStatusHolder;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
@omidp
omidp / instancerouter
Created October 15, 2021 04:53
instance router
System.out.println(env);
List<InstanceInfo> instanceList = dc.getApplication("USER-SERVICE").getInstances().stream().filter(f->{
return f.getMetadata() != null && env.equals(f.getMetadata().get("env"));
}).collect(Collectors.toList());
int randomElementIndex
= ThreadLocalRandom.current().nextInt(instanceList.size()) % instanceList.size();
InstanceInfo instanceInfo = instanceList.get(randomElementIndex);
System.out.println(instanceInfo.getHomePageUrl());
@omidp
omidp / pdep
Created August 1, 2021 17:30 — forked from robertbraeutigam/pdep
Small shell-script to visualize import dependencies between Java classes.
#!/bin/sh
cat >dependencies.dot <<EOF
digraph g {
graph [
rankdir = "LR"
];
node [
fontsize = "12"
fontname = "Courier"
@omidp
omidp / springbootmdcawarelog
Created May 10, 2021 12:16
springbootmdcawarelog
void insertIntoMDC(ServletRequest request, String userName) {
MDC.put(USER_NAME_MDC_KEY, userName);
MDC.put(ClassicConstants.REQUEST_REMOTE_HOST_MDC_KEY, request.getRemoteHost());
if (request instanceof HttpServletRequest) {
HttpServletRequest httpServletRequest = (HttpServletRequest) request;
MDC.put(ClassicConstants.REQUEST_REQUEST_URI, httpServletRequest.getRequestURI());
StringBuffer requestURL = httpServletRequest.getRequestURL();
if (requestURL != null) {
MDC.put(ClassicConstants.REQUEST_REQUEST_URL, requestURL.toString());
@omidp
omidp / freerdp
Created May 9, 2021 07:23
freerdp windows remote desktop
xfreerdp +clipboard /u:admin /v:46.ip +toggle-fullscreen /w:1024 /h:768 /drive:shared,/home/omidp/temp