public static void main(String[] args) {
Message message = new Message();
message.setText("Test message " + System.currentTimeMillis());
Client client = ClientBuilder.newClient();
client.register(JacksonJaxbJsonProvider.class);
// set basic auth filter
HttpAuthenticationFeature feature = HttpAuthenticationFeature.basic("foo", "bar");
client.register(feature);
UriBuilder uri = UriBuilder.fromUri(BASE_URI);
WebTarget target = client.target(uri.path("message").build());
System.out.println("Creating message");
Response r = target.request(MediaType.APPLICATION_JSON).post(Entity.entity(message, MediaType.APPLICATION_JSON));
String location = (String) r.getHeaders().get("location").get(0);
target = client.target(location);
Message response = target.request(MediaType.APPLICATION_JSON).get(Message.class);
WebTarget messagesResource = client.target(BASE_URI);
MessageList messages = messagesResource.request(MediaType.APPLICATION_JSON).get(MessageList.class);
for (Message entry : messages.getMessages()) {
System.out.println("The message text for id " + entry.getId() + " is: " + entry.getText());
}