use of com.hazelcast.config.MemcacheProtocolConfig in project hazelcast by hazelcast.
the class TestFullApplicationContext method testMemcacheProtocolConfig.
@Test
public void testMemcacheProtocolConfig() {
MemcacheProtocolConfig memcacheProtocolConfig = config.getNetworkConfig().getMemcacheProtocolConfig();
assertNotNull(memcacheProtocolConfig);
assertTrue(memcacheProtocolConfig.isEnabled());
}
use of com.hazelcast.config.MemcacheProtocolConfig in project hazelcast by hazelcast.
the class TcpServerContext method initMemcacheProtocolConfig.
private static MemcacheProtocolConfig initMemcacheProtocolConfig(Config config) {
AdvancedNetworkConfig advancedNetworkConfig = config.getAdvancedNetworkConfig();
boolean isAdvancedNetwork = advancedNetworkConfig.isEnabled();
if (isAdvancedNetwork && config.getAdvancedNetworkConfig().getEndpointConfigs().get(MEMCACHE) != null) {
return new MemcacheProtocolConfig().setEnabled(true);
}
return config.getNetworkConfig().getMemcacheProtocolConfig();
}
use of com.hazelcast.config.MemcacheProtocolConfig in project hazelcast by hazelcast.
the class UnifiedProtocolDecoder method onRead.
@Override
public HandlerStatus onRead() throws Exception {
upcast(src).flip();
try {
if (src.remaining() < PROTOCOL_LENGTH) {
// The protocol has not yet been fully received.
return CLEAN;
}
String protocol = loadProtocol();
serverContext.getAuditLogService().eventBuilder(AuditlogTypeIds.NETWORK_SELECT_PROTOCOL).message("Protocol bytes received for a connection").level(Level.DEBUG).addParameter("protocol", protocol).log();
if (CLUSTER.equals(protocol)) {
initChannelForCluster();
} else if (CLIENT_BINARY.equals(protocol)) {
initChannelForClient();
} else if (RestApiTextDecoder.TEXT_PARSERS.isCommandPrefix(protocol)) {
RestApiConfig restApiConfig = serverContext.getRestApiConfig();
if (!restApiConfig.isEnabledAndNotEmpty()) {
throw new IllegalStateException("REST API is not enabled. " + "To enable REST API, please do one of the following:\n" + "- Change member config using JAVA API: " + "config.getNetworkConfig().getRestApiConfig().setEnabled(true);\n" + "- Change XML/YAML configuration property: hazelcast.network.rest-api.enabled to true\n" + "- Add system property: -Dhz.network.rest-api.enabled=true\n" + "- Add environment variable property: HZ_NETWORK_RESTAPI_ENABLED=true" + " (recommended when running container/docker image)");
}
initChannelForText(protocol, true);
} else if (MemcacheTextDecoder.TEXT_PARSERS.isCommandPrefix(protocol)) {
MemcacheProtocolConfig memcacheProtocolConfig = serverContext.getMemcacheProtocolConfig();
if (!memcacheProtocolConfig.isEnabled()) {
throw new IllegalStateException("Memcache text protocol is not enabled. " + "To enable Memcache, please do one of the following:\n" + "- Change member config using JAVA API: " + "config.getNetworkConfig().getMemcacheProtocolConfig().setEnabled(true);\n" + "- Change XML/YAML configuration property: " + "hazelcast.network.memcache-protocol.enabled to true\n" + "- Add system property: -Dhz.network.memcache-protocol.enabled=true\n" + "- Add environment variable property: HZ_NETWORK_MEMCACHEPROTOCOL_ENABLED=true" + " (recommended when running container/docker image)");
}
// text doesn't have a protocol; anything that isn't cluster/client protocol will be interpreted as txt.
initChannelForText(protocol, false);
} else {
throw new IllegalStateException("Unknown protocol: " + protocol);
}
if (!channel.isClientMode()) {
protocolEncoder.signalProtocolEstablished(protocol);
}
return CLEAN;
} finally {
compactOrClear(src);
}
}
use of com.hazelcast.config.MemcacheProtocolConfig in project hazelcast by hazelcast.
the class MemcacheProtocolFilterTest method testRestApiDisabled.
/**
* <pre>
* Given: Memcache protocol is explicitly disabled
* When: version commad prefix (ver) is used by client
* Then: connection is terminated after reading the first 3 bytes (protocol header)
* </pre>
*/
@Test
public void testRestApiDisabled() throws Exception {
Config config = new Config();
config.getNetworkConfig().setMemcacheProtocolConfig(new MemcacheProtocolConfig().setEnabled(false));
HazelcastInstance hz = factory.newHazelcastInstance(config);
TextProtocolClient client = new TextProtocolClient(getAddress(hz).getInetSocketAddress());
try {
client.connect();
client.sendData("ver");
client.waitUntilClosed();
assertEquals(3, client.getSentBytesCount());
assertEquals(0, client.getReceivedBytes().length);
assertTrue(client.isConnectionClosed());
} finally {
client.close();
}
}
use of com.hazelcast.config.MemcacheProtocolConfig in project hazelcast by hazelcast.
the class MemcacheProtocolFilterTest method testRestApiWhenMemcacheEnabled.
/**
* <pre>
* Given: Memcache protocol is explicitly enabled
* When: HTTP GET command prefix is used by client
* Then: connection is terminated after reading the first 3 bytes (protocol header)
* </pre>
*/
@Test
public void testRestApiWhenMemcacheEnabled() throws Exception {
Config config = new Config();
config.getNetworkConfig().setMemcacheProtocolConfig(new MemcacheProtocolConfig().setEnabled(true));
HazelcastInstance hz = factory.newHazelcastInstance(config);
TextProtocolClient client = new TextProtocolClient(getAddress(hz).getInetSocketAddress());
try {
client.connect();
client.sendData("GET");
client.waitUntilClosed();
assertEquals(3, client.getSentBytesCount());
assertEquals(0, client.getReceivedBytes().length);
assertTrue(client.isConnectionClosed());
} finally {
client.close();
}
}
Aggregations