Skip to content

Commit

Permalink
Adding loosely-coupled-webapp & deferred-deployment examples
Browse files Browse the repository at this point in the history
  • Loading branch information
joakime committed Jun 26, 2024
1 parent 031fe9b commit 0b65c57
Show file tree
Hide file tree
Showing 25 changed files with 625 additions and 0 deletions.
24 changes: 24 additions & 0 deletions standalone/deferred-deployment/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Deferred WebApp Deployment

This example jetty.base demonstrates how to setup a deferred deployment of select webapps.


## WebApps

The webapps in use on this jetty.base

* `webapps/webapp-A.war` comes from the [`webapps/loosely-coupled-webapps/webapp-A/`](../../webapps/loosely-coupled-webapps/webapp-A) project.
* `webapps-late/webapp-B.war` comes from the [`webapps/loosely-coupled-webapps/webapp-B/`](../../webapps/loosely-coupled-webapps/webapp-B) project.


## New Modules

There is a new `deploy-late` module present in this jetty.base in the `modules/deploy-late.mod`.

This `deploy-late` module:

* provides a Jetty Deployment AppProvider that monitors for deployable
content in the `${jetty.base}/webapps-late/` directory.
* has `deferInitialDeploy` configuration set to `true`

This module is enabled via the `start.d/deploy-late.ini`.
38 changes: 38 additions & 0 deletions standalone/deferred-deployment/etc/jetty-deploy-late.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd">

<Configure id="DeploymentManager" class="org.eclipse.jetty.deploy.DeploymentManager">
<Call name="addAppProvider">
<Arg>
<New id="webapplate-provider" class="org.eclipse.jetty.deploy.providers.WebAppProvider">
<Set name="monitoredDirName">
<Call name="resolvePath" class="org.eclipse.jetty.xml.XmlConfiguration">
<Arg><Property name="jetty.base"/></Arg>
<Arg><Property name="jetty.deploy.late.monitoredDir" default="webapps-late" /></Arg>
</Call>
</Set>
<Set name="defaultsDescriptor">
<Property>
<Name>jetty.deploy.defaultsDescriptorPath</Name>
<Default>
<Property name="jetty.home" default="." />/etc/webdefault.xml
</Default>
</Property>
</Set>
<Set name="deferInitialScan">true</Set>
<Set name="scanInterval"><Property name="jetty.deploy.late.scanInterval" default="1"/></Set>
<Set name="extractWars"><Property name="jetty.deploy.late.extractWars" default="true"/></Set>
<Set name="configurationManager">
<New class="org.eclipse.jetty.deploy.PropertiesConfigurationManager">
<!-- file of context configuration properties
<Set name="file"><SystemProperty name="jetty.base"/>/etc/some.properties</Set>
-->
<!-- set a context configuration property
<Call name="put"><Arg>name</Arg><Arg>value</Arg></Call>
-->
</New>
</Set>
</New>
</Arg>
</Call>
</Configure>
22 changes: 22 additions & 0 deletions standalone/deferred-deployment/modules/deploy-late.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[description]
Enables late web application deployment from the $JETTY_BASE/webapps-late/ directory.

[depend]
deploy

[files]
webapps-late/

[xml]
etc/jetty-deploy-late.xml

[ini-template]
# Monitored directory name (relative to $jetty.base)
# jetty.deploy.late.monitoredDir=webapps-late

# Monitored directory scan period (seconds)
# jetty.deploy.late.scanInterval=1

# Whether to extract *.war files
# jetty.deploy.late.extractWars=true

10 changes: 10 additions & 0 deletions standalone/deferred-deployment/resources/jetty-logging.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
## Set logging levels from: ALL, TRACE, DEBUG, INFO, WARN, ERROR, OFF
org.eclipse.jetty.LEVEL=INFO
## Configure a level for an arbitrary logger tree
#com.example.LEVEL=INFO
## Configure a level for specific logger
#com.example.MyComponent.LEVEL=INFO
## Configure JMX Context Name
# org.eclipse.jetty.logging.jmx.context=JettyServer
## Hide stacks traces in an arbitrary logger tree
#com.example.STACKS=false
16 changes: 16 additions & 0 deletions standalone/deferred-deployment/start.d/deploy-late.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# ---------------------------------------
# Module: deploy-late
# Enables late web application deployment from the $JETTY_BASE/webapps-late/ directory.
# ---------------------------------------
--module=deploy-late

# Monitored directory name (relative to $jetty.base)
# jetty.deploy.late.monitoredDir=webapps-late

# Monitored directory scan period (seconds)
# jetty.deploy.late.scanInterval=1

# Whether to extract *.war files
# jetty.deploy.late.extractWars=true


25 changes: 25 additions & 0 deletions standalone/deferred-deployment/start.d/deploy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# ---------------------------------------
# Module: deploy
# Enables web application deployment from the $JETTY_BASE/webapps/ directory.
# ---------------------------------------
--module=deploy

# Monitored directory name (relative to $jetty.base)
# jetty.deploy.monitoredDir=webapps

