use of org.apache.karaf.examples.rest.api.Booking in project karaf by apache.
the class ListAllBookingCommand method execute.
@Override
public Object execute() throws Exception {
List providers = new ArrayList();
providers.add(new JacksonJsonProvider());
WebClient webClient = WebClient.create(restLocation, providers);
List<Attachment> atts = new LinkedList<>();
Booking b1 = new Booking();
b1.setCustomer("the one who must not be named");
b1.setFlight("101");
b1.setId(43L);
atts.add(new Attachment("root", "application/json", b1));
atts.add(new Attachment("image", "application/octet-stream", new ByteArrayInputStream("UGhvdG8=".getBytes(StandardCharsets.UTF_8))));
Collection<? extends Attachment> results = webClient.type("multipart/mixed").accept("multipart/mixed").postAndGetCollection(atts, Attachment.class);
for (Attachment a : results) {
System.out.println(a.getContentId() + ": " + a.getContentType() + ": " + a.getDataHandler().getContent());
}
return null;
}
use of org.apache.karaf.examples.rest.api.Booking in project karaf by apache.
the class AddBookingCommand method execute.
@Override
public Object execute() throws Exception {
Booking booking = new Booking();
booking.setId(id);
booking.setFlight(flight);
booking.setCustomer(customer);
Client client = ClientBuilder.newClient();
client.register(new JacksonJsonProvider());
WebTarget target = client.target(restLocation);
target.request().post(Entity.json(booking));
return null;
}
use of org.apache.karaf.examples.rest.api.Booking in project karaf by apache.
the class BookingServiceRest method traceMultipart.
@Path("/all")
@Consumes("multipart/mixed")
@Produces("multipart/mixed")
@POST
public MultipartBody traceMultipart(List<Attachment> atts) {
final List<Attachment> results = new ArrayList<>();
final Attachment att1 = new Attachment("text", MediaType.TEXT_HTML, "Hello World!");
results.add(att1);
Booking b1 = new Booking();
b1.setCustomer("me");
b1.setFlight("far far away");
b1.setId(42L);
final Attachment att2 = new Attachment("json", MediaType.APPLICATION_JSON, b1);
results.add(att2);
final Attachment att3 = new Attachment("stream", MediaType.APPLICATION_OCTET_STREAM, new ByteArrayInputStream("important information".getBytes()));
results.add(att3);
results.addAll(atts);
return new MultipartBody(results, true);
}
use of org.apache.karaf.examples.rest.api.Booking in project karaf by apache.
the class ListBookingCommand method execute.
@Override
public Object execute() throws Exception {
Client client = ClientBuilder.newClient();
client.register(new JacksonJsonProvider());
WebTarget target = client.target(restLocation);
List<Booking> bookings = (List<Booking>) target.request(MediaType.APPLICATION_JSON).get(new GenericType<List<Booking>>() {
});
for (Booking booking : bookings) {
System.out.println(booking.getId() + " " + booking.getCustomer() + " " + booking.getFlight());
}
return null;
}
use of org.apache.karaf.examples.rest.api.Booking in project karaf by apache.
the class AddBookingCommand method execute.
@Override
public Object execute() throws Exception {
Booking booking = new Booking();
booking.setId(id);
booking.setFlight(flight);
booking.setCustomer(customer);
List providers = new ArrayList();
providers.add(new JacksonJsonProvider());
WebClient webClient = WebClient.create(restLocation, providers);
webClient.header("Content-Type", MediaType.APPLICATION_JSON).post(booking);
return null;
}
Aggregations