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


Java URI.getPort方法代码示例

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


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

示例1: InnerHttpServletRequest

import java.net.URI; //导入方法依赖的package包/类
public InnerHttpServletRequest(URI uri, Map<String, String> headers, String method,
			       String body) 
  throws java.net.URISyntaxException {
    this.method = method;
    this.host = uri.getHost();
    this.scheme = uri.getScheme();
    this.port = uri.getPort();
    this.path = uri.getRawPath();
    this.queryString = uri.getRawQuery();
    extractParameters();
    extractHeaders(headers);
    this.headers.put("host", host);
    if (body != null)
	this.headers.put("content-length", Integer.toString(body.length()));
    this.body = body;
}
 
开发者ID:middle2tw,项目名称:whackpad,代码行数:17,代码来源:HttpServletRequestFactory.java

示例2: HTTPMetadataProvider

import java.net.URI; //导入方法依赖的package包/类
/**
 * Constructor.
 * 
 * @param metadataURL the URL to fetch the metadata
 * @param requestTimeout the time, in milliseconds, to wait for the metadata server to respond
 * 
 * @throws MetadataProviderException thrown if the URL is not a valid URL or the metadata can not be retrieved from
 *             the URL
 */
@Deprecated
public HTTPMetadataProvider(String metadataURL, int requestTimeout) throws MetadataProviderException {
    super();
    try {
        metadataURI = new URI(metadataURL);
    } catch (URISyntaxException e) {
        throw new MetadataProviderException("Illegal URL syntax", e);
    }

    HttpClientParams clientParams = new HttpClientParams();
    clientParams.setSoTimeout(requestTimeout);
    httpClient = new HttpClient(clientParams);
    httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(requestTimeout);
    authScope = new AuthScope(metadataURI.getHost(), metadataURI.getPort());

}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:26,代码来源:HTTPMetadataProvider.java

示例3: normalizeUrl

