org.simpleframework.http.Address.getPort()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(3.1k)|赞(0)|评价(0)|浏览(141)

本文整理了Java中org.simpleframework.http.Address.getPort()方法的一些代码示例,展示了Address.getPort()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Address.getPort()方法的具体详情如下:
包路径:org.simpleframework.http.Address
类名称:Address
方法名:getPort

Address.getPort介绍

[英]This is used to retrieve the port of the uniform resource identifier. The port part in this is an optional part, an example http://host:port/path?querypart. This will return the value of the port. If there is no port then this will return -1 because this represents an impossible uniform resource identifier port. The port is an optional part.
[中]这用于检索统一资源标识符的端口。其中的端口部分是可选部分,例如http://host:port/path?querypart。这将返回端口的值。如果没有端口,那么它将返回-1,因为这表示一个不可能的统一资源标识符端口。端口是可选部件。

代码示例

代码示例来源:origin: jersey/jersey

private URI getBaseUri(final Request request) {
  try {
    final String hostHeader = request.getValue("Host");
    if (hostHeader != null) {
      final String scheme = request.isSecure() ? "https" : "http";
      return new URI(scheme + "://" + hostHeader + "/");
    } else {
      final Address address = request.getAddress();
      return new URI(address.getScheme(), null, address.getDomain(), address.getPort(), "/", null,
          null);
    }
  } catch (final URISyntaxException ex) {
    throw new IllegalArgumentException(ex);
  }
}

代码示例来源:origin: com.sun.jersey.contribs/jersey-simple-server

private URI getBaseUri(Request request) {
  try {
    final Address address = request.getAddress();
    return new URI(
        address.getScheme(),
        null,
        address.getDomain(),
        address.getPort(),
        "/",
        null, null);
  } catch (URISyntaxException ex) {
    throw new IllegalArgumentException(ex);
  }
}

代码示例来源:origin: org.glassfish.jersey.containers/jersey-container-simple-http

private URI getBaseUri(final Request request) {
  try {
    final String hostHeader = request.getValue("Host");
    if (hostHeader != null) {
      final String scheme = request.isSecure() ? "https" : "http";
      return new URI(scheme + "://" + hostHeader + "/");
    } else {
      final Address address = request.getAddress();
      return new URI(address.getScheme(), null, address.getDomain(), address.getPort(), "/", null,
          null);
    }
  } catch (final URISyntaxException ex) {
    throw new IllegalArgumentException(ex);
  }
}

代码示例来源:origin: miltonio/milton2

if (a.getPort() != 80 && a.getPort() > 0) {
  s = s + ":" + a.getPort();

代码示例来源:origin: kristofa/mock-http-server

public static FullHttpRequest convert(final Request request) {
  byte[] data = null;
  try {
    final InputStream inputStream = request.getInputStream();
    try {
      data = IOUtils.toByteArray(inputStream);
    } finally {
      inputStream.close();
    }
  } catch (final IOException e) {
    LOGGER.error("IOException when getting request content.", e);
  }
  final FullHttpRequestImpl httpRequest = new FullHttpRequestImpl();
  httpRequest.domain(request.getAddress().getDomain());
  httpRequest.port(request.getAddress().getPort());
  httpRequest.method(Method.valueOf(request.getMethod()));
  httpRequest.path(request.getPath().getPath());
  if (data.length > 0) {
    httpRequest.content(data);
  }
  for (final String headerField : request.getNames()) {
    for (final String headerFieldValue : request.getValues(headerField)) {
      httpRequest.httpMessageHeader(headerField, headerFieldValue);
    }
  }
  for (final Entry<String, String> entry : request.getQuery().entrySet()) {
    httpRequest.queryParameter(entry.getKey(), entry.getValue());
  }
  return httpRequest;
}

相关文章