Search in sources :

Example 1 with MemcacheProtocolConfig

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());
}
Also used : MemcacheProtocolConfig(com.hazelcast.config.MemcacheProtocolConfig) Test(org.junit.Test) QuickTest(com.hazelcast.test.annotation.QuickTest)

Example 2 with MemcacheProtocolConfig

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();
}
Also used : AdvancedNetworkConfig(com.hazelcast.config.AdvancedNetworkConfig) MemcacheProtocolConfig(com.hazelcast.config.MemcacheProtocolConfig)

Example 3 with MemcacheProtocolConfig

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);
    }
}
Also used : RestApiConfig(com.hazelcast.config.RestApiConfig) MemcacheProtocolConfig(com.hazelcast.config.MemcacheProtocolConfig) StringUtil.bytesToString(com.hazelcast.internal.util.StringUtil.bytesToString)

Example 4 with MemcacheProtocolConfig

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();
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) MemcacheProtocolConfig(com.hazelcast.config.MemcacheProtocolConfig) MemcacheProtocolConfig(com.hazelcast.config.MemcacheProtocolConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 5 with MemcacheProtocolConfig

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();
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) MemcacheProtocolConfig(com.hazelcast.config.MemcacheProtocolConfig) MemcacheProtocolConfig(com.hazelcast.config.MemcacheProtocolConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

MemcacheProtocolConfig (com.hazelcast.config.MemcacheProtocolConfig)6 QuickTest (com.hazelcast.test.annotation.QuickTest)4 Test (org.junit.Test)4 Config (com.hazelcast.config.Config)3 HazelcastInstance (com.hazelcast.core.HazelcastInstance)3 AdvancedNetworkConfig (com.hazelcast.config.AdvancedNetworkConfig)1 RestApiConfig (com.hazelcast.config.RestApiConfig)1 StringUtil.bytesToString (com.hazelcast.internal.util.StringUtil.bytesToString)1