io.tracee.Utilities类的使用及代码示例

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

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

Utilities介绍

暂无

代码示例

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

@Override
public boolean handleRequest(MessageContext messageContext, Object o) {
  parseContextFromSoapHeader(messageContext.getRequest(), IncomingRequest);
  Utilities.generateInvocationIdIfNecessary(backend);
  return true;
}

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

private void httpRequestInitialized(final HttpServletRequest request) {
    final TraceeFilterConfiguration configuration = backend.getConfiguration();

    if (configuration.shouldProcessContext(IncomingRequest)) {
      final Enumeration<String> headers = request.getHeaders(HTTP_HEADER_NAME);

      if (headers != null && headers.hasMoreElements()) {
        final Map<String, String> contextMap = transportSerialization.parse(Collections.list(headers));
        backend.putAll(backend.getConfiguration().filterDeniedParams(contextMap, IncomingRequest));
      }
    }

    Utilities.generateInvocationIdIfNecessary(backend);

    final HttpSession session = request.getSession(false);
    if (session != null) {
      Utilities.generateSessionIdIfNecessary(backend, session.getId());
    }
  }
}

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

/**
 * Creates a alphanumeric projection with a given length of the given object using its {@link Object#hashCode()}.
 */
public static String createAlphanumericHash(final String str, final int length) {
  try {
    final MessageDigest md = MessageDigest.getInstance("SHA-256");
    final byte[] digest = md.digest(str.getBytes(CHARSET_UTF8));
    // To human
    final StringBuilder sb = new StringBuilder();
    for (final byte b : digest) {
      if (b < 16) sb.append("0");
      sb.append(Integer.toHexString(b & 0xff));
    }
    // repeat if to small
    while (sb.length() < length) {
      sb.append(sb.toString());
    }
    // truncation and return
    return sb.delete(length, sb.length()).toString();
  } catch (NoSuchAlgorithmException | UnsupportedCharsetException e) {
    // Hashalgo. and charset is mandatory for all kinds of JDK, so this should happend. But even when, we generate a random string.
    return createRandomAlphanumeric(length);
  }
}

代码示例来源:origin: io.tracee.inbound/tracee-servlet

private void httpRequestInitialized(HttpServletRequest request) {
  final TraceeFilterConfiguration configuration = backend.getConfiguration();
  if (configuration.shouldProcessContext(IncomingRequest)) {
    mergeIncomingContextToBackend(request);
  }
  Utilities.generateRequestIdIfNecessary(backend);
  final HttpSession session = request.getSession(false);
  if (session != null) {
    Utilities.generateSessionIdIfNecessary(backend, session.getId());
  }
}

代码示例来源:origin: io.tracee.inbound/tracee-servlet

@Override
public final void sessionCreated(HttpSessionEvent httpSessionEvent) {
  Utilities.generateSessionIdIfNecessary(backend, httpSessionEvent.getSession().getId());
}

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

/**
   * Generate session id hash if it doesn't exist in TraceeBackend and configuration asks for one
   *
   * @param backend   Currently used TraceeBackend
   * @param sessionId Current http sessionId
   */
  public static void generateSessionIdIfNecessary(final TraceeBackend backend, final String sessionId) {
    if (backend != null && !backend.containsKey(TraceeConstants.SESSION_ID_KEY) && backend.getConfiguration().shouldGenerateSessionId()) {
      backend.put(TraceeConstants.SESSION_ID_KEY, Utilities.createAlphanumericHash(sessionId, backend.getConfiguration().generatedSessionIdLength()));
    }
  }
}

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

@Override
public final void sessionCreated(HttpSessionEvent httpSessionEvent) {
  Utilities.generateSessionIdIfNecessary(backend, httpSessionEvent.getSession().getId());
}

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

@Override
public void handleMessage(Message message) {
  super.handleMessage(message);
  if (shouldHandleMessage(message)) {
    Utilities.generateInvocationIdIfNecessary(backend);
  }
}

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

@Override
public boolean preHandle(final HttpServletRequest request, final HttpServletResponse response, final Object o) {
  final TraceeFilterConfiguration configuration = backend.getConfiguration(profileName);
  if (configuration.shouldProcessContext(IncomingRequest)) {
    @SuppressWarnings("unchecked")
    final Enumeration<String> headers = request.getHeaders(incomingHeaderName);
    if (headers != null && headers.hasMoreElements()) {
      final Map<String, String> parsedContext = httpHeaderSerialization.parse(Collections.list(headers));
      backend.putAll(configuration.filterDeniedParams(parsedContext, IncomingResponse));
    }
  }
  Utilities.generateInvocationIdIfNecessary(backend);
  final HttpSession session = request.getSession(false);
  if (session != null) {
    Utilities.generateSessionIdIfNecessary(backend, session.getId());
  }
  // We add the current TPIC to the response. If the response is commited before we can replace the values with the current state
  // the current state is on the wire. -- better than nothing :-) (See #96)
  writeHeaderIfUncommitted(response);
  return true;
}

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

/**
 * Generate invocation id if it doesn't exist in TraceeBackend and configuration asks for one
 *
 * @param backend Currently used TraceeBackend
 */
