org.simpleframework.http.Address类的使用及代码示例

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

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

Address介绍

[英]The Address interface is used to represent a generic uniform resource identifier. This interface allows each section of the uniform resource identifier to be represented. A generic uniform resource identifier syntax is represented in RFC 2616 section 3.2.2 for the HTTP protocol, this allows similar URI's for example ftp, http, https, tftp. The syntax is <<$0$>> This interface represents the host, port, path and query part of the uniform resource identifier. The parameters are also represented by the URI. The parameters in a URI consist of name and value pairs in the path segment of the URI.

This will normalize the path part of the uniform resource identifier. A normalized path is one that contains no back references like "./" and "../". The normalized path will not contain the path parameters.
[中]Address接口用于表示通用统一资源标识符。此接口允许表示统一资源标识符的每个部分。RFC 2616第3.2.2节中表示了HTTP协议的通用统一资源标识符语法,这允许类似的URI,例如ftp、HTTP、https、tftp。语法为<<$0$>>此接口表示统一资源标识符的主机、端口、路径和查询部分。参数也由URI表示。URI中的参数由URI路径段中的名称和值对组成。
这将规范化统一资源标识符的路径部分。规范化路径是不包含像“/”和“./”这样的反向引用的路径。规范化路径将不包含路径参数。

代码示例

