org.glassfish.tyrus.core.Utils类的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(8.8k)|赞(0)|评价(0)|浏览(174)

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

Utils介绍

[英]Utility methods shared among Tyrus modules.
[中]Tyrus模块之间共享的实用方法。

代码示例

代码示例来源:origin: spring-projects/spring-framework

@Override
protected void handleSuccess(HttpServletRequest request, HttpServletResponse response,
    UpgradeInfo upgradeInfo, TyrusUpgradeResponse upgradeResponse) throws IOException, ServletException {
  TyrusHttpUpgradeHandler handler = request.upgrade(TyrusHttpUpgradeHandler.class);
  Writer servletWriter = newServletWriter(handler);
  handler.preInit(upgradeInfo, servletWriter, request.getUserPrincipal() != null);
  response.setStatus(upgradeResponse.getStatus());
  upgradeResponse.getHeaders().forEach((key, value) -> response.addHeader(key, Utils.getHeaderFromList(value)));
  response.flushBuffer();
}

代码示例来源:origin: org.glassfish.tyrus/tyrus-core

/**
 * Get typed property from generic property map.
 *
 * @param properties property map.
 * @param key        key of value to be retrieved.
 * @param type       type of value to be retrieved.
 * @param <T>        type of value to be retrieved.
 * @return typed value or {@code null} if property is not set or value is not assignable.
 */
public static <T> T getProperty(Map<String, Object> properties, String key, Class<T> type) {
  return getProperty(properties, key, type, null);
}

代码示例来源:origin: org.glassfish.tyrus/tyrus-client

AuthConfig authConfig = Utils.getProperty(properties, ClientProperties.AUTH_CONFIG,
                     AuthConfig.class,
                     AuthConfig.Builder.create().build());
                                     .WWW_AUTHENTICATE);
