All Downloads are FREE. Search and download functionalities are using the official Maven repository.

scouter.xtra.httpclient.SpringRestTemplateHttpRequest Maven / Gradle / Ivy

There is a newer version: 2.20.0
Show newest version
package scouter.xtra.httpclient;

import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpRequest;
import scouter.agent.proxy.IHttpClient;

import java.util.List;

public class SpringRestTemplateHttpRequest implements IHttpClient {
	public String getHost(Object o) {
		if (o instanceof HttpRequest) {
			HttpRequest chr = (HttpRequest) o;
			return chr.getURI().getHost() + ":" + chr.getURI().getPort();
		}

		return o.toString();
	}

	public void addHeader(Object o, String key, String value) {
		if (o instanceof HttpRequest) {
			HttpRequest chr = (HttpRequest) o;
			HttpHeaders headers = chr.getHeaders();
			headers.set(key, value);
		}
	}

	public String getHeader(Object o, String key) {
		if (o instanceof HttpRequest) {
			HttpRequest chr = (HttpRequest) o;
			List headerValues = chr.getHeaders().get(key);
			if(headerValues != null && headerValues.size() > 0) {
				return headerValues.get(0);
			}
		}
		return null;
	}

	public String getURI(Object o) {
		if (o instanceof HttpRequest) {
			HttpRequest chr = (HttpRequest) o;
			return chr.getURI().getPath();
		}
		return o.toString();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy