Search code examples
web-servicesrestpentahoresteasykettle

How to properly consume JAX-RS (RESTEasy) with Pentaho(kettle)


I want to send data(table employees) via HTTP POST REQUEST to my API service, and save it to database.

piece of code:

@POST
@Consumes({ "application/json" })
@Produces(MediaType.TEXT_PLAIN)
@Path("/full/json")
public Response recieveDataFJson(Employee employee) {
    System.out.println("Recieved employee with name: " + employee.getName());
    return Response.ok("works").build();
}

I'm using JSON output item to prepare the data for sending to the service, but I think the problem is that Pentaho is sending the JSON in the format:

{"Employee":[{"name":"mike"}]}

but service is just waiting for:

{"name":"mike"}

I tried to delete initial tag but then the sending item was:

{"":[{"name":"mike"}]}

my service have no authentication, the URL is correct

What can I do, or there is another way to do the same more efficiently?


Solution

  • I found a "tricky" way of solving my problem:

    In pentaho:

    pass table data to a JSON and send it as TEXT PLAIN

    In service:

    recieve the request as TEXT PLAIN and then parse String to JSON and JSON to JAVA object:

    JSONObject jsnobject = new JSONObject(recievedString);
                ObjectMapper mapper = new ObjectMapper();
                SimpleDateFormat format = new SimpleDateFormat("yy/MM/dd HH:mm:ss.SSS");
                mapper.setDateFormat(format);
                JSONArray jsonArray = jsnobject.getJSONArray("Employee");
                for (int i = 0; i < jsonArray.length(); i++) {
                    JSONObject jsonObject = jsonArray.getJSONObject(i);
                    Employee employee = mapper.readValue(jsonObject.toString(),
                            Employee.class); = new NegocioBean();
                        negocioBean.aplicarReglas(factOrdenesTransporte);
                }