List of usage examples for java.net URI getUserInfo
public String getUserInfo()
From source file:com.jgoetsch.eventtrader.source.SocketIOWebSocketMsgSource.java
protected String getTokenUrl() throws IOException, URISyntaxException { URI base = new URI(getUrl()); BufferedReader tokenReader = new BufferedReader( new InputStreamReader(new URI("http", base.getUserInfo(), base.getHost(), base.getPort(), base.getPath(), base.getQuery(), base.getFragment()).toURL().openStream())); String token = tokenReader.readLine(); tokenReader.close();//from ww w . ja va 2 s.c o m String r[] = token.split(":"); String comp[] = getUrl().split("\\?"); if (!comp[0].endsWith("/")) comp[0] += '/'; return comp[0] + "websocket/" + r[0] + (comp.length > 0 ? "?" + comp[1] : ""); }
From source file:org.ldp4j.tutorial.client.CachedRepresentationManager.java
private File createFile(String resource) { URI uri = URI.create(resource); StringBuilder builder = new StringBuilder(); builder.append(uri.getScheme()).append("_"); String userInfo = uri.getUserInfo(); if (userInfo != null) { builder.append(userInfo).append("@"); }/* ww w . ja va2 s.co m*/ builder.append(uri.getHost()); if (uri.getPort() >= 0) { builder.append("_").append(uri.getPort()); } if (uri.getPath() != null) { builder.append(uri.getRawPath().replace("/", "_")); } if (uri.getQuery() != null) { builder.append("?").append(uri.getRawQuery()); } if (uri.getFragment() != null) { builder.append("#").append(uri.getRawFragment()); } builder.append(".dat"); File file = new File(this.cacheDirectory, builder.toString()); return file; }
From source file:com.subgraph.vega.impl.scanner.urls.ResponseAnalyzer.java
private URI stripQuery(URI uri) { try {/* w ww .j a v a 2s . c o m*/ return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), uri.getPath(), null, null); } catch (URISyntaxException e) { throw new IllegalArgumentException(e); } }
From source file:com.esri.geoportal.commons.http.BotsHttpClient.java
private URI updateURI(URI uri, PHP php) throws URISyntaxException { return new URI(php.protocol != null ? php.protocol : uri.getScheme(), uri.getUserInfo(), php.host != null ? php.host : uri.getHost(), php.host != null ? php.port != null ? php.port : -1 : uri.getPort(), uri.getPath(), uri.getQuery(), uri.getFragment());/*from w w w . ja va2s . c o m*/ }
From source file:net.bluemix.connectors.core.info.CloudantServiceInfo.java
public CloudantServiceInfo(String id, String url) throws URISyntaxException { super(id);//from w ww. j a v a2 s . c o m URI uri = new URI(url); this.url = url.replaceFirst(CloudantServiceInfo.SCHEME, "http"); this.host = uri.getHost(); this.port = uri.getPort(); String serviceInfoString = uri.getUserInfo(); if (serviceInfoString != null) { String[] userInfo = serviceInfoString.split(":"); this.username = userInfo[0]; this.password = userInfo[1]; } }
From source file:com.linkedin.r2.message.rest.QueryTunnelUtil.java
/** * @param request a RestRequest object to be encoded as a tunneled POST * @param requestContext a RequestContext object associated with the request * @param threshold the size of the query params above which the request will be encoded * * @return an encoded RestRequest/* w w w. j a v a2 s. co m*/ */ public static RestRequest encode(final RestRequest request, RequestContext requestContext, int threshold) throws URISyntaxException, MessagingException, IOException { URI uri = request.getURI(); // Check to see if we should tunnel this request by testing the length of the query // if the query is NULL, we won't bother to encode. // 0 length is a special case that could occur with a url like http://www.foo.com? // which we don't want to encode, because we'll lose the "?" in the process // Otherwise only encode queries whose length is greater than or equal to the // threshold value. String query = uri.getRawQuery(); boolean forceQueryTunnel = requestContext.getLocalAttr(R2Constants.FORCE_QUERY_TUNNEL) != null && (Boolean) requestContext.getLocalAttr(R2Constants.FORCE_QUERY_TUNNEL); if (query == null || query.length() == 0 || (query.length() < threshold && !forceQueryTunnel)) { return request; } RestRequestBuilder requestBuilder = new RestRequestBuilder(request); // reconstruct URI without query uri = new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), uri.getPath(), null, uri.getFragment()); // If there's no existing body, just pass the request as x-www-form-urlencoded ByteString entity = request.getEntity(); if (entity == null || entity.length() == 0) { requestBuilder.setHeader(HEADER_CONTENT_TYPE, FORM_URL_ENCODED); requestBuilder.setEntity(ByteString.copyString(query, Data.UTF_8_CHARSET)); } else { // If we have a body, we must preserve it, so use multipart/mixed encoding MimeMultipart multi = createMultiPartEntity(entity, request.getHeader(HEADER_CONTENT_TYPE), query); requestBuilder.setHeader(HEADER_CONTENT_TYPE, multi.getContentType()); ByteArrayOutputStream os = new ByteArrayOutputStream(); multi.writeTo(os); requestBuilder.setEntity(ByteString.copy(os.toByteArray())); } // Set the base uri, supply the original method in the override header, and change method to POST requestBuilder.setURI(uri); requestBuilder.setHeader(HEADER_METHOD_OVERRIDE, requestBuilder.getMethod()); requestBuilder.setMethod(RestMethod.POST); return requestBuilder.build(); }
From source file:org.apache.camel.component.comet.CometComponent.java
@Override protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception { if (endpointCache.containsKey(uri)) { LOG.debug("Using cached endpoint for URI " + uri); return endpointCache.get(uri); }/*ww w . j av a2s .c o m*/ LOG.debug("Creating new endpoint for URI " + uri); CometEndpoint endpoint = new CometEndpoint(uri, this); URI u = new URI(uri); endpoint.setHost(u.getHost()); endpoint.setScheme(u.getScheme()); if (u.getPort() > 0) endpoint.setPort(u.getPort()); else { endpoint.setPort(endpoint.isSecure() ? 443 : 80); } if (u.getUserInfo() != null) { endpoint.setUser(u.getUserInfo()); } String remainingPath = u.getPath(); endpoint.setPath(remainingPath != null ? remainingPath : "/"); endpoint.setChannel(u.getFragment()); endpoint.initialize(); endpointCache.put(uri, endpoint); return endpoint; }
From source file:org.mobicents.servlet.restcomm.http.client.HttpRequestDescriptor.java
private URI base(final URI uri) { try {/*from w ww . j av a 2s .c o m*/ URIBuilder uriBuilder = new URIBuilder(); uriBuilder.setScheme(uri.getScheme()); uriBuilder.setHost(uri.getHost()); uriBuilder.setPort(uri.getPort()); uriBuilder.setPath(uri.getPath()); if (uri.getUserInfo() != null) { uriBuilder.setUserInfo(uri.getUserInfo()); } return uriBuilder.build(); } catch (final URISyntaxException ignored) { // This should never happen since we are using a valid URI to construct ours. return null; } }
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. com*/ 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:net.i2cat.netconf.NetconfSession.java
public NetconfSession(SessionContext sessionContext, TransportFactory transportFactory) throws TransportNotRegisteredException, ConfigurationException { this.transportFactory = transportFactory; this.sessionContext = sessionContext; URI uri = sessionContext.getURI(); if (uri.getScheme() == null || uri.getHost() == null || uri.getUserInfo() == null) throw new ConfigurationException("Insufficient information in session context's URI: " + uri); if (!transportFactory.isAwareOfScheme(uri.getScheme())) { throw new TransportNotRegisteredException( "Scheme '" + uri.getScheme() + "' given in URI has not been registered with TransportFactory."); }// ww w. java2 s. c o m }