From 10138d91a8af8d5c72f153fe5e76e8c31dc9a3e4 Mon Sep 17 00:00:00 2001 From: "Andrew J. Mauer" Date: Fri, 3 May 2019 10:13:29 -0400 Subject: [PATCH 1/5] cdi IT test bucket --- .../src/it/test-cdi-2.0/pom.xml | 199 ++++++++++++++++ .../inventory/InventoryApplication.java | 22 ++ .../guides/inventory/InventoryManager.java | 46 ++++ .../guides/inventory/InventoryResource.java | 59 +++++ .../guides/inventory/client/SystemClient.java | 95 ++++++++ .../guides/inventory/model/InventoryList.java | 32 +++ .../guides/inventory/model/SystemData.java | 30 +++ .../guides/system/SystemApplication.java | 22 ++ .../guides/system/SystemResource.java | 34 +++ .../src/main/webapp/WEB-INF/web.xml | 10 + .../test-cdi-2.0/src/main/webapp/index.html | 78 +++++++ .../inventory/InventoryEndpointTest.java | 219 ++++++++++++++++++ .../guides/system/SystemEndpointTest.java | 48 ++++ 13 files changed, 894 insertions(+) create mode 100644 boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/pom.xml create mode 100644 boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/inventory/InventoryApplication.java create mode 100644 boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/inventory/InventoryManager.java create mode 100644 boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/inventory/InventoryResource.java create mode 100644 boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/inventory/client/SystemClient.java create mode 100644 boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/inventory/model/InventoryList.java create mode 100644 boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/inventory/model/SystemData.java create mode 100644 boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/system/SystemApplication.java create mode 100644 boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/system/SystemResource.java create mode 100644 boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/webapp/WEB-INF/web.xml create mode 100644 boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/webapp/index.html create mode 100644 boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/test/java/it/io/openliberty/guides/inventory/InventoryEndpointTest.java create mode 100644 boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/test/java/it/io/openliberty/guides/system/SystemEndpointTest.java diff --git a/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/pom.xml b/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/pom.xml new file mode 100644 index 00000000..76a71cff --- /dev/null +++ b/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/pom.xml @@ -0,0 +1,199 @@ + + + + 4.0.0 + + boost + test-cdi-2.0 + war + 1.0-SNAPSHOT + + + UTF-8 + UTF-8 + 1.8 + 1.8 + + + + + + sonatype-nexus-snapshots + Sonatype Nexus Snapshots + https://oss.sonatype.org/content/repositories/snapshots/ + + true + + + false + + + + + + + + boost.boosters + ee8-bom + @pom.version@ + import + pom + + + + + + + boost.boosters + jaxrs + + + boost.boosters + jsonp + + + boost.boosters + cdi + + + + junit + junit + 4.12 + test + + + org.apache.cxf + cxf-rt-rs-client + 3.2.6 + test + + + org.apache.cxf + cxf-rt-rs-extension-providers + 3.2.6 + test + + + org.glassfish + javax.json + 1.0.4 + test + + + + + javax.activation + activation + 1.1.1 + + + + + + + boost + boost-maven-plugin + @pom.version@ + + + + package + + + + test-start-server + pre-integration-test + + start + + + + test-stop-server + post-integration-test + + stop + + + + + + org.apache.maven.plugins + maven-failsafe-plugin + 2.22.1 + + + + integration-test + verify + + + + + + + + + + ol + + + boostRuntime + ol + + + + + boost.runtimes + openliberty + + + + + wlp + + + boostRuntime + wlp + + + + + boost.runtimes + wlp + + + + + tomee + + + boostRuntime + tomee + + + + + boost.runtimes + tomee + + + + + diff --git a/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/inventory/InventoryApplication.java b/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/inventory/InventoryApplication.java new file mode 100644 index 00000000..735484ce --- /dev/null +++ b/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/inventory/InventoryApplication.java @@ -0,0 +1,22 @@ +// tag::copyright[] +/******************************************************************************* + * Copyright (c) 2017 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - Initial implementation + *******************************************************************************/ +// end::copyright[] +package io.openliberty.guides.inventory; + +// JAX-RS +import javax.ws.rs.ApplicationPath; +import javax.ws.rs.core.Application; + +@ApplicationPath("inventory") +public class InventoryApplication extends Application { + +} diff --git a/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/inventory/InventoryManager.java b/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/inventory/InventoryManager.java new file mode 100644 index 00000000..41945249 --- /dev/null +++ b/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/inventory/InventoryManager.java @@ -0,0 +1,46 @@ +// tag::copyright[] +/******************************************************************************* + * Copyright (c) 2017, 2019 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - Initial implementation + *******************************************************************************/ +// end::copyright[] +package io.openliberty.guides.inventory; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Properties; +import io.openliberty.guides.inventory.client.SystemClient; +import io.openliberty.guides.inventory.model.InventoryList; +import io.openliberty.guides.inventory.model.SystemData; +import javax.enterprise.context.ApplicationScoped; +import javax.inject.Inject; + +// tag::ApplicationScoped[] +@ApplicationScoped +// end::ApplicationScoped[] +public class InventoryManager { + + private List systems = Collections.synchronizedList(new ArrayList<>()); + + public void add(String hostname, Properties systemProps) { + Properties props = new Properties(); + props.setProperty("os.name", systemProps.getProperty("os.name")); + props.setProperty("user.name", systemProps.getProperty("user.name")); + + SystemData system = new SystemData(hostname, props); + if (!systems.contains(system)) { + systems.add(system); + } + } + + public InventoryList list() { + return new InventoryList(systems); + } +} diff --git a/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/inventory/InventoryResource.java b/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/inventory/InventoryResource.java new file mode 100644 index 00000000..03767049 --- /dev/null +++ b/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/inventory/InventoryResource.java @@ -0,0 +1,59 @@ +// tag::copyright[] +/******************************************************************************* + * Copyright (c) 2017, 2019 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - Initial implementation + *******************************************************************************/ +// end::copyright[] +package io.openliberty.guides.inventory; + +import java.util.Properties; +import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import io.openliberty.guides.inventory.model.InventoryList; +import io.openliberty.guides.inventory.client.SystemClient; + +@RequestScoped +@Path("/systems") +public class InventoryResource { + + @Inject + InventoryManager manager; + + @Inject + SystemClient systemClient; + + @GET + @Path("/{hostname}") + @Produces(MediaType.APPLICATION_JSON) + public Response getPropertiesForHost(@PathParam("hostname") String hostname) { + // Get properties for host + Properties props = systemClient.getProperties(hostname); + if (props == null) { + return Response.status(Response.Status.NOT_FOUND) + .entity("ERROR: Unknown hostname or the system service may not be " + "running on " + hostname) + .build(); + } + + // Add to inventory + manager.add(hostname, props); + return Response.ok(props).build(); + } + + @GET + @Produces(MediaType.APPLICATION_JSON) + public InventoryList listContents() { + return manager.list(); + } +} diff --git a/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/inventory/client/SystemClient.java b/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/inventory/client/SystemClient.java new file mode 100644 index 00000000..6a62f784 --- /dev/null +++ b/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/inventory/client/SystemClient.java @@ -0,0 +1,95 @@ +// tag::copyright[] +/******************************************************************************* + * Copyright (c) 2017 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - Initial implementation + *******************************************************************************/ +// end::copyright[] +package io.openliberty.guides.inventory.client; + +import javax.enterprise.context.RequestScoped; +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Invocation.Builder; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.Status; +import java.util.Properties; +import java.net.URI; + +@RequestScoped +public class SystemClient { + + // Constants for building URI to the system service. + private final int DEFAULT_PORT = Integer.valueOf(System.getProperty("default.http.port")); + private final String SYSTEM_PROPERTIES = "/system/properties"; + private final String PROTOCOL = "http"; + + // Wrapper function that gets properties + public Properties getProperties(String hostname) { + String url = buildUrl(PROTOCOL, hostname, DEFAULT_PORT, SYSTEM_PROPERTIES); + Builder clientBuilder = buildClientBuilder(url); + return getPropertiesHelper(clientBuilder); + } + + // tag::doc[] + /** + * Builds the URI string to the system service for a particular host. + * + * @param protocol + * - http or https. + * @param host + * - name of host. + * @param port + * - port number. + * @param path + * - Note that the path needs to start with a slash!!! + * @return String representation of the URI to the system properties service. + */ + // end::doc[] + protected String buildUrl(String protocol, String host, int port, String path) { + try { + URI uri = new URI(protocol, null, host, port, path, null, null); + return uri.toString(); + } catch (Exception e) { + System.err.println("Exception thrown while building the URL: " + e.getMessage()); + return null; + } + } + + // Method that creates the client builder + protected Builder buildClientBuilder(String urlString) { + try { + Client client = ClientBuilder.newClient(); + Builder builder = client.target(urlString).request(); + return builder.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON); + } catch (Exception e) { + System.err.println("Exception thrown while building the client: " + e.getMessage()); + return null; + } + } + + // Helper method that processes the request + protected Properties getPropertiesHelper(Builder builder) { + try { + Response response = builder.get(); + if (response.getStatus() == Status.OK.getStatusCode()) { + return response.readEntity(Properties.class); + } else { + System.err.println("Response Status is not OK."); + } + } catch (RuntimeException e) { + System.err.println("Runtime exception: " + e.getMessage()); + } catch (Exception e) { + System.err.println("Exception thrown while invoking the request: " + e.getMessage()); + } + return null; + } + +} diff --git a/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/inventory/model/InventoryList.java b/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/inventory/model/InventoryList.java new file mode 100644 index 00000000..27c2764f --- /dev/null +++ b/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/inventory/model/InventoryList.java @@ -0,0 +1,32 @@ +// tag::copyright[] +/******************************************************************************* + * Copyright (c) 2017, 2018 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - Initial implementation + *******************************************************************************/ +// end::copyright[] +package io.openliberty.guides.inventory.model; + +import java.util.List; + +public class InventoryList { + + private List systems; + + public InventoryList(List systems) { + this.systems = systems; + } + + public List getSystems() { + return systems; + } + + public int getTotal() { + return systems.size(); + } +} diff --git a/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/inventory/model/SystemData.java b/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/inventory/model/SystemData.java new file mode 100644 index 00000000..a237834c --- /dev/null +++ b/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/inventory/model/SystemData.java @@ -0,0 +1,30 @@ +package io.openliberty.guides.inventory.model; + +import java.util.Properties; + +public class SystemData { + + private final String hostname; + private final Properties properties; + + public SystemData(String hostname, Properties properties) { + this.hostname = hostname; + this.properties = properties; + } + + public String getHostname() { + return hostname; + } + + public Properties getProperties() { + return properties; + } + + @Override + public boolean equals(Object host) { + if (host instanceof SystemData) { + return hostname.equals(((SystemData) host).getHostname()); + } + return false; + } +} diff --git a/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/system/SystemApplication.java b/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/system/SystemApplication.java new file mode 100644 index 00000000..5782a5da --- /dev/null +++ b/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/system/SystemApplication.java @@ -0,0 +1,22 @@ +// tag::copyright[] +/******************************************************************************* + * Copyright (c) 2017 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - Initial implementation + *******************************************************************************/ +// end::copyright[] +package io.openliberty.guides.system; + +// JAX-RS +import javax.ws.rs.core.Application; +import javax.ws.rs.ApplicationPath; + +@ApplicationPath("system") +public class SystemApplication extends Application { + +} diff --git a/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/system/SystemResource.java b/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/system/SystemResource.java new file mode 100644 index 00000000..2ec7731f --- /dev/null +++ b/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/system/SystemResource.java @@ -0,0 +1,34 @@ +// tag::copyright[] +/******************************************************************************* + * Copyright (c) 2017, 2018 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - Initial implementation + *******************************************************************************/ +// end::copyright[] +package io.openliberty.guides.system; + +import java.util.Properties; + +// CDI +import javax.enterprise.context.RequestScoped; +import javax.ws.rs.GET; +// JAX-RS +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +@RequestScoped +@Path("/properties") +public class SystemResource { + + @GET + @Produces(MediaType.APPLICATION_JSON) + public Properties getProperties() { + return System.getProperties(); + } +} diff --git a/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/webapp/WEB-INF/web.xml b/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 00000000..a3823f10 --- /dev/null +++ b/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,10 @@ + + + Liberty Project + + + index.html + + \ No newline at end of file diff --git a/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/webapp/index.html b/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/webapp/index.html new file mode 100644 index 00000000..74ec6c74 --- /dev/null +++ b/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/webapp/index.html @@ -0,0 +1,78 @@ + + + +