public static void generateInvocationIdIfNecessary(final TraceeBackend backend) {
  if (backend != null && !backend.containsKey(TraceeConstants.INVOCATION_ID_KEY) && backend.getConfiguration().shouldGenerateInvocationId()) {
    backend.put(TraceeConstants.INVOCATION_ID_KEY, Utilities.createRandomAlphanumeric(backend.getConfiguration().generatedInvocationIdLength()));
  }
}

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

@Override
public void jobToBeExecuted(JobExecutionContext context) {
  final TraceeFilterConfiguration configuration = backend.getConfiguration(profile);
  if (configuration.shouldProcessContext(AsyncProcess)) {
    @SuppressWarnings("unchecked")
    final Map<String, String> traceeContext = (Map<String, String>) context.getMergedJobDataMap().get(TraceeConstants.TPIC_HEADER);
    if (traceeContext != null && !traceeContext.isEmpty()) {
      final Map<String, String> filteredContext = configuration.filterDeniedParams(traceeContext, AsyncProcess);
      backend.putAll(filteredContext);
    }
  }
  Utilities.generateInvocationIdIfNecessary(backend);
}

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

/**
 * This method handles the incoming request
 */
@Override
public void filter(final ContainerRequestContext containerRequestContext) {
  if (backend.getConfiguration().shouldProcessContext(IncomingRequest)) {
    final List<String> serializedTraceeHeaders = containerRequestContext.getHeaders().get(TraceeConstants.TPIC_HEADER);
    if (serializedTraceeHeaders != null && !serializedTraceeHeaders.isEmpty()) {
      final Map<String, String> parsed = transportSerialization.parse(serializedTraceeHeaders);
      backend.putAll(backend.getConfiguration().filterDeniedParams(parsed, IncomingRequest));
    }
  }
  Utilities.generateInvocationIdIfNecessary(backend);
}

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

@SuppressWarnings("unchecked")
public void beforeProcessing(final Message message) throws JMSException {
  if (backend.getConfiguration().shouldProcessContext(AsyncProcess)) {
    final String encodedTraceeContext = message.getStringProperty(TraceeConstants.TPIC_HEADER);
    if (encodedTraceeContext != null) {
      final Map<String, String> contextFromMessage = httpHeaderSerialization.parse(singletonList(encodedTraceeContext));
      backend.putAll(backend.getConfiguration().filterDeniedParams(contextFromMessage, AsyncProcess));
    }
  }
  Utilities.generateInvocationIdIfNecessary(backend);
}

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

/**
 * Incoming messages
 */
@Override
public MessageProperties toMessageProperties(AMQP.BasicProperties source, Envelope envelope, String charset) {
  final MessageProperties messageProperties = super.toMessageProperties(source, envelope, charset);
  final TraceeFilterConfiguration filterConfiguration = backend.getConfiguration(profile);
  if (filterConfiguration.shouldProcessContext(AsyncProcess)) {
    // Values are stored as type of LongStringHelper.ByteArrayLongString - but it's private
    final Map<String, String> traceeContextMap = transformToTraceeContextMap(
      (Map<String, ?>) messageProperties.getHeaders().get(TPIC_HEADER));
    if (traceeContextMap != null && !traceeContextMap.isEmpty()) {
      backend.putAll(filterConfiguration.filterDeniedParams(traceeContextMap, AsyncProcess));
    }
  }
  Utilities.generateInvocationIdIfNecessary(backend);
  return messageProperties;
}

代码示例来源:origin: io.tracee.binding/tracee-jaxws

protected final void handleIncoming(SOAPMessageContext context) {
  final SOAPMessage soapMessage = context.getMessage();
  try {
    final SOAPHeader header = soapMessage.getSOAPHeader();
    if (header != null && traceeBackend.getConfiguration().shouldProcessContext(IncomingRequest)) {
      final Map<String, String> parsedContext = transportSerialization.parseSoapHeader(header);
      final Map<String, String> filteredContext = traceeBackend.getConfiguration().filterDeniedParams(parsedContext, IncomingRequest);
      traceeBackend.putAll(filteredContext);
    }
  } catch (final SOAPException e) {
    logger.warn("Error during precessing of inbound soap header: {}", e.getMessage());
    logger.debug("Detailed: Error during precessing of inbound soap header: {}", e.getMessage(), e);
  }
  Utilities.generateInvocationIdIfNecessary(traceeBackend);
}

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

protected final void handleIncoming(SOAPMessageContext context) {
  final SOAPMessage soapMessage = context.getMessage();
  try {
    final SOAPHeader header = soapMessage.getSOAPHeader();
    if (header != null && traceeBackend.getConfiguration().shouldProcessContext(IncomingRequest)) {
      final Map<String, String> parsedContext = transportSerialization.parseSoapHeader(header);
      final Map<String, String> filteredContext = traceeBackend.getConfiguration().filterDeniedParams(parsedContext, IncomingRequest);
      traceeBackend.putAll(filteredContext);
    }
  } catch (final SOAPException e) {
    logger.warn("Error during precessing of inbound soap header: {}", e.getMessage());
    logger.debug("Detailed: Error during precessing of inbound soap header: {}", e.getMessage(), e);
  }
  Utilities.generateInvocationIdIfNecessary(traceeBackend);
}

相关文章