Skip to content

Commit

Permalink
GH5290 - Thin T3 client with jakartified HK2
Browse files Browse the repository at this point in the history
  • Loading branch information
danielkec committed Nov 1, 2022
1 parent 6cd679f commit 1bc94ce
Show file tree
Hide file tree
Showing 21 changed files with 845 additions and 0 deletions.
36 changes: 36 additions & 0 deletions mp/gh5290/buildAndRunWeblogic.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash
cd ./weblogic

# Attempt Oracle container registry login.
# You need to accept the licence agreement for Weblogic Server at https://container-registry.oracle.com/
docker login container-registry.oracle.com

docker build -t wls-admin .

docker run --rm -d \
-p 7001:7001 \
-p 9002:9002 \
--name wls-admin \
--hostname wls-admin \
wls-admin

printf "Waiting for WLS to start ."
while true;
do
if docker logs wls-admin | grep -q "Server state changed to RUNNING"; then
break;
fi
printf "."
sleep 5
done
printf " [READY]\n"

echo Deploying example JMS queues
docker exec wls-admin \
/bin/bash \
/u01/oracle/wlserver/common/bin/wlst.sh \
/u01/oracle/setupTestJMSQueue.py;

echo Example JMS queues deployed!
echo Console avaiable at http://localhost:7001/console with admin/Welcome1
echo 'Stop Weblogic server with "docker stop wls-admin"'
11 changes: 11 additions & 0 deletions mp/gh5290/extractThinClientLib.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copy wlthint3client.jar from docker container
docker cp wls-admin:/u01/oracle/wlserver/server/lib/wlthint3client.jar ./target/wlthint3client.jar

# Install wlthint3client.jar to local msv repo
mvn install:install-file \
-Dfile=./target/wlthint3client.jar \
-DgeneratePom=true \
-DgroupId=custom.com.oracle \
-DartifactId=wlthint3client \
-Dversion=12.2.1.4 \
-Dpackaging=jarbash
83 changes: 83 additions & 0 deletions mp/gh5290/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.helidon.applications</groupId>
<artifactId>helidon-mp</artifactId>
<version>3.0.1</version>
<relativePath/>
</parent>
<groupId>me.kec-helidon</groupId>
<artifactId>helidon-wls-jms-demo</artifactId>
<version>1.0-SNAPSHOT</version>
<name>helidon-wls-jms-demo</name>

<properties>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.source>17</maven.compiler.source>
</properties>

<dependencies>
<dependency>
<groupId>io.helidon.microprofile.bundles</groupId>
<artifactId>helidon-microprofile</artifactId>
</dependency>

<dependency>
<groupId>io.helidon.microprofile.messaging</groupId>
<artifactId>helidon-microprofile-messaging</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.messaging.jms</groupId>
<artifactId>helidon-messaging-jms</artifactId>
</dependency>

<dependency>
<groupId>custom.com.oracle</groupId>
<artifactId>wlthint3client</artifactId>
<version>12.2.1.4</version>
</dependency>

<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-sse</artifactId>
</dependency>

<dependency>
<groupId>org.jboss</groupId>
<artifactId>jandex</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>jakarta.activation</groupId>
<artifactId>jakarta.activation-api</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-libs</id>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jboss.jandex</groupId>
<artifactId>jandex-maven-plugin</artifactId>
<executions>
<execution>
<id>make-index</id>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
81 changes: 81 additions & 0 deletions mp/gh5290/src/main/java/bare/FrankResource.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@

package bare;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.SubmissionPublisher;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.sse.Sse;
import jakarta.ws.rs.sse.SseBroadcaster;
import jakarta.ws.rs.sse.SseEventSink;

import io.helidon.common.reactive.Multi;
import io.helidon.messaging.connectors.jms.JmsMessage;
import io.helidon.microprofile.server.Server;

import org.eclipse.microprofile.reactive.messaging.Incoming;
import org.eclipse.microprofile.reactive.messaging.Message;
import org.eclipse.microprofile.reactive.messaging.Outgoing;
import org.glassfish.hk2.api.ClassAnalyzer;
import org.glassfish.hk2.api.ServiceLocator;
import org.glassfish.hk2.api.ServiceLocatorFactory;
import org.glassfish.jersey.media.sse.OutboundEvent;
import org.jvnet.hk2.internal.ServiceLocatorImpl;
import org.jvnet.hk2.internal.Utilities;
import org.reactivestreams.FlowAdapters;
import org.reactivestreams.Publisher;

