List of usage examples for org.apache.http.client.utils URIBuilder getPath
public String getPath()
From source file:org.berlin.crawl.parse.WebParser.java
protected String fullURL(final Link link, final URIBuilder lastBuilder, final Set<String> urls) { final String uri = link.getUri().trim(); final boolean basicExclude = (uri.length() != 0) && !uri.equals("/"); if (basicExclude) { String fullURL = ""; // We have some URL's if (extractLinks(uri).size() > 0) { // First add full URL to set // fullURL = uri;/*from w ww. j a va 2 s . com*/ } else { if (uri.startsWith("/")) { fullURL = lastBuilder.getScheme() + "://" + lastBuilder.getHost() + uri; } else { final String path = parsePath(lastBuilder.getPath()); fullURL = lastBuilder.getScheme() + "://" + lastBuilder.getHost() + path + uri; } // End of the if - else // } // End // if (urls.contains(fullURL)) { // Return null so we don't reprocess return null; } // We should have a valid full URL. urls.add(fullURL); return fullURL; } // End of the if // return null; }
From source file:fr.gael.dhus.olingo.v1.Processor.java
private URI makeLink(boolean remove_last_segment) throws ODataException { try {// w w w . ja v a 2 s . c o m URIBuilder ub = new URIBuilder(ServiceFactory.EXTERNAL_URL); StringBuilder sb = new StringBuilder(); String prefix = ub.getPath(); String path = getContext().getPathInfo().getRequestUri().getPath(); if (path == null || path.isEmpty() || prefix != null && !prefix.isEmpty() && !path.startsWith(ub.getPath())) { sb.append(prefix); if (path != null) { if (prefix.endsWith("/") && path.startsWith("/")) { sb.deleteCharAt(sb.length() - 1); } if (!prefix.endsWith("/") && !path.startsWith("/")) { sb.append('/'); } } } sb.append(path); if (remove_last_segment) { // Removes the last segment. int lio = sb.lastIndexOf("/"); while (lio != -1 && lio == sb.length() - 1) { sb.deleteCharAt(lio); lio = sb.lastIndexOf("/"); } if (lio != -1) { sb.delete(lio + 1, sb.length()); } // Removes the `$links` segment. lio = sb.lastIndexOf("$links/"); if (lio != -1) { sb.delete(lio, lio + 7); } } else if (!sb.toString().endsWith("/") && !sb.toString().endsWith("\\")) { sb.append("/"); } ub.setPath(sb.toString()); return ub.build(); } catch (NullPointerException | URISyntaxException e) { throw new ODataException(e); } }
From source file:nl.nn.adapterframework.http.HttpSenderBase.java
protected URIBuilder getURI(String url) throws URISyntaxException { URIBuilder uri = new URIBuilder(url); if (uri.getPath() == null) { uri.setPath("/"); }/*from ww w . j a v a2 s . c om*/ log.info(getLogPrefix() + "created uri: scheme=[" + uri.getScheme() + "] host=[" + uri.getHost() + "] path=[" + uri.getPath() + "]"); return uri; }
From source file:com.buffalokiwi.api.API.java
/** * Convert a string representing a URI into a URI object. * This combines url with the host, port and scheme from the defined host * in the constructor.//from www .j a v a2s. c o m * @param uri The URI (path/fragment/querystring) * @return The URI object representing the full address * @throws APIException If there is a problem building the URI */ private URI stringToURI(final String url) throws APIException { try { final URIBuilder b = new URIBuilder(url.replace(" ", "%20")); //..Overwrite the host if necessary if (lockHost && client.getHost().getHost() != null && !client.getHost().getHost().isEmpty() //..Kind of stupid, but I didn't think ahead on this one. && !url.startsWith("http://") && !url.startsWith("https://")) { b.setHost(client.getHost().getHost()).setPort(client.getHost().getPort()) .setScheme(client.getHost().getScheme()); if (client.getHost().getPath() != null && !client.getHost().getPath().isEmpty()) { b.setPath(client.getHost().getPath() + b.getPath()); } } //...done final URI out = b.build(); APILog.debug(LOG, "Query:", out.toString()); return out; } catch (Exception e) { throw new APIException("Could not build url: " + url, e); } }
From source file:nl.nn.adapterframework.extensions.akamai.NetStorageSender.java
@Override public HttpRequestBase getMethod(URIBuilder uri, String message, ParameterValueList parameters, Map<String, String> headersParamsMap, IPipeLineSession session) throws SenderException { NetStorageAction netStorageAction = new NetStorageAction(getAction()); netStorageAction.setVersion(actionVersion); netStorageAction.setHashAlgorithm(hashAlgorithm); if (parameters != null) netStorageAction.mapParameters(parameters); try {// w w w. j a va 2s .c o m URL url = uri.build().toURL(); setMethodType(netStorageAction.getMethod()); log.debug("opening [" + netStorageAction.getMethod() + "] connection to [" + url + "] with action [" + getAction() + "]"); NetStorageCmsSigner signer = new NetStorageCmsSigner(url, accessTokenCf.getUsername(), accessTokenCf.getPassword(), netStorageAction, getSignType()); Map<String, String> headers = signer.computeHeaders(); boolean queryParametersAppended = false; StringBuffer path = new StringBuffer(uri.getPath()); if (getMethodType().equals("GET")) { if (parameters != null) { queryParametersAppended = appendParameters(queryParametersAppended, path, parameters, headersParamsMap); log.debug(getLogPrefix() + "path after appending of parameters [" + path.toString() + "]"); } HttpGet method = new HttpGet(uri.build()); for (Map.Entry<String, String> entry : headers.entrySet()) { log.debug("append header [" + entry.getKey() + "] with value [" + entry.getValue() + "]"); method.setHeader(entry.getKey(), entry.getValue()); } log.debug(getLogPrefix() + "HttpSender constructed GET-method [" + method.getURI() + "] query [" + method.getURI().getQuery() + "] "); return method; } else if (getMethodType().equals("PUT")) { HttpPut method = new HttpPut(uri.build()); for (Map.Entry<String, String> entry : headers.entrySet()) { log.debug("append header [" + entry.getKey() + "] with value [" + entry.getValue() + "]"); method.setHeader(entry.getKey(), entry.getValue()); } log.debug(getLogPrefix() + "HttpSender constructed GET-method [" + method.getURI() + "] query [" + method.getURI().getQuery() + "] "); if (netStorageAction.getFile() != null) { HttpEntity entity = new InputStreamEntity(netStorageAction.getFile()); method.setEntity(entity); } return method; } else if (getMethodType().equals("POST")) { HttpPost method = new HttpPost(uri.build()); for (Map.Entry<String, String> entry : headers.entrySet()) { log.debug("append header [" + entry.getKey() + "] with value [" + entry.getValue() + "]"); method.setHeader(entry.getKey(), entry.getValue()); } log.debug(getLogPrefix() + "HttpSender constructed GET-method [" + method.getURI() + "] query [" + method.getURI().getQuery() + "] "); if (netStorageAction.getFile() != null) { HttpEntity entity = new InputStreamEntity(netStorageAction.getFile()); method.setEntity(entity); } return method; } } catch (Exception e) { throw new SenderException(e); } return null; }
From source file:org.apache.ambari.server.controller.ganglia.GangliaPropertyProviderTest.java
@Test public void testPopulateResources_paramsMixed() throws Exception { TestStreamProvider streamProvider = new TestStreamProvider("flume_ganglia_data.txt"); TestGangliaHostProvider hostProvider = new TestGangliaHostProvider(); Map<String, Map<String, PropertyInfo>> gangliaPropertyIds = PropertyHelper .getGangliaPropertyIds(Resource.Type.HostComponent); GangliaPropertyProvider propertyProvider = new GangliaHostComponentPropertyProvider(gangliaPropertyIds, streamProvider, configuration, hostProvider, CLUSTER_NAME_PROPERTY_ID, HOST_NAME_PROPERTY_ID, COMPONENT_NAME_PROPERTY_ID); // flume/*from w w w . j ava2 s .co m*/ Resource resource = new ResourceImpl(Resource.Type.HostComponent); resource.setProperty(HOST_NAME_PROPERTY_ID, "ip-10-39-113-33.ec2.internal"); resource.setProperty(COMPONENT_NAME_PROPERTY_ID, "FLUME_HANDLER"); // only ask for one property Map<String, TemporalInfo> temporalInfoMap = new HashMap<String, TemporalInfo>(); Set<String> ids = new HashSet<String>(); ids.add(FLUME_CATEGORY2); ids.add(PROPERTY_ID2); Request request = PropertyHelper.getReadRequest(ids, temporalInfoMap); Assert.assertEquals(1, propertyProvider.populateResources(Collections.singleton(resource), request, null).size()); List<String> metricsRegexes = new ArrayList<String>(); metricsRegexes.add("metrics/flume"); metricsRegexes.add("metrics/cpu/cpu_wio"); String metricsList = getMetricsRegexes(metricsRegexes, gangliaPropertyIds, "FLUME_HANDLER"); URIBuilder expectedUri = new URIBuilder(); expectedUri.setScheme((configuration.isGangliaSSL() ? "https" : "http")); expectedUri.setHost("domU-12-31-39-0E-34-E1.compute-1.internal"); expectedUri.setPath("/cgi-bin/rrd.py"); expectedUri.setParameter("c", "HDPFlumeServer,HDPSlaves"); expectedUri.setParameter("h", "ip-10-39-113-33.ec2.internal"); expectedUri.setParameter("m", metricsList); expectedUri.setParameter("e", "now"); expectedUri.setParameter("pt", "true"); URIBuilder actualUri = new URIBuilder(streamProvider.getLastSpec()); Assert.assertEquals(expectedUri.getScheme(), actualUri.getScheme()); Assert.assertEquals(expectedUri.getHost(), actualUri.getHost()); Assert.assertEquals(expectedUri.getPath(), actualUri.getPath()); Assert.assertTrue(isUrlParamsEquals(actualUri, expectedUri)); Assert.assertEquals(22, PropertyHelper.getProperties(resource).size()); Assert.assertNotNull(resource.getPropertyValue(PROPERTY_ID2)); Assert.assertNotNull(resource.getPropertyValue(FLUME_CHANNEL_CAPACITY_PROPERTY)); }
From source file:org.apache.ambari.server.controller.ganglia.GangliaPropertyProviderTest.java
@Test public void testPopulateResources_params_category1() throws Exception { TestStreamProvider streamProvider = new TestStreamProvider("flume_ganglia_data.txt"); TestGangliaHostProvider hostProvider = new TestGangliaHostProvider(); Map<String, Map<String, PropertyInfo>> gangliaPropertyIds = PropertyHelper .getGangliaPropertyIds(Resource.Type.HostComponent); GangliaPropertyProvider propertyProvider = new GangliaHostComponentPropertyProvider(gangliaPropertyIds, streamProvider, configuration, hostProvider, CLUSTER_NAME_PROPERTY_ID, HOST_NAME_PROPERTY_ID, COMPONENT_NAME_PROPERTY_ID); // flume//from ww w .jav a2s. c o m Resource resource = new ResourceImpl(Resource.Type.HostComponent); resource.setProperty(HOST_NAME_PROPERTY_ID, "ip-10-39-113-33.ec2.internal"); resource.setProperty(COMPONENT_NAME_PROPERTY_ID, "FLUME_HANDLER"); // only ask for one property Map<String, TemporalInfo> temporalInfoMap = new HashMap<String, TemporalInfo>(); temporalInfoMap.put(FLUME_CATEGORY, new TemporalInfoImpl(10L, 20L, 1L)); Request request = PropertyHelper.getReadRequest(Collections.singleton(FLUME_CATEGORY), temporalInfoMap); Assert.assertEquals(1, propertyProvider.populateResources(Collections.singleton(resource), request, null).size()); List<String> metricsRegexes = new ArrayList<String>(); metricsRegexes.add("metrics/flume"); String metricsList = getMetricsRegexes(metricsRegexes, gangliaPropertyIds, "FLUME_HANDLER"); URIBuilder expectedUri = new URIBuilder(); expectedUri.setScheme((configuration.isGangliaSSL() ? "https" : "http")); expectedUri.setHost("domU-12-31-39-0E-34-E1.compute-1.internal"); expectedUri.setPath("/cgi-bin/rrd.py"); expectedUri.setParameter("c", "HDPFlumeServer,HDPSlaves"); expectedUri.setParameter("h", "ip-10-39-113-33.ec2.internal"); expectedUri.setParameter("m", metricsList); expectedUri.setParameter("s", "10"); expectedUri.setParameter("e", "20"); expectedUri.setParameter("r", "1"); URIBuilder actualUri = new URIBuilder(streamProvider.getLastSpec()); Assert.assertEquals(expectedUri.getScheme(), actualUri.getScheme()); Assert.assertEquals(expectedUri.getHost(), actualUri.getHost()); Assert.assertEquals(expectedUri.getPath(), actualUri.getPath()); Assert.assertTrue(isUrlParamsEquals(actualUri, expectedUri)); Assert.assertEquals(21, PropertyHelper.getProperties(resource).size()); Assert.assertNotNull(resource.getPropertyValue(FLUME_CHANNEL_CAPACITY_PROPERTY)); }
From source file:org.apache.ambari.server.controller.ganglia.GangliaPropertyProviderTest.java
@Test public void testPopulateResources_params_category2() throws Exception { TestStreamProvider streamProvider = new TestStreamProvider("flume_ganglia_data.txt"); TestGangliaHostProvider hostProvider = new TestGangliaHostProvider(); Map<String, Map<String, PropertyInfo>> gangliaPropertyIds = PropertyHelper .getGangliaPropertyIds(Resource.Type.HostComponent); GangliaPropertyProvider propertyProvider = new GangliaHostComponentPropertyProvider(gangliaPropertyIds, streamProvider, configuration, hostProvider, CLUSTER_NAME_PROPERTY_ID, HOST_NAME_PROPERTY_ID, COMPONENT_NAME_PROPERTY_ID); // flume/*from w ww.ja v a 2s. com*/ Resource resource = new ResourceImpl(Resource.Type.HostComponent); resource.setProperty(HOST_NAME_PROPERTY_ID, "ip-10-39-113-33.ec2.internal"); resource.setProperty(COMPONENT_NAME_PROPERTY_ID, "FLUME_HANDLER"); // only ask for one property Map<String, TemporalInfo> temporalInfoMap = new HashMap<String, TemporalInfo>(); temporalInfoMap.put(FLUME_CATEGORY2, new TemporalInfoImpl(10L, 20L, 1L)); Request request = PropertyHelper.getReadRequest(Collections.singleton(FLUME_CATEGORY2), temporalInfoMap); Assert.assertEquals(1, propertyProvider.populateResources(Collections.singleton(resource), request, null).size()); List<String> metricsRegexes = new ArrayList<String>(); metricsRegexes.add("metrics/flume/"); String metricsList = getMetricsRegexes(metricsRegexes, gangliaPropertyIds, "FLUME_HANDLER"); URIBuilder expectedUri = new URIBuilder(); expectedUri.setScheme((configuration.isGangliaSSL() ? "https" : "http")); expectedUri.setHost("domU-12-31-39-0E-34-E1.compute-1.internal"); expectedUri.setPath("/cgi-bin/rrd.py"); expectedUri.setParameter("c", "HDPFlumeServer,HDPSlaves"); expectedUri.setParameter("h", "ip-10-39-113-33.ec2.internal"); expectedUri.setParameter("m", metricsList); expectedUri.setParameter("s", "10"); expectedUri.setParameter("e", "20"); expectedUri.setParameter("r", "1"); URIBuilder actualUri = new URIBuilder(streamProvider.getLastSpec()); Assert.assertEquals(expectedUri.getScheme(), actualUri.getScheme()); Assert.assertEquals(expectedUri.getHost(), actualUri.getHost()); Assert.assertEquals(expectedUri.getPath(), actualUri.getPath()); Assert.assertTrue(isUrlParamsEquals(actualUri, expectedUri)); Assert.assertEquals(21, PropertyHelper.getProperties(resource).size()); Assert.assertNotNull(resource.getPropertyValue(FLUME_CHANNEL_CAPACITY_PROPERTY)); }
From source file:org.apache.ambari.server.controller.ganglia.GangliaPropertyProviderTest.java
@Test public void testPopulateResources_params() throws Exception { TestStreamProvider streamProvider = new TestStreamProvider("flume_ganglia_data.txt"); TestGangliaHostProvider hostProvider = new TestGangliaHostProvider(); Map<String, Map<String, PropertyInfo>> gangliaPropertyIds = PropertyHelper .getGangliaPropertyIds(Resource.Type.HostComponent); GangliaPropertyProvider propertyProvider = new GangliaHostComponentPropertyProvider(gangliaPropertyIds, streamProvider, configuration, hostProvider, CLUSTER_NAME_PROPERTY_ID, HOST_NAME_PROPERTY_ID, COMPONENT_NAME_PROPERTY_ID); // flume/* w w w. j a v a2s. c om*/ Resource resource = new ResourceImpl(Resource.Type.HostComponent); resource.setProperty(HOST_NAME_PROPERTY_ID, "ip-10-39-113-33.ec2.internal"); resource.setProperty(COMPONENT_NAME_PROPERTY_ID, "FLUME_HANDLER"); // only ask for one property Map<String, TemporalInfo> temporalInfoMap = new HashMap<String, TemporalInfo>(); temporalInfoMap.put(FLUME_CHANNEL_CAPACITY_PROPERTY, new TemporalInfoImpl(10L, 20L, 1L)); Request request = PropertyHelper.getReadRequest(Collections.singleton(FLUME_CHANNEL_CAPACITY_PROPERTY), temporalInfoMap); Assert.assertEquals(1, propertyProvider.populateResources(Collections.singleton(resource), request, null).size()); List<String> metricsRegexes = new ArrayList<String>(); metricsRegexes.add(FLUME_CHANNEL_CAPACITY_PROPERTY); String metricsList = getMetricsRegexes(metricsRegexes, gangliaPropertyIds, "FLUME_HANDLER"); URIBuilder expectedUri = new URIBuilder(); expectedUri.setScheme((configuration.isGangliaSSL() ? "https" : "http")); expectedUri.setHost("domU-12-31-39-0E-34-E1.compute-1.internal"); expectedUri.setPath("/cgi-bin/rrd.py"); expectedUri.setParameter("c", "HDPFlumeServer,HDPSlaves"); expectedUri.setParameter("h", "ip-10-39-113-33.ec2.internal"); expectedUri.setParameter("m", metricsList); expectedUri.setParameter("s", "10"); expectedUri.setParameter("e", "20"); expectedUri.setParameter("r", "1"); URIBuilder actualUri = new URIBuilder(streamProvider.getLastSpec()); Assert.assertEquals(expectedUri.getScheme(), actualUri.getScheme()); Assert.assertEquals(expectedUri.getHost(), actualUri.getHost()); Assert.assertEquals(expectedUri.getPath(), actualUri.getPath()); Assert.assertTrue(isUrlParamsEquals(actualUri, expectedUri)); Assert.assertEquals(3, PropertyHelper.getProperties(resource).size()); Assert.assertNotNull(resource.getPropertyValue(FLUME_CHANNEL_CAPACITY_PROPERTY)); }