Consul { public boolean writeSessionData(final String name, final String data, final String sessionId) { final Response response = httpClient .target(endpoint) .path("/v1/kv/").path(name) .queryParam("acquire", sessionId) .request() .put(Entity.text(data)); if (response.getStatus() != Response.Status.OK.getStatusCode()) { LOG.log(Level.WARNING, "Could not write value " + name + "=" + data + " for session " + sessionId + " got response " + response.getStatus() + " but expected 200. Consul Agent says " + response.readEntity(String.class)); return false; } if (response.readEntity(String.class).equals("true")) { return true; } return false; } Consul(final String endpoint); boolean isValid(); ConsulSession createSession(final String name, final int ttlMs, final int lockDelay); boolean writeSessionData(final String name, final String data, final String sessionId); boolean createPermanentData(final String name, final String data); boolean writePermanentData(
            final String name, final String data); boolean removePermanentData(final String name); String readData(final String name); ConsulWatch createWatch(final String pathToWatch); static final int DEFAULT_LOCK_DELAY; }
@Test public void writeSessionData() throws Exception { final Consul consul = new Consul(System.getProperty(EP_PROPERTY)); assertTrue(consul.isValid()); final ConsulSession session = consul.createSession(getSessionName(), 10, 0); System.out.println(session.getId()); assertThat(session, is(notNullValue())); assertTrue(consul.writeSessionData("TheKey", "TheValue", session.getId())); assertThat(consul.readData("TheKey"), is("TheValue")); assertTrue(consul.writeSessionData("TheKey", "TheNewValue", session.getId())); assertThat(consul.readData("TheKey"), is("TheNewValue")); session.close(); }