Welcome to your Liberty Application

+

Thanks for generating this project using the app accelerator. Please see below for some extra information on each of the technologies you chose

+ +
+

REST

+

+ For the complete feature documentation, see the jaxrs-2.0 + feature description in IBM Knowledge Center. +

+
+ +
+

MicroProfile

+

+ The MicroProfile project is an open + community with the aim of optimizing Enterprise Java for a microservices + architecture. MicroProfile will be evolving with guidance from the community. +

+

+ For the complete feature documentation, see the + microProfile-1.0 + feature description in IBM Knowledge Center. +

+

+ If you want to share your thoughts you can post straight to the + MicroProfile Google group. +

+
+
+
+ + diff --git a/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/test/java/it/io/openliberty/guides/inventory/InventoryEndpointTest.java b/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/test/java/it/io/openliberty/guides/inventory/InventoryEndpointTest.java new file mode 100644 index 00000000..dd86315b --- /dev/null +++ b/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/test/java/it/io/openliberty/guides/inventory/InventoryEndpointTest.java @@ -0,0 +1,219 @@ +// tag::copyright[] +/******************************************************************************* + * Copyright (c) 2017, 2018 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - Initial implementation + *******************************************************************************/ +// end::copyright[] +// tag::testClass[] +package it.io.openliberty.guides.inventory; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import javax.json.JsonObject; +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import org.apache.cxf.jaxrs.provider.jsrjsonp.JsrJsonpProvider; +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +public class InventoryEndpointTest { + + private static String port; + private static String baseUrl; + + private Client client; + + private final String SYSTEM_PROPERTIES = "system/properties"; + private final String INVENTORY_SYSTEMS = "inventory/systems"; + + @BeforeClass + public static void oneTimeSetup() { + // port = System.getProperty("liberty.test.port"); + String port = "9080"; + baseUrl = "http://localhost:" + port + "/"; + } + + @Before + public void setup() { + client = ClientBuilder.newClient(); + client.register(JsrJsonpProvider.class); + } + + @After + public void teardown() { + client.close(); + } + + // tag::tests[] + // tag::testSuite[] + @Test + public void testSuite() { + this.testEmptyInventory(); + this.testHostRegistration(); + this.testSystemPropertiesMatch(); + this.testUnknownHost(); + } + // end::testSuite[] + + // tag::testEmptyInventory[] + public void testEmptyInventory() { + Response response = this.getResponse(baseUrl + INVENTORY_SYSTEMS); + this.assertResponse(baseUrl, response); + + JsonObject obj = response.readEntity(JsonObject.class); + + int expected = 0; + int actual = obj.getInt("total"); + assertEquals("The inventory should be empty on application start but it wasn't", expected, actual); + + response.close(); + } + // end::testEmptyInventory[] + + // tag::testHostRegistration[] + public void testHostRegistration() { + this.visitLocalhost(); + + Response response = this.getResponse(baseUrl + INVENTORY_SYSTEMS); + this.assertResponse(baseUrl, response); + + JsonObject obj = response.readEntity(JsonObject.class); + + int expected = 1; + int actual = obj.getInt("total"); + assertEquals("The inventory should have one entry for localhost", expected, actual); + + boolean localhostExists = obj.getJsonArray("systems").getJsonObject(0).get("hostname").toString() + .contains("localhost"); + assertTrue("A host was registered, but it was not localhost", localhostExists); + + response.close(); + } + // end::testHostRegistration[] + + // tag::testSystemPropertiesMatch[] + public void testSystemPropertiesMatch() { + Response invResponse = this.getResponse(baseUrl + INVENTORY_SYSTEMS); + Response sysResponse = this.getResponse(baseUrl + SYSTEM_PROPERTIES); + + this.assertResponse(baseUrl, invResponse); + this.assertResponse(baseUrl, sysResponse); + + JsonObject jsonFromInventory = (JsonObject) invResponse.readEntity(JsonObject.class).getJsonArray("systems") + .getJsonObject(0).get("properties"); + + JsonObject jsonFromSystem = sysResponse.readEntity(JsonObject.class); + + String osNameFromInventory = jsonFromInventory.getString("os.name"); + String osNameFromSystem = jsonFromSystem.getString("os.name"); + this.assertProperty("os.name", "localhost", osNameFromSystem, osNameFromInventory); + + String userNameFromInventory = jsonFromInventory.getString("user.name"); + String userNameFromSystem = jsonFromSystem.getString("user.name"); + this.assertProperty("user.name", "localhost", userNameFromSystem, userNameFromInventory); + + invResponse.close(); + sysResponse.close(); + } + // end::testSystemPropertiesMatch[] + + // tag::testUnknownHost[] + public void testUnknownHost() { + Response response = this.getResponse(baseUrl + INVENTORY_SYSTEMS); + this.assertResponse(baseUrl, response); + + Response badResponse = client.target(baseUrl + INVENTORY_SYSTEMS + "/" + "badhostname") + .request(MediaType.APPLICATION_JSON).get(); + + String obj = badResponse.readEntity(String.class); + + boolean isError = obj.contains("ERROR"); + assertTrue("badhostname is not a valid host but it didn't raise an error", isError); + + response.close(); + badResponse.close(); + } + + // end::testUnknownHost[] + // end::tests[] + // tag::helpers[] + // tag::javadoc[] + /** + *

