当前位置: 首页>>代码示例>>Java>>正文


Java URL.getUserInfo方法代码示例

本文整理汇总了Java中java.net.URL.getUserInfo方法的典型用法代码示例。如果您正苦于以下问题:Java URL.getUserInfo方法的具体用法?Java URL.getUserInfo怎么用?Java URL.getUserInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.net.URL的用法示例。


在下文中一共展示了URL.getUserInfo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: encodeUrlToHttpFormat

import java.net.URL; //导入方法依赖的package包/类
public static String encodeUrlToHttpFormat(String urlString)
{
    String encodedUrl=null;
    try
    {
        URL url=new URL(urlString);
        URI uri= new URI(url.getProtocol(),url.getUserInfo(),url.getHost(),url.getPort(),url.getPath(),
                url.getQuery(),url.getRef());
        //System.out.println(uri.toURL().toString());
        encodedUrl=uri.toURL().toString();
    }
    catch (Exception exc)
    {
        return null;
    }
    return  encodedUrl;
}
 
开发者ID:gerard-bisama,项目名称:DHIS2-fhir-lab-app,代码行数:18,代码来源:FhirMediatorUtilities.java

示例2: getUrlWithQueryString

import java.net.URL; //导入方法依赖的package包/类
/**
 * Will encode url, if not disabled, and adds params on the end of it
 *
 * @param url             String with URL, should be valid URL without params
 * @param params          RequestParams to be appended on the end of URL
 * @param shouldEncodeUrl whether url should be encoded (replaces spaces with %20)
 * @return encoded url if requested with params appended if any available
 */
