How to Update an Entry with the Infinispan REST API

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;

import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;

@SuppressWarnings("serial")
@WebServlet(name = "SampleInfinispanServlet", value = "/")
public final class SampleInfinispanServlet extends HttpServlet {

  @Override
  protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) {
    final Client client = ClientBuilder.newClient();

    client.register(HttpAuthenticationFeature.basic("username", "password"));

    final Entity entity = ...

    client.target("http://localhost:8080/rest/samplecache/samplekey").request().post(entity);

    client.close();
  }

}
Advertisements

How to Search MBeans with the Jolokia REST API

import java.io.IOException;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.core.Response;

@SuppressWarnings("serial")
@WebServlet(name = "SampleJolokiaServlet", value = "/")
public final class SampleJolokiaServlet extends HttpServlet {

  @Override
  protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws IOException {
    final Client client = ClientBuilder.newClient();

    final Response res = client.target("http://localhost:8161/jolokia/search/<Pattern>").request().get();

    resp.getWriter().println(res.readEntity(String.class));

    client.close();
  }

}

How to Execute an Operation with the Jolokia REST API

import java.io.IOException;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.core.Response;

@SuppressWarnings("serial")
@WebServlet(name = "SampleJolokiaServlet", value = "/")
public final class SampleJolokiaServlet extends HttpServlet {

  @Override
  protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws IOException {
    final Client client = ClientBuilder.newClient();

    final Response res = client.target("http://localhost:8161/jolokia/exec/<MBean Name>/<Operation Name>/<Arg>/<Arg2>/...").request().get();

    resp.getWriter().println(res.readEntity(String.class));

    client.close();
  }

}

How to Write an Attribute with the Jolokia REST API

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;

@SuppressWarnings("serial")
@WebServlet(name = "SampleJolokiaServlet", value = "/")
public final class SampleJolokiaServlet extends HttpServlet {

  @Override
  protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) {
    final Client client = ClientBuilder.newClient();

    client.target("http://localhost:8161/jolokia/write/<MBean Name>/<Attribute Name>/<Attribute Value>/<Inner Path>").request().get();

    client.close();
  }

}

How to Read an Attribute with the Jolokia REST API

import java.io.IOException;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.core.Response;

@SuppressWarnings("serial")
@WebServlet(name = "SampleJolokiaServlet", value = "/")
public final class SampleJolokiaServlet extends HttpServlet {

  @Override
  protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws IOException {
    final Client client = ClientBuilder.newClient();

    final Response res = client.target("http://localhost:8161/jolokia/read/<MBean Name>/<Attribute Name>/<Inner Path>").request().get();

    resp.getWriter().println(res.readEntity(String.class));

    client.close();
  }

}

How to List MBeans with the Jolokia REST API

import java.io.IOException;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.core.Response;

@SuppressWarnings("serial")
@WebServlet(name = "SampleJolokiaServlet", value = "/")
public final class SampleJolokiaServlet extends HttpServlet {

  @Override
  protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws IOException {
    final Client client = ClientBuilder.newClient();

    final Response res = client.target("http://localhost:8161/jolokia/list").request().get();

    resp.getWriter().println(res.readEntity(String.class));

    client.close();
  }

}

How to Receive a Message from an Apache ActiveMQ Topic with JAX-RS

import java.io.IOException;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.core.Response;

@WebServlet(name = "SampleActiveMQServlet", value = "/")
public final class SampleActiveMQServlet extends HttpServlet {

  protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws IOException {
    final Client client = ClientBuilder.newClient();

    final Response res = client.target("http://localhost:8161/api/message/SampleTopic").request().get();

    resp.getWriter().println(res.readEntity(String.class));

    client.close();
  }

}

How to Receive a Message from an Apache ActiveMQ Queue with JAX-RS

import java.io.IOException;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.core.Response;

@WebServlet(name = "SampleActiveMQServlet", value = "/")
public final class SampleActiveMQServlet extends HttpServlet {

  protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws IOException {
    final Client client = ClientBuilder.newClient();

    final Response res = client.target("http://localhost:8161/api/message/SampleQueue").queryParam("type", "queue").request().get();

    resp.getWriter().println(res.readEntity(String.class));

    client.close();
  }

}

How to Send a Message to an Apache ActiveMQ Topic with JAX-RS

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.MediaType;

@WebServlet(name = "SampleActiveMQServlet", value = "/")
public final class SampleActiveMQServlet extends HttpServlet {

  protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) {
    final Client client = ClientBuilder.newClient();

    client.target("http://localhost:8161/api/message/SampleTopic").queryParam("body", "Simples Assim").request(MediaType.TEXT_XML_TYPE).post(Entity.xml(""));

    client.close();
  }

}

How to Send a Message to an Apache ActiveMQ Queue with JAX-RS

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.MediaType;

@WebServlet(name = "SampleActiveMQServlet", value = "/")
public final class SampleActiveMQServlet extends HttpServlet {

  protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) {
    final Client client = ClientBuilder.newClient();

    client.target("http://localhost:8161/api/message/SampleTopic").queryParam("type", "queue").queryParam("body", "Simples Assim").request(MediaType.TEXT_XML_TYPE).post(Entity.xml(""));

    client.close();
  }

}