Using MicroProfile Config to Render Web Components on the Server with JSP

To inject dynamic content to *.js files on the server side, the JSP's (Jakarta Server Pages) file extension has to be configured in web.xml:


<?xml version="1.0" encoding="UTF-8"?>
<web-app>
    <jsp-config>
        <jsp-property-group>
            <url-pattern>*.js</url-pattern>
            <page-encoding>UTF-8</page-encoding>
            <default-content-type>text/javascript</default-content-type>
        </jsp-property-group>
    </jsp-config>
</web-app>

Now a String array exposed from a CDI bean:


import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.inject.Named;
import org.eclipse.microprofile.config.inject.ConfigProperty;

@Named
@ApplicationScoped
public class Developer {

    @Inject
    @ConfigProperty(name = "languages")
    String languages;

    public String getLanguages() {
        return languages;
    }
}

...and configured in microprofile-config.properties:


languages=jsp,javascript,java    

...can be directly used to generate e.g. Web Components / Custom Elements:


<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

class Languages extends HTMLElement{

        connectedCallback() {
        this.innerHTML = `
            <select>
                <c:forEach items="${developer.languages}" var="language">
                    <option>${language}</option>
                </c:forEach>
            </select>`;

    }
}
customElements.define('a-languages',Languages);    

See it in action and from scratch:

The 4kB ThinWAR project was created with Jakarta EE Essentials Archetype and deployed with: wad.sh in 2.4s


NEW airhacks.com workshops: MicroProfile with Quarkus and Micro Frontends with Web Components at MUC airport

airhacks.fm the podcast:

Stay in touch: airhacks.news.

Productivity with Plain Vanilla Web Components--airhacks.fm podcast

Subscribe to airhacks.fm podcast via: spotify| iTunes| RSS

The #71 airhacks.fm episode with Robert Brem (@bremrobert) about:
"replacing dependencies and frameworks with web standards and Web Components to increase productivity"
is available for download.


NEW airhacks.com workshops: MicroProfile with Quarkus and Micro Frontends with Web Components at MUC airport

airhacks.fm the podcast:

Stay in touch: airhacks.news.

Injecting List of Strings with MicroProfile Config

A comma-separated String in microprofile-config.properties:


messages=hello,bye

...can be injected as a List of Strings (other types are injectable as well):

import java.util.List;
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import org.eclipse.microprofile.config.inject.ConfigProperty;

@Path("messages")
public class MessagesResource {

    @Inject
    @ConfigProperty(name = "messages")
    List<String> messages;    

    @GET
    public List<String> messages() {
        return this.messages;
    }
}

The following command: curl -i localhost:8080/[THIN_WAR_NAME]/resources/messages prints: ["hello","bye"]

The 4kB ThinWAR project was created with Jakarta EE Essentials Archetype and deployed with: wad.sh in 1.9s


NEW airhacks.com workshops: MicroProfile with Quarkus and Micro Frontends with Web Components at MUC airport

airhacks.fm the podcast:

Stay in touch: airhacks.news.

Using Jakarta Server Pages (JSP)s For Web Component Generation / Configuration

JavaScript can be pre-generated on the backend and delivered as static content with JSPs. Jakarta Server Pages (JSP) are used in this screencast to configure a stage-dependent URI in a Web Component / Custom Element defined with MicroProfile Config and exposed via CDI:

The ThinWAR project was created with Jakarta EE Essentials Archetype, the 216kB ThinWAR (JS dependencies included) was built and deployed to Payara 5.193 #badassfish with: wad.sh in 3.2s


NEW airhacks.com workshops: MicroProfile with Quarkus and Micro Frontends with Web Components at MUC airport

airhacks.fm the podcast:

Stay in touch: airhacks.news.

Memory Consumption: WildFly Full ThinWAR vs. Quarkus SkimmedJAR

Comparing the memory consumption of WildFly 18.0.1.Final (Java EE Full & Web Distribution) and Quarkus by deploying identical microprofile application to both runtimes:

The ThinWAR project was created with Jakarta EE Essentials Archetype, the 6kB ThinWAR was built and deployed with: wad.sh in 3.1s.

The Quarkus Runner 20.3kB "SkimmedJAR" was built in 4.3s from scratch. The file size of the native executable was 32 MB, the built took 53.7s.


NEW airhacks.com workshops: MicroProfile with Quarkus and Micro Frontends with Web Components at MUC airport

airhacks.fm the podcast:

Stay in touch: airhacks.news.

CSRF, XSS, JWT, Reactive Databases, TX and WebSockets, JSON-B, OpenShift -- the 70th airhacks.tv

The 70th airhacks.tv episode covering:

CSRF, XSS, JWT, Reactive Databases or R2DBC, transactions with WebSockets, Java 9 modules vs Microservices, JSONB Configuration on JAX-RS, openshift in production, mixing microservice runtimes, GraalVM importance in 2020: wad.sh vs IDE deployments, standard headers for HTTP warnings

Any questions left? Ask now: https://gist.github.com/AdamBien/76c4af6d6e59d2632bb265fee112bb02 and get the answers at the next airhacks.tv.

See you at Web, MicroProfile and Java EE Workshops at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting. Is Munich's airport too far? Learn from home: airhacks.io.


NEW airhacks.com workshops: MicroProfile with Quarkus and Micro Frontends with Web Components at MUC airport

airhacks.fm the podcast:

Stay in touch: airhacks.news.

JavaFX Strikes Back -- airhacks.fm podcast

Subscribe to airhacks.fm podcast via: spotify| iTunes| RSS

The #70 airhacks.fm episode with Johan Vos (@johanvos) about:
Advantages of JavaFX, the JavaFX ecosystem, OpenJFX, GraalVM and Java on mobile
is available for download.

See you at Web, MicroProfile and Java EE Workshops at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting. Is Munich's airport too far? Learn from home: airhacks.io.


NEW airhacks.com workshops: MicroProfile with Quarkus and Micro Frontends with Web Components at MUC airport

airhacks.fm the podcast:

Stay in touch: airhacks.news.

Quarkus: Configuring Context and Resource Paths

A Quarkus application exposes the JAX-RS resources directly from the "root":

The HelloResource:


@Path("/hello")
public class HelloResource {

    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String hello() {
        return "hello";
    }
}    

is available from: http://localhost:8080/hello

By adding the "servlet" extension with: mvn quarkus:add-extension -Dextension="servlet" the JAX-RS as well as the context path can be configured in src/main/resources/application.properties

The following configuration:


quarkus.servlet.context-path=/quark
quarkus.resteasy.path=/resources    

exposes the HelloResource as: http://localhost:8080/quark/resources/hello

See you at Web, MicroProfile and Java EE Workshops at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting. Is Munich's airport too far? Learn from home: airhacks.io.


NEW airhacks.com workshops: MicroProfile with Quarkus and Micro Frontends with Web Components at MUC airport

airhacks.fm the podcast:

Stay in touch: airhacks.news.

Online Workshops
realworldpatterns.com
...the last 150 posts
...the last 10 comments
License