throws AMQException
{
_log.debug("public void methodReceived(AMQStateManager stateManager, AMQProtocolSession protocolSession, "
+ "AMQMethodEvent evt): called");
final AMQProtocolSession session = stateManager.getProtocolSession();
ProtocolVersion pv = new ProtocolVersion((byte) body.getVersionMajor(), (byte) body.getVersionMinor());
// For the purposes of interop, we can make the client accept the broker's version string.
// If it does, it then internally records the version as being the latest one that it understands.
// It needs to do this since frame lookup is done by version.
if (Boolean.getBoolean("qpid.accept.broker.version") && !pv.isSupported())
{
pv = ProtocolVersion.getLatestSupportedVersion();
}
if (pv.isSupported())
{
session.setProtocolVersion(pv);
try
{
// Used to hold the SASL mechanism to authenticate with.
String mechanism;
if (body.getMechanisms()== null)
{
throw new AMQException("mechanism not specified in ConnectionStart method frame");
}
else
{
mechanism = chooseMechanism(body.getMechanisms());
_log.debug("mechanism = " + mechanism);
}
if (mechanism == null)
{
throw new AMQException("No supported security mechanism found, passed: " + new String(body.getMechanisms()));
}
byte[] saslResponse;
try
{
SaslClient sc =
Sasl.createSaslClient(new String[] { mechanism }, null, "AMQP", "localhost", null,
createCallbackHandler(mechanism, session));
if (sc == null)
{
throw new AMQException(
"Client SASL configuration error: no SaslClient could be created for mechanism " + mechanism
+ ". Please ensure all factories are registered. See DynamicSaslRegistrar for "
+ " details of how to register non-standard SASL client providers.");
}
session.setSaslClient(sc);
saslResponse = (sc.hasInitialResponse() ? sc.evaluateChallenge(new byte[0]) : null);
}
catch (SaslException e)
{
session.setSaslClient(null);
throw new AMQException("Unable to create SASL client: " + e, e);
}
if (body.getLocales() == null)
{
throw new AMQException("Locales is not defined in Connection Start method");
}
final String locales = new String(body.getLocales(), "utf8");
final StringTokenizer tokenizer = new StringTokenizer(locales, " ");
String selectedLocale = null;
if (tokenizer.hasMoreTokens())
{
selectedLocale = tokenizer.nextToken();
}
else
{
throw new AMQException("No locales sent from server, passed: " + locales);
}
stateManager.changeState(AMQState.CONNECTION_NOT_TUNED);
FieldTable clientProperties = FieldTableFactory.newFieldTable();
clientProperties.setString(new AMQShortString(ClientProperties.instance.toString()),
session.getClientID());
clientProperties.setString(new AMQShortString(ClientProperties.product.toString()),
QpidProperties.getProductName());
clientProperties.setString(new AMQShortString(ClientProperties.version.toString()),
QpidProperties.getReleaseVersion());
clientProperties.setString(new AMQShortString(ClientProperties.platform.toString()), getFullSystemInfo());
ConnectionStartOkBody connectionStartOkBody = session.getMethodRegistry().createConnectionStartOkBody(clientProperties,new AMQShortString(mechanism),saslResponse,new AMQShortString(locales));
// AMQP version change: Hardwire the version to 0-8 (major=8, minor=0)
// TODO: Connect this to the session version obtained from ProtocolInitiation for this session.
// Be aware of possible changes to parameter order as versions change.
session.writeFrame(connectionStartOkBody.generateFrame(channelId));
}
catch (UnsupportedEncodingException e)
{
throw new AMQException("Unable to decode data: " + e, e);
}
}
else
{
_log.error("Broker requested Protocol [" + body.getVersionMajor() + "-" + body.getVersionMinor()
+ "] which is not supported by this version of the client library");
session.closeProtocolSession();
}
}