# Defaults Descriptor for all deployed webapps
# jetty.deploy.defaultsDescriptorPath=${jetty.base}/etc/webdefault.xml

# Defer Initial Scan
# true to have the initial scan deferred until the Server component is started.
# Note: deploy failures do not fail server startup in a deferred initial scan mode.
# false (default) to have initial scan occur as normal.
# jetty.deploy.deferInitialScan=false

# Monitored directory scan period (seconds)
# jetty.deploy.scanInterval=1

# Whether to extract *.war files
# jetty.deploy.extractWars=true


47 changes: 47 additions & 0 deletions standalone/deferred-deployment/start.d/http.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# ---------------------------------------
# Module: http
# Enables a clear-text HTTP connector.
# By default clear-text HTTP/1.1 is enabled, and clear-text HTTP/2 may be added by enabling the "http2c" module.
# ---------------------------------------
--module=http

### Clear-Text HTTP Connector Configuration

## The host/address to bind the connector to.
# jetty.http.host=0.0.0.0

## The port the connector listens on.
# jetty.http.port=8080

## The connector idle timeout, in milliseconds.
# jetty.http.idleTimeout=30000

## The number of acceptors (-1 picks a default value based on number of cores).
# jetty.http.acceptors=1

## The number of selectors (-1 picks a default value based on number of cores).
# jetty.http.selectors=-1

## The ServerSocketChannel accept queue backlog (0 picks the platform default).
# jetty.http.acceptQueueSize=0

## The thread priority delta to give to acceptor threads.
# jetty.http.acceptorPriorityDelta=0

## Whether to enable the SO_REUSEADDR socket option.
# jetty.http.reuseAddress=true

## Whether to enable the SO_REUSEPORT socket option.
# jetty.http.reusePort=false

## Whether to enable the TCP_NODELAY socket option on accepted sockets.
# jetty.http.acceptedTcpNoDelay=true

## The SO_RCVBUF socket option to set on accepted sockets.
## A value of -1 indicates that the platform default is used.
# jetty.http.acceptedReceiveBufferSize=-1

## The SO_SNDBUF socket option to set on accepted sockets.
## A value of -1 indicates that the platform default is used.
# jetty.http.acceptedSendBufferSize=-1

90 changes: 90 additions & 0 deletions standalone/deferred-deployment/start.d/server.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# ---------------------------------------
# Module: server
# Enables and configures the Jetty server.
# This module does not enable any network protocol support.
# To enable a specific network protocol such as HTTP/1.1, you must enable the correspondent Jetty module.
# ---------------------------------------
--module=server

### Common HTTP configuration
## Scheme to use to build URIs for secure redirects
# jetty.httpConfig.secureScheme=https

## Port to use to build URIs for secure redirects
# jetty.httpConfig.securePort=8443

## Response content buffer size (in bytes)
# jetty.httpConfig.outputBufferSize=32768

## Max response content write length that is buffered (in bytes)
# jetty.httpConfig.outputAggregationSize=8192

## If HTTP/1.x persistent connections should be enabled
# jetty.httpConfig.persistentConnectionsEnabled=true

## Max request headers size (in bytes)
# jetty.httpConfig.requestHeaderSize=8192

## Max response headers size (in bytes)
# jetty.httpConfig.responseHeaderSize=8192

## Whether to send the Server: header
# jetty.httpConfig.sendServerVersion=true

## Whether to send the Date: header
# jetty.httpConfig.sendDateHeader=false

## Max per-connection header cache size (in nodes)
# jetty.httpConfig.headerCacheSize=1024

## Whether, for requests with content, delay dispatch until some content has arrived
# jetty.httpConfig.delayDispatchUntilContent=true

## Maximum number of error dispatches to prevent looping
# jetty.httpConfig.maxErrorDispatches=10

## Relative Redirect Locations allowed
# jetty.httpConfig.relativeRedirectAllowed=false

## Whether to use direct ByteBuffers for reading or writing
# jetty.httpConfig.useInputDirectByteBuffers=true
# jetty.httpConfig.useOutputDirectByteBuffers=true

## HTTP Compliance: RFC7230, RFC7230_LEGACY, RFC2616, RFC2616_LEGACY, LEGACY
# jetty.httpConfig.compliance=RFC7230

## URI Compliance: DEFAULT, LEGACY, RFC3986, RFC3986_UNAMBIGUOUS, UNSAFE
# jetty.httpConfig.uriCompliance=DEFAULT

## Cookie compliance mode for parsing request Cookie headers: RFC6265_STRICT, RFC6265, RFC6265_LEGACY, RFC2965, RFC2965_LEGACY
# jetty.httpConfig.requestCookieCompliance=RFC6265

## Cookie compliance mode for generating response Set-Cookie: RFC2965, RFC6265
# jetty.httpConfig.responseCookieCompliance=RFC6265

## multipart/form-data compliance mode of: LEGACY(slow), RFC7578(fast)
# jetty.httpConfig.multiPartFormDataCompliance=RFC7578

### Server configuration
## Whether ctrl+c on the console gracefully stops the Jetty server
# jetty.server.stopAtShutdown=true

