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

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

本文整理了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

  1. private URI getBaseUri(final Request request) {
  2. try {
  3. final String hostHeader = request.getValue("Host");
  4. if (hostHeader != null) {
  5. final String scheme = request.isSecure() ? "https" : "http";
  6. return new URI(scheme + "://" + hostHeader + "/");
  7. } else {
  8. final Address address = request.getAddress();
  9. return new URI(address.getScheme(), null, address.getDomain(), address.getPort(), "/", null,
  10. null);
  11. }
  12. } catch (final URISyntaxException ex) {
  13. throw new IllegalArgumentException(ex);
  14. }
  15. }

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

  1. private URI getBaseUri(Request request) {
  2. try {
  3. final Address address = request.getAddress();
  4. return new URI(
  5. address.getScheme(),
  6. null,
  7. address.getDomain(),
  8. address.getPort(),
  9. "/",
  10. null, null);
  11. } catch (URISyntaxException ex) {
  12. throw new IllegalArgumentException(ex);
  13. }
  14. }

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

  1. private URI getBaseUri(final Request request) {
  2. try {
  3. final String hostHeader = request.getValue("Host");
  4. if (hostHeader != null) {
  5. final String scheme = request.isSecure() ? "https" : "http";
  6. return new URI(scheme + "://" + hostHeader + "/");
  7. } else {
  8. final Address address = request.getAddress();
  9. return new URI(address.getScheme(), null, address.getDomain(), address.getPort(), "/", null,
  10. null);
  11. }
  12. } catch (final URISyntaxException ex) {
  13. throw new IllegalArgumentException(ex);
  14. }
  15. }

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

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

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

  1. public static FullHttpRequest convert(final Request request) {
  2. byte[] data = null;
  3. try {
  4. final InputStream inputStream = request.getInputStream();
  5. try {
  6. data = IOUtils.toByteArray(inputStream);
  7. } finally {
  8. inputStream.close();
  9. }
  10. } catch (final IOException e) {
  11. LOGGER.error("IOException when getting request content.", e);
  12. }
  13. final FullHttpRequestImpl httpRequest = new FullHttpRequestImpl();
  14. httpRequest.domain(request.getAddress().getDomain());
  15. httpRequest.port(request.getAddress().getPort());
  16. httpRequest.method(Method.valueOf(request.getMethod()));
  17. httpRequest.path(request.getPath().getPath());
  18. if (data.length > 0) {
  19. httpRequest.content(data);
  20. }
  21. for (final String headerField : request.getNames()) {
  22. for (final String headerFieldValue : request.getValues(headerField)) {
  23. httpRequest.httpMessageHeader(headerField, headerFieldValue);
  24. }
  25. }
  26. for (final Entry<String, String> entry : request.getQuery().entrySet()) {
  27. httpRequest.queryParameter(entry.getKey(), entry.getValue());
  28. }
  29. return httpRequest;
  30. }

相关文章