How to Get an Asset with the Drools Guvnor 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;

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

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

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

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

    Response res = client.target("http://host:8080/guvnor/rest/packages/samplePackage/assets/sampleAsset").request().get();

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

    client.close();
  }

}

Published by:

Fernando Ribeiro

Experienced tech executive with a 24-year track record in enterprise computing. Leading AWS's professional services application modernization division in Brazil. He's held diverse roles including management, solutions architecture, sales consultancy, and full-stack development at major players like Oracle, Red Hat, and IBM. Fernando also contributes to open source and writes about emerging technologies. The views expressed here are his own and do not necessarily reflect the views of AWS.

Categories SoftwareTags , , , , , , Leave a comment

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.