Example usage for com.rabbitmq.client.impl LongStringHelper asLongString

List of usage examples for com.rabbitmq.client.impl LongStringHelper asLongString

Introduction

In this page you can find the example usage for com.rabbitmq.client.impl LongStringHelper asLongString.

Prototype

public static LongString asLongString(byte[] bytes) 

Source Link

Document

Converts a binary block to a LongString.

Usage

From source file:com.sonyericsson.hudson.plugins.gerrit.trigger.impls.RabbitMQMessageListenerImplTest.java

License:Open Source License

/**
 * Tests if received event with header./* w  w w. j a v  a  2  s  .co m*/
 *
 * @throws PluginNotFoundException throw if plugin is not found.
 * @throws PluginStatusException throw if plugin status is wrong.
 */
@Test
public void onReceiveWithHeaderTest() throws PluginNotFoundException, PluginStatusException {
    Handler handlerMock = mock(Handler.class);
    doReturn(handlerMock).when(apiMock).getHandler();

    RabbitMQMessageListenerImpl listener = new RabbitMQMessageListenerImpl();
    Whitebox.setInternalState(listener, GerritTriggerApi.class, apiMock);

    Map<String, Object> header = new HashMap<String, Object>();
    header.put("gerrit-name", LongStringHelper.asLongString("gerrit1"));
    header.put("gerrit-host", LongStringHelper.asLongString("gerrit1.localhost"));
    header.put("gerrit-port", LongStringHelper.asLongString("29418"));
    header.put("gerrit-scheme", LongStringHelper.asLongString("ssh"));
    header.put("gerrit-front-url", LongStringHelper.asLongString("http://gerrit1.localhost"));
    header.put("gerrit-version", "2.8.4");

    listener.onBind("TEST");
    listener.onReceive("TEST", "application/json", header, "test message".getBytes());
    verify(handlerMock).post("test message",
            new Provider(header.get("gerrit-name").toString(), header.get("gerrit-host").toString(),
                    header.get("gerrit-port").toString(), header.get("gerrit-scheme").toString(),
                    header.get("gerrit-front-url").toString(), header.get("gerrit-version").toString()));
}

From source file:de.htwk_leipzig.bis.connection.handshake.clientRewrite.Copyright.java

License:Mozilla Public License

/**
 * Retrieve a copy of the default table of client properties that will be
 * sent to the server during connection startup. This method is called when
 * each new ConnectionFactory instance is constructed.
 * //from   w  w  w  . java  2 s  .c  o m
 * @return a map of client properties
 * @see Connection#getClientProperties
 */
public static final Map<String, Object> defaultClientProperties() {
    Map<String, Object> props = new HashMap<String, Object>();
    props.put("product", LongStringHelper.asLongString("RabbitMQ"));
    props.put("version", LongStringHelper.asLongString(ClientVersion.VERSION));
    props.put("platform", LongStringHelper.asLongString("Java"));
    props.put("copyright", LongStringHelper.asLongString(Copyright.COPYRIGHT));
    props.put("information", LongStringHelper.asLongString(Copyright.LICENSE));

    Map<String, Object> capabilities = new HashMap<String, Object>();
    capabilities.put("publisher_confirms", true);
    capabilities.put("exchange_exchange_bindings", true);
    capabilities.put("basic.nack", true);
    capabilities.put("consumer_cancel_notify", true);
    capabilities.put("connection.blocked", true);
    capabilities.put("authentication_failure_close", true);

    props.put("capabilities", capabilities);

    return props;
}

From source file:de.maxikg.messenger.publisher.AmqpPublisher.java

License:Apache License

private static Map<String, Object> headers(String type) {
    ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder();
    if (type != null)
        builder.put(AmqpUtils.HEADER_TYPE, LongStringHelper.asLongString(type));
    return builder.build();
}

From source file:io.bigwig.sasl.PublicKeyMechanism.java

License:Mozilla Public License

@Override
public LongString handleChallenge(LongString challenge, String username, String password) {

    if (challenge == null) {
        return LongStringHelper.asLongString(username);
    } else {/*  w  w w.ja  va2 s. c  o m*/

        Signature signer;

        try {

            signer = Signature.getInstance("SHA512WITHECDSA", "BC");

        } catch (NoSuchAlgorithmException e) {
            log.error("Could not load DSA algorithm");
            throw new RuntimeException(e);
        } catch (NoSuchProviderException e) {
            log.error("Could load Bouncy Castle provider");
            throw new RuntimeException(e);
        }

        try {

            signer.initSign(privateKey);

        } catch (InvalidKeyException e) {
            log.error("Private key was invalid: {}", e.getMessage());
            throw new RuntimeException(e);
        }

        try {

            signer.update(challenge.getBytes());
            byte[] sig = signer.sign();

            log.debug("Signature: {}", encoder.encode(sig));

            return LongStringHelper.asLongString(sig);

        } catch (SignatureException e) {
            log.error("Failed to sign nonce: {} ", e.getMessage());
            throw new RuntimeException(e);
        }

    }
}

From source file:org.apache.camel.component.rabbitmq.RabbitMQEndpointTest.java

License:Apache License