import java.net.URI; //导入方法依赖的package包/类
protected static String normalizeUrl(String url) throws URISyntaxException {
    URI uri = new URI(url);
    String scheme = uri.getScheme().toLowerCase();
    String authority = uri.getAuthority().toLowerCase();
    boolean dropPort = (scheme.equals("http") && uri.getPort() == 80)
                       || (scheme.equals("https") && uri.getPort() == 443);
    if (dropPort) {
        // find the last : in the authority
        int index = authority.lastIndexOf(":");
        if (index >= 0) {
            authority = authority.substring(0, index);
        }
    }
    String path = uri.getRawPath();
    if (path == null || path.length() <= 0) {
        path = "/"; // conforms to RFC 2616 section 3.2.2
    }
    // we know that there is no query and no fragment here.
    return scheme + "://" + authority + path;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:21,代码来源:OAuthSignatureMethod.java

示例4: initializeClientFromURI

import java.net.URI; //导入方法依赖的package包/类
private void initializeClientFromURI(URI uri) {
  if (!JedisURIHelper.isValid(uri)) {
    throw new InvalidURIException(String.format(
      "Cannot open Redis connection due invalid URI. %s", uri.toString()));
  }

  client = new Client(uri.getHost(), uri.getPort());

  String password = JedisURIHelper.getPassword(uri);
  if (password != null) {
    client.auth(password);
    client.getStatusCodeReply();
  }

  int dbIndex = JedisURIHelper.getDBIndex(uri);
  if (dbIndex > 0) {
    client.select(dbIndex);
    client.getStatusCodeReply();
    client.setDb(dbIndex);
  }
}
 
开发者ID:x7-framework,项目名称:x7,代码行数:22,代码来源:BinaryJedis.java

示例5: createServerGate

import java.net.URI; //导入方法依赖的package包/类
@Override
public ServerGate createServerGate(URI uri) {
	String host = uri.getHost();
	int port = uri.getPort();
	if (port < 0) {
		port = DEFAULT_PORT;
	}
	HashMap<String,String> query = GateFactory.parseQuery(uri.getQuery());
	jSpaceMarshaller marshaller = getMarshaller(query.get(GateFactory.LANGUAGE_QUERY_ELEMENT));
	String mode = query.getOrDefault(GateFactory.MODE_QUERY_ELEMENT,DEFAULT_MODE).toUpperCase();
	if (query.containsKey(KEEP_MODE)) {
		return new KeepServerGate(marshaller,new InetSocketAddress(host, port),DEFAULT_BACKLOG);
	}
	if (query.containsKey(CONN_MODE)) {
		return new ConnServerGate(marshaller, new InetSocketAddress(host, port),DEFAULT_BACKLOG);
	}
	//TODO: Add here other modes!
	return new KeepServerGate(marshaller,new InetSocketAddress(host, port),DEFAULT_BACKLOG);
}
 
开发者ID:pSpaces,项目名称:jSpace,代码行数:20,代码来源:TcpGateBuilder.java

示例6: getDefaultOrigin

import java.net.URI; //导入方法依赖的package包/类
/**
 * Get the default HTTP(S) origin for a specific WebSocket URI
 *
 * @param String uri
 * @return A string of the endpoint converted to HTTP protocol (http[s]://host[:port])
 */

private static String getDefaultOrigin(String uri) {
  try {
    String defaultOrigin;
    String scheme = "";

    URI requestURI = new URI(uri);
    if (requestURI.getScheme().equals("wss")) {
      scheme += "https";
    } else if (requestURI.getScheme().equals("ws")) {
      scheme += "http";
    } else if (requestURI.getScheme().equals("http") || requestURI.getScheme().equals("https")) {
      scheme += requestURI.getScheme();
    }

    if (requestURI.getPort() != -1) {
      defaultOrigin = String.format(
        "%s://%s:%s",
        scheme,
        requestURI.getHost(),
        requestURI.getPort());
    } else {
      defaultOrigin = String.format("%s://%s/", scheme, requestURI.getHost());
    }

    return defaultOrigin;
  } catch (URISyntaxException e) {
    throw new IllegalArgumentException("Unable to set " + uri + " as default origin header");
  }
}
 
开发者ID:qq565999484,项目名称:RNLearn_Project1,代码行数:37,代码来源:WebSocketModule.java

示例7: newNameResolver

import java.net.URI; //导入方法依赖的package包/类
@Nullable
@Override
public ConsulNameResolver newNameResolver(final URI targetUri, final Attributes params) {
    if (!SCHEME.equals(targetUri.getScheme())) {
        return null;
    }

    final String targetPath = checkNotNull(targetUri.getPath(), "targetPath");
    checkArgument(targetPath.startsWith("/"));

    final String serviceName = targetPath.substring(1);
    checkArgument(serviceName.length() > 0, "serviceName");

    String consulHost = targetUri.getHost();
    if (Strings.isNullOrEmpty(consulHost)) {
        consulHost = DEFAULT_HOST;
    }

    int consulPort = targetUri.getPort();
    if (consulPort == -1) {
        consulPort = DEFAULT_PORT;
    }

    final String tag = Strings.emptyToNull(targetUri.getFragment());

    final ConsulClient consulClient = ConsulClientManager.getInstance(consulHost, consulPort);

    return new ConsulNameResolver(
            consulClient /* CatalogClient */,
            consulClient /* KeyValueClient */,
            serviceName,
            Optional.ofNullable(tag),
            GrpcUtil.TIMER_SERVICE,
            GrpcUtil.SHARED_CHANNEL_EXECUTOR
    );
}
 
开发者ID:indeedeng-alpha,项目名称:indeed-grpc-java,代码行数:37,代码来源:ConsulNameResolverProvider.java

示例8: callbackUrlFor

import java.net.URI; //导入方法依赖的package包/类
protected static String callbackUrlFor(final URI baseUrl, final MultiValueMap<String, String> additionalParams) {
    final String path = baseUrl.getPath();

    final String callbackPath = path + "credentials/callback";

    try {
        final URI base = new URI(baseUrl.getScheme(), null, baseUrl.getHost(), baseUrl.getPort(), callbackPath,
            null, null);

        return UriComponentsBuilder.fromUri(base).queryParams(additionalParams).build().toUriString();
    } catch (final URISyntaxException e) {
        throw new IllegalStateException("Unable to generate callback URI", e);
    }
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:15,代码来源:BaseCredentialProvider.java

示例9: execute

import java.net.URI; //导入方法依赖的package包/类
public HttpResponse execute(HttpUriRequest request, HttpContext context)
        throws IOException {
    URI uri = request.getURI();
    HttpHost httpHost = new HttpHost(uri.getHost(), uri.getPort(),
            uri.getScheme());
    return execute(httpHost, request, context);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:8,代码来源:AutoRetryHttpClient.java

示例10: createSocketAddr

import java.net.URI; //导入方法依赖的package包/类
/**
 * Create an InetSocketAddress from the given target string and
 * default port. If the string cannot be parsed correctly, the
 * <code>configName</code> parameter is used as part of the
 * exception message, allowing the user to better diagnose
 * the misconfiguration.
 *
 * @param target a string of either "host" or "host:port"
 * @param defaultPort the default port if <code>target</code> does not
 *                    include a port number
 * @param configName the name of the configuration from which
 *                   <code>target</code> was loaded. This is used in the
 *                   exception message in the case that parsing fails. 
 */
public static InetSocketAddress createSocketAddr(String target,
                                                 int defaultPort,
                                                 String configName) {
  String helpText = "";
  if (configName != null) {
    helpText = " (configuration property '" + configName + "')";
  }
  if (target == null) {
    throw new IllegalArgumentException("Target address cannot be null." +
        helpText);
  }
  target = target.trim();
  boolean hasScheme = target.contains("://");    
  URI uri = null;
  try {
    uri = hasScheme ? URI.create(target) : URI.create("dummyscheme://"+target);
  } catch (IllegalArgumentException e) {
    throw new IllegalArgumentException(
        "Does not contain a valid host:port authority: " + target + helpText
    );
  }

  String host = uri.getHost();
  int port = uri.getPort();
  if (port == -1) {
    port = defaultPort;
  }
  String path = uri.getPath();
  
  if ((host == null) || (port < 0) ||
      (!hasScheme && path != null && !path.isEmpty()))
  {
    throw new IllegalArgumentException(
        "Does not contain a valid host:port authority: " + target + helpText
    );
  }
  return createSocketAddrForHost(host, port);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:53,代码来源:NetUtils.java

示例11: doRun

import java.net.URI; //导入方法依赖的package包/类
private static void doRun ( URI u, final Object payloadObject, String username, String password ) {
    ConnectionProvider instance = null;
    ConnectionProviderContextImpl context = null;
    ConnectionHandler ch = null;
    Channel c = null;
    VersionedConnection vc = null;
    try {
        Logger logger = LogManager.getLogManager().getLogger("");
        logger.addHandler(new ConsoleLogHandler());
        logger.setLevel(Level.INFO);
        OptionMap options = OptionMap.builder().set(Options.SSL_ENABLED, u.getScheme().equals("https")).getMap();
        context = new ConnectionProviderContextImpl(options, "endpoint");
        instance = new HttpUpgradeConnectionProviderFactory().createInstance(context, options);
        String host = u.getHost();
        int port = u.getPort() > 0 ? u.getPort() : 9990;
        SocketAddress destination = new InetSocketAddress(host, port);
        ConnectionHandlerFactory chf = getConnection(destination, username, password, context, instance, options);
        ch = chf.createInstance(new ConnectionHandlerContextImpl(context));
        c = getChannel(context, ch, options);
        System.err.println("Connected");
        vc = makeVersionedConnection(c);
        MBeanServerConnection mbc = vc.getMBeanServerConnection(null);
        doExploit(payloadObject, mbc);
        System.err.println("DONE");
    }
    catch ( Throwable e ) {
        e.printStackTrace(System.err);
    }
    finally {
        cleanup(instance, context, ch, c, vc);
    }
}
 
开发者ID:pimps,项目名称:ysoserial-modified,代码行数:33,代码来源:JBoss.java

示例12: getNode

import java.net.URI; //导入方法依赖的package包/类
@Override
public N getNode(String address) {
    Collection<N> clients = (Collection<N>) connectionManager.getClients();
    URI uri = URIBuilder.create(address);
    InetSocketAddress addr = new InetSocketAddress(uri.getHost(), uri.getPort());
    for (N node : clients) {
        if (node.getAddr().equals(addr)) {
            return node;
        }
    }
    return null;
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:13,代码来源:RedisNodes.java

示例13: initialize

import java.net.URI; //导入方法依赖的package包/类
@Override
public void initialize(URI name, Configuration conf) throws IOException {
  super.initialize(name, conf);
  if (name.getHost() == null || name.getPort() == -1) {
    throw new IllegalArgumentException("FileSystem name needs a complete authority element.");
  }
  uri = name;  }
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:8,代码来源:RemoteNodeFileSystem.java

示例14: generateTmpDirectory

import java.net.URI; //导入方法依赖的package包/类
public static Path generateTmpDirectory(Configuration conf, String appId, Path outputPath) {
  URI uri = outputPath.toUri();
  String path = (uri.getScheme() != null ? uri.getScheme() : "hdfs") + "://"
           + (uri.getHost() != null ? uri.getHost() : "")
           + (uri.getPort() > 0 ? (":" + uri.getPort()) : "");
  String user = conf.get(AngelConf.USER_NAME, "");
  String tmpDir = conf.get(AngelConf.ANGEL_JOB_TMP_OUTPUT_PATH_PREFIX, "/tmp/" + user);
  String finalTmpDirForApp = path + tmpDir + "/" + appId + "_" + UUID.randomUUID().toString();
  LOG.info("tmp output dir is " + finalTmpDirForApp);
  return new Path(finalTmpDirForApp);
}
 
开发者ID:Tencent,项目名称:angel,代码行数:12,代码来源:HdfsUtil.java

示例15: Node

import java.net.URI; //导入方法依赖的package包/类
public Node(String enodeURL) {
    try {
        URI uri = new URI(enodeURL);
        if (!uri.getScheme().equals("enode")) {
            throw new RuntimeException("expecting URL in the format enode://[email protected]:PORT");
        }
        this.id = Hex.decode(uri.getUserInfo());
        this.host = uri.getHost();
        this.port = uri.getPort();
    } catch (URISyntaxException e) {
        throw new RuntimeException("expecting URL in the format enode://[email protected]:PORT", e);
    }
}
 
开发者ID:talentchain,项目名称:talchain,代码行数:14,代码来源:Node.java


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