List of usage examples for java.net URI getPath
public String getPath()
From source file:com.esri.geoportal.commons.http.BotsHttpClient.java
private String getRelativePath(URI u) throws MalformedURLException { return String.format("%s%s%s", u.getPath() != null ? u.getPath() : "/", u.getQuery() != null ? "?" + u.getQuery() : "", u.getFragment() != null ? "#" + u.getFragment() : ""); }
From source file:org.mobicents.servlet.sip.restcomm.interpreter.http.HttpRequestDescriptor.java
public HttpRequestDescriptor(final URI uri, final String method, final List<NameValuePair> parameters) throws UnsupportedEncodingException, URISyntaxException { super();/*from ww w . j av a 2 s . c o m*/ this.uri = URIUtils.createURI(uri.getScheme(), uri.getHost(), uri.getPort(), uri.getPath(), null, null); this.method = method; final String query = uri.getQuery(); if (query != null) { parameters.addAll(URLEncodedUtils.parse(uri, "UTF-8")); } this.parameters = parameters; }
From source file:org.mcxiaoke.commons.http.util.URIUtilsEx.java
/** * A convenience method that creates a new {@link URI} whose scheme, host, * port, path, query are taken from the existing URI, dropping any fragment * or user-information. The path is set to "/" if not explicitly specified. * The existing URI is returned unmodified if it has no fragment or * user-information and has a path./* ww w . ja v a 2s . co m*/ * * @param uri * original URI. * @throws URISyntaxException * If the resulting URI is invalid. */ public static URI rewriteURI(final URI uri) throws URISyntaxException { if (uri == null) { throw new IllegalArgumentException("URI may not be null"); } if (uri.getFragment() != null || uri.getUserInfo() != null || (uri.getPath() == null || uri.getPath().length() == 0)) { URIBuilderEx uribuilder = new URIBuilderEx(uri); uribuilder.setFragment(null).setUserInfo(null); if (uribuilder.getPath() == null || uribuilder.getPath().length() == 0) { uribuilder.setPath("/"); } return uribuilder.build(); } else { return uri; } }
From source file:com.netflix.spinnaker.kork.jedis.JedisPoolFactory.java
public Pool<Jedis> build(String name, JedisDriverProperties properties) { if (properties.connection == null || "".equals(properties.connection)) { throw new MissingRequiredConfiguration("Jedis client must have a connection defined"); }/*from w w w.j a va 2 s . c om*/ URI redisConnection = URI.create(properties.connection); String host = redisConnection.getHost(); int port = redisConnection.getPort() == -1 ? Protocol.DEFAULT_PORT : redisConnection.getPort(); int database = parseDatabase(redisConnection.getPath()); String password = parsePassword(redisConnection.getUserInfo()); GenericObjectPoolConfig objectPoolConfig = properties.poolConfig; boolean isSSL = redisConnection.getScheme().equals("rediss"); return new InstrumentedJedisPool(registry, // Pool name should always be "null", as setting this is incompat with some SaaS Redis offerings new JedisPool(objectPoolConfig, host, port, properties.timeoutMs, password, database, null, isSSL), name); }
From source file:com.appdirect.sdk.support.FakeAppmarket.java
public FakeAppmarket start() { Predicate<HttpExchange> oauthInTheHeader = httpExchange -> { String authorization = httpExchange.getRequestHeaders().getFirst("Authorization"); return authorization != null && authorization.startsWith("OAuth oauth_consumer_key=\"" + isvKey + "\","); };/*from ww w. j ava 2s . c o m*/ server.createContext("/v1/events/", new ReturnResourceContent(oauthInTheHeader)); server.createContext("/api/integration/v1/events/", new OauthSecuredHandler(oauthInTheHeader) { @Override byte[] buildJsonResponse(URI requestUri) throws IOException { String eventToken = requestUri.getPath().split("/")[5]; markEventAsResolved(eventToken); return "".getBytes(UTF_8); } }); server.start(); return this; }
From source file:com.nebhale.cyclinglibrary.repository.RepositoryConfiguration.java
@Bean DataSource dataSource() throws URISyntaxException { String dbUrlProperty = System.getenv(DB_URL_PROPERTY_NAME); Assert.hasText(dbUrlProperty,/*from w w w .j av a2 s . co m*/ String.format("The enviroment variable '%s' must be specified", DB_URL_PROPERTY_NAME)); URI dbUri = new URI(dbUrlProperty); String username = dbUri.getUserInfo().split(":")[0]; String password = dbUri.getUserInfo().split(":")[1]; String dbUrl = "jdbc:postgresql://" + dbUri.getHost() + ':' + dbUri.getPort() + dbUri.getPath() + "?ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory"; BoneCPDataSource dataSource = new BoneCPDataSource(); dataSource.setDriverClass(Driver.class.getCanonicalName()); dataSource.setJdbcUrl(dbUrl); dataSource.setUsername(username); dataSource.setPassword(password); Flyway flyway = new Flyway(); flyway.setDataSource(dataSource); flyway.migrate(); return dataSource; }
From source file:com.anrisoftware.simplerest.owncloudocs.OwncloudOcsCreateShare.java
private URI getRequestURI0() throws URISyntaxException { URI baseUri = account.getBaseUri(); String extraPath = baseUri.getPath(); URIBuilder builder = new URIBuilder(baseUri); builder.setUserInfo(account.getUser(), account.getPassword()); addParameters(builder);/*from w w w .jav a 2s. c o m*/ String statusPath = String.format("%s%s", extraPath, propertiesProvider.getOwncloudSharesPath()); builder.setPath(statusPath); return builder.build(); }
From source file:xyz.cloudbans.client.DefaultClient.java
private URIBuilder createUri(String path) { if (path.startsWith("/")) path = path.substring(1);//w w w .ja v a 2 s .c o m URI baseUri = config.getBaseUri(); return new URIBuilder(baseUri) .setPath((baseUri.getPath().endsWith("/") ? baseUri.getPath() : baseUri.getPath() + "/") + path); }
From source file:leap.webunit.client.THttpRequestImpl.java
protected String buildRequestUrl() { String url = null;/*from ww w .j av a 2s. c o m*/ if (Strings.isEmpty(uri)) { url = tclient.getBaseUrl(); } else if (uri.indexOf("://") > 0) { url = uri; } else if (Strings.startsWith(uri, "/")) { url = tclient.getBaseUrl() + uri; } else { url = tclient.getBaseUrl() + "/" + uri; } if (!queryString.isEmpty()) { url = Urls.appendQueryString(url, queryString.build()); } URI uri = URI.create(url); String path = uri.getPath(); if (!"".equals(path)) { for (String contextPath : tclient.getContextPaths()) { if (path.equals(contextPath)) { url = uri.getScheme() + ":" + uri.getSchemeSpecificPart() + "/"; if (null != uri.getQuery()) { url = url + "?" + uri.getRawQuery(); } break; } } } return url; }
From source file:com.woonoz.proxy.servlet.UrlRewriterImpl.java
public URI rewriteUri(URI url) throws URISyntaxException, MalformedURLException { if (requestedUrlPointsToServlet(url)) { final String targetPath = rewritePathIfNeeded(url.getPath()); return URIUtils.createURI(targetServer.getProtocol(), targetServer.getHost(), targetServer.getPort(), targetPath, servletRequest.getQueryString(), null); } else {/*from w ww . j av a 2 s .com*/ return url; } }