public static String getUrlWithQueryString(boolean shouldEncodeUrl, String url, RequestParams params) {
    if (url == null)
        return null;

    if (shouldEncodeUrl) {
        try {
            String decodedURL = URLDecoder.decode(url, "UTF-8");
            URL _url = new URL(decodedURL);
            URI _uri = new URI(_url.getProtocol(), _url.getUserInfo(), _url.getHost(), _url.getPort(), _url.getPath(), _url.getQuery(), _url.getRef());
            url = _uri.toASCIIString();
        } catch (Exception ex) {
            // Should not really happen, added just for sake of validity
            log.e(LOG_TAG, "getUrlWithQueryString encoding URL", ex);
        }
    }

    if (params != null) {
        // Construct the query string and trim it, in case it
        // includes any excessive white spaces.
        String paramString = params.getParamString().trim();

        // Only add the query string if it isn't empty and it
        // isn't equal to '?'.
        if (!paramString.equals("") && !paramString.equals("?")) {
            url += url.contains("?") ? "&" : "?";
            url += paramString;
        }
    }

    return url;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:40,代码来源:AsyncHttpClient.java

示例3: initializeProxy

import java.net.URL; //导入方法依赖的package包/类
@PostConstruct
private void initializeProxy() {
    if (!isBlank(proxyUrlEnv)) {
        try {
            URL proxyUrl = new URL(proxyUrlEnv);
            String authString = proxyUrl.getUserInfo();
            user = authString.split(":")[0];
            password = authString.split(":")[1];
            host = proxyUrl.getHost();
            port = proxyUrl.getPort();
            auth = new ProxyAuthenticator(user, password);
            setProxy();
            log.info("Set up global HTTP/HTTPS proxy to host:port {}:{} ", this.host, this.port);
        } catch (MalformedURLException e) {
            throw new RuntimeException(e);
        }
    } else {
        log.warn("Environemnt variable QUOTAGUARDSTATIC_URL is not set, not configuring proxy!");
    }
}
 
开发者ID:TulevaEE,项目名称:onboarding-service,代码行数:21,代码来源:QuotaGuardProxyConfiguration.java

示例4: FtpURLConnection

import java.net.URL; //导入方法依赖的package包/类
/**
 * Same as FtpURLconnection(URL) with a per connection proxy specified
 */
FtpURLConnection(URL url, Proxy p) {
    super(url);
    instProxy = p;
    host = url.getHost();
    port = url.getPort();
    String userInfo = url.getUserInfo();

    if (userInfo != null) { // get the user and password
        int delimiter = userInfo.indexOf(':');
        if (delimiter == -1) {
            user = ParseUtil.decode(userInfo);
            password = null;
        } else {
            user = ParseUtil.decode(userInfo.substring(0, delimiter++));
            password = ParseUtil.decode(userInfo.substring(delimiter));
        }
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:22,代码来源:FtpURLConnection.java

示例5: readURL

import java.net.URL; //导入方法依赖的package包/类
public static String readURL(String rawURL) throws IOException {
    try
    {
        URL url = new URL(rawURL);
        URLConnection urlConnection = url.openConnection();

        if (url.getUserInfo() != null) {
            String basicAuth = "Basic " + new String(Base64.getEncoder().encode(url.getUserInfo().getBytes()));
            urlConnection.setRequestProperty("Authorization", basicAuth);
        }

        InputStream inputStream = urlConnection.getInputStream();
        BufferedReader in = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));

        String inputLine = in.readLine();
        in.close();
        inputStream.close();

        return inputLine;
    } catch (IOException e)
    {
        throw e;
    }
}
 
开发者ID:SamaGames,项目名称:Hydroangeas,代码行数:25,代码来源:NetworkUtils.java

示例6: MiniFtp

import java.net.URL; //导入方法依赖的package包/类
/**
 * Initial MiniFtp by url string.
 *
 * @param urlStr
 * @throws Exception
 */
public MiniFtp(String urlStr) throws Exception {
    URL url = new URL(urlStr);

    /** Parse user info. */
    String userInfo = url.getUserInfo();
    if (userInfo != null && !"".equals(userInfo)) {
        String[] userInfoArray = userInfo.split(":");
        user = userInfoArray[0];
        password = userInfoArray[1];
    }

    /** Parse host and port. */
    commandPort = url.getPort();
    host = url.getHost();

    /** Parse file and type. */
    file = url.getPath();
    if (file.contains(";")) {
        type = file.substring(file.lastIndexOf(";") + 1).replace("type=", "");
        file = file.substring(0, file.lastIndexOf(";"));
    }
}
 
开发者ID:xyhuangjinfu,项目名称:MiniDownloader,代码行数:29,代码来源:MiniFtp.java

示例7: getProxyExecutor

import java.net.URL; //导入方法依赖的package包/类
public static HttpCommandExecutor getProxyExecutor(URL url, Properties prop) {

        prop = decrypt(prop);

        String proxyHost = prop.getProperty("proxyHost");
        int proxyPort = Integer.valueOf(prop.getProperty("proxyPort"));
        String proxyUserDomain = prop.getProperty("proxyUserDomain");
        String proxyUser = prop.getProperty("proxyUser");
        String proxyPassword = prop.getProperty("proxyPassword");

        HttpClientBuilder builder = HttpClientBuilder.create();
        HttpHost proxy = new HttpHost(proxyHost, proxyPort);
        CredentialsProvider credsProvider = new BasicCredentialsProvider();

        credsProvider.setCredentials(new AuthScope(proxyHost, proxyPort),
                new NTCredentials(proxyUser, proxyPassword, getWorkstation(), proxyUserDomain));
        if (url.getUserInfo() != null && !url.getUserInfo().isEmpty()) {
            credsProvider.setCredentials(new AuthScope(url.getHost(), (url.getPort() > 0 ? url.getPort() : url.getDefaultPort())),
                    new UsernamePasswordCredentials(proxyUser, proxyPassword));
        }
        builder.setProxy(proxy);
        builder.setDefaultCredentialsProvider(credsProvider);
        HttpClient.Factory factory = new SimpleHttpClientFactory(builder);
        return new HttpCommandExecutor(new HashMap<String, CommandInfo>(), url, factory);

    }
 
开发者ID:CognizantQAHub,项目名称:Cognizant-Intelligent-Test-Scripter,代码行数:27,代码来源:RemoteProxy.java

示例8: getAuthenticationFromURL

import java.net.URL; //导入方法依赖的package包/类
private PasswordAuthentication getAuthenticationFromURL() {
    URL u = this.getRequestingURL();
    if (u != null) {
        String auth = u.getUserInfo();
        if (auth != null) {
            int i = auth.indexOf(':');
            String user = (i == -1) ? auth : auth.substring(0, i);
            String pwd = (i == -1) ? "" : auth.substring(i + 1);
            return new PasswordAuthentication(user, pwd.toCharArray());
        }
    }
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:14,代码来源:NbAuthenticator.java

示例9: getAuthentication

import java.net.URL; //导入方法依赖的package包/类
@Override
public PasswordAuthentication
getAuthentication(
	String		realm,
	URL			tracker )
{
	if ( user_name == null || password == null ){

		String user_info = tracker.getUserInfo();

		if ( user_info == null ){

			return( null );
		}

		String	user_bit	= user_info;
		String	pw_bit		= "";

		int	pos = user_info.indexOf(':');

		if ( pos != -1 ){

			user_bit	= user_info.substring(0,pos);
			pw_bit		= user_info.substring(pos+1);
		}

		return( new PasswordAuthentication( user_bit, pw_bit.toCharArray()));
	}

	return( new PasswordAuthentication( user_name, password.toCharArray()));
}
 
开发者ID:BiglySoftware,项目名称:BiglyBT,代码行数:32,代码来源:ResourceUploaderURLImpl.java

示例10: calculateNonProxyUri

import java.net.URL; //导入方法依赖的package包/类
private static URI calculateNonProxyUri(HttpServletRequest request) throws MalformedURLException, URISyntaxException {
    URL url = new URL(request.getRequestURL().toString());
    String host = url.getHost();
    String scheme = url.getProtocol();
    int port = url.getPort();
    String userInfo = url.getUserInfo();
    return new URI(scheme, userInfo, host, port, urlPathHelper.getContextPath(request), null, null);
}
 
开发者ID:airsonic,项目名称:airsonic,代码行数:9,代码来源:NetworkService.java

示例11: MultipartUtility

import java.net.URL; //导入方法依赖的package包/类
/**
 * This constructor initializes a new HTTP POST request with content type
 * is set to multipart/form-data
 * @param requestURL
 * @param charset
 * @throws IOException
 */
public MultipartUtility(String requestURL, String charset)
        throws IOException {
    this.charset = charset;

    // creates a unique boundary based on time stamp
    boundary = "===" + System.currentTimeMillis() + "===";

    URL url = new URL(requestURL);
    httpConn = (HttpURLConnection) url.openConnection();
    httpConn.setUseCaches(false);
    httpConn.setDoOutput(true); // indicates POST method
    httpConn.setDoInput(true);
    httpConn.setRequestProperty("Content-Type",
            "multipart/form-data; boundary=" + boundary);
    httpConn.setRequestProperty("User-Agent", "MaBite");

    //Basic auth auto
    if (url.getUserInfo() != null) {
        String basicAuth = "Basic " + new String(java.util.Base64.getEncoder().encode(url.getUserInfo().getBytes()));
        httpConn.setRequestProperty("Authorization", basicAuth);
    }

    outputStream = httpConn.getOutputStream();
    writer = new PrintWriter(new OutputStreamWriter(outputStream, charset),
            true);
}
 
开发者ID:SamaGames,项目名称:SamaGamesCore,代码行数:34,代码来源:MultipartUtility.java

示例12: ProxyInformation

import java.net.URL; //导入方法依赖的package包/类
public ProxyInformation(String rawProxy, Optional<String> nonProxyHosts) {
    try {
        URL proxyUrl = new URL(rawProxy);
        String userInfo = proxyUrl.getUserInfo();
        if (userInfo != null && !userInfo.isEmpty()) {
            String[] parts = userInfo.split(":");
            if (parts.length != 2) {
                throw new IllegalArgumentException(String.format("Malformed proxy URL '%s'", rawProxy));
            }
            this.username = Optional.of(parts[0]);
            this.password = Optional.of(parts[1]);
        } else {
            this.username = Optional.empty();
            this.password = Optional.empty();
        }
        this.host = proxyUrl.getHost();
        this.port = proxyUrl.getPort();

        // Turn "foo, .other.com" into ["foo", "*.other.com"]
        this.nonProxyHosts = nonProxyHosts.map(
            s -> Arrays.stream(s.split(","))
                .map(host -> host.trim().replaceAll("^\\.", "*."))
                .collect(Collectors.toList())
            ).orElseGet(ArrayList::new);
    } catch (MalformedURLException e) {
        throw new IllegalArgumentException(String.format("Malformed proxy URL '%s'", rawProxy), e);
    }
}
 
开发者ID:schibsted,项目名称:strongbox,代码行数:29,代码来源:ProxyInformation.java

示例13: test

import java.net.URL; //导入方法依赖的package包/类
@Test
	public void test() throws JSONException, IOException {
		
		String requestUrl  = "http://elastic:[email protected]:9200/log_idx/_search?sort=dateTime:desc&size=1";
		
		



		URL url = new URL(requestUrl);
		URLConnection urlConnection = url.openConnection();
		
		if(  url.getUserInfo() != null && url.getUserInfo().split(":").length==2 ) {
			LOGGER.info("Basic authentication usr/pwd >   " + url.getUserInfo());
			String name = url.getUserInfo().split(":")[0];
			String password = url.getUserInfo().split(":")[1];
	        byte[] authEncBytes = Base64.getEncoder().encode( (name + ":" + password).getBytes() );
	        urlConnection.setRequestProperty("Authorization", "Basic " + new String(authEncBytes));
	        

		} 
        
        InputStream is = urlConnection.getInputStream();
		
		String xmlResp = XML.toString(new JSONObject(IOUtils.toString(is)));
        
		StringBuilder response = new StringBuilder().append("<root>").append(xmlResp).append("</root>");
        LOGGER.info( response );

		
//		HTTPGetConnector httpget = HTTPGetConnector();
		
//		http://elastic:[email protected]:9200/log_idx/_search?sort=dateTime:desc&size=1
			

	}
 
开发者ID:rockitconsulting,项目名称:test.rockitizer,代码行数:37,代码来源:HTTPGetConnectorIntegration.java

示例14: URLBuilder

import java.net.URL; //导入方法依赖的package包/类
/**
 * Constructor.
 * 
 * @param baseURL URL to parse and use as basis for creating other URLs
 * 
 * @throws IllegalArgumentException thrown if the given base URL is not well formed
 */
public URLBuilder(String baseURL) {
    try {
        URL url = new URL(baseURL);

        setScheme(url.getProtocol());

        String userInfo = url.getUserInfo();
        if (!DatatypeHelper.isEmpty(userInfo)) {
            if (userInfo.contains(":")) {
                String[] userInfoComps = userInfo.split(":");
                setUsername(HTTPTransportUtils.urlDecode(userInfoComps[0]));
                setPassword(HTTPTransportUtils.urlDecode(userInfoComps[1]));
            } else {
                setUsername(userInfo);
            }
        }

        setHost(url.getHost());
        setPort(url.getPort());
        setPath(url.getPath());

        queryParams = new ArrayList<Pair<String, String>>();
        String queryString = url.getQuery();
        if (!DatatypeHelper.isEmpty(queryString)) {
            String[] queryComps = queryString.split("&");
            String queryComp;
            String[] paramComps;
            String paramName;
            String paramValue;
            for (int i = 0; i < queryComps.length; i++) {
                queryComp = queryComps[i];
                if (!queryComp.contains("=")) {
                    paramName = HTTPTransportUtils.urlDecode(queryComp);
                    queryParams.add(new Pair<String, String>(paramName, null));
                } else {
                    paramComps = queryComp.split("=");
                    paramName = HTTPTransportUtils.urlDecode(paramComps[0]);
                    paramValue = HTTPTransportUtils.urlDecode(paramComps[1]);
                    queryParams.add(new Pair<String, String>(paramName, paramValue));
                }
            }
        }

        setFragment(url.getRef());
    } catch (MalformedURLException e) {
        throw new IllegalArgumentException("Given URL is not well formed", e);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:56,代码来源:URLBuilder.java

示例15: equals

import java.net.URL; //导入方法依赖的package包/类
protected boolean equals(URL u1, URL u2) {
    String userInfo1 = u1.getUserInfo();
    String userInfo2 = u2.getUserInfo();
    return super.equals(u1, u2) &&
        (userInfo1 == null? userInfo2 == null: userInfo1.equals(userInfo2));
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:7,代码来源:Handler.java


注:本文中的java.net.URL.getUserInfo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。