if (authHeader != null) {
  wwwAuthenticateHeader = Utils.getHeaderFromList(authHeader);

代码示例来源:origin: eclipse-ee4j/tyrus

requestContext.getHeaders().put(name, Utils.parseHeaderValue(
      headerValues.nextElement().trim()));
} else {
  values.addAll(Utils.parseHeaderValue(headerValues.nextElement().trim()));
  httpServletResponse.addHeader(entry.getKey(), Utils.getHeaderFromList(entry.getValue()));

代码示例来源:origin: org.glassfish.tyrus/tyrus-client

final List<String> locationHeader = upgradeResponse.getHeaders().get(UpgradeResponse.LOCATION);
if (locationHeader != null) {
  locationString = Utils.getHeaderFromList(locationHeader);
    scheme = "wss";
  int port = Utils.getWsPort(location, scheme);
  location = new URI(scheme, location.getUserInfo(), location.getHost(), port, location
      .getPath(), location.getQuery(), location.getFragment());

代码示例来源:origin: eclipse-ee4j/tyrus

+ "response: \n" + Utils.stringifyUpgradeResponse(upgradeResponse));
} else {
  if (logUpgradeMessages) {
    debugContext.appendStandardOutputMessage(DebugContext.Type.MESSAGE_IN, "Received handshake response: "
        + "\n" + Utils.stringifyUpgradeResponse(upgradeResponse));
                                 .get(UpgradeResponse.RETRY_AFTER);
      if (retryAfterHeader != null) {
        retryAfterString = Utils.getHeaderFromList(retryAfterHeader);
        try {
          Date date = Utils.parseHttpDate(retryAfterString);
          delay = (date.getTime() - System.currentTimeMillis()) / 1000;
        } catch (ParseException e) {

代码示例来源:origin: org.glassfish.tyrus/tyrus-core

/**
 * Get port from provided {@link URI}.
 * <p>
 * Expected schemes are {@code "ws"} and {@code "wss"} and this method will return {@code 80} or
 * {@code 443} when the port is not explicitly set in the provided {@link URI}.
 *
 * @param uri provided uri.
 * @return port number which should be used for creating connections/etc.
 */
public static int getWsPort(URI uri) {
  return getWsPort(uri, uri.getScheme());
}

代码示例来源:origin: org.glassfish.tyrus/tyrus-core

@Override
public void sendBinary(ByteBuffer data, SendHandler handler) {
  checkNotNull(data, "data");
  checkNotNull(handler, "handler");
  clusterContext.sendBinary(sessionId, Utils.getRemainingArray(data), handler);
}

代码示例来源:origin: eclipse-ee4j/tyrus

TyrusUpgradeResponse parseUpgradeResponse() throws ParseException {
  String response = bufferToString();
  String[] tokens = response.split(LINE_SEPARATOR);
  TyrusUpgradeResponse tyrusUpgradeResponse = new TyrusUpgradeResponse();
  parseFirstLine(tokens, tyrusUpgradeResponse);
  List<String> lines = new LinkedList<>();
  lines.addAll(Arrays.asList(tokens).subList(1, tokens.length));
  Map<String, String> headers = parseHeaders(lines);
  for (Map.Entry<String, String> entry : headers.entrySet()) {
    final List<String> values = tyrusUpgradeResponse.getHeaders().get(entry.getKey());
    if (values == null) {
      tyrusUpgradeResponse.getHeaders().put(entry.getKey(), Utils.parseHeaderValue(entry.getValue()));
    } else {
      values.addAll(Utils.parseHeaderValue(entry.getValue()));
    }
  }
  return tyrusUpgradeResponse;
}

代码示例来源:origin: eclipse-ee4j/tyrus

private String bufferToString() {
  byte[] bytes = Utils.getRemainingArray(buffer);
  String str;
  try {
    str = new String(bytes, ENCODING);
  } catch (UnsupportedEncodingException e) {
    throw new RuntimeException("Unsupported encoding" + ENCODING, e);
  }
  return str;
}

代码示例来源:origin: eclipse-ee4j/tyrus

void append(ByteBuffer b) {
    if (buffer == null) {
      buffer = ByteBuffer.allocate(b.remaining());
      buffer.flip();
    }
    int newSize = buffer.limit() + b.remaining();
    buffer = Utils.appendBuffers(buffer, b, newSize, 50);
  }
}

代码示例来源:origin: org.glassfish.tyrus/tyrus-core

"Received handshake request:\n" + Utils.stringifyUpgradeRequest(request));
  debugContext.appendLogMessage(LOGGER, Level.FINE, DebugContext.Type.MESSAGE_OUT,
                 "Sending handshake response:\n"
                     + Utils.stringifyUpgradeResponse(response));
debugContext.appendLogMessage(LOGGER, Level.FINE, DebugContext.Type.MESSAGE_OUT,
               "Sending handshake response:\n"
                   + Utils.stringifyUpgradeResponse(response) + "\n");

代码示例来源:origin: org.glassfish.tyrus/tyrus-client

private void logUpgradeRequest(UpgradeRequest upgradeRequest) {
  if (LOGGER.isLoggable(Level.FINE)) {
    debugContext.appendLogMessage(LOGGER, Level.FINE, DebugContext.Type.MESSAGE_OUT, "Sending handshake "
        + "request:\n" + Utils.stringifyUpgradeRequest(upgradeRequest));
  } else {
    if (logUpgradeMessages) {
      debugContext.appendStandardOutputMessage(DebugContext.Type.MESSAGE_OUT, "Sending handshake "
          + "request:\n" + Utils.stringifyUpgradeRequest(upgradeRequest));
    }
  }
}

代码示例来源:origin: eclipse-ee4j/tyrus

/**
 * Get typed property from generic property map.
 *
 * @param properties property map.
 * @param key        key of value to be retrieved.
 * @param type       type of value to be retrieved.
 * @param <T>        type of value to be retrieved.
 * @return typed value or {@code null} if property is not set or value is not assignable.
 */
public static <T> T getProperty(Map<String, Object> properties, String key, Class<T> type) {
  return getProperty(properties, key, type, null);
}

代码示例来源:origin: eclipse-ee4j/tyrus

AuthConfig authConfig = Utils.getProperty(properties, ClientProperties.AUTH_CONFIG,
                     AuthConfig.class,
                     AuthConfig.Builder.create().build());
                                     .WWW_AUTHENTICATE);
if (authHeader != null) {
  wwwAuthenticateHeader = Utils.getHeaderFromList(authHeader);

代码示例来源:origin: eclipse-ee4j/tyrus

final List<String> locationHeader = upgradeResponse.getHeaders().get(UpgradeResponse.LOCATION);
if (locationHeader != null) {
  locationString = Utils.getHeaderFromList(locationHeader);
    scheme = "wss";
  int port = Utils.getWsPort(location, scheme);
  location = new URI(scheme, location.getUserInfo(), location.getHost(), port, location
      .getPath(), location.getQuery(), location.getFragment());

代码示例来源:origin: org.glassfish.tyrus/tyrus-client

+ "response: \n" + Utils.stringifyUpgradeResponse(upgradeResponse));
} else {
  if (logUpgradeMessages) {
    debugContext.appendStandardOutputMessage(DebugContext.Type.MESSAGE_IN, "Received handshake response: "
        + "\n" + Utils.stringifyUpgradeResponse(upgradeResponse));
                                 .get(UpgradeResponse.RETRY_AFTER);
      if (retryAfterHeader != null) {
        retryAfterString = Utils.getHeaderFromList(retryAfterHeader);
        try {
          Date date = Utils.parseHttpDate(retryAfterString);
          delay = (date.getTime() - System.currentTimeMillis()) / 1000;
        } catch (ParseException e) {

代码示例来源:origin: eclipse-ee4j/tyrus

/**
 * Get port from provided {@link URI}.
 * <p>
 * Expected schemes are {@code "ws"} and {@code "wss"} and this method will return {@code 80} or
 * {@code 443} when the port is not explicitly set in the provided {@link URI}.
 *
 * @param uri provided uri.
 * @return port number which should be used for creating connections/etc.
 */
public static int getWsPort(URI uri) {
  return getWsPort(uri, uri.getScheme());
}

代码示例来源:origin: eclipse-ee4j/tyrus

@Override
public void sendBinary(ByteBuffer data, SendHandler handler) {
  checkNotNull(data, "data");
  checkNotNull(handler, "handler");
  clusterContext.sendBinary(sessionId, Utils.getRemainingArray(data), handler);
}

代码示例来源:origin: org.glassfish.tyrus/tyrus-container-grizzly-client

private static UpgradeResponse getUpgradeResponse(HttpResponsePacket httpResponsePacket) {
  TyrusUpgradeResponse tyrusUpgradeResponse = new TyrusUpgradeResponse();
  for (String name : httpResponsePacket.getHeaders().names()) {
    for (String headerValue : httpResponsePacket.getHeaders().values(name)) {
      final List<String> values = tyrusUpgradeResponse.getHeaders().get(name);
      if (values == null) {
        tyrusUpgradeResponse.getHeaders().put(name, Utils.parseHeaderValue(headerValue.trim()));
      } else {
        values.addAll(Utils.parseHeaderValue(headerValue.trim()));
      }
    }
  }
  tyrusUpgradeResponse.setStatus(httpResponsePacket.getStatus());
  return tyrusUpgradeResponse;
}

相关文章