@Path("/frank")
@ApplicationScoped
public class FrankResource {

SubmissionPublisher<String> emitter = new SubmissionPublisher<>();
private SseBroadcaster sseBroadcaster;

@Incoming("from-wls")
public CompletionStage<Void> receive(JmsMessage<String> msg) {
if (sseBroadcaster == null) {
System.out.println("No SSE client subscribed yet: " + msg.getPayload());
return CompletableFuture.completedStage(null);
}
sseBroadcaster.broadcast(new OutboundEvent.Builder().data(msg.getPayload()).build());
return CompletableFuture.completedStage(null);
}

@Outgoing("to-wls")
public Publisher<Message<String>> registerPublisher() {
return FlowAdapters.toPublisher(Multi.create(emitter).map(s -> JmsMessage.builder(s)
//.property("JMS_BEA_DeliveryTime", 60000)
.build()
));
}

@POST
@Path("/send/{msg}")
public void send(@PathParam("msg") String msg) {
emitter.submit(msg);
}

@GET
@Path("sse")
@Produces(MediaType.SERVER_SENT_EVENTS)
public void listenToEvents(@Context SseEventSink eventSink, @Context Sse sse) {
if (sseBroadcaster == null) {
sseBroadcaster = sse.newBroadcaster();
}
sseBroadcaster.register(eventSink);
}

public static void main(String[] args) {

Server.create().start();
}
}
8 changes: 8 additions & 0 deletions mp/gh5290/src/main/resources/META-INF/beans.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/beans_2_0.xsd"
version="2.0"
bean-discovery-mode="all"><scan></scan>
</beans>
Binary file added mp/gh5290/src/main/resources/WEB/favicon.ico
Binary file not shown.
Binary file added mp/gh5290/src/main/resources/WEB/img/arrow-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mp/gh5290/src/main/resources/WEB/img/arrow-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mp/gh5290/src/main/resources/WEB/img/cloud.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mp/gh5290/src/main/resources/WEB/img/frank.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
85 changes: 85 additions & 0 deletions mp/gh5290/src/main/resources/WEB/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Helidon Reactive Messaging</title>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<link rel="stylesheet" type="text/css" href="main.css">
</head>
<body>

<div id="root">
<div id="producer">
<div id="inputCloud">
<input type="text" id="input" value="Fly Helidon!"/>
</div>
<div id="submit">Send</div>
</div>
<div id="helidon"></div>
<div id="rest-tip">
<div id="rest-tip-arrow"></div>
<div id="rest-tip-label">REST call /frank/send/{msg}</div>
</div>
<div id="sse-tip">
<div id="sse-tip-label">SSE messages received</div>
<div id="sse-tip-arrow"></div>
</div>
<div id="msgBox"></div>
</div>

<script>

const helidon = $('#helidon');
const messageBox = $('#msgBox');
const input = $("#input");
const submit = $("#submit");

// Pre-filled example messages
const templates = ["Fly Helidon!", "We ❤️ microservices!", "Reactive wings are faster!"];
let template_idx = 1;

submit.on("click", onSubmit);
new EventSource("frank/sse").onmessage = e => this.onSSE(e.data);

function onSSE(data) {
fly();
messageBox.prepend(`<div id="msg">${data}</div>`);
cleanQueue();
}

function cleanQueue() {
const messageQueue = $("#msgBox div");
if (messageQueue.length > 6) {
messageQueue
.last()
.fadeOut(100, function () {
$(this).remove();
cleanQueue();
});
}
}

function onSubmit() {
fetch("frank/send/" + input.val(), {method: 'POST'});
template_idx = template_idx < templates.length - 1 ? template_idx + 1 : 0;
input.val(templates[template_idx]);
}

function fly() {
const id = setInterval(handler, 2);
let position = -500;

function handler() {
if (position > (window.innerWidth)) {
clearInterval(id);
} else {
position += 50;
helidon.css("left", `${position}px`);
}
}
}
</script>

</body>
</html>
Loading

0 comments on commit 1bc94ce

Please sign in to comment.