use of org.apache.qpid.protonj2.client.ErrorCondition in project qpid-protonj2 by apache.
the class ClientExceptionSupport method createLinkRedirectException.
/**
* When a link redirect type exception is received this method is called to create the
* appropriate redirect exception type containing the error details needed.
*
* @param error
* the Symbol that defines the redirection error type.
* @param message
* the basic error message that should used or amended for the returned exception.
* @param condition
* the ErrorCondition that describes the redirection.
*
* @return an Exception that captures the details of the redirection error.
*/
public static ClientLinkRemotelyClosedException createLinkRedirectException(Symbol error, String message, ErrorCondition condition) {
ClientLinkRemotelyClosedException result;
Map<?, ?> info = condition.getInfo();
if (info == null) {
result = new ClientLinkRemotelyClosedException(message + " : Redirection information not set.", new ClientErrorCondition(condition));
} else {
@SuppressWarnings("unchecked") ClientRedirect redirect = new ClientRedirect((Map<Symbol, Object>) info);
try {
result = new ClientLinkRedirectedException(message, redirect.validate(), new ClientErrorCondition(condition));
} catch (Exception ex) {
result = new ClientLinkRemotelyClosedException(message + " : " + ex.getMessage(), new ClientErrorCondition(condition));
}
}
return result;
}
use of org.apache.qpid.protonj2.client.ErrorCondition in project qpid-protonj2 by apache.
the class ClientExceptionSupport method createConnectionRedirectException.
/**
* When a connection redirect type exception is received this method is called to create the
* appropriate redirect exception type containing the error details needed.
*
* @param error
* the Symbol that defines the redirection error type.
* @param message
* the basic error message that should used or amended for the returned exception.
* @param condition
* the ErrorCondition that describes the redirection.
*
* @return an Exception that captures the details of the redirection error.
*/
public static ClientConnectionRemotelyClosedException createConnectionRedirectException(Symbol error, String message, ErrorCondition condition) {
ClientConnectionRemotelyClosedException result;
Map<?, ?> info = condition.getInfo();
if (info == null) {
result = new ClientConnectionRemotelyClosedException(message + " : Redirection information not set.", new ClientErrorCondition(condition));
} else {
@SuppressWarnings("unchecked") ClientRedirect redirect = new ClientRedirect((Map<Symbol, Object>) info);
try {
result = new ClientConnectionRedirectedException(message, redirect.validate(), new ClientErrorCondition(condition));
} catch (Exception ex) {
result = new ClientConnectionRemotelyClosedException(message + " : " + ex.getMessage(), new ClientErrorCondition(condition));
}
}
return result;
}
use of org.apache.qpid.protonj2.client.ErrorCondition in project qpid-protonj2 by apache.
the class ClientExceptionSupport method convertToLinkClosedException.
/**
* Given an ErrorCondition instance create a new Exception that best matches
* the error type that indicates the link creation failed for some reason.
*
* @param errorCondition
* The ErrorCondition returned from the remote peer.
* @param defaultMessage
* The message to use if the remote provided no condition for the closure
*
* @return a new Exception instance that best matches the ErrorCondition value.
*/
public static ClientLinkRemotelyClosedException convertToLinkClosedException(ErrorCondition errorCondition, String defaultMessage) {
final ClientLinkRemotelyClosedException remoteError;
if (errorCondition != null && errorCondition.getCondition() != null) {
String message = extractErrorMessage(errorCondition);
Symbol error = errorCondition.getCondition();
if (message == null) {
message = defaultMessage;
}
if (error.equals(LinkError.REDIRECT)) {
remoteError = createLinkRedirectException(error, message, errorCondition);
} else {
remoteError = new ClientLinkRemotelyClosedException(message, new ClientErrorCondition(errorCondition));
}
} else {
remoteError = new ClientLinkRemotelyClosedException(defaultMessage);
}
return remoteError;
}
use of org.apache.qpid.protonj2.client.ErrorCondition in project qpid-protonj2 by apache.
the class ClientExceptionSupport method convertToSessionClosedException.
/**
* Given an ErrorCondition instance create a new Exception that best matches
* the error type that indicates the session creation failed for some reason.
*
* @param errorCondition
* The ErrorCondition returned from the remote peer.
*
* @return a new Exception instance that best matches the ErrorCondition value.
*/
public static ClientSessionRemotelyClosedException convertToSessionClosedException(ErrorCondition errorCondition) {
final ClientSessionRemotelyClosedException remoteError;
if (errorCondition != null && errorCondition.getCondition() != null) {
String message = extractErrorMessage(errorCondition);
if (message == null) {
message = "Session remotely closed without explanation";
}
remoteError = new ClientSessionRemotelyClosedException(message, new ClientErrorCondition(errorCondition));
} else {
remoteError = new ClientSessionRemotelyClosedException("Session remotely closed without explanation");
}
return remoteError;
}
use of org.apache.qpid.protonj2.client.ErrorCondition in project qpid-protonj2 by apache.
the class ClientErrorConditionTest method testCreateWithErrorConditionThatOnlyHasConditionData.
@Test
void testCreateWithErrorConditionThatOnlyHasConditionData() {
ErrorCondition condition = ErrorCondition.create("amqp:error", null);
ClientErrorCondition clientCondition = new ClientErrorCondition(condition);
assertEquals("amqp:error", clientCondition.condition());
assertNull(clientCondition.description());
assertNotNull(clientCondition.info());
org.apache.qpid.protonj2.types.transport.ErrorCondition protonError = clientCondition.getProtonErrorCondition();
assertNotNull(protonError);
assertEquals("amqp:error", protonError.getCondition().toString());
assertNull(protonError.getDescription());
assertNotNull(protonError.getInfo());
}
Aggregations