Java Code Examples for org.apache.qpid.proton.amqp.transport.ErrorCondition#setInfo()

The following examples show how to use org.apache.qpid.proton.amqp.transport.ErrorCondition#setInfo() . 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 File: ErrorConditionType.java    From qpid-proton-j with Apache License 2.0 6 votes vote down vote up
public ErrorCondition newInstance(Object described)
{
    List l = (List) described;

    ErrorCondition o = new ErrorCondition();

    if(l.isEmpty())
    {
        throw new DecodeException("The condition field cannot be omitted");
    }

    switch(3 - l.size())
    {

        case 0:
            o.setInfo( (Map) l.get( 2 ) );
        case 1:
            o.setDescription( (String) l.get( 1 ) );
        case 2:
            o.setCondition( (Symbol) l.get( 0 ) );
    }


    return o;
}
 
Example 2
Source File: AmqpSupportTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateRedirectionExceptionWithNoNetworkHost() throws URISyntaxException {
    AmqpProvider mockProvider = Mockito.mock(AmqpProvider.class);
    Mockito.when(mockProvider.getRemoteURI()).thenReturn(new URI("amqp://localhost:5672"));

    ErrorCondition condition = new ErrorCondition();

    Map<Symbol, Object> info = new HashMap<>();
    info.put(AmqpSupport.PORT, "5672");
    info.put(AmqpSupport.OPEN_HOSTNAME, "localhost");
    info.put(AmqpSupport.SCHEME, "amqp");
    info.put(AmqpSupport.PATH, "websocket");

    condition.setInfo(info);

    Symbol error = AmqpError.INTERNAL_ERROR;
    String message = "Failed to connect";

    Exception result = AmqpSupport.createRedirectException(mockProvider, error, message, condition);

    assertNotNull(result);
    assertFalse(result instanceof ProviderConnectionRedirectedException);
    assertTrue(result instanceof ProviderException);
}
 
Example 3
Source File: AmqpSupportTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateRedirectionExceptionWithEmptyNetworkHost() throws URISyntaxException {
    AmqpProvider mockProvider = Mockito.mock(AmqpProvider.class);
    Mockito.when(mockProvider.getRemoteURI()).thenReturn(new URI("amqp://localhost:5672"));

    ErrorCondition condition = new ErrorCondition();

    Map<Symbol, Object> info = new HashMap<>();
    info.put(AmqpSupport.PORT, "5672");
    info.put(AmqpSupport.NETWORK_HOST, "");
    info.put(AmqpSupport.OPEN_HOSTNAME, "localhost");
    info.put(AmqpSupport.SCHEME, "amqp");
    info.put(AmqpSupport.PATH, "websocket");

    condition.setInfo(info);

    Symbol error = AmqpError.INTERNAL_ERROR;
    String message = "Failed to connect";

    Exception result = AmqpSupport.createRedirectException(mockProvider, error, message, condition);

    assertNotNull(result);
    assertFalse(result instanceof ProviderConnectionRedirectedException);
    assertTrue(result instanceof ProviderException);
}
 
Example 4
Source File: AmqpSupportTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateRedirectionExceptionWithInvalidPort() throws URISyntaxException {
    AmqpProvider mockProvider = Mockito.mock(AmqpProvider.class);
    Mockito.when(mockProvider.getRemoteURI()).thenReturn(new URI("amqp://localhost:5672"));

    ErrorCondition condition = new ErrorCondition();

    Map<Symbol, Object> info = new HashMap<>();
    info.put(AmqpSupport.PORT, "L5672");
    info.put(AmqpSupport.OPEN_HOSTNAME, "localhost");
    info.put(AmqpSupport.NETWORK_HOST, "localhost");
    info.put(AmqpSupport.SCHEME, "amqp");
    info.put(AmqpSupport.PATH, "websocket");

    condition.setInfo(info);

    Symbol error = AmqpError.INTERNAL_ERROR;
    String message = "Failed to connect";

    Exception result = AmqpSupport.createRedirectException(mockProvider, error, message, condition);

    assertNotNull(result);
    assertFalse(result instanceof ProviderConnectionRedirectedException);
    assertTrue(result instanceof ProviderException);
}
 
Example 5
Source File: ConnectionTest.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
/**
 * "each peer MUST write a close frame with a code indicating the reason for closing"
 * Also see 2.8.16 Connection Error
 */
@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testCloseConnectionWithErrorCode_causesCloseFrameContainingErrorCodeToBeSent()
{
    bindAndOpenConnections();

    /*
     * TODO javadoc for {@link Connection#getCondition()} states null is returned if there is no condition,
     * this differs from the implementation of both Proton-c and Proton-j.
     */
    assertNull(_clientConnection.getCondition().getCondition());
    assertNull(_serverConnection.getCondition().getCondition());

    assertNull(_clientConnection.getRemoteCondition().getCondition());
    assertNull(_serverConnection.getRemoteCondition().getCondition());

    ErrorCondition clientErrorCondition = new ErrorCondition(Symbol.getSymbol("myerror"), "mydescription");
    Map info = new HashMap();
    info.put(Symbol.getSymbol("simplevalue"), "value");
    info.put(Symbol.getSymbol("list"), Arrays.asList("e1", "e2", "e3"));
    clientErrorCondition.setInfo(info);
    _clientConnection.setCondition(clientErrorCondition);

    _clientConnection.close();
    _pumper.pumpAll();

    assertEquals(clientErrorCondition, _serverConnection.getRemoteCondition());
    assertNull(_serverConnection.getCondition().getCondition());
}
 
Example 6
Source File: AmqpSupportTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateRedirectionException() throws URISyntaxException {
    ErrorCondition condition = new ErrorCondition();

    AmqpProvider mockProvider = Mockito.mock(AmqpProvider.class);
    Mockito.when(mockProvider.getRemoteURI()).thenReturn(new URI("amqp://localhost:5672"));

    Map<Symbol, Object> info = new HashMap<>();
    info.put(AmqpSupport.PORT, "5672");
    info.put(AmqpSupport.OPEN_HOSTNAME, "localhost.localdomain");
    info.put(AmqpSupport.NETWORK_HOST, "localhost");
    info.put(AmqpSupport.SCHEME, "amqp");
    info.put(AmqpSupport.PATH, "/websocket");

    condition.setInfo(info);

    Symbol error = AmqpError.INTERNAL_ERROR;
    String message = "Failed to connect";

    Exception result = AmqpSupport.createRedirectException(mockProvider, error, message, condition);

    assertNotNull(result);
    assertTrue(result instanceof ProviderConnectionRedirectedException);

    ProviderConnectionRedirectedException pre = (ProviderConnectionRedirectedException) result;

    URI redirection = pre.getRedirectionURI();

    assertEquals(5672, redirection.getPort());
    assertTrue("localhost.localdomain", redirection.getQuery().contains("amqp.vhost=localhost.localdomain"));
    assertEquals("localhost", redirection.getHost());
    assertEquals("amqp", redirection.getScheme());
    assertEquals("/websocket", redirection.getPath());
}