List of usage examples for org.apache.commons.httpclient URI getPort
public int getPort()
From source file:com.eviware.soapui.impl.support.HttpUtils.java
public static java.net.URI createUri(URI uri) throws URISyntaxException, URIException { return createUri(uri.getScheme(), uri.getUserinfo(), uri.getHost(), uri.getPort(), uri.getEscapedPath(), uri.getEscapedQuery(), uri.getEscapedFragment()); }
From source file:com.linkedin.pinot.controller.api.restlet.resources.ServerTableSizeReader.java
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);/*from www . j ava 2 s . c om*/ } 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++) { try { GetMethod 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); } } LOGGER.info("Finished reading segment sizes for table: {}", table); return serverSegmentSizes; }
From source file:com.linkedin.pinot.controller.api.resources.ServerTableSizeReader.java
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);/* w ww .java 2 s . com*/ } 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; }
From source file:com.eviware.soapui.impl.wsdl.submit.filters.EndpointRequestFilter.java
@Override public void filterAbstractHttpRequest(SubmitContext context, AbstractHttpRequest<?> request) { HttpRequestBase httpMethod = (HttpRequestBase) context.getProperty(BaseHttpRequestTransport.HTTP_METHOD); String strURL = request.getEndpoint(); strURL = PropertyExpander.expandProperties(context, strURL); try {/*w ww.j a v a 2s. c o m*/ if (StringUtils.hasContent(strURL)) { URI uri = new URI(strURL, request.getSettings().getBoolean(HttpSettings.ENCODED_URLS)); context.setProperty(BaseHttpRequestTransport.REQUEST_URI, uri); httpMethod.setURI(new java.net.URI(uri.getScheme(), uri.getUserinfo(), uri.getHost(), uri.getPort(), (uri.getPath()) == null ? "/" : uri.getPath(), uri.getQuery(), uri.getFragment())); } } catch (Exception e) { SoapUI.logError(e); } }
From source file:com.navercorp.pinpoint.plugin.httpclient3.HttpClient3RequestTrace.java
@Override public String getHost() { try {//from w ww.ja v a 2s .c o m final URI uri = this.httpMethod.getURI(); // if uri have schema if (uri.isAbsoluteURI()) { return getEndpoint(uri.getHost(), uri.getPort()); } if (this.httpConnection != null) { final String host = this.httpConnection.getHost(); final int port = getPort(this.httpConnection); return getEndpoint(host, port); } } catch (Exception e) { if (isDebug) { logger.debug("Failed to get host. httpMethod={}", this.httpMethod, e); } } return null; }
From source file:com.navercorp.pinpoint.plugin.httpclient3.interceptor.HttpMethodBaseExecuteMethodInterceptor.java
private String getHost(HttpMethod httpMethod, HttpConnection httpConnection) { try {//from w ww .j a v a 2 s .c o m final URI uri = httpMethod.getURI(); // if uri have schema if (uri.isAbsoluteURI()) { return HttpClient3RequestWrapper.getEndpoint(uri.getHost(), uri.getPort()); } if (httpConnection != null) { final String host = httpConnection.getHost(); final int port = HttpClient3RequestWrapper.getPort(httpConnection); return HttpClient3RequestWrapper.getEndpoint(host, port); } } catch (Exception e) { if (isDebug) { logger.debug("Failed to get host. httpMethod={}", httpMethod, e); } } return null; }
From source file:com.navercorp.pinpoint.plugin.httpclient3.HttpClient3RequestTrace.java
@Override public String getDestinationId() { try {/*from w w w .j a v a 2 s . c om*/ final URI uri = this.httpMethod.getURI(); // if uri have schema or not found HttpConnection argument. if (uri.isAbsoluteURI() || this.httpConnection == null) { return getEndpoint(uri.getHost(), uri.getPort()); } final String host = this.httpConnection.getHost(); final int port = getPort(this.httpConnection); return getEndpoint(host, port); } catch (Exception e) { if (isDebug) { logger.debug("Failed to get destinationId. httpMethod={}", this.httpMethod, e); } } return "unknown"; }
From source file:com.baidu.oped.apm.profiler.modifier.connector.httpclient3.interceptor.ExecuteInterceptor.java
@Override public void after(Object target, Object[] args, Object result, Throwable throwable) { if (isDebug) { logger.afterInterceptor(target, args); }//from w ww . j a v a 2s . c o m final Trace trace = traceContext.currentTraceObject(); if (trace == null) { return; } try { HttpMethod httpMethod = getHttpMethod(args); if (httpMethod != null) { try { final URI uri = httpMethod.getURI(); String uriString = uri.getURI(); trace.recordAttribute(AnnotationKey.HTTP_URL, uriString); trace.recordDestinationId(getEndpoint(uri.getHost(), uri.getPort())); } catch (URIException e) { logger.error("Fail get URI", e); } recordRequest(trace, httpMethod, throwable); } if (result != null) { trace.recordAttribute(AnnotationKey.HTTP_STATUS_CODE, result); } trace.recordApi(descriptor); trace.recordException(throwable); trace.markAfterTime(); } finally { trace.traceBlockEnd(); } }
From source file:com.navercorp.pinpoint.plugin.httpclient3.interceptor.ExecuteInterceptor.java
@Override public void after(Object target, Object[] args, Object result, Throwable throwable) { if (isDebug) { logger.afterInterceptor(target, args); }// w w w . ja v a 2 s . c om final Trace trace = traceContext.currentTraceObject(); if (trace == null) { return; } try { HttpMethod httpMethod = getHttpMethod(args); if (httpMethod != null) { try { final URI uri = httpMethod.getURI(); String uriString = uri.getURI(); trace.recordAttribute(AnnotationKey.HTTP_URL, uriString); trace.recordDestinationId(getEndpoint(uri.getHost(), uri.getPort())); } catch (URIException e) { logger.error("Fail get URI", e); } recordRequest(trace, httpMethod, throwable); } if (result != null) { trace.recordAttribute(AnnotationKey.HTTP_STATUS_CODE, result); } trace.recordApi(descriptor); trace.recordException(throwable); trace.markAfterTime(); } finally { trace.traceBlockEnd(); } }
From source file:com.eviware.soapui.impl.wsdl.submit.transports.http.HttpClientRequestTransport.java
private ExtendedGetMethod followRedirects(HttpClient httpClient, int redirectCount, ExtendedHttpMethod httpMethod, org.apache.http.HttpResponse httpResponse, HttpContext httpContext) throws Exception { ExtendedGetMethod getMethod = new ExtendedGetMethod(); getMethod.getMetrics().getTotalTimer().set(httpMethod.getMetrics().getTotalTimer().getStart(), httpMethod.getMetrics().getTotalTimer().getStop()); getMethod.getMetrics().setHttpMethod(httpMethod.getMethod()); captureMetrics(httpMethod, httpClient); String location = httpResponse.getFirstHeader("Location").getValue(); URI uri = new URI(new URI(httpMethod.getURI().toString(), true), location, true); java.net.URI newUri = new java.net.URI(uri.getScheme(), uri.getUserinfo(), uri.getHost(), uri.getPort(), uri.getPath(), uri.getQuery(), uri.getFragment()); getMethod.setURI(newUri);//w ww.j av a2s .c om org.apache.http.HttpResponse response = HttpClientSupport.execute(getMethod, httpContext); if (isRedirectResponse(response.getStatusLine().getStatusCode())) { if (redirectCount == 10) throw new Exception("Maximum number of Redirects reached [10]"); try { getMethod = followRedirects(httpClient, redirectCount + 1, getMethod, response, httpContext); } finally { //getMethod.releaseConnection(); } } for (Header header : httpMethod.getAllHeaders()) getMethod.addHeader(header); return getMethod; }