HttpInvokerMicroserviceProvider implements MicroserviceProvider, HttpInvokerSilverService { @Override public Context getContext() { return context; }  @Override void initialize(final Context context); @Override Context getContext(); @Override void run();  }
@Test public void testHttpInvoker() throws Exception { final BootUtil bootUtil = new BootUtil(); final Map<String, Object> platformProperties = bootUtil.getContext().getProperties(); final Thread platform = bootUtil.getMicroservicePlatform(this.getClass().getPackage().getName(), HttpServerMicroserviceProvider.class.getPackage().getName(), CdiMicroserviceProvider.class.getPackage().getName()); platform.start(); while (httpInvokerSilverService == null) { httpInvokerSilverService = (HttpInvokerSilverService) bootUtil.getContext().getProvider(HttpInvokerSilverService.class); Thread.sleep(200); } while (bootUtil.getContext().getProperties().get(CdiSilverService.BEAN_MANAGER) == null) { Thread.sleep(200); } String urlBase = "http: Assert.assertTrue(Utils.waitForHttp(urlBase, 204)); HttpURLConnection con = (HttpURLConnection) new URL(urlBase + "query").openConnection(); con.setRequestMethod("POST"); con.setDoInput(true); con.setDoOutput(true); con.connect(); final MicroserviceMetaData metaData = new MicroserviceMetaData("sumService", SumService.class, Collections.emptySet(), Collections.emptySet(), null, null); JsonWriter jsonWriter = new JsonWriter(con.getOutputStream()); jsonWriter.write(metaData); Assert.assertEquals(con.getResponseMessage(), "OK"); JsonReader jsonReader = new JsonReader(con.getInputStream()); final List<HttpServiceHandle> handles = (List<HttpServiceHandle>) jsonReader.readObject(); Assert.assertEquals(handles.size(), 1); con.disconnect(); final HttpServiceHandle handle = handles.get(0); Utils.waitForCDIProvider(bootUtil.getContext()); long l = (Long) handle.invoke(bootUtil.getContext(), "sum", new Class[] { short.class, int.class }, new Object[] { (short) 3, 4 }); Assert.assertEquals(l, 7L); con = (HttpURLConnection) new URL(urlBase + "invoke").openConnection(); con.setRequestMethod("POST"); con.setDoInput(true); con.setDoOutput(true); con.connect(); Invocation invocation = new Invocation(handles.get(0).getHandle(), "sum", new Class[] { short.class, int.class }, new Object[] { (short) 3, 4 }); jsonWriter = new JsonWriter(con.getOutputStream()); jsonWriter.write(invocation); jsonReader = new JsonReader(con.getInputStream()); Object response = jsonReader.readObject(); Assert.assertEquals(response, 7L); con.disconnect(); con = (HttpURLConnection) new URL(urlBase + "invoke").openConnection(); con.setRequestMethod("POST"); con.setDoInput(true); con.setDoOutput(true); con.connect(); invocation = new Invocation(handles.get(0).getHandle(), "allTypes", new Class[] { byte.class, short.class, int.class, long.class, float.class, double.class, boolean.class, char.class }, new Object[] { Byte.MAX_VALUE, Short.MAX_VALUE, Integer.MAX_VALUE, Long.MAX_VALUE, Float.MIN_VALUE, Double.MIN_VALUE, true, 'c' }); jsonWriter = new JsonWriter(con.getOutputStream()); jsonWriter.write(invocation); jsonReader = new JsonReader(con.getInputStream()); response = jsonReader.readObject(); Assert.assertEquals(response, "9.223372036854776E18truec"); con.disconnect(); con = (HttpURLConnection) new URL(urlBase + "invoke").openConnection(); con.setRequestMethod("POST"); con.setDoInput(true); con.setDoOutput(true); con.connect(); invocation = new Invocation(handles.get(0).getHandle(), "allTypes2", new Class[] { Byte.class, Short.class, Integer.class, Long.class, Float.class, Double.class, Boolean.class, Character.class }, new Object[] { Byte.MAX_VALUE, Short.MAX_VALUE, Integer.MAX_VALUE, Long.MAX_VALUE, Float.MIN_VALUE, Double.MIN_VALUE, true, 'c' }); jsonWriter = new JsonWriter(con.getOutputStream()); jsonWriter.write(invocation); jsonReader = new JsonReader(con.getInputStream()); response = jsonReader.readObject(); Assert.assertEquals(response, "9.223372036854776E18truec"); con.disconnect(); con = (HttpURLConnection) new URL(urlBase + "invoke").openConnection(); con.setRequestMethod("POST"); con.setDoInput(true); con.setDoOutput(true); con.connect(); MagicBox box = new MagicBox(); invocation = new Invocation(handles.get(0).getHandle(), "doMagic", new Class[] { MagicBox.class }, new Object[] { box }); jsonWriter = new JsonWriter(con.getOutputStream()); jsonWriter.write(invocation); jsonReader = new JsonReader(con.getInputStream()); response = jsonReader.readObject(); Assert.assertTrue(response instanceof MagicBox); Assert.assertEquals((short) ((MagicBox) response).getS(), Short.MAX_VALUE); Assert.assertEquals((float) ((MagicBox) response).getF(), Float.MAX_VALUE); con.disconnect(); platform.interrupt(); platform.join(); }