+ * Returns response information from the specified URL. + *

+ * + * @param url + * - target URL. + * @return Response object with the response from the specified URL. + */ + // end::javadoc[] + private Response getResponse(String url) { + return client.target(url).request().get(); + } + + // tag::javadoc[] + /** + *

+ * Asserts that the given URL has the correct response code of 200. + *

+ * + * @param url + * - target URL. + * @param response + * - response received from the target URL. + */ + // end::javadoc[] + private void assertResponse(String url, Response response) { + assertEquals("Incorrect response code from " + url, 200, response.getStatus()); + } + + // tag::javadoc[] + /** + * Asserts that the specified JVM system property is equivalent in both the + * system and inventory services. + * + * @param propertyName + * - name of the system property to check. + * @param hostname + * - name of JVM's host. + * @param expected + * - expected name. + * @param actual + * - actual name. + */ + // end::javadoc[] + private void assertProperty(String propertyName, String hostname, String expected, String actual) { + assertEquals("JVM system property [" + propertyName + "] " + + "in the system service does not match the one stored in " + "the inventory service for " + hostname, + expected, actual); + } + + // tag::javadoc[] + /** + * Makes a simple GET request to inventory/localhost. + */ + // end::javadoc[] + private void visitLocalhost() { + Response response = this.getResponse(baseUrl + SYSTEM_PROPERTIES); + this.assertResponse(baseUrl, response); + response.close(); + + Response targetResponse = client.target(baseUrl + INVENTORY_SYSTEMS + "/localhost").request().get(); + targetResponse.close(); + } + // end::helpers[] +} +// end::testClass[] diff --git a/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/test/java/it/io/openliberty/guides/system/SystemEndpointTest.java b/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/test/java/it/io/openliberty/guides/system/SystemEndpointTest.java new file mode 100644 index 00000000..60e11067 --- /dev/null +++ b/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/test/java/it/io/openliberty/guides/system/SystemEndpointTest.java @@ -0,0 +1,48 @@ +//tag::copyright[] +/******************************************************************************* +* Copyright (c) 2017, 2019 IBM Corporation and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* IBM Corporation - initial API and implementation +*******************************************************************************/ +// end::copyright[] +package it.io.openliberty.guides.system; + +import static org.junit.Assert.assertEquals; +import javax.json.JsonObject; +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.Response; + +import org.apache.cxf.jaxrs.provider.jsrjsonp.JsrJsonpProvider; +import org.junit.Test; + +public class SystemEndpointTest { + + @Test + public void testGetProperties() { + // String port = System.getProperty("liberty.test.port"); + String port = "9080"; + String url = "http://localhost:" + port + "/"; + + Client client = ClientBuilder.newClient(); + client.register(JsrJsonpProvider.class); + + WebTarget target = client.target(url + "system/properties"); + Response response = target.request().get(); + + assertEquals("Incorrect response code from " + url, 200, response.getStatus()); + + JsonObject obj = response.readEntity(JsonObject.class); + + assertEquals("The system property for the local and remote JVM should match", System.getProperty("os.name"), + obj.getString("os.name")); + + response.close(); + } +} From ce9e26dba748f8e46d3f301d5493db7957da763a Mon Sep 17 00:00:00 2001 From: "Andrew J. Mauer" Date: Fri, 3 May 2019 10:27:36 -0400 Subject: [PATCH 2/5] bom updates for cdi and jsonp --- boost-maven/boost-boosters/booster-cdi-ee8/pom.xml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/boost-maven/boost-boosters/booster-cdi-ee8/pom.xml b/boost-maven/boost-boosters/booster-cdi-ee8/pom.xml index 0111d9b5..47e1d084 100644 --- a/boost-maven/boost-boosters/booster-cdi-ee8/pom.xml +++ b/boost-maven/boost-boosters/booster-cdi-ee8/pom.xml @@ -10,6 +10,7 @@ + + + boost.boosters + boost-ee8-apis-bom + 0.1-SNAPSHOT + import + pom + From f114966295ad48934ff889473df3bc6fb6230375 Mon Sep 17 00:00:00 2001 From: "Andrew J. Mauer" Date: Tue, 7 May 2019 18:02:37 -0400 Subject: [PATCH 3/5] rename test classes to allow tests to run --- boost-maven/boost-boms/booster-ee8-bom/pom.xml | 4 ++-- .../boost-maven-plugin/src/it/test-cdi-2.0/pom.xml | 9 +++------ .../guides/inventory/client/SystemClient.java | 4 +++- ...ventoryEndpointTest.java => InventoryEndpointIT.java} | 4 ++-- .../{SystemEndpointTest.java => SystemEndpointIT.java} | 4 ++-- 5 files changed, 12 insertions(+), 13 deletions(-) rename boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/test/java/it/io/openliberty/guides/inventory/{InventoryEndpointTest.java => InventoryEndpointIT.java} (99%) rename boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/test/java/it/io/openliberty/guides/system/{SystemEndpointTest.java => SystemEndpointIT.java} (96%) diff --git a/boost-maven/boost-boms/booster-ee8-bom/pom.xml b/boost-maven/boost-boms/booster-ee8-bom/pom.xml index a9b98643..a8097b0d 100644 --- a/boost-maven/boost-boms/booster-ee8-bom/pom.xml +++ b/boost-maven/boost-boms/booster-ee8-bom/pom.xml @@ -60,12 +60,12 @@ provided - io.openliberty.boosters + boost.boosters cdi 0.2-SNAPSHOT - io.openliberty.boosters + boost.boosters jsonp 0.2-SNAPSHOT diff --git a/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/pom.xml b/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/pom.xml index 76a71cff..4d886d36 100644 --- a/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/pom.xml +++ b/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/pom.xml @@ -1,7 +1,6 @@ - - - - 4.0.0 + + 4.0.0 boost test-cdi-2.0 @@ -81,7 +80,6 @@ test - javax.activation activation diff --git a/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/inventory/client/SystemClient.java b/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/inventory/client/SystemClient.java index 6a62f784..11bfab81 100644 --- a/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/inventory/client/SystemClient.java +++ b/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/inventory/client/SystemClient.java @@ -27,7 +27,9 @@ public class SystemClient { // Constants for building URI to the system service. - private final int DEFAULT_PORT = Integer.valueOf(System.getProperty("default.http.port")); + // private final int DEFAULT_PORT = + // Integer.valueOf(System.getProperty("default.http.port")); + private final int DEFAULT_PORT = 9000; private final String SYSTEM_PROPERTIES = "/system/properties"; private final String PROTOCOL = "http"; diff --git a/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/test/java/it/io/openliberty/guides/inventory/InventoryEndpointTest.java b/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/test/java/it/io/openliberty/guides/inventory/InventoryEndpointIT.java similarity index 99% rename from boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/test/java/it/io/openliberty/guides/inventory/InventoryEndpointTest.java rename to boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/test/java/it/io/openliberty/guides/inventory/InventoryEndpointIT.java index dd86315b..1228ceea 100644 --- a/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/test/java/it/io/openliberty/guides/inventory/InventoryEndpointTest.java +++ b/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/test/java/it/io/openliberty/guides/inventory/InventoryEndpointIT.java @@ -28,7 +28,7 @@ import org.junit.BeforeClass; import org.junit.Test; -public class InventoryEndpointTest { +public class InventoryEndpointIT { private static String port; private static String baseUrl; @@ -41,7 +41,7 @@ public class InventoryEndpointTest { @BeforeClass public static void oneTimeSetup() { // port = System.getProperty("liberty.test.port"); - String port = "9080"; + String port = "9000"; baseUrl = "http://localhost:" + port + "/"; } diff --git a/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/test/java/it/io/openliberty/guides/system/SystemEndpointTest.java b/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/test/java/it/io/openliberty/guides/system/SystemEndpointIT.java similarity index 96% rename from boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/test/java/it/io/openliberty/guides/system/SystemEndpointTest.java rename to boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/test/java/it/io/openliberty/guides/system/SystemEndpointIT.java index 60e11067..54b689ba 100644 --- a/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/test/java/it/io/openliberty/guides/system/SystemEndpointTest.java +++ b/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/test/java/it/io/openliberty/guides/system/SystemEndpointIT.java @@ -22,12 +22,12 @@ import org.apache.cxf.jaxrs.provider.jsrjsonp.JsrJsonpProvider; import org.junit.Test; -public class SystemEndpointTest { +public class SystemEndpointIT { @Test public void testGetProperties() { // String port = System.getProperty("liberty.test.port"); - String port = "9080"; + String port = "9000"; String url = "http://localhost:" + port + "/"; Client client = ClientBuilder.newClient(); From c50abb73d37411ed8ee6aaa075871cca9d4cecb0 Mon Sep 17 00:00:00 2001 From: "Andrew J. Mauer" Date: Tue, 4 Jun 2019 17:49:49 -0400 Subject: [PATCH 4/5] switching jsonb providers on tomee --- .../src/it/test-cdi-2.0/pom.xml | 22 +++++ .../guides/inventory/InventoryResource.java | 2 + .../client/InventoryListJsonBImpl.java | 81 +++++++++++++++++++ .../inventory/client/PropertiesReader.java | 81 +++++++++++++++++++ .../guides/inventory/client/SystemClient.java | 4 +- .../guides/system/SystemResource.java | 2 + 6 files changed, 191 insertions(+), 1 deletion(-) create mode 100644 boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/inventory/client/InventoryListJsonBImpl.java create mode 100644 boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/inventory/client/PropertiesReader.java diff --git a/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/pom.xml b/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/pom.xml index 4d886d36..bde573f8 100644 --- a/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/pom.xml +++ b/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/pom.xml @@ -100,6 +100,28 @@ activation 1.1.1 + + javax.annotation + javax.annotation-api + 1.2 + + + javax.json + javax.json-api + true + + + jakarta.json.bind + jakarta.json.bind-api + 1.0.1 + true + + + org.glassfish + javax.json + 1.0.4 + true + diff --git a/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/inventory/InventoryResource.java b/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/inventory/InventoryResource.java index 03767049..8ca569ec 100644 --- a/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/inventory/InventoryResource.java +++ b/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/inventory/InventoryResource.java @@ -19,6 +19,8 @@ import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; +import javax.ws.rs.Produces; +import javax.ws.rs.Consumes; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import io.openliberty.guides.inventory.model.InventoryList; diff --git a/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/inventory/client/InventoryListJsonBImpl.java b/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/inventory/client/InventoryListJsonBImpl.java new file mode 100644 index 00000000..dd16d38f --- /dev/null +++ b/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/inventory/client/InventoryListJsonBImpl.java @@ -0,0 +1,81 @@ +package io.openliberty.guides.inventory.client; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; +import io.openliberty.guides.inventory.model.InventoryList; + +import javax.json.Json; +import javax.json.JsonObject; +import javax.json.JsonReader; +import javax.json.JsonString; +import javax.json.JsonValue; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.ext.MessageBodyReader; +import javax.ws.rs.ext.MessageBodyWriter; +import javax.ws.rs.ext.Provider; +import javax.ws.rs.Consumes; +import javax.ws.rs.Produces; +import javax.annotation.*; +import javax.json.bind.*; + +@Provider +@Consumes(MediaType.APPLICATION_JSON) +@Produces(MediaType.APPLICATION_JSON) +@Priority(2) +public class InventoryListJsonBImpl implements MessageBodyReader, MessageBodyWriter { + + @Override + public boolean isReadable(Class type, Type genericType, Annotation[] annotations, MediaType mediaType) { + System.out.println("AJM: will read prop data from stream?"); + return true; + } + + @Override + public InventoryList readFrom(Class type, Type genericType, Annotation[] annotations, + MediaType mediaType, MultivaluedMap httpHeaders, InputStream entityStream) + throws IOException, WebApplicationException { + + // JsonReader jr = Json.createReader(entityStream); + Jsonb jsonb = JsonbBuilder.create(); + InventoryList il = jsonb.fromJson(entityStream, InventoryList.class); + System.out.println("AJM: il obj just read in - \n" + il.toString()); + + /* + * JsonObject json = jr.readObject(); + * + * Properties retVal = new Properties(); + * + * json.keySet().forEach(key -> { JsonValue value = json.get(key); if + * (!JsonValue.NULL.equals(value)) { if (value.getValueType() != + * JsonValue.ValueType.STRING) { throw new + * IllegalArgumentException("Non-String JSON prop value found in payload. Sample data is more than this sample can deal with. It's not intended to handle any payload." + * ); } JsonString jstr = (JsonString)value; + * + * retVal.setProperty(key, jstr.getString()); } }); return retVal; + */ + return il; + } + + @Override + public boolean isWriteable(Class type, Type genericType, Annotation[] annotations, MediaType mediaType) { + // TODO Auto-generated method stub + return true; + } + + @Override + public void writeTo(InventoryList t, Class type, Type genericType, Annotation[] annotations, MediaType mediaType, + MultivaluedMap httpHeaders, OutputStream entityStream) + throws IOException, WebApplicationException { + // TODO Auto-generated method stub + System.out.println("AJM: in the write method, will need to write out this -> \n" + t.toString()); + Jsonb jsonb = JsonbBuilder.create(); + String ilstr = jsonb.toJson(t); + System.out.println("AJM: just wrote out this prop obj -> \n" + ilstr); + } + +} diff --git a/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/inventory/client/PropertiesReader.java b/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/inventory/client/PropertiesReader.java new file mode 100644 index 00000000..77bb9dfd --- /dev/null +++ b/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/inventory/client/PropertiesReader.java @@ -0,0 +1,81 @@ +package io.openliberty.guides.inventory.client; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; +import java.util.Properties; + +import javax.json.Json; +import javax.json.JsonObject; +import javax.json.JsonReader; +import javax.json.JsonString; +import javax.json.JsonValue; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.ext.MessageBodyReader; +import javax.ws.rs.ext.MessageBodyWriter; +import javax.ws.rs.ext.Provider; +import javax.ws.rs.Consumes; +import javax.ws.rs.Produces; +import javax.annotation.*; +import javax.json.bind.*; + +@Provider +@Consumes(MediaType.APPLICATION_JSON) +@Produces(MediaType.APPLICATION_JSON) +@Priority(1) +public class PropertiesReader implements MessageBodyReader, MessageBodyWriter { + + @Override + public boolean isReadable(Class type, Type genericType, Annotation[] annotations, MediaType mediaType) { + System.out.println("AJM: will read prop data from stream?"); + return true; + } + + @Override + public Properties readFrom(Class type, Type genericType, Annotation[] annotations, MediaType mediaType, + MultivaluedMap httpHeaders, InputStream entityStream) + throws IOException, WebApplicationException { + + // JsonReader jr = Json.createReader(entityStream); + Jsonb jsonb = JsonbBuilder.create(); + Properties props = jsonb.fromJson(entityStream, Properties.class); + System.out.println("AJM: props obj just read in - \n" + props.toString()); + + /* + * JsonObject json = jr.readObject(); + * + * Properties retVal = new Properties(); + * + * json.keySet().forEach(key -> { JsonValue value = json.get(key); if + * (!JsonValue.NULL.equals(value)) { if (value.getValueType() != + * JsonValue.ValueType.STRING) { throw new + * IllegalArgumentException("Non-String JSON prop value found in payload. Sample data is more than this sample can deal with. It's not intended to handle any payload." + * ); } JsonString jstr = (JsonString)value; + * + * retVal.setProperty(key, jstr.getString()); } }); return retVal; + */ + return props; + } + + @Override + public boolean isWriteable(Class type, Type genericType, Annotation[] annotations, MediaType mediaType) { + // TODO Auto-generated method stub + return true; + } + + @Override + public void writeTo(Properties t, Class type, Type genericType, Annotation[] annotations, MediaType mediaType, + MultivaluedMap httpHeaders, OutputStream entityStream) + throws IOException, WebApplicationException { + // TODO Auto-generated method stub + System.out.println("AJM: in the write method, will need to write out this -> \n" + t.toString()); + Jsonb jsonb = JsonbBuilder.create(); + String propStr = jsonb.toJson(t); + System.out.println("AJM: just wrote out this prop obj -> \n" + propStr); + } + +} diff --git a/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/inventory/client/SystemClient.java b/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/inventory/client/SystemClient.java index 11bfab81..c27f682d 100644 --- a/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/inventory/client/SystemClient.java +++ b/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/inventory/client/SystemClient.java @@ -68,7 +68,8 @@ protected String buildUrl(String protocol, String host, int port, String path) { // Method that creates the client builder protected Builder buildClientBuilder(String urlString) { try { - Client client = ClientBuilder.newClient(); + // Client client = ClientBuilder.newClient(); + Client client = ClientBuilder.newBuilder().register(PropertiesReader.class).build(); Builder builder = client.target(urlString).request(); return builder.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON); } catch (Exception e) { @@ -88,6 +89,7 @@ protected Properties getPropertiesHelper(Builder builder) { } } catch (RuntimeException e) { System.err.println("Runtime exception: " + e.getMessage()); + e.printStackTrace(); } catch (Exception e) { System.err.println("Exception thrown while invoking the request: " + e.getMessage()); } diff --git a/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/system/SystemResource.java b/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/system/SystemResource.java index 2ec7731f..370e68ee 100644 --- a/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/system/SystemResource.java +++ b/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/system/SystemResource.java @@ -20,7 +20,9 @@ // JAX-RS import javax.ws.rs.Path; import javax.ws.rs.Produces; +import javax.ws.rs.Consumes; import javax.ws.rs.core.MediaType; +import javax.ws.rs.ext.Provider; @RequestScoped @Path("/properties") From 4d8184b072cac105655600f2e4f0e8416ae3dda2 Mon Sep 17 00:00:00 2001 From: "Andrew J. Mauer" Date: Mon, 10 Jun 2019 14:03:42 -0400 Subject: [PATCH 5/5] try using resteasy as jax-rs jsonb provider --- .../src/it/test-cdi-2.0/pom.xml | 27 ++++++++++++++----- .../client/InventoryListJsonBImpl.java | 6 ++++- .../inventory/client/PropertiesReader.java | 6 ++++- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/pom.xml b/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/pom.xml index bde573f8..dfee3f6a 100644 --- a/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/pom.xml +++ b/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/pom.xml @@ -116,12 +116,27 @@ 1.0.1 true - - org.glassfish - javax.json - 1.0.4 - true - + + + org.jboss.resteasy + resteasy-json-binding-provider + 4.0.0.Final + + + + org.jboss.resteasy + resteasy-jaxrs + 3.7.0.Final + provided + + + + org.jboss.resteasy + resteasy-context-propagation + 4.0.0.Final + + + diff --git a/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/inventory/client/InventoryListJsonBImpl.java b/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/inventory/client/InventoryListJsonBImpl.java index dd16d38f..6f37bece 100644 --- a/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/inventory/client/InventoryListJsonBImpl.java +++ b/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/inventory/client/InventoryListJsonBImpl.java @@ -22,11 +22,12 @@ import javax.ws.rs.Produces; import javax.annotation.*; import javax.json.bind.*; +import java.io.*; @Provider @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) -@Priority(2) +@Priority(5000) public class InventoryListJsonBImpl implements MessageBodyReader, MessageBodyWriter { @Override @@ -76,6 +77,9 @@ public void writeTo(InventoryList t, Class type, Type genericType, Annotation Jsonb jsonb = JsonbBuilder.create(); String ilstr = jsonb.toJson(t); System.out.println("AJM: just wrote out this prop obj -> \n" + ilstr); + Writer pw = new PrintWriter(entityStream); + pw.write(ilstr); + pw.flush(); } } diff --git a/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/inventory/client/PropertiesReader.java b/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/inventory/client/PropertiesReader.java index 77bb9dfd..bd1d5ed5 100644 --- a/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/inventory/client/PropertiesReader.java +++ b/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/inventory/client/PropertiesReader.java @@ -22,11 +22,12 @@ import javax.ws.rs.Produces; import javax.annotation.*; import javax.json.bind.*; +import java.io.*; @Provider @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) -@Priority(1) +@Priority(5000) public class PropertiesReader implements MessageBodyReader, MessageBodyWriter { @Override @@ -76,6 +77,9 @@ public void writeTo(Properties t, Class type, Type genericType, Annotation[] Jsonb jsonb = JsonbBuilder.create(); String propStr = jsonb.toJson(t); System.out.println("AJM: just wrote out this prop obj -> \n" + propStr); + Writer pw = new PrintWriter(entityStream); + pw.write(propStr); + pw.flush(); } }