代码示例来源: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: mpetazzoni/ttorrent

  1. myRequestProcessor.process(request.getAddress().toString(), request.getClientAddress().getAddress().getHostAddress(),
  2. getRequestHandler(response));
  3. } else {
  4. myMultiAnnounceRequestProcessor.process(request.getContent(), request.getAddress().toString(),
  5. request.getClientAddress().getAddress().getHostAddress(), getRequestHandler(response));

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

  1. Address a = baseRequest.getAddress();
  2. if (host == null) {
  3. host = a.getDomain();
  4. if (a.getPort() != 80 && a.getPort() > 0) {
  5. s = s + ":" + a.getPort();

代码示例来源:origin: org.simpleframework/simple-http

  1. /**
  2. * This is used to acquire the path as extracted from the
  3. * the HTTP request URI. The <code>Path</code> object that is
  4. * provided by this method is immutable, it represents the
  5. * normalized path only part from the request URI.
  6. *
  7. * @return this returns the normalized path for the request
  8. */
  9. public Path getPath() {
  10. return getAddress().getPath();
  11. }

代码示例来源:origin: org.simpleframework/simple

  1. /**
  2. * This method is used to acquire the query part from the
  3. * HTTP request URI target. This will return only the values
  4. * that have been extracted from the request URI target.
  5. *
  6. * @return the query associated with the HTTP target URI
  7. */
  8. public Query getQuery() {
  9. return getAddress().getQuery();
  10. }

代码示例来源: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. }

代码示例来源:origin: org.simpleframework/simple

  1. /**
  2. * This is used to acquire the path as extracted from the
  3. * the HTTP request URI. The <code>Path</code> object that is
  4. * provided by this method is immutable, it represents the
  5. * normalized path only part from the request URI.
  6. *
  7. * @return this returns the normalized path for the request
  8. */
  9. public Path getPath() {
  10. return getAddress().getPath();
  11. }

代码示例来源:origin: ngallagher/simpleframework

  1. /**
  2. * This method is used to acquire the query part from the
  3. * HTTP request URI target. This will return only the values
  4. * that have been extracted from the request URI target.
  5. *
  6. * @return the query associated with the HTTP target URI
  7. */
  8. public Query getQuery() {
  9. return getAddress().getQuery();
  10. }

代码示例来源: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: miltonio/milton2

  1. @Override
  2. public String getFromAddress() {
  3. Address add = baseRequest.getAddress();
  4. if (add == null) {
  5. return null;
  6. }
  7. return add.toString();
  8. }

代码示例来源:origin: ngallagher/simpleframework

  1. /**
  2. * This is used to acquire the path as extracted from the
  3. * the HTTP request URI. The <code>Path</code> object that is
  4. * provided by this method is immutable, it represents the
  5. * normalized path only part from the request URI.
  6. *
  7. * @return this returns the normalized path for the request
  8. */
  9. public Path getPath() {
  10. return getAddress().getPath();
  11. }

代码示例来源:origin: org.simpleframework/simple-http

  1. /**
  2. * This method is used to acquire the query part from the
  3. * HTTP request URI target. This will return only the values
  4. * that have been extracted from the request URI target.
  5. *
  6. * @return the query associated with the HTTP target URI
  7. */
  8. public Query getQuery() {
  9. return getAddress().getQuery();
  10. }

代码示例来源: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. @Override
  2. public String toString() {
  3. return request.getMethod() + " " + request.getAddress().toString();
  4. }

代码示例来源:origin: zanata/zanata-platform

  1. @Override
  2. public void handle(Request request, Response response) {
  3. try {
  4. PrintStream body = response.getPrintStream();
  5. long time = System.currentTimeMillis();
  6. response.setValue("Content-Type", "text/plain");
  7. response.setContentType("application/xml;charset=utf-8");
  8. response.setDate("Date", time);
  9. response.setDate("Last-Modified", time);
  10. String path = request.getAddress().getPath().getPath();
  11. log.trace("request path is {}", path);
  12. StatusAndContent statusAndContent = tryMatchPath(path);
  13. Status status = statusAndContent.status;
  14. response.setStatus(status);
  15. String content = statusAndContent.content;
  16. log.trace("mock container returning: status [{}], content [{}]",
  17. status, content);
  18. body.println(content);
  19. body.close();
  20. } catch (Exception e) {
  21. e.printStackTrace();
  22. response.setStatus(Status.INTERNAL_SERVER_ERROR);
  23. try {
  24. response.close();
  25. } catch (IOException e1) {
  26. throw new RuntimeException(e1);
  27. }
  28. }
  29. }

代码示例来源:origin: org.kie.remote/kie-remote-client

  1. public void handle( Request req, Response resp ) {
  2. try {
  3. PrintStream out = resp.getPrintStream(1024);
  4. String address = req.getAddress().toString();
  5. if( address.equals(DEFAULT_ENPOINT) ) {
  6. String content = readInputStreamAsString(req.getInputStream());
  7. JaxbCommandsRequest cmdsReq = (JaxbCommandsRequest) jaxbSerializationProvider.deserialize(content);
  8. String [] headerNames = {
  9. TEST_HEADER_NAME,
  10. ANOTHER_TEST_HEADER_NAME,
  11. NOT_SENT_HEADER_NAME
  12. };
  13. List<String> headerValues = new ArrayList<String>();
  14. for( String headerName : headerNames ) {
  15. String headerVal = req.getValue(headerName);
  16. if( headerVal != null ) {
  17. headerValues.add(headerVal);
  18. }
  19. }
  20. String output = handleJaxbCommandsRequest(cmdsReq, headerValues);
  21. resp.setCode(HttpURLConnection.HTTP_OK);
  22. out.print(output);
  23. } else {
  24. resp.setCode(HttpURLConnection.HTTP_BAD_REQUEST);
  25. }
  26. out.close();
  27. } catch( Exception e ) {
  28. e.printStackTrace();
  29. }
  30. }

代码示例来源:origin: org.kie.remote/kie-remote-client

  1. logger.debug(headers[0] + ": " + user + "/" + pass);
  2. String address = req.getAddress().toString();
  3. if( address.equals(DEFAULT_ENDPOINT) ) {
  4. resp.setValue(HttpHeaders.CONTENT_TYPE, "text/plain");

代码示例来源:origin: org.kie.remote/kie-remote-client

  1. public void handle( Request req, Response resp ) {
  2. try {
  3. PrintStream out = resp.getPrintStream(1024);
  4. String address = req.getAddress().toString();
  5. if( address.equals(REDIRECT_PATH) ) {
  6. resp.setValue(HttpHeaders.LOCATION, REAL_ENDPOINT_PATH);

相关文章