List of usage examples for java.net URI getUserInfo
public String getUserInfo()
From source file:org.codehaus.stomp.tcp.TcpTransportServer.java
public void start() throws IOException { URI bind = bindLocation; String host = bind.getHost(); host = (host == null || host.length() == 0) ? "localhost" : host; InetAddress addr = InetAddress.getByName(host); try {// ww w .ja v a2 s .co m this.serverSocket = serverSocketFactory.createServerSocket(bind.getPort(), backlog, addr); this.serverSocket.setSoTimeout(2000); } catch (IOException e) { throw new IOException("Failed to bind to server socket: " + bind + " due to: " + e, e); } try { connectURI = new URI(bind.getScheme(), bind.getUserInfo(), bind.getHost(), serverSocket.getLocalPort(), bind.getPath(), bind.getQuery(), bind.getFragment()); } catch (URISyntaxException e) { throw new IOException(e.getMessage(), e); } log.info("Listening for connections at: " + connectURI); runner = new Thread(this, "StompConnect Server Thread: " + toString()); runner.setDaemon(daemon); runner.start(); }
From source file:org.wso2.carbon.identity.webfinger.builders.DefaultWebFingerRequestBuilder.java
@Override public WebFingerRequest buildRequest(HttpServletRequest request) throws WebFingerEndpointException { WebFingerRequest webFingerRequest = new WebFingerRequest(); List<String> parameters = Collections.list(request.getParameterNames()); if (parameters.size() != 2 || !parameters.contains(WebFingerConstants.REL) || !parameters.contains(WebFingerConstants.RESOURCE)) { throw new WebFingerEndpointException(WebFingerConstants.ERROR_CODE_INVALID_REQUEST, "Bad Web " + "Finger request."); }//from w ww .jav a2 s . com webFingerRequest.setServletRequest(request); String resource = request.getParameter(WebFingerConstants.RESOURCE); webFingerRequest.setRel(request.getParameter(WebFingerConstants.REL)); webFingerRequest.setResource(resource); if (StringUtils.isBlank(resource)) { log.warn("Can't normalize null or empty URI: " + resource); throw new WebFingerEndpointException(WebFingerConstants.ERROR_CODE_INVALID_RESOURCE, "Null or empty URI."); } else { URI resourceURI = URI.create(resource); if (StringUtils.isBlank(resourceURI.getScheme())) { throw new WebFingerEndpointException("Scheme of the resource cannot be empty"); } String userInfo; if (WebFingerConstants.ACCT_SCHEME.equals(resourceURI.getScheme())) { //acct scheme userInfo = resourceURI.getSchemeSpecificPart(); userInfo = userInfo.substring(0, userInfo.lastIndexOf('@')); } else { //https scheme userInfo = resourceURI.getUserInfo(); webFingerRequest.setScheme(resourceURI.getScheme()); webFingerRequest.setHost(resourceURI.getHost()); webFingerRequest.setPort(resourceURI.getPort()); webFingerRequest.setPath(resourceURI.getPath()); webFingerRequest.setQuery(resourceURI.getQuery()); } String tenant; if (StringUtils.isNotBlank(userInfo)) { try { userInfo = URLDecoder.decode(userInfo, "UTF-8"); } catch (UnsupportedEncodingException e) { throw new WebFingerEndpointException("Cannot decode the userinfo"); } tenant = MultitenantUtils.getTenantDomain(userInfo); webFingerRequest.setUserInfo(resourceURI.getUserInfo()); } else { tenant = MultitenantConstants.SUPER_TENANT_DOMAIN_NAME; } validateTenant(tenant); webFingerRequest.setTenant(tenant); } return webFingerRequest; }
From source file:com.aliyun.fs.oss.blk.JetOssFileSystemStore.java
public void initialize(URI uri, Configuration conf) throws IOException { if (uri.getHost() == null) { throw new IllegalArgumentException("Invalid hostname in URI " + uri); }//from w ww. j a v a 2s .c o m this.conf = conf; String userInfo = uri.getUserInfo(); if (userInfo != null) { String[] ossCredentials = userInfo.split(":"); if (ossCredentials.length >= 2) { accessKeyId = ossCredentials[0]; accessKeySecret = ossCredentials[1]; } if (ossCredentials.length == 3) { securityToken = ossCredentials[2]; } } String host = uri.getHost(); if (!StringUtils.isEmpty(host) && !host.contains(".")) { bucket = host; } else if (!StringUtils.isEmpty(host)) { bucket = host.substring(0, host.indexOf(".")); endpoint = host.substring(host.indexOf(".") + 1); } if (accessKeyId == null) { accessKeyId = conf.getTrimmed("fs.oss.accessKeyId"); } if (accessKeySecret == null) { accessKeySecret = conf.getTrimmed("fs.oss.accessKeySecret"); } if (securityToken == null) { securityToken = conf.getTrimmed("fs.oss.securityToken"); } if (endpoint == null) { endpoint = conf.getTrimmed("fs.oss.endpoint"); } ClientConfiguration cc = initializeOSSClientConfig(conf); if (securityToken == null) { this.ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret, cc); } else { this.ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret, securityToken, cc); } this.bufferSize = conf.getInt("io.file.buffer.size", 4096); }
From source file:de.thingweb.thing.Thing.java
public String resolveActionUri(String name, int index) { URI uri = getUri(index); Action a = getAction(name);//from w ww . ja v a2s . c o m if (a != null) { try { String path = uri.getPath(); if (path.endsWith("/")) { path = path + a.getHrefs().get(index); } else { path = path + "/" + a.getHrefs().get(index); } uri = new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), path, uri.getQuery(), uri.getFragment()); } catch (URISyntaxException e) { throw new RuntimeException("TD with malformed hrefs"); } } else { throw new RuntimeException("No such Property"); } return uri.toString(); }
From source file:com.tripit.auth.OAuthCredential.java
public boolean validateSignature(URI requestUri) throws URISyntaxException, UnsupportedEncodingException, InvalidKeyException, NoSuchAlgorithmException { List<NameValuePair> argList = URLEncodedUtils.parse(requestUri, "UTF-8"); SortedMap<String, String> args = new TreeMap<String, String>(); for (NameValuePair arg : argList) { args.put(arg.getName(), arg.getValue()); }//from w w w . ja v a 2 s .c o m String signature = args.remove("oauth_signature"); String baseUrl = new URI(requestUri.getScheme(), requestUri.getUserInfo(), requestUri.getAuthority(), requestUri.getPort(), requestUri.getPath(), null, requestUri.getFragment()).toString(); return (signature != null && signature.equals(generateSignature(baseUrl, args))); }
From source file:org.openhab.binding.squeezebox.internal.handler.SqueezeBoxPlayerHandler.java
private String sanitizeUrl(String url) { String sanitizedUrl = url;// w w w . java 2 s .c om try { URI uri = new URI(url); String userInfo = uri.getUserInfo(); if (userInfo != null) { String[] userInfoParts = userInfo.split(":"); if (userInfoParts.length == 2) { sanitizedUrl = url.replace(userInfoParts[1], "**********"); } } } catch (URISyntaxException e) { // Just return what was passed in } return sanitizedUrl; }
From source file:org.talend.core.nexus.HttpClientTransport.java
private IProxySelectorProvider createProxySelectorProvider() { IProxySelectorProvider proxySelectorProvider = new TalendProxySelector.AbstractProxySelectorProvider() { private Thread currentThread = Thread.currentThread(); @Override//ww w . j a v a 2 s . c o m public List<Proxy> select(URI uri) { // return Collections.EMPTY_LIST; List<Proxy> newProxys = new ArrayList<>(); if (uri == null) { return newProxys; } String schema = uri.getScheme(); if (schema != null && schema.toLowerCase().startsWith("socket")) { //$NON-NLS-1$ try { URI newUri = new URI("https", uri.getUserInfo(), uri.getHost(), uri.getPort(), uri.getPath(), uri.getQuery(), uri.getFragment()); List<Proxy> proxys = TalendProxySelector.getInstance().getDefaultProxySelector() .select(newUri); if (proxys != null && !proxys.isEmpty()) { newProxys.addAll(proxys); } else { newUri = new URI("http", uri.getUserInfo(), uri.getHost(), uri.getPort(), uri.getPath(), uri.getQuery(), uri.getFragment()); proxys = TalendProxySelector.getInstance().getDefaultProxySelector().select(newUri); if (proxys != null && !proxys.isEmpty()) { newProxys.addAll(proxys); } } } catch (URISyntaxException e) { ExceptionHandler.process(e); } } return newProxys; } @Override public boolean canHandle(URI uri) { if (Thread.currentThread() == currentThread) { return true; } return false; } }; return proxySelectorProvider; }
From source file:com.github.parisoft.resty.request.Request.java
/** * Creates a request from a {@link URI}.<br> * The URI must conform the <a href=https://www.ietf.org/rfc/rfc2396.txt>RFC 2396</a> with the <i>path</i> and <i>query</i> properly encoded.<br> * <br>/*from w w w . j a v a 2s . c om*/ * For your convenience, call this constructor with the base address of your request - like {@literal <scheme>://<authority>} - * and use {@link #path(String...)} and {@link #query(String, String)} to configure the URI path and query respectively without worring about escape.<br> * <br> * As example, you can do<br> * <pre> * URI partialUri = new URI("http://some.domain.org:1234"); * Request request = new Request(partialUri) * .path("any unescaped path") * .query("don't", "scape too"); * </pre> * or * <pre> * URI fullUri = new URI("http://some.domain.org:1234/any%20unescaped%20path?don%27t=scape+too"); * Request request = new Request(fullUri); * </pre> * <i>Note:</i> this is equivalent to {@link RESTy#request(URI)} * * @param uri A {@link URI} as defined by <a href=https://www.ietf.org/rfc/rfc2396.txt>RFC 2396</a> * @throws IllegalArgumentException If the URI is null */ public Request(URI uri) { if (uri == null) { throw new IllegalArgumentException("Cannot create a request: URI cannot be null"); } path(emptyIfNull(uri.getPath())); try { query(URLEncodedUtils.parse(uri, UTF_8.name())); rootUri = new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), null, null, uri.getFragment()); } catch (Exception e) { throw new IllegalArgumentException("Cannot create a request: " + e.getMessage()); } }
From source file:org.mule.impl.endpoint.MuleEndpointURI.java
public MuleEndpointURI(String address, String endpointName, String connectorName, String transformers, String responseTransformers, int createConnector, Properties properties, URI uri) { this.address = address; this.endpointName = endpointName; this.connectorName = connectorName; this.transformers = transformers; this.responseTransformers = responseTransformers; this.createConnector = createConnector; this.params = properties; this.uri = uri; this.userInfo = uri.getUserInfo(); if (properties != null) { resourceInfo = (String) properties.remove("resourceInfo"); }//from w w w . jav a2 s . c o m }
From source file:org.mule.endpoint.MuleEndpointURI.java
public MuleEndpointURI(String address, String endpointName, String connectorName, String transformers, String responseTransformers, Properties properties, URI uri, MuleContext muleContext) { this.address = address; this.endpointName = endpointName; this.connectorName = connectorName; this.transformers = transformers; this.responseTransformers = responseTransformers; this.params = properties; this.uri = uri; this.userInfo = uri.getUserInfo(); this.muleContext = muleContext; if (properties != null) { resourceInfo = (String) properties.remove("resourceInfo"); }//from ww w . j av a 2s. com }