@Test
public void testCreatingRabbitExchangeSetsCustomHeaders() throws Exception {
    RabbitMQEndpoint endpoint = context.getEndpoint("rabbitmq:localhost/exchange", RabbitMQEndpoint.class);

    String routingKey = UUID.randomUUID().toString();
    String exchangeName = UUID.randomUUID().toString();
    long tag = UUID.randomUUID().toString().hashCode();

    Mockito.when(envelope.getRoutingKey()).thenReturn(routingKey);
    Mockito.when(envelope.getExchange()).thenReturn(exchangeName);
    Mockito.when(envelope.getDeliveryTag()).thenReturn(tag);

    Map<String, Object> customHeaders = new HashMap<String, Object>();
    customHeaders.put("stringHeader", "A string");
    customHeaders.put("bigDecimalHeader", new BigDecimal("12.34"));
    customHeaders.put("integerHeader", 42);
    customHeaders.put("doubleHeader", 42.24);
    customHeaders.put("booleanHeader", true);
    customHeaders.put("dateHeader", new Date(0));
    customHeaders.put("byteArrayHeader", "foo".getBytes());
    customHeaders.put("longStringHeader", LongStringHelper.asLongString("Some really long string"));
    Mockito.when(properties.getHeaders()).thenReturn(customHeaders);

    byte[] body = new byte[20];
    Exchange exchange = endpoint.createRabbitExchange(envelope, properties, body);
    assertEquals(exchangeName, exchange.getIn().getHeader(RabbitMQConstants.EXCHANGE_NAME));
    assertEquals(routingKey, exchange.getIn().getHeader(RabbitMQConstants.ROUTING_KEY));
    assertEquals(tag, exchange.getIn().getHeader(RabbitMQConstants.DELIVERY_TAG));
    assertEquals("A string", exchange.getIn().getHeader("stringHeader"));
    assertEquals(new BigDecimal("12.34"), exchange.getIn().getHeader("bigDecimalHeader"));
    assertEquals(42, exchange.getIn().getHeader("integerHeader"));
    assertEquals(42.24, exchange.getIn().getHeader("doubleHeader"));
    assertEquals(true, exchange.getIn().getHeader("booleanHeader"));
    assertEquals(new Date(0), exchange.getIn().getHeader("dateHeader"));
    assertArrayEquals("foo".getBytes(), (byte[]) exchange.getIn().getHeader("byteArrayHeader"));
    assertEquals("Some really long string", exchange.getIn().getHeader("longStringHeader"));
    assertEquals(body, exchange.getIn().getBody());
}

From source file:org.geoserver.notification.common.AnonymousMechanism.java

License:Open Source License

@Override
public LongString handleChallenge(LongString challenge, String username, String password) {
    return LongStringHelper.asLongString("");
}

From source file:org.springframework.amqp.rabbit.support.DefaultMessagePropertiesConverterTests.java

License:Apache License

@Test
public void testLongLongString() {
    Map<String, Object> headers = new HashMap<String, Object>();
    headers.put("longString", longString);
    headers.put("string1025", LongStringHelper.asLongString(new byte[1025]));
    byte[] longBytes = new byte[1026];
    longBytes[0] = 'a';
    longBytes[1025] = 'z';
    LongString longString1026 = LongStringHelper.asLongString(longBytes);
    headers.put("string1026", longString1026);
    BasicProperties source = new BasicProperties.Builder().headers(headers).build();
    MessagePropertiesConverter converter = new DefaultMessagePropertiesConverter(1024, true);
    MessageProperties messageProperties = converter.toMessageProperties(source, envelope, "UTF-8");
    assertThat(messageProperties.getHeaders().get("longString"), instanceOf(String.class));
    assertThat(messageProperties.getHeaders().get("string1025"), instanceOf(DataInputStream.class));
    assertThat(messageProperties.getHeaders().get("string1026"), instanceOf(DataInputStream.class));
    MessagePropertiesConverter longConverter = new DefaultMessagePropertiesConverter(1025, true);
    messageProperties = longConverter.toMessageProperties(source, envelope, "UTF-8");
    assertThat(messageProperties.getHeaders().get("longString"), instanceOf(String.class));
    assertThat(messageProperties.getHeaders().get("string1025"), instanceOf(String.class));
    assertThat(messageProperties.getHeaders().get("string1026"), instanceOf(DataInputStream.class));

    longConverter = new DefaultMessagePropertiesConverter(1025);
    messageProperties = longConverter.toMessageProperties(source, envelope, "UTF-8");
    assertThat(messageProperties.getHeaders().get("longString"), instanceOf(String.class));
    assertThat(messageProperties.getHeaders().get("string1025"), instanceOf(String.class));
    assertThat(messageProperties.getHeaders().get("string1026"), instanceOf(LongString.class));

    BasicProperties basicProperties = longConverter.fromMessageProperties(messageProperties, "UTF-8");
    assertEquals(longString1026.toString(), basicProperties.getHeaders().get("string1026").toString());
}

From source file:ox.softeng.burst.xml.LongStringAdapter.java

@Override
public LongString unmarshal(String v) throws Exception {
    return LongStringHelper.asLongString(v);
}