use of org.apache.commons.httpclient.URI in project pinot by linkedin.
the class ServerTableSizeReader method getSizeDetailsFromServers.
public Map<String, List<SegmentSizeInfo>> getSizeDetailsFromServers(BiMap<String, String> serverEndPoints, String table, int timeoutMsec) {
List<String> serverUrls = new ArrayList<>(serverEndPoints.size());
BiMap<String, String> endpointsToServers = serverEndPoints.inverse();
for (String endpoint : endpointsToServers.keySet()) {
String tableSizeUri = "http://" + endpoint + "/table/" + table + "/size";
serverUrls.add(tableSizeUri);
}
MultiGetRequest mget = new MultiGetRequest(executor, connectionManager);
LOGGER.info("Reading segment sizes from servers for table: {}, timeoutMsec: {}", table, timeoutMsec);
CompletionService<GetMethod> completionService = mget.execute(serverUrls, timeoutMsec);
Map<String, List<SegmentSizeInfo>> serverSegmentSizes = new HashMap<>(serverEndPoints.size());
for (int i = 0; i < serverUrls.size(); i++) {
GetMethod getMethod = null;
try {
getMethod = completionService.take().get();
URI uri = getMethod.getURI();
String instance = endpointsToServers.get(uri.getHost() + ":" + uri.getPort());
if (getMethod.getStatusCode() >= 300) {
LOGGER.error("Server: {} returned error: {}", instance, getMethod.getStatusCode());
continue;
}
TableSizeInfo tableSizeInfo = new ObjectMapper().readValue(getMethod.getResponseBodyAsString(), TableSizeInfo.class);
serverSegmentSizes.put(instance, tableSizeInfo.segments);
} catch (InterruptedException e) {
LOGGER.warn("Interrupted exception while reading segment size for table: {}", table, e);
} catch (ExecutionException e) {
if (Throwables.getRootCause(e) instanceof SocketTimeoutException) {
LOGGER.warn("Server request to read table size was timed out for table: {}", table, e);
} else if (Throwables.getRootCause(e) instanceof ConnectTimeoutException) {
LOGGER.warn("Server request to read table size timed out waiting for connection. table: {}", table, e);
} else if (Throwables.getRootCause(e) instanceof ConnectionPoolTimeoutException) {
LOGGER.warn("Server request to read table size timed out on getting a connection from pool, table: {}", table, e);
} else {
LOGGER.warn("Execution exception while reading segment sizes for table: {}", table, e);
}
} catch (Exception e) {
LOGGER.warn("Error while reading segment sizes for table: {}", table);
} finally {
if (getMethod != null) {
getMethod.releaseConnection();
}
}
}
LOGGER.info("Finished reading segment sizes for table: {}", table);
return serverSegmentSizes;
}
use of org.apache.commons.httpclient.URI in project pinpoint by naver.
the class HttpMethodBaseExecuteMethodInterceptor method recordDestination.
private void recordDestination(final Trace trace, final HttpMethod httpMethod, final Object[] args) {
final SpanEventRecorder recorder = trace.currentSpanEventRecorder();
try {
final URI uri = httpMethod.getURI();
final HttpConnection httpConnection = getHttpConnection(args);
// if uri have schema or not found HttpConnection argument.
if (uri.isAbsoluteURI() || httpConnection == null) {
recorder.recordAttribute(AnnotationKey.HTTP_URL, InterceptorUtils.getHttpUrl(uri.getURI(), param));
recorder.recordDestinationId(getEndpoint(uri.getHost(), uri.getPort()));
return;
}
if (isDebug) {
logger.debug("URI is not absolute. {}", uri.getURI());
}
// use HttpConnection argument.
final String host = httpConnection.getHost();
int port = httpConnection.getPort();
final StringBuilder httpUrl = new StringBuilder();
final Protocol protocol = httpConnection.getProtocol();
if (protocol != null) {
httpUrl.append(protocol.getScheme()).append("://");
httpUrl.append(httpConnection.getHost());
// if port is default port number.
if (httpConnection.getPort() == protocol.getDefaultPort()) {
port = -1;
} else {
httpUrl.append(":").append(port);
}
}
httpUrl.append(uri.getURI());
recorder.recordAttribute(AnnotationKey.HTTP_URL, InterceptorUtils.getHttpUrl(httpUrl.toString(), param));
recorder.recordDestinationId(getEndpoint(host, port));
} catch (URIException e) {
logger.error("Fail get URI", e);
recorder.recordDestinationId("unknown");
}
}
use of org.apache.commons.httpclient.URI in project zaproxy by zaproxy.
the class AbstractDefaultFilePlugin method createURI.
private URI createURI(URI base, String dir, String file) throws URIException {
if (!dir.startsWith("/")) {
dir = "/" + dir;
}
if (!file.startsWith("/") && !dir.endsWith("/")) {
file = "/" + file;
}
String path = dir + file;
URI uri = new URI(base, path, true);
return uri;
}
use of org.apache.commons.httpclient.URI in project zaproxy by zaproxy.
the class AbstractDefaultFilePlugin method scan.
@Override
public void scan() {
for (int i = 0; i < getListURI().size() && !isStop(); i++) {
// ZAP: Removed unnecessary cast.
URI uri = getListURI().get(i);
HttpMessage msg = getNewMsg();
try {
msg.getRequestHeader().setURI(uri);
msg.getRequestBody().setLength(0);
sendAndReceive(msg);
if (isFileExist(msg)) {
bingo(Alert.RISK_MEDIUM, Alert.CONFIDENCE_LOW, uri.toString(), "", "", "", "", msg);
}
} catch (Exception e) {
}
}
}
use of org.apache.commons.httpclient.URI in project zaproxy by zaproxy.
the class Analyser method isFileExist.
public boolean isFileExist(HttpMessage msg) {
if (msg.getResponseHeader().isEmpty()) {
return false;
}
// RFC
if (msg.getResponseHeader().getStatusCode() == HttpStatusCode.NOT_FOUND) {
return false;
}
// ZAP: catch CloneNotSupportedException as introduced with version 3.1 of HttpClient
URI uri = null;
String sUri = null;
try {
uri = (URI) msg.getRequestHeader().getURI().clone();
// strip off last part of path - use folder only
uri.setQuery(null);
String path = uri.getPath();
path = path.replaceAll("/[^/]*$", "");
uri.setPath(path);
} catch (Exception e) {
} finally {
if (uri != null) {
sUri = uri.toString();
}
}
// get sample with same relative path position when possible.
// if not exist, use the host only
// ZAP: Removed unnecessary cast.
SampleResponse sample = mapVisited.get(sUri);
if (sample == null) {
try {
uri.setPath(null);
} catch (URIException e2) {
}
String sHostOnly = uri.toString();
// ZAP: Removed unnecessary cast.
sample = mapVisited.get(sHostOnly);
}
// check if any analysed result.
if (sample == null) {
if (msg.getResponseHeader().getStatusCode() == HttpStatusCode.OK) {
// no anlaysed result to confirm, assume file exist and return
return true;
} else {
return false;
}
}
// check for redirect response. If redirect to same location, then file does not exist
if (HttpStatusCode.isRedirection(msg.getResponseHeader().getStatusCode())) {
try {
if (sample.getMessage().getResponseHeader().getStatusCode() == msg.getResponseHeader().getStatusCode()) {
String location = msg.getResponseHeader().getHeader(HttpHeader.LOCATION);
if (location != null && location.equals(sample.getMessage().getResponseHeader().getHeader(HttpHeader.LOCATION))) {
return false;
}
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
return true;
}
// Not success code
if (msg.getResponseHeader().getStatusCode() != HttpStatusCode.OK) {
return false;
}
// remain only OK response here
// nothing more to determine. Check for possible not found page pattern.
Matcher matcher = patternNotFound.matcher(msg.getResponseBody().toString());
if (matcher.find()) {
return false;
}
// static response
String body = msg.getResponseBody().toString().replaceAll(p_REMOVE_HEADER, "");
if (sample.getErrorPageType() == SampleResponse.ERROR_PAGE_STATIC) {
try {
if (sample.getMessage().getResponseBody().toString().equals(body)) {
return false;
}
} catch (HttpMalformedHeaderException | DatabaseException e) {
logger.error("Failed to read the message: " + e.getMessage(), e);
}
return true;
}
uri = msg.getRequestHeader().getURI();
try {
if (sample.getErrorPageType() == SampleResponse.ERROR_PAGE_DYNAMIC_BUT_DETERMINISTIC) {
body = msg.getResponseBody().toString().replaceAll(getPathRegex(uri), "").replaceAll("\\s[012]\\d:[0-5]\\d:[0-5]\\d\\s", "");
// ZAP: FindBugs fix - added call to HttpBody.toString()
if (sample.getMessage().getResponseBody().toString().equals(body)) {
return false;
}
return true;
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
return true;
}
Aggregations