Java Code Examples for com.rabbitmq.client.LongString

The following examples show how to use com.rabbitmq.client.LongString. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: vertx-rabbitmq-client   Source File: Utils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Converts the given object in case of a LongString or List including a LongString to String.
 *
 * @return consolidated object
 */
private static Object convertLongStringToString( Object value ) {

  if ( value instanceof Date ) {
    return ((Date) value).toInstant();
  }

  if ( value instanceof LongString ) {
    return value.toString();
  }

  if ( value instanceof List ) {
    List<Object> newList = new ArrayList<>();
    for ( Object item : (List<?>) value ) {
      newList.add( convertLongStringToString( item ) );
    }
    return newList;
  }

  if ( value instanceof Map) {
    return convertMapLongStringToString((Map<String, Object>) value);
  }

  return value;
}
 
Example 2
Source Project: beam   Source File: RabbitMqMessage.java    License: Apache License 2.0 5 votes vote down vote up
private static Map<String, Object> serializableHeaders(Map<String, Object> headers) {
  Map<String, Object> returned = new HashMap<>();
  if (headers != null) {
    for (Map.Entry<String, Object> h : headers.entrySet()) {
      Object value = h.getValue();
      if (!(value instanceof Serializable)) {
        try {
          if (value instanceof LongString) {
            LongString longString = (LongString) value;
            byte[] bytes = longString.getBytes();
            String s = new String(bytes, StandardCharsets.UTF_8);
            value = s;
          } else {
            throw new RuntimeException(String.format("no transformation defined for %s", value));
          }
        } catch (Throwable t) {
          throw new UnsupportedOperationException(
              String.format(
                  "can't make unserializable value %s a serializable value (which is mandatory for Apache Beam dataflow implementation)",
                  value),
              t);
        }
      }
      returned.put(h.getKey(), value);
    }
  }
  return returned;
}
 
Example 3
Source Project: pinpoint   Source File: RabbitMQTestConstants.java    License: Apache License 2.0 5 votes vote down vote up
public SaslMechanism getSaslMechanism(String[] mechanisms) {
    return new SaslMechanism() {
        public String getName() {
            return "ANONYMOUS";
        }

        public LongString handleChallenge(LongString challenge, String username, String password) {
            return LongStringHelper.asLongString("");
        }
    };
}
 
Example 4
@Test
public void parseMessageHeaderIntoBackend() throws Exception {
	final Map<String, LongString> rabbitTraceeHeader = new HashMap<>();
	rabbitTraceeHeader.put(INVOCATION_ID_KEY, new TestLongString("Crazy ID"));

	unit.toMessageProperties(createRabbitHeaderWith(TPIC_HEADER, rabbitTraceeHeader), mock(Envelope.class), CHARSET_UTF8);

	assertThat(backend.copyToMap(), hasEntry(INVOCATION_ID_KEY, "Crazy ID"));
}
 
Example 5
Source Project: storm-rabbitmq   Source File: RabbitMQMessageScheme.java    License: MIT License 5 votes vote down vote up
private Map<String, Object> serializableHeaders(Map<String, Object> headers) {
    if (headers == null) {
        return new HashMap<String, Object>();
    }

    Map<String, Object> headersSerializable = new HashMap<String, Object>(headers.size());
    for (Map.Entry<String, Object> entry : headers.entrySet()) {
        if (entry.getValue() instanceof Number ||
                entry.getValue() instanceof Boolean ||
                entry.getValue() instanceof Character ||
                entry.getValue() instanceof String ||
                entry.getValue() instanceof Date) {
            headersSerializable.put(entry.getKey(), entry.getValue());
        } else if (entry.getValue() instanceof LongString) {
            headersSerializable.put(entry.getKey(), entry.getValue().toString());
        } else if (entry.getValue() instanceof ArrayList) {
            ArrayList serializedList = new ArrayList();
            for (Object elm : ((ArrayList) entry.getValue())) {
                if (elm instanceof HashMap) {
                    serializedList.add(serializableHeaders((HashMap<String, Object>) elm));
                }
            }
            headersSerializable.put(entry.getKey(), serializedList);
        }
    }
    return headersSerializable;
}