## Timeout in ms to apply when stopping the server gracefully
# jetty.server.stopTimeout=5000

## Dump the state of the Jetty server, components, and webapps after startup
# jetty.server.dumpAfterStart=false

## Dump the state of the Jetty server, components, and webapps before shutdown
# jetty.server.dumpBeforeStop=false

### Server Scheduler Configuration
## The scheduler thread name, defaults to "Scheduler-{hashCode()}" if blank.
# jetty.scheduler.name=

## Whether the server scheduler threads are daemon.
# jetty.scheduler.daemon=false

## The number of server scheduler threads.
# jetty.scheduler.threads=1

23 changes: 23 additions & 0 deletions standalone/deferred-deployment/start.d/webapp.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# ---------------------------------------
# Module: webapp
# Adds support for servlet specification web applications to the server classpath.
# Without this, only Jetty-specific handlers may be deployed.
# ---------------------------------------
--module=webapp

## Add to the server wide default jars and packages protected or hidden from webapps.
## System classes are protected and cannot be overridden by a webapp.
## Server classes are hidden and cannot be seen by a webapp
## Lists of patterns are comma separated and may be either:
## + a qualified classname e.g. 'com.acme.Foo'
## + a package name e.g. 'net.example.'
## + a jar file e.g. '${jetty.base.uri}/lib/dependency.jar'
## + a directory of jars,resource or classes e.g. '${jetty.base.uri}/resources'
## + A pattern preceded with a '-' is an exclusion, all other patterns are inclusions
##
## The +=, operator appends to a CSV list with a comma as needed.
##
#jetty.webapp.addSystemClasses+=,org.example.
#jetty.webapp.addServerClasses+=,org.example.


Binary file not shown.
11 changes: 11 additions & 0 deletions standalone/deferred-deployment/webapps-late/webapp-B.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd">

<Configure class="org.eclipse.jetty.webapp.WebAppContext" id="webappB">
<Set name="war"><Property name="jetty.base"/>/webapps-late/webapp-B.war</Set>
<Set name="contextPath">/appB</Set>
<!-- add active logging impls to webapp too -->
<Set name="extraClasspath">
<Property name="jetty.home"/>/lib/logging/*
</Set>
</Configure>
Binary file not shown.
11 changes: 11 additions & 0 deletions standalone/deferred-deployment/webapps/webapp-A.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd">

<Configure class="org.eclipse.jetty.webapp.WebAppContext" id="webappA">
<Set name="war"><Property name="jetty.base"/>/webapps/webapp-A.war</Set>
<Set name="contextPath">/appA</Set>
<!-- add active logging impls to webapp too -->
<Set name="extraClasspath">
<Property name="jetty.home"/>/lib/logging/*
</Set>
</Configure>
33 changes: 33 additions & 0 deletions webapps/loosely-coupled-webapps/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Examples of Loosely Coupled WebApps

Sometimes the WebApp you are making is loosely coupled to another WebApp.

"Loosely Coupled" in this situation refers to a runtime dependency to another WebApp.
One that is not defined via a build tool dependency.

In the examples here, we have 2 WebApps.

## The WebApps

### WebApp A

This WebApp is standalone, and it:

* Provides the [`/css/main.css`](webapp-A/src/main/webapp/css/main.css) used by other webapps.
* Has a [`DebugFilter`](webapp-A/src/main/java/examples/a/DebugFilter.java) to show when this webapp is used by logging access to it (such as when a request to `/css/main.css` occurs)

### WebApp B

This WebApp is loosely coupled with WebApp A, and it:

* It has a [`CssServlet`](webapp-B/src/main/java/examples/b/CssServlet.java) on [url-pattern `/dyncss/*`](webapp-B/src/main/webapp/WEB-INF/web.xml)
* The `CssServlet` load on start and will initialize itself from a GET request to `http://localhost:8080/appA/css/`
* It has an [`index.html`](webapp-B/src/main/webapp/index.html) with a css reference to `<link rel="stylesheet" href="dyncss/main.css" />`

## Problems with Loosely Coupled WebApps

When you have a webapp that needs content from another webapp, then this means the webapp
deployment order is important.

The jetty-example project [`/standalone/deferred-deployment/`](../../standalone/deferred-deployment/) shows how
to setup a standalone environment for this kind of dependency.
28 changes: 28 additions & 0 deletions webapps/loosely-coupled-webapps/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.eclipse.jetty.examples.webapps</groupId>
<artifactId>jetty-webapp-examples</artifactId>
<version>10.0.x</version>
</parent>
<groupId>org.eclipse.jetty.examples.webapps.loosely-coupled</groupId>
<artifactId>loosely-coupled-webapps</artifactId>
<version>10.0.x</version>
<packaging>pom</packaging>
<name>Jetty Examples :: Jetty 10.0.x :: Loosely Coupled WebApps</name>

<modules>
<module>webapp-A</module>
<module>webapp-B</module>
</modules>

<dependencies>
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>4.0.4</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
Loading

0 comments on commit 0b65c57

Please sign in to comment.