8

I don't get to work REST API of Hazelcast, receiving always :

  1. at client side : ERR_EMPTY_RESPONSE via Browser or java.net.SocketException: Unexpected end of file from server via a Java Test Program.
  2. at hazelcast node:

    INFO: [myIP]:5701 [dev] [3.6] Established socket connection between /127.0.0.1:5701 and /127.0.0.1:62816
    06-may-2016 13:04:20 com.hazelcast.nio.tcp.TcpIpConnection
    INFO: [myIP]:5701 [dev] [3.6] Connection [/127.0.0.1:62816] lost. Reason: Socket explicitly closed
    

The used code is just hazaelcast multimap sample: and the REST API uri http://localhost:5701/hazelcast/rest/maps/my-distributed-map/key

Vikrant Kashyap
  • 6,398
  • 3
  • 32
  • 52
Azimuts
  • 1,212
  • 4
  • 16
  • 35
  • Do you try to access a multimap? Multimaps are not supported, only cluster information, maps and queues. – noctarius May 06 '16 at 11:25
  • Just a map, like the sample program: ConcurrentMap map = h.getMap("my-distributed-map") and also IMap, Multimap ...always the same response – Azimuts May 06 '16 at 11:50
  • 1
    Is the REST available? By default it should be disabled after `3.6`. – Murat Ayan May 06 '16 at 12:07
  • @Murat, you are OK. The same sample with 3.5.2 works fine.... I dont know how to enable. I have tried "hazelcast.mc.rest.enabled", but nothing – Azimuts May 06 '16 at 12:38
  • 2
    The correct property to enable REST is: -Dhazelcast.rest.enabled=true . This way works after 3.6 – Azimuts May 06 '16 at 12:50
  • Cheers. `hazelcast.mc.rest.enabled` is for Management Center REST imho. – Murat Ayan May 06 '16 at 13:31

4 Answers4

10

i think that REST interface was disabled by default until certain version. add jvm argument for your application.

-Dhazelcast.rest.enabled=true
magulla
  • 499
  • 1
  • 9
  • 22
4

You can add hazelcast.rest.enabled to your hazelcast.xml config.

<hazelcast>
   ...
  <properties>
    ...
    <property name="hazelcast.rest.enabled">true</property>
  </properties> 
</hazelcast>
Chikipowpow
  • 809
  • 8
  • 9
4

If you want to do it programatically, for example using Spring Boot @Configuration Bean, use this method on your returned com.hazelcast.config.Config class:

.setProperty("hazelcast.rest.enabled", "true")
Daniel Perník
  • 5,464
  • 2
  • 38
  • 46
3

The property hazelcast.rest.enabled was removed in Hazelcast 4.

If you wish to do this programatically in Hazelcast 4, you can use the REST endpoint groups

RestApiConfig restApiConfig = new RestApiConfig()
        .setEnabled(true)
        .enableGroups(RestEndpointGroup.DATA);
config.getNetworkConfig().setRestApiConfig(restApiConfig);

Or in the declarative configuration

<hazelcast>
    ...
    <network>
        <rest-api enabled="true">
            <endpoint-group name="DATA" enabled="true"/>
        </rest-api>
    </network>
</hazelcast>