use of org.apache.activemq.artemis.core.version.Version in project activemq-artemis by apache.
the class ActiveMQPacketHandler method handleCreateSession.
private void handleCreateSession(final CreateSessionMessage request) {
boolean incompatibleVersion = false;
Packet response;
try {
Version version = server.getVersion();
if (!version.isCompatible(request.getVersion())) {
throw ActiveMQMessageBundle.BUNDLE.incompatibleClientServer();
}
if (!server.isStarted()) {
throw ActiveMQMessageBundle.BUNDLE.serverNotStarted();
}
if (connection.getChannelVersion() == 0) {
connection.setChannelVersion(request.getVersion());
} else if (connection.getChannelVersion() != request.getVersion()) {
ActiveMQServerLogger.LOGGER.incompatibleVersionAfterConnect(request.getVersion(), connection.getChannelVersion());
}
Channel channel = connection.getChannel(request.getSessionChannelID(), request.getWindowSize());
ActiveMQPrincipal activeMQPrincipal = null;
if (request.getUsername() == null) {
activeMQPrincipal = connection.getDefaultActiveMQPrincipal();
}
OperationContext sessionOperationContext = server.newOperationContext();
Map<SimpleString, RoutingType> routingTypeMap = protocolManager.getPrefixes();
CoreSessionCallback sessionCallback = new CoreSessionCallback(request.getName(), protocolManager, channel, connection);
ServerSession session = server.createSession(request.getName(), activeMQPrincipal == null ? request.getUsername() : activeMQPrincipal.getUserName(), activeMQPrincipal == null ? request.getPassword() : activeMQPrincipal.getPassword(), request.getMinLargeMessageSize(), connection, request.isAutoCommitSends(), request.isAutoCommitAcks(), request.isPreAcknowledge(), request.isXA(), request.getDefaultAddress(), sessionCallback, true, sessionOperationContext, routingTypeMap);
ServerProducer serverProducer = new ServerProducerImpl(session.getName(), "CORE", request.getDefaultAddress());
session.addProducer(serverProducer);
ServerSessionPacketHandler handler = new ServerSessionPacketHandler(server, protocolManager, session, server.getStorageManager(), channel);
channel.setHandler(handler);
sessionCallback.setSessionHandler(handler);
// TODO - where is this removed?
protocolManager.addSessionHandler(request.getName(), handler);
response = new CreateSessionResponseMessage(server.getVersion().getIncrementingVersion());
} catch (ActiveMQClusterSecurityException | ActiveMQSecurityException e) {
ActiveMQServerLogger.LOGGER.securityProblemWhileCreatingSession(e.getMessage());
response = new ActiveMQExceptionMessage(e);
} catch (ActiveMQException e) {
if (e.getType() == ActiveMQExceptionType.INCOMPATIBLE_CLIENT_SERVER_VERSIONS) {
incompatibleVersion = true;
logger.debug("Sending ActiveMQException after Incompatible client", e);
} else {
ActiveMQServerLogger.LOGGER.failedToCreateSession(e);
}
response = new ActiveMQExceptionMessage(e);
} catch (Exception e) {
ActiveMQServerLogger.LOGGER.failedToCreateSession(e);
response = new ActiveMQExceptionMessage(new ActiveMQInternalErrorException());
}
// are not compatible
if (incompatibleVersion) {
channel1.sendAndFlush(response);
} else {
channel1.send(response);
}
}
use of org.apache.activemq.artemis.core.version.Version in project activemq-artemis by apache.
the class VersionLoaderTest method testLoadVersion.
// Constants -----------------------------------------------------
// Attributes ----------------------------------------------------
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
@Test
public void testLoadVersion() throws Exception {
Version version = VersionLoader.getVersion();
Properties props = new Properties();
props.load(ClassLoader.getSystemResourceAsStream(VersionLoader.DEFAULT_PROP_FILE_NAME));
Assert.assertEquals(props.get("activemq.version.versionName"), version.getVersionName());
Assert.assertEquals(Integer.parseInt(props.getProperty("activemq.version.majorVersion")), version.getMajorVersion());
Assert.assertEquals(Integer.parseInt(props.getProperty("activemq.version.minorVersion")), version.getMinorVersion());
Assert.assertEquals(Integer.parseInt(props.getProperty("activemq.version.microVersion")), version.getMicroVersion());
Assert.assertEquals(Integer.parseInt(new StringTokenizer(props.getProperty("activemq.version.incrementingVersion"), ",").nextToken()), version.getIncrementingVersion());
}
use of org.apache.activemq.artemis.core.version.Version in project activemq-artemis by apache.
the class VersionLoader method load.
private static Version[] load() {
Properties versionProps = new Properties();
final InputStream in = VersionImpl.class.getClassLoader().getResourceAsStream(VersionLoader.PROP_FILE_NAME);
try {
if (in == null) {
ActiveMQClientLogger.LOGGER.noVersionOnClasspath(getClasspathString());
throw new RuntimeException(VersionLoader.PROP_FILE_NAME + " is not available");
}
try {
versionProps.load(in);
String versionName = versionProps.getProperty("activemq.version.versionName");
int majorVersion = Integer.valueOf(versionProps.getProperty("activemq.version.majorVersion"));
int minorVersion = Integer.valueOf(versionProps.getProperty("activemq.version.minorVersion"));
int microVersion = Integer.valueOf(versionProps.getProperty("activemq.version.microVersion"));
int[] incrementingVersions = parseCompatibleVersionList(versionProps.getProperty("activemq.version.incrementingVersion"));
int[] compatibleVersionArray = parseCompatibleVersionList(versionProps.getProperty("activemq.version.compatibleVersionList"));
List<Version> definedVersions = new ArrayList<>(incrementingVersions.length);
for (int incrementingVersion : incrementingVersions) {
definedVersions.add(new VersionImpl(versionName, majorVersion, minorVersion, microVersion, incrementingVersion, compatibleVersionArray));
}
// We want the higher version to be the first
Collections.sort(definedVersions, new Comparator<Version>() {
@Override
public int compare(Version version1, Version version2) {
return version2.getIncrementingVersion() - version1.getIncrementingVersion();
}
});
return definedVersions.toArray(new Version[incrementingVersions.length]);
} catch (IOException e) {
// way
throw new RuntimeException("unable to load " + VersionLoader.PROP_FILE_NAME, e);
}
} finally {
try {
if (in != null)
in.close();
} catch (Throwable ignored) {
}
}
}
Aggregations