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.

Maintainability or Deletion over Upgrade -- airhacks.fm podcast

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

The #69 airhacks.fm episode with Robert Brem (@bremrobert) about:
"the joy of maintaining dependencies and rethinking Jakarta EE"
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.

JAX-RS: A JSON-B Configuration per @ApplicationPath

The serialization / deserialization behaviour of the JsonbBuilder from the Jakarta EE JSON-B API can be configured with various strategies residing in the javax.json.bind.config package.

In JAX-RS you can statically configure JSON-B with ContextResolver for all JAX-RS resources:


import javax.ws.rs.ext.ContextResolver;
import javax.ws.rs.ext.Provider;    
@Provider
public class JSONConfigurator implements ContextResolver {

    @Override
    public Jsonb getContext(Class type) {
        JsonbConfig config = new JsonbConfig().
                withPropertyNamingStrategy(PropertyNamingStrategy.UPPER_CAMEL_CASE);
        return JsonbBuilder.newBuilder().
                withConfig(config).
                build();
    }
}

Also, a ContextResolver instance can be also registered programmaticaly per javax.ws.rs.core.Application implementation:


@ApplicationPath("secondapi")
public class SecondJAXRConfiguration extends Application {

    @Override
    public Set<Class<?>> getClasses() {
        Set<Class<?>> resources = new HashSet<>();
        resources.add(SecondPing.class);
        return resources;
    }

    @Override
    public Set<Object> getSingletons() {
        Set<Object> singletons = new HashSet<>();
        ContextResolver resolver = getJSONBConfiguration();
        singletons.add(resolver);
        return singletons;
    }

    ContextResolver getJSONBConfiguration() {
        return new ContextResolver<Jsonb>() {
            @Override
            public Jsonb getContext(Class type) {
                JsonbConfig config = new JsonbConfig().
                        withPropertyNamingStrategy(PropertyNamingStrategy.UPPER_CAMEL_CASE);
                return JsonbBuilder.newBuilder().
                        withConfig(config).
                        build();
            }
        };
    }

Another JAX-RS application inside the same ThinWAR could expose the resources with different JSON-B configuration, or just rely on the defaults:


@ApplicationPath("firstapi")
public class FirstJAXRSConfiguration extends Application {

    @Override
    public Set<Class<?>> getClasses() {
        Set<Class<?>> resources = new HashSet<>();
        resources.add(FirstPing.class);
        return resources;
    }
}

Now the FirstPing resource:


@Path("ping")
public class FirstPing {
    @GET
    public Ping ping() {
        return new Ping("first", 1);
    }
}    

...exposes the Ping entity:


public class Ping {

    public String name;
    public long duration;

    public Ping(String name, long duration) {
        this.name = name;
        this.duration = duration;
    }
}

...using the default JSON-B configuration as: {"duration":1,"name":"first"} (with: curl http://localhost:8080/jaxrs-multiple-uris/firstapi/ping)

The SecondPing:


@Path("ping")
public class SecondPing {
    @GET
    public Ping ping() {
        return new Ping("second", 2);
    }
}

...generates the following output: {"Duration":2,"Name":"second"} (with: curl http://localhost:8080/jaxrs-multiple-uris/secondapi/ping)

The sample was created with javaee8-essentials-archetype, the 7kB ThinWAR was built and deployed with: wad.sh in 2.5s to Payara 5.193.

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