use of org.apache.qpid.server.protocol.v1_0.type.ErrorCondition in project qpid-broker-j by apache.
the class FrameHandler method createError.
private Error createError(final ErrorCondition framingError, final String description, final Object... args) {
Error error = new Error();
error.setCondition(framingError);
Formatter formatter = new Formatter();
error.setDescription(formatter.format(description, args).toString());
return error;
}
use of org.apache.qpid.server.protocol.v1_0.type.ErrorCondition in project qpid-broker-j by apache.
the class Session_1_0Test method assertDetachSent.
private void assertDetachSent(final AMQPConnection_1_0 connection, final Session_1_0 session, final ErrorCondition expectedError, final int invocationOffset) {
ArgumentCaptor<FrameBody> frameCapture = ArgumentCaptor.forClass(FrameBody.class);
verify(connection, times(invocationOffset + 1)).sendFrame(eq(session.getChannelId()), frameCapture.capture());
List<FrameBody> sentFrames = frameCapture.getAllValues();
final boolean condition = sentFrames.get(invocationOffset) instanceof Detach;
assertTrue("unexpected Frame sent", condition);
Detach sentDetach = (Detach) sentFrames.get(invocationOffset);
assertTrue("Unexpected closed state", sentDetach.getClosed());
assertEquals("Closed with unexpected error condition", expectedError, sentDetach.getError().getCondition());
}
use of org.apache.qpid.server.protocol.v1_0.type.ErrorCondition in project qpid-broker-j by apache.
the class ProtocolAsserts method assertAttachError.
/**
* When core spec is not vocal about how the error on attach can be reported,
* there are potentially several ways of communicating error back to the client:
* <pre>
* Attach, Detach(with error)
* Attach, Detach, End(with error)
* Attach, Detach, End, Close(with error)
* End(with error)
* End, Close(with error)
* </pre>
* Thus, in order to assert the error possible codes, we need to get {@link ErrorCarryingFrameBody}
* (implemented by {@link Detach}, {@link End}, {@link Close}) and examine error field there.
* If error is set, than assert the error code, otherwise, receive subsequent {@link ErrorCarryingFrameBody}
* and examine error field there.
*
* @param interaction interaction
* @param expected possible errors
*/
public static void assertAttachError(final Interaction interaction, final ErrorCondition... expected) throws Exception {
Response<?> response = interaction.consumeResponse().getLatestResponse();
assertThat(response, is(notNullValue()));
Object responseBody = response.getBody();
assertThat(responseBody, is(notNullValue()));
if (response.getBody() instanceof Attach) {
// expected either Detach or End or Close
response = interaction.consumeResponse().getLatestResponse();
assertThat(response, is(notNullValue()));
responseBody = response.getBody();
assertThat(responseBody, is(notNullValue()));
}
assertThat(responseBody, instanceOf(ErrorCarryingFrameBody.class));
Error error = ((ErrorCarryingFrameBody) responseBody).getError();
if (error != null) {
assumeThat(error.getCondition(), is(not(NOT_IMPLEMENTED)));
assertThat(error.getCondition(), oneOf(expected));
} else {
// expected either End or Close
response = interaction.consumeResponse().getLatestResponse();
assertThat(response, is(notNullValue()));
Object nextBody = response.getBody();
assertThat(nextBody, is(notNullValue()));
assertThat(nextBody, instanceOf(ErrorCarryingFrameBody.class));
error = ((ErrorCarryingFrameBody) nextBody).getError();
if (error != null) {
assumeThat(error.getCondition(), is(not(NOT_IMPLEMENTED)));
assertThat(error.getCondition(), oneOf(expected));
} else {
// expected Close
response = interaction.consumeResponse().getLatestResponse();
assertThat(response, is(notNullValue()));
Object body = response.getBody();
assertThat(body, is(notNullValue()));
assertThat(body, instanceOf(Close.class));
error = ((ErrorCarryingFrameBody) body).getError();
assertThat(error.getCondition(), is(notNullValue()));
assumeThat(error.getCondition(), is(not(NOT_IMPLEMENTED)));
assertThat(error.getCondition(), oneOf(expected));
}
}
}
use of org.apache.qpid.server.protocol.v1_0.type.ErrorCondition in project qpid-broker-j by apache.
the class AMQPConnection_1_0Impl method sendConnectionCloseAsync.
@Override
public void sendConnectionCloseAsync(final CloseReason reason, final String description) {
stopConnection();
final ErrorCondition cause;
switch(reason) {
case MANAGEMENT:
cause = ConnectionError.CONNECTION_FORCED;
break;
case TRANSACTION_TIMEOUT:
cause = AmqpError.RESOURCE_LIMIT_EXCEEDED;
break;
default:
cause = AmqpError.INTERNAL_ERROR;
}
Action<ConnectionHandler> action = object -> closeConnection(cause, description);
addAsyncTask(action);
}
use of org.apache.qpid.server.protocol.v1_0.type.ErrorCondition in project qpid-broker-j by apache.
the class AMQPConnection_1_0Impl method receiveClose.
@Override
public void receiveClose(final int channel, final Close close) {
switch(_connectionState) {
case AWAIT_AMQP_OR_SASL_HEADER:
case AWAIT_SASL_INIT:
case AWAIT_SASL_RESPONSE:
case AWAIT_AMQP_HEADER:
throw new ConnectionScopedRuntimeException("Received unexpected close when AMQP connection has not been established.");
case AWAIT_OPEN:
closeReceived();
closeConnection(ConnectionError.CONNECTION_FORCED, "Connection close sent before connection was opened");
break;
case OPENED:
_connectionState = ConnectionState.CLOSE_RECEIVED;
closeReceived();
if (close.getError() != null) {
final Error error = close.getError();
ErrorCondition condition = error.getCondition();
Symbol errorCondition = condition == null ? null : condition.getValue();
LOGGER.info("{} : Connection closed with error : {} - {}", getLogSubject(), errorCondition, close.getError().getDescription());
}
sendClose(new Close());
_connectionState = ConnectionState.CLOSED;
_orderlyClose.set(true);
addCloseTicker();
break;
case CLOSE_SENT:
closeReceived();
_connectionState = ConnectionState.CLOSED;
_orderlyClose.set(true);
break;
case CLOSE_RECEIVED:
case CLOSED:
break;
default:
throw new ServerScopedRuntimeException("Unknown state: " + _connectionState);
}
}
Aggregations