org.apache.meecrowave.Meecrowave Java Examples
The following examples show how to use
org.apache.meecrowave.Meecrowave.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ListeningTest.java From openwebbeans-meecrowave with Apache License 2.0 | 6 votes |
@Test public void events() { final Listener listener; final String base; int count = 0; try (final Meecrowave meecrowave = new Meecrowave( new Meecrowave.Builder() .randomHttpPort() .includePackages(ListeningTest.class.getName())).bake()) { count++; listener = CDI.current().select(Listener.class).get(); assertEquals(count, listener.getEvents().size()); base = "http://localhost:" + meecrowave.getConfiguration().getHttpPort(); assertEquals(base, listener.getEvents().iterator().next().getFirstBase()); } count++; assertEquals(count, listener.getEvents().size()); assertEquals(base, listener.getEvents().get(count - 1).getFirstBase()); }
Example #2
Source File: MeecrowaveBus.java From openwebbeans-meecrowave with Apache License 2.0 | 6 votes |
@Inject public MeecrowaveBus(final ServletContext context) { final ClassLoader appLoader = context.getClassLoader(); final Meecrowave meecrowave = Meecrowave.class.cast(context.getAttribute("meecrowave.instance")); final Configuration builder = Configuration.class.cast(context.getAttribute("meecrowave.configuration")); if (meecrowave.getClientBus() == null) { delegate = new ConfigurableBus(); if (builder != null && builder.isJaxrsProviderSetup()) { delegate.initProviders(builder, appLoader); } } else { delegate = meecrowave.getClientBus(); if (builder != null && !builder.isInitializeClientBus() && builder.isJaxrsProviderSetup()) { delegate.initProviders(builder, appLoader); } } setProperty(ClassUnwrapper.class.getName(), this); setExtension(appLoader, ClassLoader.class); // ServletController locks on the classloader otherwise }
Example #3
Source File: MeecrowaveSeContainerInitializer.java From openwebbeans-meecrowave with Apache License 2.0 | 6 votes |
@Override protected SeContainer newContainer(final WebBeansContext context) { final Meecrowave meecrowave = new Meecrowave(builder); if (!services.containsKey(ContextsService.class.getName())) { // forced otherwise we mess up the env with owb-se context.registerService(ContextsService.class, new WebContextsService(context)); } return new OWBContainer(context, meecrowave) { { meecrowave.bake(); } @Override protected void doClose() { meecrowave.close(); } }; }
Example #4
Source File: ApiMockUpdate.java From component-runtime with Apache License 2.0 | 6 votes |
private static void updateMocks(final File apiPath) throws ExecutionException, InterruptedException, UnknownHostException { try (final Meecrowave server = new Meecrowave(new Meecrowave.Builder() { { randomHttpPort(); setScanningExcludes( "classworlds,container,freemarker,zipkin,backport,commons,component-form,component-runtime-junit," + "component-tools,crawler,doxia,exec,jsch,jcl,org.osgi,talend-component,component-server-vault-proxy"); setScanningPackageExcludes( "org.talend.sdk.component.proxy,org.talend.sdk.component.runtime.server.vault,org.talend.sdk.component.server.vault.proxy"); } }).bake()) { captureMocks(format("http://%s:%d", InetAddress.getLocalHost().getHostName(), server.getConfiguration().getHttpPort()), apiPath); } log.warn("[updateMocks] finished."); }
Example #5
Source File: OWBAutoSetup.java From openwebbeans-meecrowave with Apache License 2.0 | 6 votes |
private void customizeContext(final WebBeansContext instance) { final BeanManagerImpl beanManager = instance.getBeanManagerImpl(); beanManager.addInternalBean(newBean(instance, configurator -> configurator.beanClass(Meecrowave.Builder.class) .scope(ApplicationScoped.class) .qualifiers(DefaultLiteral.INSTANCE) .types(Configuration.class, Meecrowave.Builder.class, Object.class) .createWith(cc -> meecrowave.getConfiguration()))); beanManager.addInternalBean(newBean(instance, configurator -> configurator.beanClass(Meecrowave.class) .scope(ApplicationScoped.class) .qualifiers(DefaultLiteral.INSTANCE) .types(Meecrowave.class, AutoCloseable.class, Object.class) .createWith(cc -> meecrowave))); }
Example #6
Source File: OWBAutoSetup.java From openwebbeans-meecrowave with Apache License 2.0 | 6 votes |
@Override public void onStartup(final Set<Class<?>> c, final ServletContext ctx) { final Configuration builder = Configuration.class.cast(ctx.getAttribute("meecrowave.configuration")); final Meecrowave instance = Meecrowave.class.cast(ctx.getAttribute("meecrowave.instance")); if (builder.isCdiConversation()) { try { final Class<? extends Filter> clazz = (Class<? extends Filter>) OWBAutoSetup.class.getClassLoader() .loadClass("org.apache.webbeans.web.context.WebConversationFilter"); final FilterRegistration.Dynamic filter = ctx.addFilter("owb-conversation", clazz); filter.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), false, "/*"); } catch (final Exception e) { // no-op } } // eager boot to let injections work in listeners final EagerBootListener bootListener = new EagerBootListener(instance); bootListener.doContextInitialized(new ServletContextEvent(ctx)); ctx.addListener(bootListener); }
Example #7
Source File: JohnzonBufferTest.java From openwebbeans-meecrowave with Apache License 2.0 | 6 votes |
@Test public void test() { DebugJohnzonBufferStrategy.resetCounter(); try (final Meecrowave meecrowave = new Meecrowave(new Meecrowave.Builder() .randomHttpPort() .withJsonpBufferStrategy(DebugJohnzonBufferStrategy.class.getName()) .includePackages("org.superbiz.app.TestJsonEndpoint")).bake()) { final Client client = ClientBuilder.newClient(); try { String jsonResponse = client .target("http://localhost:" + meecrowave.getConfiguration().getHttpPort() + "/testjsonendpoint/book") .request(MediaType.APPLICATION_JSON) .get(String.class); assertEquals("{\"isbn\":\"dummyisbn\"}", jsonResponse); assertEquals(3, DebugJohnzonBufferStrategy.getCounter()); // reader fact -> parser fact (2 buffers) + writer -> generator (1 buffer) } finally { client.close(); } } }
Example #8
Source File: DispatchEndpointTest.java From openwebbeans-meecrowave with Apache License 2.0 | 6 votes |
@Test public void dispatch() { final Client client = ClientBuilder.newClient(); try (final Meecrowave container = new Meecrowave(new Meecrowave.Builder() .randomHttpPort() .includePackages("org.apache.meecrowave.it.jsp.dispatch")) .bake()) { final String html = client.target("http://localhost:" + container.getConfiguration().getHttpPort()) .path("dispatch") .request(TEXT_HTML_TYPE) .get(String.class); assertEquals("\n\n" + "<!DOCTYPE html>\n" + "<html>\n<head>\n<meta charset=\"utf-8\">\n" + "<title>Meecrowave :: IT :: Dispatch</title>\n" + "</head>\n<body>\n" + " <h2>Endpoint</h2>\n" + "</body>\n</html>\n", html); } finally { client.close(); } }
Example #9
Source File: ServiceTest.java From openwebbeans-meecrowave with Apache License 2.0 | 6 votes |
@Test public void bval() { try (final Meecrowave container = new Meecrowave(new Meecrowave.Builder() .includePackages(Service.class.getPackage().getName()) .randomHttpPort()) .bake()) { final String uri = "http://localhost:" + container.getConfiguration().getHttpPort() + "/test"; final Client client = ClientBuilder.newClient(); try { assertEquals( "{\"value\":\"ok\"}", client.target(uri) .queryParam("val", "ok") .request(APPLICATION_JSON_TYPE) .get(String.class)); assertEquals( Response.Status.BAD_REQUEST.getStatusCode(), client.target(uri) .request(APPLICATION_JSON_TYPE) .get() .getStatus()); } finally { client.close(); } } }
Example #10
Source File: RunWithoutCxfTest.java From openwebbeans-meecrowave with Apache License 2.0 | 6 votes |
@Test public void runServlet() throws IOException { try (final Meecrowave container = new Meecrowave(new Meecrowave.Builder() {{ addServletContextInitializer((c, ctx) -> ctx.addServlet("test", new HttpServlet() { @Override protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws IOException { resp.getWriter() .write("servlet :)"); } }).addMapping("/test")); }}.randomHttpPort()).bake()) { final String url = "http://localhost:" + container.getConfiguration().getHttpPort() + "/test"; final StringWriter output = new StringWriter(); try (final BufferedReader stream = new BufferedReader(new InputStreamReader(new URL(url).openStream()))) { output.write(stream.readLine()); } assertEquals("servlet :)", output.toString().trim()); } }
Example #11
Source File: MeecrowaveRunMojo.java From openwebbeans-meecrowave with Apache License 2.0 | 6 votes |
private void reload(final Meecrowave meecrowave, final String context, final Supplier<ClassLoader> loaderSupplier, final ClassLoader mojoLoader) { if (reloadGoals != null && !reloadGoals.isEmpty()) { final List<String> goals = session.getGoals(); session.getRequest().setGoals(reloadGoals); try { lifecycleStarter.execute(session); } finally { session.getRequest().setGoals(goals); } } final Context ctx = Context.class.cast(meecrowave.getTomcat().getHost().findChild(context)); if (useClasspathDeployment) { final Thread thread = Thread.currentThread(); destroyTcclIfNeeded(thread, mojoLoader); thread.setContextClassLoader(loaderSupplier.get()); ctx.setLoader(new ProvidedLoader(thread.getContextClassLoader(), meecrowave.getConfiguration().isTomcatWrapLoader())); } ctx.reload(); }
Example #12
Source File: InjectRule.java From openwebbeans-meecrowave with Apache License 2.0 | 6 votes |
@Override public Statement apply(final Statement base, final Description description) { return new Statement() { @Override public void evaluate() throws Throwable { CreationalContext<?> creationalContext = null; try { creationalContext = Injector.inject(instance); Injector.injectConfig(CDI.current().select(Meecrowave.Builder.class).get(), instance); base.evaluate(); } finally { if (creationalContext != null) { creationalContext.release(); } } } }; }
Example #13
Source File: Injector.java From openwebbeans-meecrowave with Apache License 2.0 | 6 votes |
public static void injectConfig(final Meecrowave.Builder config, final Object test) { if (test == null) { return; } final Class<?> aClass = test.getClass(); Stream.of(aClass.getDeclaredFields()) .filter(f -> f.isAnnotationPresent(ConfigurationInject.class)) .forEach(f -> { if (!f.isAccessible()) { f.setAccessible(true); } try { f.set(test, config); } catch (final IllegalAccessException e) { throw new IllegalStateException(e); } }); }
Example #14
Source File: Cli.java From openwebbeans-meecrowave with Apache License 2.0 | 5 votes |
public static Meecrowave.Builder create(final String[] args) { final ParsedCommand command = new ParsedCommand(args).invoke(); if (command.isFailed()) { return null; } return command.getBuilder(); }
Example #15
Source File: MeecrowaveRunMojo.java From openwebbeans-meecrowave with Apache License 2.0 | 5 votes |
private void deploy(final Meecrowave meecrowave, final Meecrowave.DeploymentMeta deploymentMeta) { if (useClasspathDeployment) { meecrowave.deployClasspath(deploymentMeta); } else { meecrowave.deployWebapp(deploymentMeta); } }
Example #16
Source File: MeecrowaveSeContainerInitializerTest.java From openwebbeans-meecrowave with Apache License 2.0 | 5 votes |
@Test public void run() { try (final SeContainer container = SeContainerInitializer.newInstance() .addProperty("httpPort", new Meecrowave.Builder().randomHttpPort().getHttpPort()) .disableDiscovery() .addBeanClasses(Configured.class) .initialize()) { final Client client = ClientBuilder.newClient(); assertNotNull(container.select(Meecrowave.class).get()); assertEquals("configured", client .target(String.format("http://localhost:%d/configured", container.select(Meecrowave.Builder.class).get().getHttpPort())) .request(TEXT_PLAIN_TYPE) .get(String.class)); } }
Example #17
Source File: MeecrowaveExtension.java From openwebbeans-meecrowave with Apache License 2.0 | 5 votes |
@Override public void afterAll(final ExtensionContext context) { final ExtensionContext.Store store = context.getStore(NAMESPACE); ofNullable(store.get(LifecyleState.class, LifecyleState.class)) .ifPresent(s -> s.afterLastTest(context)); if (isPerClass(context)) { store.get(Meecrowave.class, Meecrowave.class).close(); } }
Example #18
Source File: MeecrowaveExtension.java From openwebbeans-meecrowave with Apache License 2.0 | 5 votes |
private void doInject(final ExtensionContext context) { scopes.beforeEach(context); final ExtensionContext.Store store = context.getStore(NAMESPACE); store.put(CreationalContext.class, Injector.inject(context.getTestInstance().orElse(null))); Injector.injectConfig( store.get(Meecrowave.Builder.class, Meecrowave.Builder.class), context.getTestInstance().orElse(null)); }
Example #19
Source File: Cli.java From openwebbeans-meecrowave with Apache License 2.0 | 5 votes |
private static Meecrowave.Builder buildConfig(final CommandLine line, final List<Field> fields, final Map<Object, List<Field>> propertiesOptions) { final Meecrowave.Builder config = new Meecrowave.Builder(); bind(config, line, fields, config); propertiesOptions.forEach((o, f) -> { bind(config, line, f, o); config.setExtension(o.getClass(), o); }); return config; }
Example #20
Source File: MeecrowaveRule.java From openwebbeans-meecrowave with Apache License 2.0 | 5 votes |
@Override protected AutoCloseable onStart() { final Meecrowave meecrowave = new Meecrowave(configuration); meecrowave.start(); meecrowave.deployClasspath(new Meecrowave.DeploymentMeta(context, docBase, customizer)); return meecrowave; }
Example #21
Source File: Cli.java From openwebbeans-meecrowave with Apache License 2.0 | 5 votes |
public void run() { final ParsedCommand parsedCommand = new ParsedCommand(args).invoke(); if (parsedCommand.isFailed()) { return; } final Meecrowave.Builder builder = parsedCommand.getBuilder(); final CommandLine line = parsedCommand.getLine(); try (final Meecrowave meecrowave = new Meecrowave(builder)) { synchronized (this) { if (closed) { return; } this.instance = meecrowave; } final String ctx = line.getOptionValue("context", ""); final String fixedCtx = !ctx.isEmpty() && !ctx.startsWith("/") ? '/' + ctx : ctx; final String war = line.getOptionValue("webapp"); meecrowave.start(); if (war == null) { meecrowave.deployClasspath(new Meecrowave.DeploymentMeta( ctx, ofNullable(line.getOptionValue("docbase")).map(File::new).orElseGet(() -> Stream.of("base", "home") .map(it -> System.getProperty("meecrowave." + it)) .filter(Objects::nonNull) .map(it -> new File(it, "docBase")) .filter(File::isDirectory) .findFirst() .orElse(null)), null)); } else { meecrowave.deployWebapp(fixedCtx, new File(war)); } doWait(meecrowave, line); } }
Example #22
Source File: Server.java From tutorials with MIT License | 5 votes |
public static void main(String[] args) { final Meecrowave.Builder builder = new Meecrowave.Builder(); builder.setScanningPackageIncludes("com.baeldung.meecrowave"); builder.setJaxrsMapping("/api/*"); builder.setJsonpPrettify(true); try (Meecrowave meecrowave = new Meecrowave(builder)) { meecrowave.bake().await(); } }
Example #23
Source File: GenerateCertificateAndActivateHttpsTest.java From component-runtime with Apache License 2.0 | 5 votes |
private void assertCert(final Meecrowave.Builder builder) throws Exception { final KeyStore keyStore = KeyStore.getInstance(builder.getKeystoreType()); try (final InputStream inputStream = new FileInputStream(builder.getKeystoreFile())) { keyStore.load(inputStream, builder.getKeystorePass().toCharArray()); } final Key key = keyStore.getKey(builder.getKeyAlias(), builder.getKeystorePass().toCharArray()); assertTrue(PrivateKey.class.isInstance(key)); final Certificate certificate = keyStore.getCertificate(builder.getKeyAlias()); assertTrue(X509Certificate.class.isInstance(certificate)); final Certificate[] chain = keyStore.getCertificateChain(builder.getKeyAlias()); assertEquals(1, chain.length); assertEquals(certificate, chain[0]); }
Example #24
Source File: GenerateCertificateAndActivateHttpsTest.java From component-runtime with Apache License 2.0 | 5 votes |
@Test void generate() throws Exception { final File cert = new File( "target/test/GenerateCertificateAndActivateHttpsTest/cert_" + UUID.randomUUID().toString() + ".p12"); final Map<String, String> systemPropsToSet = new HashMap<>(); systemPropsToSet.put("talend.component.server.ssl.active", "true"); systemPropsToSet.put("talend.component.server.ssl.keystore.location", cert.getPath()); systemPropsToSet.put("talend.component.server.ssl.port", "1234"); // ensure we don't init there the repo otherwise next tests will be broken (@MonoMeecrowave) systemPropsToSet.put("org.talend.sdk.component.server.test.InitTestInfra.skip", "true"); final Collection<Runnable> reset = systemPropsToSet.entrySet().stream().map(it -> { final String property = System.getProperty(it.getKey()); System.setProperty(it.getKey(), it.getValue()); if (property == null) { return (Runnable) () -> System.clearProperty(it.getKey()); } return (Runnable) () -> System.setProperty(it.getKey(), property); }).collect(toList()); try { final Meecrowave.Builder builder = new Meecrowave.Builder(); assertTrue(cert.exists()); assertTrue(builder.isSsl()); assertEquals(1234, builder.getHttpsPort()); assertEquals("talend", builder.getKeyAlias()); assertEquals("changeit", builder.getKeystorePass()); assertEquals("PKCS12", builder.getKeystoreType()); assertEquals(cert.getAbsolutePath(), builder.getKeystoreFile()); assertCert(builder); } finally { reset.forEach(Runnable::run); } }
Example #25
Source File: EnhancedCli.java From component-runtime with Apache License 2.0 | 5 votes |
@Override public void run() { try { try (final Meecrowave meecrowave = new Meecrowave(create(args)) { @Override protected Connector createConnector() { return new Connector(CustomPefixHttp11NioProtocol.class.getName()); } }) { this.instance = meecrowave; meecrowave.start(); meecrowave.deployClasspath(new Meecrowave.DeploymentMeta("", null, stdCtx -> { stdCtx.setResources(new StandardRoot() { @Override protected void registerURLStreamHandlerFactory() { // no-op: not supported into OSGi since there is already one and it must set a // single time } }); stdCtx.addServletContainerInitializer(new WsSci(), null); })); doWait(meecrowave, null); } } catch (final Exception e) { throw new IllegalStateException(e); } }
Example #26
Source File: Configuration.java From openwebbeans-meecrowave with Apache License 2.0 | 5 votes |
public Configuration() { // load defaults extensions.put(Meecrowave.ValueTransformers.class, new Meecrowave.ValueTransformers()); StreamSupport.stream(ServiceLoader.load(Meecrowave.ConfigurationCustomizer.class).spliterator(), false) .sorted(Priotities::sortByPriority) .forEach(c -> c.accept(this)); loadFrom(meecrowaveProperties); }
Example #27
Source File: TlsVirtualHostPropertiesTest.java From openwebbeans-meecrowave with Apache License 2.0 | 5 votes |
@Test public void run() throws IOException { try (final Meecrowave CONTAINER = new Meecrowave(new Builder() {{ randomHttpsPort(); setSkipHttp(true); includePackages("org.apache.meecrowave.tests.ssl"); setSsl(true); setDefaultSSLHostConfigName("localhost"); setTomcatNoJmx(false); setProperties(p); }}).bake()) { final String confPath = CONTAINER.getBase().getCanonicalPath() + "/conf/"; SSLHostConfig[] sslHostConfigs = CONTAINER.getTomcat().getService().findConnectors()[0].findSslHostConfigs(); assertEquals(3, sslHostConfigs.length); assertTrue(isFilesSame(confPath + keyStorePath1, sslHostConfigs[0].getCertificateKeystoreFile())); assertEquals("JKS", sslHostConfigs[0].getCertificateKeystoreType()); assertEquals("meecrowave", sslHostConfigs[0].getCertificateKeystorePassword()); assertEquals("meecrowave", sslHostConfigs[0].getCertificateKeyAlias()); assertEquals("localhost", sslHostConfigs[0].getHostName()); assertTrue(isFilesSame(confPath + "meecrowave_trust.jks", sslHostConfigs[0].getTruststoreFile())); assertEquals("meecrowave", sslHostConfigs[0].getTruststorePassword()); assertTrue(isFilesSame(confPath + keyStorePath2, sslHostConfigs[1].getCertificateKeystoreFile())); assertEquals("JKS", sslHostConfigs[1].getCertificateKeystoreType()); assertEquals("meecrowave", sslHostConfigs[1].getCertificateKeystorePassword()); assertEquals("meecrowave", sslHostConfigs[1].getCertificateKeyAlias()); assertEquals("meecrowave-localhost", sslHostConfigs[1].getHostName()); assertEquals(2, sslHostConfigs[1].getProtocols().size()); assertEquals("meecrowave.apache.org", sslHostConfigs[2].getHostName()); assertTrue(isFilesSame(confPath + "meecrowave.key.pem", sslHostConfigs[2].getCertificateKeyFile())); assertTrue(isFilesSame(confPath + "meecrowave.cert.pem", sslHostConfigs[2].getCertificateFile())); assertTrue(isFilesSame(confPath + "ca-chain.cert.pem", sslHostConfigs[2].getCertificateChainFile())); assertEquals("TLSv1.2", sslHostConfigs[2].getProtocols().toArray()[0]); assertEquals("Hello", TestSetup.callJaxrsService(CONTAINER.getConfiguration().getHttpsPort())); } }
Example #28
Source File: ComponentConfigurationLoader.java From component-runtime with Apache License 2.0 | 5 votes |
void doInit(@Observes final AfterDeploymentValidation afterDeploymentValidation, final Config config, final Meecrowave.Builder builder) { StreamSupport .stream(config.getConfigSources().spliterator(), false) .filter(ComponentConfigurationLoader.class::isInstance) .map(ComponentConfigurationLoader.class::cast) .forEach(it -> it.doInit(builder)); }
Example #29
Source File: MonoMeecrowave.java From openwebbeans-meecrowave with Apache License 2.0 | 4 votes |
@Override public Meecrowave.Builder getConfiguration() { return BASE.getConfiguration(); }
Example #30
Source File: ClientProducer.java From component-runtime with Apache License 2.0 | 4 votes |
@Produces @ApplicationScoped public WebTarget webTarget(final Client client, final Meecrowave.Builder config) { return client.target(String.format("http://localhost:%d/api/v1", config.getHttpPort())); }