Merged branch 'jetty-10.0.x' into 'jetty-10.0.x-3897-new_docs_2'.

This commit is contained in:
Simone Bordet 2020-03-28 18:31:05 +01:00
commit 4d612b077f
4201 changed files with 123389 additions and 90454 deletions

View File

@ -0,0 +1,18 @@
---
name: Issue
about: Reporting bugs and problems in Eclipse Jetty
title: ''
assignees: ''
---
**Jetty version**
**Java version**
**OS type/version**
**Description**

View File

@ -0,0 +1,16 @@
---
name: Question
about: Asking questions about Eclipse Jetty
title: ''
labels: Question
assignees: ''
---
**Jetty version**
**Java version**
**Question**

20
.github/stale.yml vendored Normal file
View File

@ -0,0 +1,20 @@
# Number of days of inactivity before an issue becomes stale
daysUntilStale: 365
# Number of days of inactivity before a stale issue is closed
daysUntilClose: 30
# Issues with these labels will never be considered stale
exemptLabels:
- Pinned
- Security
- Specification
- TCK
# Label to use when marking an issue as stale
staleLabel: Stale
# Comment to post when marking an issue as stale. Set to `false` to disable
markComment: >
This issue has been automatically marked as stale because it has been a
full year without activity. It will be closed if no further activity occurs.
Thank you for your contributions.
# Comment to post when closing a stale issue. Set to `false` to disable
closeComment: >
This issue has been closed due to it having no activity.

View File

@ -53,10 +53,10 @@ Be sure to search for existing bugs before you create another one. Remember that
Reporting Security Issues
-----------------
There are a number of avenues for reporting security issues to the Jetty project available.
If the issue is directly related to Jetty itself then reporting to the Jetty developers is encouraged.
The most direct method is to mail [security@webtide.com](mailto:security@webtide.com).
Webtide is comprised of the active committers of the Jetty project is our preferred reporting method.
There are a number of avenues for reporting security issues to the Jetty project available.
If the issue is directly related to Jetty itself then reporting to the Jetty developers is encouraged.
The most direct method is to mail [security@webtide.com](mailto:security@webtide.com).
Webtide is comprised of the active committers of the Jetty project is our preferred reporting method.
We are flexible in how we work with reporters of security issues but we reserve the right to act in the interests of the Jetty project in all circumstances.
If the issue is related to Eclipse or its Jetty integration then we encourage you to reach out to [security@eclipse.org](mailto:security@eclipse.org).

123
Jenkinsfile vendored
View File

@ -11,65 +11,53 @@ pipeline {
agent { node { label 'linux' } }
options { timeout(time: 120, unit: 'MINUTES') }
steps {
mavenBuild("jdk11", "-Pmongodb install", "maven3", true) // -Pautobahn
mavenBuild("jdk11", "-T3 -Pmongodb clean install", "maven3", true) // -Pautobahn
// Collect up the jacoco execution results (only on main build)
jacoco inclusionPattern: '**/org/eclipse/jetty/**/*.class',
exclusionPattern: '' +
// build tools
'**/org/eclipse/jetty/ant/**' +
',**/org/eclipse/jetty/maven/**' +
',**/org/eclipse/jetty/jspc/**' +
// example code / documentation
',**/org/eclipse/jetty/embedded/**' +
',**/org/eclipse/jetty/asyncrest/**' +
',**/org/eclipse/jetty/demo/**' +
// special environments / late integrations
',**/org/eclipse/jetty/gcloud/**' +
',**/org/eclipse/jetty/infinispan/**' +
',**/org/eclipse/jetty/osgi/**' +
',**/org/eclipse/jetty/spring/**' +
',**/org/eclipse/jetty/http/spi/**' +
// test classes
',**/org/eclipse/jetty/tests/**' +
',**/org/eclipse/jetty/test/**',
execPattern: '**/target/jacoco.exec',
classPattern: '**/target/classes',
sourcePattern: '**/src/main/java'
exclusionPattern: '' +
// build tools
'**/org/eclipse/jetty/ant/**' +
',**/org/eclipse/jetty/maven/**' +
',**/org/eclipse/jetty/jspc/**' +
// example code / documentation
',**/org/eclipse/jetty/embedded/**' +
',**/org/eclipse/jetty/asyncrest/**' +
',**/org/eclipse/jetty/demo/**' +
// special environments / late integrations
',**/org/eclipse/jetty/gcloud/**' +
',**/org/eclipse/jetty/infinispan/**' +
',**/org/eclipse/jetty/osgi/**' +
',**/org/eclipse/jetty/spring/**' +
',**/org/eclipse/jetty/http/spi/**' +
// test classes
',**/org/eclipse/jetty/tests/**' +
',**/org/eclipse/jetty/test/**',
execPattern: '**/target/jacoco.exec',
classPattern: '**/target/classes',
sourcePattern: '**/src/main/java'
warnings consoleParsers: [[parserName: 'Maven'], [parserName: 'Java']]
junit testResults: '**/target/surefire-reports/*.xml,**/target/invoker-reports/TEST*.xml,**/target/autobahntestsuite-reports/*.xml'
}
}
stage("Build / Test - JDK12") {
stage("Build / Test - JDK13") {
agent { node { label 'linux' } }
options { timeout(time: 120, unit: 'MINUTES') }
steps {
mavenBuild("jdk12", "-Pmongodb install", "maven3", true)
warnings consoleParsers: [[parserName: 'Maven'], [parserName: 'Java']]
junit testResults: '**/target/surefire-reports/*.xml,**/target/invoker-reports/TEST*.xml'
timeout(time: 120, unit: 'MINUTES') {
mavenBuild("jdk13", "-T3 -Pmongodb clean install", "maven3", true)
warnings consoleParsers: [[parserName: 'Maven'], [parserName: 'Java']]
junit testResults: '**/target/surefire-reports/*.xml,**/target/invoker-reports/TEST*.xml'
}
}
}
stage("Build Javadoc") {
agent { node { label 'linux' } }
options { timeout(time: 30, unit: 'MINUTES') }
steps {
mavenBuild("jdk11", "install javadoc:javadoc -DskipTests", "maven3", true)
warnings consoleParsers: [[parserName: 'Maven'], [parserName: 'JavaDoc'], [parserName: 'Java']]
}
}
stage("Checkstyle ") {
agent { node { label 'linux' } }
options { timeout(time: 30, unit: 'MINUTES') }
steps {
mavenBuild("jdk11", "install -DskipTests", "maven3", true)
mavenBuild("jdk11", "install -f build-resources", "maven3", true)
mavenBuild("jdk11", "install checkstyle:check -DskipTests", "maven3", true)
recordIssues(
enabledForFailure: true, aggregatingResults: true,
tools: [java(), checkStyle(pattern: '**/target/checkstyle-result.xml', reportEncoding: 'UTF-8')]
)
timeout(time: 30, unit: 'MINUTES') {
mavenBuild("jdk11", "package source:jar javadoc:jar javadoc:aggregate-jar -Peclipse-release -DskipTests -Dpmd.skip=true -Dcheckstyle.skip=true", "maven3", true)
warnings consoleParsers: [[parserName: 'Maven'], [parserName: 'JavaDoc'], [parserName: 'Java']]
}
}
}
}
@ -88,28 +76,24 @@ pipeline {
}
}
def slackNotif() {
script {
try
{
if ( env.BRANCH_NAME == 'jetty-10.0.x' || env.BRANCH_NAME == 'jetty-9.4.x' )
{
//BUILD_USER = currentBuild.rawBuild.getCause(Cause.UserIdCause).getUserId()
// by ${BUILD_USER}
COLOR_MAP = ['SUCCESS': 'good', 'FAILURE': 'danger', 'UNSTABLE': 'danger', 'ABORTED': 'danger']
slackSend channel: '#jenkins',
color: COLOR_MAP[currentBuild.currentResult],
message: "*${currentBuild.currentResult}:* Job ${env.JOB_NAME} build ${env.BUILD_NUMBER} - ${env.BUILD_URL}"
}
} catch (Exception e) {
e.printStackTrace()
echo "skip failure slack notification: " + e.getMessage()
script {
try {
if (env.BRANCH_NAME == 'jetty-10.0.x' || env.BRANCH_NAME == 'jetty-9.4.x') {
//BUILD_USER = currentBuild.rawBuild.getCause(Cause.UserIdCause).getUserId()
// by ${BUILD_USER}
COLOR_MAP = ['SUCCESS': 'good', 'FAILURE': 'danger', 'UNSTABLE': 'danger', 'ABORTED': 'danger']
slackSend channel: '#jenkins',
color: COLOR_MAP[currentBuild.currentResult],
message: "*${currentBuild.currentResult}:* Job ${env.JOB_NAME} build ${env.BUILD_NUMBER} - ${env.BUILD_URL}"
}
} catch (Exception e) {
e.printStackTrace()
echo "skip failure slack notification: " + e.getMessage()
}
}
}
/**
* To other developers, if you are using this method above, please use the following syntax.
*
@ -125,15 +109,16 @@ def mavenBuild(jdk, cmdline, mvnName, junitPublishDisabled) {
def mavenOpts = '-Xms1g -Xmx4g -Djava.awt.headless=true'
withMaven(
maven: mvnName,
jdk: "$jdk",
publisherStrategy: 'EXPLICIT',
options: [junitPublisher(disabled: junitPublishDisabled),mavenLinkerPublisher(disabled: false),pipelineGraphPublisher(disabled: false)],
mavenOpts: mavenOpts,
mavenLocalRepo: localRepo) {
maven: mvnName,
jdk: "$jdk",
publisherStrategy: 'EXPLICIT',
options: [junitPublisher(disabled: junitPublishDisabled), mavenLinkerPublisher(disabled: false), pipelineGraphPublisher(disabled: false)],
mavenOpts: mavenOpts,
mavenLocalRepo: localRepo) {
// Some common Maven command line + provided command line
sh "mvn -Pci -V -B -T3 -e -fae -Dmaven.test.failure.ignore=true -Djetty.testtracker.log=true $cmdline -Dunix.socket.tmp=" + env.JENKINS_HOME
sh "mvn -Pci -V -B -e -fae -Dmaven.test.failure.ignore=true -Djetty.testtracker.log=true $cmdline -Dunix.socket.tmp=" + env.JENKINS_HOME
}
}
// vim: et:ts=2:sw=2:ft=groovy

View File

@ -2,6 +2,6 @@
Jan Bartel <janb@mortbay.com> AED5 EE6C 45D0 FE8D 5D1B 164F 27DE D4BF 6216 DB8F
Jesse McConnell <jesse.mcconnell@gmail.com> 2A68 4B57 436A 81FA 8706 B53C 61C3 351A 438A 3B7D
Joakim Erdfelt <joakim.erdfelt@gmail.com> 5989 BAF7 6217 B843 D66B E55B 2D0E 1FB8 FE4B 68B4
Joakim Erdfelt <joakim@apache.org> B59B 67FD 7904 9843 67F9 3180 0818 D9D6 8FB6 7BAC
Joakim Erdfelt <joakime@apache.org> B59B 67FD 7904 9843 67F9 3180 0818 D9D6 8FB6 7BAC
Joakim Erdfelt <joakim@erdfelt.com> BFBB 21C2 46D7 7768 3628 7A48 A04E 0C74 ABB3 5FEA
Simone Bordet <simone.bordet@gmail.com> 8B09 6546 B1A8 F026 56B1 5D3B 1677 D141 BCF3 584D

413
LICENSE
View File

@ -1,215 +1,290 @@
This program and the accompanying materials are made available under the
terms of the Eclipse Public License 1.0 which is available at
https://www.eclipse.org/org/documents/epl-1.0/EPL-1.0.txt
or the Apache Software License 2.0 which is available at
This program and the accompanying materials are made available under
the terms of the Eclipse Public License 2.0 which is available at
https://www.eclipse.org/legal/epl-2.0
This Source Code may also be made available under the following
Secondary Licenses when the conditions for such availability set
forth in the Eclipse Public License, v. 2.0 are satisfied:
the Apache License v2.0 which is available at
https://www.apache.org/licenses/LICENSE-2.0
Eclipse Public License - v 2.0
Eclipse Public License - v 1.0
THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC
LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM
CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE
PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION
OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
1. DEFINITIONS
"Contribution" means:
a) in the case of the initial Contributor, the initial code and documentation
distributed under this Agreement, and
b) in the case of each subsequent Contributor:
i) changes to the Program, and
ii) additions to the Program;
a) in the case of the initial Contributor, the initial content
Distributed under this Agreement, and
where such changes and/or additions to the Program originate from and are
distributed by that particular Contributor. A Contribution 'originates'
from a Contributor if it was added to the Program by such Contributor
itself or anyone acting on such Contributor's behalf. Contributions do not
include additions to the Program which: (i) are separate modules of
software distributed in conjunction with the Program under their own
license agreement, and (ii) are not derivative works of the Program.
b) in the case of each subsequent Contributor:
i) changes to the Program, and
ii) additions to the Program;
where such changes and/or additions to the Program originate from
and are Distributed by that particular Contributor. A Contribution
"originates" from a Contributor if it was added to the Program by
such Contributor itself or anyone acting on such Contributor's behalf.
Contributions do not include changes or additions to the Program that
are not Modified Works.
"Contributor" means any person or entity that distributes the Program.
"Contributor" means any person or entity that Distributes the Program.
"Licensed Patents" mean patent claims licensable by a Contributor which are
necessarily infringed by the use or sale of its Contribution alone or when
combined with the Program.
"Licensed Patents" mean patent claims licensable by a Contributor which
are necessarily infringed by the use or sale of its Contribution alone
or when combined with the Program.
"Program" means the Contributions distributed in accordance with this
"Program" means the Contributions Distributed in accordance with this
Agreement.
"Recipient" means anyone who receives the Program under this Agreement,
including all Contributors.
"Recipient" means anyone who receives the Program under this Agreement
or any Secondary License (as applicable), including Contributors.
"Derivative Works" shall mean any work, whether in Source Code or other
form, that is based on (or derived from) the Program and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship.
"Modified Works" shall mean any work in Source Code or other form that
results from an addition to, deletion from, or modification of the
contents of the Program, including, for purposes of clarity any new file
in Source Code form that contains any contents of the Program. Modified
Works shall not include works that contain only declarations,
interfaces, types, classes, structures, or files of the Program solely
in each case in order to link to, bind by name, or subclass the Program
or Modified Works thereof.
"Distribute" means the acts of a) distributing or b) making available
in any manner that enables the transfer of a copy.
"Source Code" means the form of a Program preferred for making
modifications, including but not limited to software source code,
documentation source, and configuration files.
"Secondary License" means either the GNU General Public License,
Version 2.0, or any later versions of that license, including any
exceptions or additional permissions as identified by the initial
Contributor.
2. GRANT OF RIGHTS
a) Subject to the terms of this Agreement, each Contributor hereby grants
Recipient a non-exclusive, worldwide, royalty-free copyright license to
reproduce, prepare derivative works of, publicly display, publicly
perform, distribute and sublicense the Contribution of such Contributor,
if any, and such derivative works, in source code and object code form.
b) Subject to the terms of this Agreement, each Contributor hereby grants
Recipient a non-exclusive, worldwide, royalty-free patent license under
Licensed Patents to make, use, sell, offer to sell, import and otherwise
transfer the Contribution of such Contributor, if any, in source code and
object code form. This patent license shall apply to the combination of
the Contribution and the Program if, at the time the Contribution is
added by the Contributor, such addition of the Contribution causes such
combination to be covered by the Licensed Patents. The patent license
shall not apply to any other combinations which include the Contribution.
No hardware per se is licensed hereunder.
c) Recipient understands that although each Contributor grants the licenses
to its Contributions set forth herein, no assurances are provided by any
Contributor that the Program does not infringe the patent or other
intellectual property rights of any other entity. Each Contributor
disclaims any liability to Recipient for claims brought by any other
entity based on infringement of intellectual property rights or
otherwise. As a condition to exercising the rights and licenses granted
hereunder, each Recipient hereby assumes sole responsibility to secure
any other intellectual property rights needed, if any. For example, if a
third party patent license is required to allow Recipient to distribute
the Program, it is Recipient's responsibility to acquire that license
before distributing the Program.
d) Each Contributor represents that to its knowledge it has sufficient
copyright rights in its Contribution, if any, to grant the copyright
license set forth in this Agreement.
a) Subject to the terms of this Agreement, each Contributor hereby
grants Recipient a non-exclusive, worldwide, royalty-free copyright
license to reproduce, prepare Derivative Works of, publicly display,
publicly perform, Distribute and sublicense the Contribution of such
Contributor, if any, and such Derivative Works.
b) Subject to the terms of this Agreement, each Contributor hereby
grants Recipient a non-exclusive, worldwide, royalty-free patent
license under Licensed Patents to make, use, sell, offer to sell,
import and otherwise transfer the Contribution of such Contributor,
if any, in Source Code or other form. This patent license shall
apply to the combination of the Contribution and the Program if, at
the time the Contribution is added by the Contributor, such addition
of the Contribution causes such combination to be covered by the
Licensed Patents. The patent license shall not apply to any other
combinations which include the Contribution. No hardware per se is
licensed hereunder.
c) Recipient understands that although each Contributor grants the
licenses to its Contributions set forth herein, no assurances are
provided by any Contributor that the Program does not infringe the
patent or other intellectual property rights of any other entity.
Each Contributor disclaims any liability to Recipient for claims
brought by any other entity based on infringement of intellectual
property rights or otherwise. As a condition to exercising the
rights and licenses granted hereunder, each Recipient hereby
assumes sole responsibility to secure any other intellectual
property rights needed, if any. For example, if a third party
patent license is required to allow Recipient to Distribute the
Program, it is Recipient's responsibility to acquire that license
before distributing the Program.
d) Each Contributor represents that to its knowledge it has
sufficient copyright rights in its Contribution, if any, to grant
the copyright license set forth in this Agreement.
e) Notwithstanding the terms of any Secondary License, no
Contributor makes additional grants to any Recipient (other than
those set forth in this Agreement) as a result of such Recipient's
receipt of the Program under the terms of a Secondary License
(if permitted under the terms of Section 3).
3. REQUIREMENTS
A Contributor may choose to distribute the Program in object code form under
its own license agreement, provided that:
3.1 If a Contributor Distributes the Program in any form, then:
a) it complies with the terms and conditions of this Agreement; and
b) its license agreement:
i) effectively disclaims on behalf of all Contributors all warranties
and conditions, express and implied, including warranties or
conditions of title and non-infringement, and implied warranties or
conditions of merchantability and fitness for a particular purpose;
ii) effectively excludes on behalf of all Contributors all liability for
damages, including direct, indirect, special, incidental and
consequential damages, such as lost profits;
iii) states that any provisions which differ from this Agreement are
offered by that Contributor alone and not by any other party; and
iv) states that source code for the Program is available from such
Contributor, and informs licensees how to obtain it in a reasonable
manner on or through a medium customarily used for software exchange.
a) the Program must also be made available as Source Code, in
accordance with section 3.2, and the Contributor must accompany
the Program with a statement that the Source Code for the Program
is available under this Agreement, and informs Recipients how to
obtain it in a reasonable manner on or through a medium customarily
used for software exchange; and
When the Program is made available in source code form:
b) the Contributor may Distribute the Program under a license
different than this Agreement, provided that such license:
i) effectively disclaims on behalf of all other Contributors all
warranties and conditions, express and implied, including
warranties or conditions of title and non-infringement, and
implied warranties or conditions of merchantability and fitness
for a particular purpose;
a) it must be made available under this Agreement; and
b) a copy of this Agreement must be included with each copy of the Program.
Contributors may not remove or alter any copyright notices contained
within the Program.
ii) effectively excludes on behalf of all other Contributors all
liability for damages, including direct, indirect, special,
incidental and consequential damages, such as lost profits;
Each Contributor must identify itself as the originator of its Contribution,
if
any, in a manner that reasonably allows subsequent Recipients to identify the
originator of the Contribution.
iii) does not attempt to limit or alter the recipients' rights
in the Source Code under section 3.2; and
iv) requires any subsequent distribution of the Program by any
party to be under a license that satisfies the requirements
of this section 3.
3.2 When the Program is Distributed as Source Code:
a) it must be made available under this Agreement, or if the
Program (i) is combined with other material in a separate file or
files made available under a Secondary License, and (ii) the initial
Contributor attached to the Source Code the notice described in
Exhibit A of this Agreement, then the Program may be made available
under the terms of such Secondary Licenses, and
b) a copy of this Agreement must be included with each copy of
the Program.
3.3 Contributors may not remove or alter any copyright, patent,
trademark, attribution notices, disclaimers of warranty, or limitations
of liability ("notices") contained within the Program from any copy of
the Program which they Distribute, provided that Contributors may add
their own appropriate notices.
4. COMMERCIAL DISTRIBUTION
Commercial distributors of software may accept certain responsibilities with
respect to end users, business partners and the like. While this license is
intended to facilitate the commercial use of the Program, the Contributor who
includes the Program in a commercial product offering should do so in a manner
which does not create potential liability for other Contributors. Therefore,
if a Contributor includes the Program in a commercial product offering, such
Contributor ("Commercial Contributor") hereby agrees to defend and indemnify
every other Contributor ("Indemnified Contributor") against any losses,
damages and costs (collectively "Losses") arising from claims, lawsuits and
other legal actions brought by a third party against the Indemnified
Contributor to the extent caused by the acts or omissions of such Commercial
Contributor in connection with its distribution of the Program in a commercial
product offering. The obligations in this section do not apply to any claims
or Losses relating to any actual or alleged intellectual property
infringement. In order to qualify, an Indemnified Contributor must:
a) promptly notify the Commercial Contributor in writing of such claim, and
b) allow the Commercial Contributor to control, and cooperate with the
Commercial Contributor in, the defense and any related settlement
negotiations. The Indemnified Contributor may participate in any such claim at
its own expense.
Commercial distributors of software may accept certain responsibilities
with respect to end users, business partners and the like. While this
license is intended to facilitate the commercial use of the Program,
the Contributor who includes the Program in a commercial product
offering should do so in a manner which does not create potential
liability for other Contributors. Therefore, if a Contributor includes
the Program in a commercial product offering, such Contributor
("Commercial Contributor") hereby agrees to defend and indemnify every
other Contributor ("Indemnified Contributor") against any losses,
damages and costs (collectively "Losses") arising from claims, lawsuits
and other legal actions brought by a third party against the Indemnified
Contributor to the extent caused by the acts or omissions of such
Commercial Contributor in connection with its distribution of the Program
in a commercial product offering. The obligations in this section do not
apply to any claims or Losses relating to any actual or alleged
intellectual property infringement. In order to qualify, an Indemnified
Contributor must: a) promptly notify the Commercial Contributor in
writing of such claim, and b) allow the Commercial Contributor to control,
and cooperate with the Commercial Contributor in, the defense and any
related settlement negotiations. The Indemnified Contributor may
participate in any such claim at its own expense.
For example, a Contributor might include the Program in a commercial product
offering, Product X. That Contributor is then a Commercial Contributor. If
that Commercial Contributor then makes performance claims, or offers
warranties related to Product X, those performance claims and warranties are
such Commercial Contributor's responsibility alone. Under this section, the
Commercial Contributor would have to defend claims against the other
Contributors related to those performance claims and warranties, and if a
court requires any other Contributor to pay any damages as a result, the
Commercial Contributor must pay those damages.
For example, a Contributor might include the Program in a commercial
product offering, Product X. That Contributor is then a Commercial
Contributor. If that Commercial Contributor then makes performance
claims, or offers warranties related to Product X, those performance
claims and warranties are such Commercial Contributor's responsibility
alone. Under this section, the Commercial Contributor would have to
defend claims against the other Contributors related to those performance
claims and warranties, and if a court requires any other Contributor to
pay any damages as a result, the Commercial Contributor must pay
those damages.
5. NO WARRANTY
EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON AN
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR
IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each
Recipient is solely responsible for determining the appropriateness of using
and distributing the Program and assumes all risks associated with its
exercise of rights under this Agreement , including but not limited to the
risks and costs of program errors, compliance with applicable laws, damage to
or loss of data, programs or equipment, and unavailability or interruption of
operations.
EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, AND TO THE EXTENT
PERMITTED BY APPLICABLE LAW, THE PROGRAM IS PROVIDED ON AN "AS IS"
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR
IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF
TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR
PURPOSE. Each Recipient is solely responsible for determining the
appropriateness of using and distributing the Program and assumes all
risks associated with its exercise of rights under this Agreement,
including but not limited to the risks and costs of program errors,
compliance with applicable laws, damage to or loss of data, programs
or equipment, and unavailability or interruption of operations.
6. DISCLAIMER OF LIABILITY
EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY
CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION
LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, AND TO THE EXTENT
PERMITTED BY APPLICABLE LAW, NEITHER RECIPIENT NOR ANY CONTRIBUTORS
SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST
PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE
EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGES.
EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
7. GENERAL
If any provision of this Agreement is invalid or unenforceable under
applicable law, it shall not affect the validity or enforceability of the
remainder of the terms of this Agreement, and without further action by the
parties hereto, such provision shall be reformed to the minimum extent
necessary to make such provision valid and enforceable.
applicable law, it shall not affect the validity or enforceability of
the remainder of the terms of this Agreement, and without further
action by the parties hereto, such provision shall be reformed to the
minimum extent necessary to make such provision valid and enforceable.
If Recipient institutes patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Program itself
(excluding combinations of the Program with other software or hardware)
infringes such Recipient's patent(s), then such Recipient's rights granted
under Section 2(b) shall terminate as of the date such litigation is filed.
If Recipient institutes patent litigation against any entity
(including a cross-claim or counterclaim in a lawsuit) alleging that the
Program itself (excluding combinations of the Program with other software
or hardware) infringes such Recipient's patent(s), then such Recipient's
rights granted under Section 2(b) shall terminate as of the date such
litigation is filed.
All Recipient's rights under this Agreement shall terminate if it fails to
comply with any of the material terms or conditions of this Agreement and does
not cure such failure in a reasonable period of time after becoming aware of
such noncompliance. If all Recipient's rights under this Agreement terminate,
Recipient agrees to cease use and distribution of the Program as soon as
reasonably practicable. However, Recipient's obligations under this Agreement
and any licenses granted by Recipient relating to the Program shall continue
and survive.
All Recipient's rights under this Agreement shall terminate if it
fails to comply with any of the material terms or conditions of this
Agreement and does not cure such failure in a reasonable period of
time after becoming aware of such noncompliance. If all Recipient's
rights under this Agreement terminate, Recipient agrees to cease use
and distribution of the Program as soon as reasonably practicable.
However, Recipient's obligations under this Agreement and any licenses
granted by Recipient relating to the Program shall continue and survive.
Everyone is permitted to copy and distribute copies of this Agreement, but in
order to avoid inconsistency the Agreement is copyrighted and may only be
modified in the following manner. The Agreement Steward reserves the right to
publish new versions (including revisions) of this Agreement from time to
time. No one other than the Agreement Steward has the right to modify this
Agreement. The Eclipse Foundation is the initial Agreement Steward. The
Eclipse Foundation may assign the responsibility to serve as the Agreement
Steward to a suitable separate entity. Each new version of the Agreement will
be given a distinguishing version number. The Program (including
Contributions) may always be distributed subject to the version of the
Agreement under which it was received. In addition, after a new version of the
Agreement is published, Contributor may elect to distribute the Program
(including its Contributions) under the new version. Except as expressly
stated in Sections 2(a) and 2(b) above, Recipient receives no rights or
licenses to the intellectual property of any Contributor under this Agreement,
whether expressly, by implication, estoppel or otherwise. All rights in the
Program not expressly granted under this Agreement are reserved.
Everyone is permitted to copy and distribute copies of this Agreement,
but in order to avoid inconsistency the Agreement is copyrighted and
may only be modified in the following manner. The Agreement Steward
reserves the right to publish new versions (including revisions) of
this Agreement from time to time. No one other than the Agreement
Steward has the right to modify this Agreement. The Eclipse Foundation
is the initial Agreement Steward. The Eclipse Foundation may assign the
responsibility to serve as the Agreement Steward to a suitable separate
entity. Each new version of the Agreement will be given a distinguishing
version number. The Program (including Contributions) may always be
Distributed subject to the version of the Agreement under which it was
received. In addition, after a new version of the Agreement is published,
Contributor may elect to Distribute the Program (including its
Contributions) under the new version.
This Agreement is governed by the laws of the State of New York and the
intellectual property laws of the United States of America. No party to this
Agreement will bring a legal action under this Agreement more than one year
after the cause of action arose. Each party waives its rights to a jury trial in
any resulting litigation.
Except as expressly stated in Sections 2(a) and 2(b) above, Recipient
receives no rights or licenses to the intellectual property of any
Contributor under this Agreement, whether expressly, by implication,
estoppel or otherwise. All rights in the Program not expressly granted
under this Agreement are reserved. Nothing in this Agreement is intended
to be enforceable by any entity that is not a Contributor or Recipient.
No third-party beneficiary rights are created under this Agreement.
Exhibit A - Form of Secondary Licenses Notice
"This Source Code may also be made available under the following
Secondary Licenses when the conditions for such availability set forth
in the Eclipse Public License, v. 2.0 are satisfied: {name license(s),
version(s), and exceptions or additional permissions here}."
Simply including a copy of this Agreement, including this Exhibit A
is not sufficient to license the Source Code under Secondary Licenses.
If it is not possible or desirable to put the notice in a particular
file, then You may include the notice in a location (such as a LICENSE
file in a relevant directory) where a recipient would be likely to
look for such a notice.
You may add additional accurate notices of copyright ownership.
Apache License
@ -413,3 +488,7 @@ any resulting litigation.
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
SPDX-License-Identifier: EPL-2.0
SPDX-License-Identifier: Apache-2.0

View File

@ -1,41 +1,42 @@
==============================================================
Jetty Web Container
Copyright 1995-2019 Mort Bay Consulting Pty Ltd.
==============================================================
Notices for Eclipse Jetty
=========================
This content is produced and maintained by the Eclipse Jetty project.
The Jetty Web Container is Copyright Mort Bay Consulting Pty Ltd
unless otherwise noted.
Project home: https://www.eclipse.org/jetty/
Jetty is dual licensed under both
Trademarks
----------
Eclipse Jetty, and Jetty are trademarks of the Eclipse Foundation.
* The Apache 2.0 License
http://www.apache.org/licenses/LICENSE-2.0.html
Copyright
---------
All contributions are the property of the respective authors or of
entities to which copyright has been assigned by the authors (eg. employer).
and
Declared Project Licenses
-------------------------
This artifacts of this project are made available under the terms of:
* The Eclipse Public 1.0 License
http://www.eclipse.org/legal/epl-v10.html
* the Eclipse Public License v2.0
https://www.eclipse.org/legal/epl-2.0
SPDX-License-Identifier: EPL-2.0
Jetty may be distributed under either license.
or
------
Eclipse
* the Apache License, Version 2.0
https://www.apache.org/licenses/LICENSE-2.0
SPDX-License-Identifier: Apache-2.0
The following artifacts are EPL.
The following dependencies are EPL.
* org.eclipse.jetty.orbit:org.eclipse.jdt.core
The following artifacts are EPL and ASL2.
The following dependencies are EPL and ASL2.
* org.eclipse.jetty.orbit:javax.security.auth.message
The following artifacts are EPL and CDDL 1.0.
The following dependencies are EPL and CDDL 1.0.
* org.eclipse.jetty.orbit:javax.mail.glassfish
------
Oracle
The following artifacts are CDDL + GPLv2 with classpath exception.
The following dependencies are CDDL + GPLv2 with classpath exception.
https://glassfish.dev.java.net/nonav/public/CDDL+GPL.html
* javax.servlet:javax.servlet-api
@ -43,72 +44,46 @@ https://glassfish.dev.java.net/nonav/public/CDDL+GPL.html
* javax.transaction:javax.transaction-api
* javax.websocket:javax.websocket-api
------
Oracle OpenJDK
If ALPN is used to negotiate HTTP/2 connections, then the following
artifacts may be included in the distribution or downloaded when ALPN
module is selected.
* java.sun.security.ssl
These artifacts replace/modify OpenJDK classes. The modififications
are hosted at github and both modified and original are under GPL v2 with
classpath exceptions.
http://openjdk.java.net/legal/gplv2+ce.html
------
OW2
The following artifacts are licensed by the OW2 Foundation according to the
The following dependencies are licensed by the OW2 Foundation according to the
terms of http://asm.ow2.org/license.html
org.ow2.asm:asm-commons
org.ow2.asm:asm
* org.ow2.asm:asm-commons
* org.ow2.asm:asm
The following dependencies are ASL2 licensed.
------
Apache
* org.apache.taglibs:taglibs-standard-spec
* org.apache.taglibs:taglibs-standard-impl
The following artifacts are ASL2 licensed.
org.apache.taglibs:taglibs-standard-spec
org.apache.taglibs:taglibs-standard-impl
------
MortBay
The following artifacts are ASL2 licensed. Based on selected classes from
The following dependencies are ASL2 licensed. Based on selected classes from
following Apache Tomcat jars, all ASL2 licensed.
org.mortbay.jasper:apache-jsp
org.apache.tomcat:tomcat-jasper
org.apache.tomcat:tomcat-juli
org.apache.tomcat:tomcat-jsp-api
org.apache.tomcat:tomcat-el-api
org.apache.tomcat:tomcat-jasper-el
org.apache.tomcat:tomcat-api
org.apache.tomcat:tomcat-util-scan
org.apache.tomcat:tomcat-util
org.mortbay.jasper:apache-el
org.apache.tomcat:tomcat-jasper-el
org.apache.tomcat:tomcat-el-api
------
Mortbay
* org.mortbay.jasper:apache-jsp
* org.apache.tomcat:tomcat-jasper
* org.apache.tomcat:tomcat-juli
* org.apache.tomcat:tomcat-jsp-api
* org.apache.tomcat:tomcat-el-api
* org.apache.tomcat:tomcat-jasper-el
* org.apache.tomcat:tomcat-api
* org.apache.tomcat:tomcat-util-scan
* org.apache.tomcat:tomcat-util
* org.mortbay.jasper:apache-el
* org.apache.tomcat:tomcat-jasper-el
* org.apache.tomcat:tomcat-el-api
The following artifacts are CDDL + GPLv2 with classpath exception.
https://glassfish.dev.java.net/nonav/public/CDDL+GPL.html
org.eclipse.jetty.toolchain:jetty-servlet-api
* org.eclipse.jetty.toolchain:jetty-schemas
------
Assorted
Cryptography
------------
Content may contain encryption software. The country in which you are currently
may have restrictions on the import, possession, and use, and/or re-export to
another country, of encryption software. BEFORE using any encryption software,
please check the country's laws, regulations and policies concerning the import,
possession, or use, and re-export of encryption software, to see if this is
permitted.
The UnixCrypt.java code implements the one way cryptography used by
Unix systems for simple password protection. Copyright 1996 Aki Yoshida,

View File

@ -23,7 +23,7 @@ Documentation
Project documentation is available on the Jetty Eclipse website.
- [http://www.eclipse.org/jetty/documentation](http://www.eclipse.org/jetty/documentation)
- [https://www.eclipse.org/jetty/documentation](https://www.eclipse.org/jetty/documentation)
Building
========
@ -40,9 +40,9 @@ The first build may take a longer than expected as Maven downloads all the depen
The build tests do a lot of stress testing, and on some machines it is necessary to set the file descriptor limit to greater than 2048 for the tests to all pass successfully.
It is possible to bypass tests by building with `mvn -Dmaven.test.skip=true install` but note that this will not produce some of the test jars that are leveraged in other places in the build.
It is possible to bypass tests by building with `mvn clean install -DskipTests`.
Professional Services
---------------------
Expert advice and production support are available through [Webtide.com](http://webtide.com).
Expert advice and production support are available through [Webtide.com](https://webtide.com).

View File

@ -1,5 +1,168 @@
jetty-10.0.0-SNAPSHOT
jetty-10.0.0.alpha1 - 26 November 2019
+ 97 Permanent UnavailableException thrown during servlet request handling
should cause servlet destroy
+ 137 Support OAuth
+ 155 No way to set keystore for JSR 356 websocket clients, needed for SSL
client authentication
+ 250 Implement HTTP CONNECT for HTTP/2
+ 995 UrlEncoded.encodeString should skip more characters
+ 1036 Allow easy configuration of Scheduler-Threads and name them more
appropriate
+ 1485 Add systemd service file
+ 1743 Refactor jetty maven plugin goals to be more orthogonal
+ 2266 Jetty maven plugin reload is triggered each time the
`scanIntervalSeconds` pass
+ 2340 Remove raw ServletHandler usage examples from documentation
+ 2429 Review HttpClient backpressure semantic
+ 2578 Use addEventListener(EventListener listener)
+ 2709 current default for headerCacheSize is not large enough for many
requests
+ 2815 hpack fields are opaque octets
+ 3040 Allow RFC6265 Cookies to include optional SameSite attribute.
+ 3083 The ini-template for jetty.console-capture.dir does not match the
default value
+ 3106 Websocket connection stats and request stats
+ 3558 Error notifications can be received after a successful websocket close
+ 3601 HTTP2 stall on reset streams
+ 3705 Review ClientUpgradeRequest exception handling
+ 3734 websocket suspend when input closed
+ 3747 Make Jetty Demo work with JPMS
+ 3787 Jetty client sometimes returns EOFException instead of
SSLHandshakeException on certificate errors.
+ 3804 Weld/CDI XML backwards compat?
+ 3806 Error Page handling Async race with ProxyServlet
+ 3822 trustAll will not work on some servers
+ 3829 Avoid sending empty trailer frames for http/2 responses
+ 3840 Byte-range request performance problems with large files
+ 3856 Different behaviour with maxFormContentSize=0 if Content-Length header
is present/missing
+ 3863 Enforce use of SNI
+ 3869 Update to ASM 7.2 for jdk 13
+ 3872 Review exposure of JavaxWebSocketServletContainerInitializer
+ 3876 WebSocketPartialListener is only called for initial frames, not for
continuation frames
+ 3884 @WebSocket without @OnWebSocketMessage handler fails when receiving a
continuation frame
+ 3888 BufferUtil.toBuffer(Resource resource,boolean direct) does not like
large (4G+) Resources
+ 3906 Fix for #3840 breaks Path encapsulation in PathResource
+ 3913 Clustered HttpSession IllegalStateException: Invalid for read
+ 3929 Deadlock between new HTTP2Connection() and Server.stop()
+ 3936 Race condition when modifying session + sendRedirect()
+ 3940 Double initialization of Log
+ 3951 Consider adding demand API to HTTP/2
+ 3952 Server configuration for direct/heap ByteBuffers
+ 3956 Remove and warn on use of illegal HTTP/2 response headers
+ 3957 CustomRequestLog bad usage of MethodHandles.lookup()
+ 3960 Fix HttpConfiguration copy constructor
+ 3964 Improve efficiency of listeners
+ 3968 WebSocket sporadic ReadPendingException using suspend/resume
+ 3969 X-Forwarded-Port header customization isn't possible
+ 3978 HTTP/2 fixes for robustly handling abnormal traffic and resource
exhaustion
+ 3983 JarFileResource incorrectly lists the contents of directories with
spaces
+ 3985 Improve lenient Cookie parsing
+ 3989 Inform custom ManagedSelector of dead selector via optional
onFailedSelect()
+ 4000 Add SameFileAliasChecker to help with FileSystem static file access
normalization on Mac and Windows
+ 4003 Quickstart broken in jetty-10
+ 4007 Getting NullPointerException while trying to run jetty start.run on
Windows
+ 4009 ServletContextHandler setSecurityHandler broke handler chain
+ 4020 Revert WebSocket ExtensionFactory change to interface
+ 4022 Servlet which is added by ServletRegistration can't be started
+ 4025 Provide more write-through behaviours for DefaultSessionCache
+ 4027 Ensure AbstractSessionDataStore cannot be used unless it is started
+ 4033 Ignore bad percent encodings in paths during
URIUtil.equalsIgnoreEncodings()
+ 4047 Gracefully stopped Jetty not flushing all response data
+ 4048 Multiple values in X-Forwarded-Port throw NumberFormatException
+ 4057 NullPointerException in o.e.j.h.HttpFields
+ 4058 Review Locker
+ 4064 java.lang.NullPointerException initializing embedded servlet
+ 4075 Do not fail on servlet-mapping with url-pattern /On*
+ 4076 Restarting quickstarted webapp throws IllegalStateException:
ServletContainerInitializersStarter already exists
+ 4082 Debug logging causes NullPointerException in client
+ 4084 Use of HttpConfiguration.setBlockingTimeout(long) in jetty.xml produces
warning on jetty-home startup
+ 4096 Thread in ReservedThreadExecutor does not exit when stopped
+ 4104 Frames are sent through ExtensionStack even if WebSocket Session is
closed
+ 4105 QueuedThreadPool increased thread usage and no idle thread decay
+ 4113 HttpClient fails with JDK 13 and TLS 1.3
+ 4115 Drop HTTP/2 pseudo headers
+ 4121 QueuedThreadPool should support ThreadFactory behaviors
+ 4122 QueuedThreadPool should reset thread interrupted on failed run
+ 4124 Run websocket autobahn tests with jetty and javax apis instead of just
with core.
+ 4128 OpenIdCredentials can't decode JWT ID token
+ 4132 Should be possible to use OIDC without metadata
+ 4138 OpenID module should use HttpClient instead of HttpURLConnection
+ 4141 ClassCastException with non-async Servlet + async Filter +
HttpServletRequestWrapper
+ 4142 Configurable HTTP/2 RateControl
+ 4144 Naked cast to Request should be avoided
+ 4150 Module org.eclipse.jetty.alpn.client not found, required by
org.eclipse.jetty.proxy
+ 4152 WebSocket autoFragment does not fragment based on maxFrameSize
+ 4156 IllegalStateException when forwarding to jsp with new session
+ 4161 Regression: EofException: request lifecycle violation
+ 4170 Client-side alias selection based on SSLEngine
+ 4173 NullPointerException warning in log from WebInfConfiguration after
upgrade
+ 4174 ConcurrentModificationException when stopping jetty:run-war
+ 4176 Should not set header if sendError has been called
+ 4177 Configure HTTP proxy with SslContextFactory
+ 4179 Improve HttpChannel$SendCallback references for GC
+ 4183 Jetty considers bootstrap injected class to be a "server class"
+ 4188 Spin in HttpOutput.close
+ 4190 Jetty hangs after thread blocked in SharedBlockingCallback.block()
called by HttpOutput.close
+ 4191 Increase GzipHandler minGzipSize default value
+ 4193 InetAccessHandler - new includeConnectors/excludeConnectors not quite
correct anymore
+ 4201 Throw SSLHandshakeException in case of TLS handshake failures
+ 4203 Some Transfer-Encoding and Content-Length combinations do not result in
expected 400 Bad Request
+ 4204 Transfer-Encoding behavior does not follow RFC7230
+ 4208 304 response with Content-Length fails, not conform to RFC7230
+ 4209 Unused TLS connection is not closed in Java 11
+ 4217 SslConnection.DecryptedEnpoint.flush eternal busy loop
+ 4222 Major/Minor Version wrong (jetty 10 is servlet 4)
+ 4227 First authorization request produced by OIDC module fails due to
inclusion of sessionid
+ 4236 clean up redirect code calculation for OpenIdAuthenticator
+ 4237 simplify openid module configuration
+ 4240 CGI form post results in 500 response if no character encoding
+ 4243 ErrorHandler produces invalid json error response
+ 4247 Cookie security attributes are going to mandated by Google Chrome
+ 4248 Websocket client UpgradeListener never reports success
+ 4251 Http 2.0 clients cannot upgrade protocol
+ 4258 RateControl should be per-connection
+ 4264 Spring Boot BasicErrorController no longer invoked
+ 4265 HttpChannel SEND_ERROR should use ErrorHandler.doError()
+ 4277 Reading streamed gzipped body never terminates
+ 4279 Regression: ResponseWriter#close blocks indefinitely
+ 4282 Review HttpParser handling in case of no content
+ 4283 Wrong package for OpenJDK8ClientALPNProcessor
+ 4284 Possible NullPointerException in Main.java when stopped from command
line
+ 4287 Move getUriLastPathSegment(URI uri) to URIUtil
+ 4296 Unable to create WebSocket connect if the query string of the URL has %
symbol.
+ 4301 Demand beforeContent is not forwarded
+ 4305 Jetty server ALPN shall alert fatal no_application_protocol if no
client application protocol is supported
+ 4325 Deprecate SniX509ExtendedKeyManager constructor without
SslContextFactory$Server
+ 4334 Better test ErrorHandler changes
+ 4342 OpenID module cannot create HttpClient in Jetty 10
jetty-10.0.0-alpha0 - 11 July 2019
+ 113 Add support for NCSA Extended Log File Format
+ 114 Bring back overlay deployer
@ -7,7 +170,7 @@ jetty-10.0.0-alpha0 - 11 July 2019
+ 207 Support javax.websocket version 1.1
+ 215 Add Conscrypt for native ALPN/TLS/SSL
+ 300 Implement Deflater / Inflater Object Pool
+ 482 [jetty-osgi] The CCL while parsing the xml files should be set to a
+ 482 jetty-osgi] The CCL while parsing the xml files should be set to a
combination of Jetty and Bundle-Classloader
+ 592 Support no-value Host header in HttpParser
+ 632 JMX tests rely on fixed port
@ -77,8 +240,9 @@ jetty-10.0.0-alpha0 - 11 July 2019
+ 2061 WebSocket hangs in blockingWrite
+ 2075 Deprecating MultiException
+ 2095 Remove FastCGI multiplexing
+ 2103 Server should open connectors early in start sequence
+ 2103 Server should open connectors early in start sequence
+ 2108 Update licence headers and plugin for 2018
+ 2140 Infinispan and hazelcast changes to scavenge zombie expired sessions
+ 2172 Support javax.websocket 1.1
+ 2175 Refactor WebSocket close handling
+ 2191 JPMS Support
@ -91,13 +255,12 @@ jetty-10.0.0-alpha0 - 11 July 2019
+ 2978 Add module-info.java to relevant Jetty modules
+ 2983 Jetty 10 Configuration abstraction
+ 2985 Jetty 10 Configuration replacement algorithm incorrect
+ 2996 ContextHandler.setDefaultContextPath() not implemented for quickstart.
+ 2996 ContextHandler.setDefaultContextPath() not implemented for quickstart
+ 3009 Update Jetty 10 to use non-LEGACY Compliance Modes
+ 3010 Move old MultiPart parsing implementation to jetty-http
+ 3011 Move HttpCompliance to HttpConfiguration
+ 3012 Refactor HttpCompliance and HttpComplianceSection to be friendlier to
customization
+ 3106 Websocket connection stats and request stats
+ 3129 javax-websocket-common pom.xml is wrong
+ 3139 NPE on
WebSocketServerContainerInitializer.configureContext(ServletContextHandler)
@ -114,7 +277,7 @@ jetty-10.0.0-alpha0 - 11 July 2019
+ 3197 Use jetty specific websocket API jar
+ 3213 MetaInfConfigurationTest tests disabled in jetty-10.0.x
+ 3216 Autobahn WebSocketServer failures in jetty 10
+ 3225 Response.sendError should not set reason.
+ 3225 Response.sendError should not set reason
+ 3246 javax-websocket-tests exception stacktraces
+ 3249 Update to apache jasper 9.0.14 for jetty-10
+ 3274 OSGi versions of java.base classes in
@ -122,7 +285,7 @@ jetty-10.0.0-alpha0 - 11 July 2019
+ 3279 WebSocket write may hang forever
+ 3288 Correct websocket artifactIds on jetty-10.0.x
+ 3290 async websocket onOpen, onError and onClose in 10.0.x
+ 3298 Review jetty-10 websocket CompletableFuture usage.
+ 3298 Review jetty-10 websocket CompletableFuture usage
+ 3303 Update to jakarta ee javax artifacts for jetty-10
+ 3308 Remove deprecated methods from sessions
+ 3320 Review Jetty 10 module-info.java
@ -156,7 +319,7 @@ jetty-10.0.0-alpha0 - 11 July 2019
+ 3648 javax.websocket client container incorrectly creates Server
SslContextFactory
+ 3661 JettyWebSocketServerContainer exposes websocket common classes
+ 3666 WebSocket - Handling sent 1009 close frame.
+ 3666 WebSocket - Handling sent 1009 close frame
+ 3696 Unwrap JavaxWebSocketClientContainer.connectToServer() exceptions
+ 3698 Missing WebSocket ServerContainer after server restart
+ 3700 stackoverflow in WebAppClassLoaderUrlStreamTest
@ -191,8 +354,256 @@ jetty-10.0.0-alpha0 - 11 July 2019
+ 3840 Byte-range request performance problems with large files
+ 3849 ClosedChannelException from jetty-test-webapp javax websocket chat
example
+ 467246 null
+ jetty-10 null
jetty-9.4.27.v20200227 - 27 February 2020
+ 3247 Generate jetty-maven-plugin website
+ 4247 Cookie security attributes are going to mandated by Google Chrome
+ 4360 Upgrade to Apache Jasper 8.5.49
+ 4475 WebSocket JSR356 implementation not honoring javadoc of MessageHandler
on Whole<Reader>
+ 4495 Review ReservedThreadExecutor's concurrency model
+ 4504 X-Forwarded-Server header overwrites X-Forwarded-Host
+ 4520 Jetty jdbc session manager causing exceptions for violating primary key
in inserting session in the table
+ 4529 ErrorHandler showing servlet info, can not be disabled unless
overriding most of its functionality
+ 4533 Reinstate hard close in dispatcher
+ 4537 High CPU on Jetty Websocket thread
+ 4541 Jetty server always allocates maximum response header size
+ 4550 XmlConfiguration constructor selection based on number of arguments
+ 4567 Jetty logging supporting Throwable as last argument
+ 4573 Order dependency of X-Forwarded-Host and X-Forwarded-Port
+ 4575 Stopping ReservedThreadExecutor may hang
+ 4577 request getPathInfo returns null
+ 4594 ServletContextListeners added to destroyServletContextListeners in
ContextHandler::startContext() are not removed by
ContextHandler::removeEventListener()
+ 4606 DateCache.formatNow(long now) does not honor the passed in long
+ 4612 ReservedThreadExecutor hangs when the last reserved thread idles out
jetty-9.4.26.v20200117 - 17 January 2020
+ 2620 Exception from user endpoint onClose results in unclosed
WebSocketSession
+ 4383 Errors deleting multipart tmp files java.lang.NullPointerException
under heavy load
+ 4444 TLS Connection Timeout Intermittently
+ 4461 IllegalStateException in HttpOutput with Jersey
jetty-9.4.25.v20191220 - 20 December 2019
+ 995 UrlEncoded.encodeString should skip more characters
+ 2195 Add parameter expansion to start.jar --exec parameters
+ 3512 File descriptor is not released after zip file uploaded via
jetty-client
+ 3730 WebSocketClient constructor cleanup (and deprecations)
+ 4269 ResponseWriter should not throw RuntimeIOExceptions
+ 4323 QOS Filter does not handle IllegalStateException and never releases
passes
+ 4329 rewrite prevents URL session tracking.
+ 4331 Improve handling of HttpOutput.close() for pending writes
+ 4350 Deprecated MultiPartInputStreamParser still used in jetty-server
(MultiPartsUtilParser) but OSGi ExportPackage suppressed
+ 4351 Servlet.service called before Servlet.init is finished when servlet is
lazily initialized
+ 4363 jetty-maven-plugin no longer processes supplied context.xml-file.
+ 4366 HTTP client uses SOCKS4 proxy hostname for SSL hostname verification
+ 4374 Jetty client: Response.AsyncContentListener.onContent is not called
+ 4376 Async Content Complete bug results in
org.eclipse.jetty.io.EofException: Async closed
+ 4385 Limit new UnsupportedOperationException to direct base class
SslContextFactory usage
+ 4392 Suppress logging of QuietException in HttpChannelState.asyncError()
+ 4402 NPE in JettyRunWarExplodedMojo
+ 4411 Jetty server spins on incomplete request due to delayed dispatch
until content
+ 4415 GzipHandler invalid input zip size on large
(over 2,147,483,647 bytes) request body content
+ 4421 HttpClient support for PROXY protocol
+ 4427 Retried HttpClient Requests can result in duplicates cookies
jetty-9.4.24.v20191120 - 20 November 2019
+ 3083 The ini-template for jetty.console-capture.dir does not match the
default value
+ 4128 OpenIdCredetials can't decode JWT ID token
+ 4334 Better test ErrorHandler changes
jetty-9.4.23.v20191118 - 18 November 2019
+ 1485 Add systemd service file
+ 2266 Jetty maven plugin reload is triggered each time the
`scanIntervalSeconds` pass
+ 2340 Remove raw ServletHandler usage examples from documentation
+ 2709 current default for headerCacheSize is not large enough for many
requests
+ 3863 Enforce use of SNI
+ 3869 Update to ASM 7.2 for jdk 13
+ 4033 Ignore bad percent encodings in paths during
URIUtil.equalsIgnoreEncodings()
+ 4138 OpenID module should use HttpClient instead of HttpURLConnection
+ 4156 IllegalStateException when forwarding to jsp with new session
+ 4161 Regression: EofException: request lifecycle violation
+ 4173 NullPointerException warning in log from WebInfConfiguration after
upgrade
+ 4217 SslConnection.DecryptedEnpoint.flush eternal busy loop
+ 4236 clean up redirect code calculation for OpenIdAuthenticator
+ 4237 simplify openid module configuration
+ 4240 CGI form post results in 500 response if no character encoding
+ 4243 ErrorHandler produces invalid json error response
+ 4247 Cookie security attributes are going to mandated by Google Chrome
+ 4248 Websocket client UpgradeListener never reports success
+ 4251 Http 2.0 clients cannot upgrade protocol
+ 4258 RateControl should be per-connection
+ 4264 Spring Boot BasicErrorController no longer invoked
+ 4265 HttpChannel SEND_ERROR should use ErrorHandler.doError()
+ 4277 Reading streamed gzipped body never terminates
+ 4279 Regression: ResponseWriter#close blocks indefinitely
+ 4282 Review HttpParser handling in case of no content
+ 4283 Wrong package for OpenJDK8ClientALPNProcessor
+ 4284 Possible NullPointerException in Main.java when stopped from command
line
+ 4287 Move getUriLastPathSegment(URI uri) to URIUtil
+ 4296 Unable to create WebSocket connect if the query string of the URL has %
symbol.
+ 4301 Demand beforeContent is not forwarded
+ 4305 Jetty server ALPN shall alert fatal no_application_protocol if no
client application protocol is supported
+ 4325 Deprecate SniX509ExtendedKeyManager constructor without
SslContextFactory$Server
jetty-9.4.22.v20191022 - 22 October 2019
+ 2429 HttpClient backpressure improved
+ 3558 Error notifications can be received after a successful websocket
+ 3787 Jetty client sometimes returns EOFException instead of
SSLHandshakeException on certificate errors.
+ 3913 Clustered HttpSession IllegalStateException: Invalid for read
+ 3989 Inform custom ManagedSelector of dead selector via optional
onFailedSelect()
+ 4096 Thread in ReservedThreadExecutor does not exit when stopped
+ 4104 Frames are sent through ExtensionStack even if WebSocket Session is
closed
+ 4105 QueuedThreadPool increased thread usage and no idle thread decay
+ 4115 Drop HTTP/2 pseudo headers
+ 4121 QueuedThreadPool should support ThreadFactory behaviors
+ 4122 QueuedThreadPool should reset thread interrupted on failed run
+ 4128 OpenIdCredetials can't decode JWT ID token
+ 4132 Should be possible to use OIDC without metadata
+ 4141 ClassCastException with non-async Servlet + async Filter +
HttpServletRequestWrapper
+ 4142 Configurable HTTP/2 RateControl
+ 4144 Naked cast to Request should be avoided
+ 4156 IllegalStateException when forwarding to jsp with new session
+ 4158 Behaviour change in session handling in 9.4.21.v20190926
+ 4170 Client-side alias selection based on SSLEngine
+ 4174 ConcurrentModificationException when stopping jetty:run-war
+ 4176 Should not set header if sendError has been called
+ 4177 Configure HTTP proxy with SslContextFactory
+ 4179 Improve HttpChannel$SendCallback references for GC
+ 4183 Jetty considers bootstrap injected class to be a "server class"
+ 4188 Spin in HttpOutput.close
+ 4190 Jetty hangs after thread blocked in SharedBlockingCallback.block()
called by HttpOutput.close
+ 4191 Increase GzipHandler minGzipSize default size
+ 4193 InetAccessHandler - new includeConnectors/excludeConnectors not quite
correct anymore
+ 4201 Throw SSLHandshakeException in case of TLS handshake failures
+ 4203 Some Transfer-Encoding and Content-Length combinations do not result in
expected 400 Bad Request
+ 4204 Transfer-Encoding behavior does not follow RFC7230
+ 4208 Regression in Jetty 9.4.21: 304 response with Content-Length fails
+ 4209 Unused TLS connection is not closed in Java 11
+ 4217 SslConnection.DecryptedEnpoint.flush eternal busy loop
+ 4227 First authorization request produced by OIDC module fails due to
inclusion of sessionid
jetty-9.4.21.v20190926 - 26 September 2019
+ 97 Permanent UnavailableException thrown during servlet request handling
should cause servlet destroy
+ 137 Support OAuth
+ 155 No way to set keystore for JSR 356 websocket clients, needed for SSL
client authentication
+ 1036 Allow easy configuration of Scheduler-Threads and name them more
appropriate
+ 2815 HPack fields are opaque octets
+ 3040 Allow RFC6265 Cookies to include optional SameSite attribute
+ 3106 WebSocket connection stats and request stats
+ 3734 WebSocket suspend when input closed
+ 3747 Make Jetty Demo work with JPMS
+ 3806 Error Page handling Async race with ProxyServlet
+ 3913 Clustered HttpSession IllegalStateException: Invalid for read
+ 3936 Race condition when modifying session + sendRedirect()
+ 3956 Remove and warn on use of illegal HTTP/2 response headers
+ 3964 Improve efficiency of listeners
+ 3968 WebSocket sporadic ReadPendingException using suspend/resume
+ 3978 HTTP/2 fixes for robustly handling abnormal traffic and resource
exhaustion
+ 3983 JarFileResource incorrectly lists the contents of directories with
spaces
+ 3985 Improve lenient Cookie parsing
+ 3989 Inform custom ManagedSelector of dead selector via optional
onFailedSelect()
+ 4000 Add SameFileAliasChecker to help with FileSystem static file access
normalization on Mac and Windows
+ 4007 NullPointerException while trying to run jetty start.run on Windows
+ 4009 ServletContextHandler setSecurityHandler broke handler chain
+ 4020 Revert WebSocket ExtensionFactory change to interface
+ 4022 Servlet which is added by ServletRegistration can't be started
+ 4025 Provide more write-through behaviours for DefaultSessionCache
+ 4027 Ensure AbstractSessionDataStore cannot be used unless it is started
+ 4033 Ignore bad percent encodings in paths during
URIUtil.equalsIgnoreEncodings()
+ 4047 Gracefully stopped Jetty not flushing all response data
+ 4048 Multiple values in X-Forwarded-Port throw NumberFormatException
+ 4057 NullPointerException in o.e.j.h.HttpFields
+ 4064 NullPointerException initializing embedded servlet
+ 4075 Do not fail on servlet-mapping with url-pattern /On*
+ 4082 NullPointerExceptoin while Debug logging in client
+ 4084 Use of HttpConfiguration.setBlockingTimeout(long) in jetty.xml produces
warning on jetty-home startup
+ 4105 Cleanup of Idle thread count in QueuedThreadPool
+ 4113 HttpClient fails with JDK 13 and TLS 1.3
jetty-9.4.20.v20190813 - 13 August 2019
+ 300 Implement Deflater / Inflater Object Pool
+ 2061 WebSocket hangs in blockingWrite
+ 3601 HTTP2 stall on reset streams
+ 3648 javax.websocket client container incorrectly creates Server
SslContextFactory
+ 3698 Missing WebSocket ServerContainer after server restart
+ 3700 stackoverflow in WebAppClassLoaderUrlStreamTest
+ 3708 Swap various java.lang.String replace() methods for better performant
ones
+ 3731 Add testing of CDI behaviors
+ 3736 NPE from WebAppClassLoader during CDI
+ 3746 ClassCastException in WriteFlusher.java - IdleState cannot be cast to
FailedState
+ 3749 Memory leak while processing AsyncListener annotations
+ 3755 ServerWithAnnotations doesn't do anything
+ 3758 Avoid sending empty trailer frames for http/2 requests
+ 3782 X-Forwarded-Port overrides X-Forwarded-For
+ 3786 ALPN support for Java 14
+ 3798 ClasspathPattern match method throws NPE. URI can be null
+ 3799 Programmatically added listeners from
ServletContextListener.contextInitialzed() are not called
+ 3804 Weld/CDI XML backwards compat
+ 3805 XmlConfiguration odd behavior for numbers
+ 3806 The error page handler didn't process correctly in proxy
+ 3815 PropertyFileLoginModule adds user principle as a role
+ 3822 trustAll will not work on some servers
+ 3829 Avoid sending empty trailer frames for http/2 responses
+ 3835 WebSocketSession are not being stopped properly
+ 3840 Byte-range request performance problems with large files
+ 3856 Different behaviour with maxFormContentSize=0 if Content-Length header
is present/missing
+ 3876 WebSocketPartialListener is only called for initial frames, not for
continuation frames
+ 3884 @WebSocket without @OnWebSocketMessage handler fails when receiving a
continuation frame
+ 3888 BufferUtil.toBuffer(Resource resource,boolean direct) does not like
large (4G+) Resources
+ 3906 Fix for #3840 breaks Path encapsulation in PathResource
+ 3929 Deadlock between new HTTP2Connection() and Server.stop()
+ 3940 Double initialization of Log
+ 3957 CustomRequestLog bad usage of MethodHandles.lookup()
+ 3960 Fix HttpConfiguration copy constructor
+ 3969 X-Forwarded-Port header customization isn't possible
jetty-9.4.19.v20190610 - 10 June 2019
+ 2909 Remove B64Code
@ -246,6 +657,7 @@ jetty-9.4.18.v20190429 - 29 April 2019
+ 3609 Fix infinispan start module dependencies
jetty-9.4.17.v20190418 - 18 April 2019
+ 2140 Infinispan and hazelcast changes to scavenge zombie expired sessions
+ 3464 Split SslContextFactory into Client and Server
+ 3549 Directory Listing on Windows reveals Resource Base path
+ 3555 DefaultHandler Reveals Base Resource Path of each Context
@ -323,6 +735,11 @@ jetty-9.4.15.v20190215 - 15 February 2019
+ 3350 Do not expect to be able to connect to https URLs with the HttpClient
created from a parameterless constructor
jetty-9.3.28.v20191105 - 05 November 2019
+ 3989 Inform custom ManagedSelector of dead selector via optional
onFailedSelect()
+ 4217 SslConnection.DecryptedEnpoint.flush eternal busy loop
jetty-9.3.27.v20190418 - 18 April 2019
+ 3549 Directory Listing on Windows reveals Resource Base path
+ 3555 DefaultHandler Reveals Base Resource Path of each Context
@ -335,6 +752,9 @@ jetty-9.3.26.v20190403 - 03 April 2019
ForwardedRequestCustomizer
+ 3319 Allow reverse sort for directory listed files
jetty-9.2.29.v20191105 - 05 November 2019
+ 4217 SslConnection.DecryptedEnpoint.flush eternal busy loop
jetty-9.2.28.v20190418 - 18 April 2019
+ 3549 Directory Listing on Windows reveals Resource Base path
+ 3555 DefaultHandler Reveals Base Resource Path of each Context

View File

@ -183,12 +183,12 @@
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>javax-websocket-server</artifactId>
<artifactId>websocket-javax-server</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>jetty-websocket-client</artifactId>
<artifactId>websocket-jetty-client</artifactId>
<version>${project.version}</version>
</dependency>
<!-- http/2 support -->

View File

@ -113,7 +113,7 @@
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>javax-websocket-server</artifactId>
<artifactId>websocket-javax-server</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>

View File

@ -63,6 +63,10 @@
</build>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-util</artifactId>
@ -101,6 +105,11 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-slf4j-impl</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.toolchain</groupId>
<artifactId>jetty-test-helper</artifactId>

View File

@ -1,19 +1,19 @@
//
// ========================================================================
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
import javax.servlet.ServletContainerInitializer;
@ -31,6 +31,7 @@ module org.eclipse.jetty.apache.jsp
requires jetty.servlet.api;
requires org.eclipse.jetty.util;
requires org.mortbay.apache.jasper;
requires org.slf4j;
provides Log with JuliLog;
provides ServletContainerInitializer with JettyJasperInitializer;

View File

@ -1,19 +1,19 @@
//
// ========================================================================
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.apache.jsp;
@ -54,27 +54,18 @@ public class JettyJasperInitializer extends JasperInitializer
super(context, namespaceAware, validation, blockExternal);
}
/**
* @see org.apache.jasper.servlet.TldScanner#scan()
*/
@Override
public void scan() throws IOException, SAXException
{
return; //do nothing
}
/**
* @see org.apache.jasper.servlet.TldScanner#getListeners()
*/
@Override
public List<String> getListeners()
{
return Collections.emptyList();
}
/**
* @see org.apache.jasper.servlet.TldScanner#scanJars()
*/
@Override
public void scanJars()
{

View File

@ -1,19 +1,19 @@
//
// ========================================================================
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.apache.jsp;
@ -48,9 +48,6 @@ public class JettyTldPreScanned extends TldPreScanned
_jettyPreScannedURLs = preScannedTlds;
}
/**
* @see org.apache.jasper.servlet.TldPreScanned#scanJars()
*/
@Override
public void scanJars()
{

View File

@ -1,23 +1,25 @@
//
// ========================================================================
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.apache.jsp;
import org.slf4j.LoggerFactory;
public class JuliLog implements org.apache.juli.logging.Log
{
public static org.apache.juli.logging.Log getInstance(String name)
@ -25,19 +27,16 @@ public class JuliLog implements org.apache.juli.logging.Log
return new JuliLog(name);
}
private final org.eclipse.jetty.util.log.Logger _logger;
private final org.eclipse.jetty.util.log.StdErrLog _stdErrLog;
private final org.slf4j.Logger _logger;
public JuliLog()
{
_logger = org.eclipse.jetty.util.log.Log.getRootLogger();
_stdErrLog = (_logger instanceof org.eclipse.jetty.util.log.StdErrLog) ? (org.eclipse.jetty.util.log.StdErrLog)_logger : null;
_logger = LoggerFactory.getLogger("");
}
public JuliLog(String name)
{
_logger = org.eclipse.jetty.util.log.Log.getLogger(name);
_stdErrLog = (_logger instanceof org.eclipse.jetty.util.log.StdErrLog) ? (org.eclipse.jetty.util.log.StdErrLog)_logger : null;
_logger = LoggerFactory.getLogger(name);
}
@Override
@ -49,31 +48,31 @@ public class JuliLog implements org.apache.juli.logging.Log
@Override
public boolean isErrorEnabled()
{
return _stdErrLog == null ? true : _stdErrLog.getLevel() <= org.eclipse.jetty.util.log.StdErrLog.LEVEL_WARN;
return _logger.isErrorEnabled();
}
@Override
public boolean isFatalEnabled()
{
return _stdErrLog == null ? true : _stdErrLog.getLevel() <= org.eclipse.jetty.util.log.StdErrLog.LEVEL_WARN;
return _logger.isErrorEnabled();
}
@Override
public boolean isInfoEnabled()
{
return _stdErrLog == null ? true : _stdErrLog.getLevel() <= org.eclipse.jetty.util.log.StdErrLog.LEVEL_INFO;
return _logger.isInfoEnabled();
}
@Override
public boolean isTraceEnabled()
{
return _stdErrLog == null ? true : _stdErrLog.getLevel() <= org.eclipse.jetty.util.log.StdErrLog.LEVEL_DEBUG;
return _logger.isTraceEnabled();
}
@Override
public boolean isWarnEnabled()
{
return _stdErrLog == null ? true : _stdErrLog.getLevel() <= org.eclipse.jetty.util.log.StdErrLog.LEVEL_WARN;
return _logger.isWarnEnabled();
}
@Override

View File

@ -1,19 +1,19 @@
//
// ========================================================================
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.jsp;

View File

@ -1,19 +1,19 @@
//
// ========================================================================
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.jsp;
@ -62,9 +62,6 @@ public class TestJettyJspServlet
super();
}
/**
* @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
{

View File

@ -1,19 +1,19 @@
//
// ========================================================================
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.jsp;

View File

@ -1,19 +1,19 @@
//
// ========================================================================
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.jsp;

View File

@ -1,19 +1,19 @@
//
// ========================================================================
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.jstl;

View File

@ -1,19 +1,19 @@
//
// ========================================================================
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.jstl;

View File

@ -1,19 +1,19 @@
//
// ========================================================================
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.jstl;

View File

@ -1,3 +1,3 @@
org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog
# Jetty Logging using jetty-slf4j-impl
# org.eclipse.jetty.LEVEL=INFO
# org.eclipse.jetty.util.LEVEL=DEBUG

View File

@ -347,7 +347,7 @@
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.wrap_before_string_concatenation" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_between_import_groups" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.lineSplit" value="128"/>
<setting id="org.eclipse.jdt.core.formatter.lineSplit" value="512"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch" value="insert"/>
</profile>

View File

@ -1,4 +1,4 @@
<code_scheme name="Jetty-StyleChecked" version="173">
<code_scheme name="Jetty" version="173">
<option name="AUTODETECT_INDENTS" value="false" />
<option name="LINE_SEPARATOR" value="&#xA;" />
<option name="RIGHT_MARGIN" value="128" />
@ -9,7 +9,6 @@
<option name="HTML_ATTRIBUTE_WRAP" value="0" />
</HTMLCodeStyleSettings>
<JavaCodeStyleSettings>
<option name="FIELD_NAME_PREFIX" value="_" />
<option name="USE_EXTERNAL_ANNOTATIONS" value="true" />
<option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="999" />
<option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="999" />
@ -67,9 +66,11 @@
<option name="WHILE_ON_NEW_LINE" value="true" />
<option name="CATCH_ON_NEW_LINE" value="true" />
<option name="FINALLY_ON_NEW_LINE" value="true" />
<option name="ALIGN_MULTILINE_PARAMETERS" value="true" />
<option name="ALIGN_MULTILINE_ARRAY_INITIALIZER_EXPRESSION" value="true" />
<option name="SPACE_AFTER_TYPE_CAST" value="false" />
<option name="RESOURCE_LIST_WRAP" value="2" />
<option name="KEEP_SIMPLE_METHODS_IN_ONE_LINE" value="false" />
<option name="KEEP_SIMPLE_LAMBDAS_IN_ONE_LINE" value="true" />
<option name="KEEP_SIMPLE_CLASSES_IN_ONE_LINE" value="true" />
<option name="ARRAY_INITIALIZER_WRAP" value="1" />
@ -80,6 +81,7 @@
<option name="FOR_BRACE_FORCE" value="3" />
<indentOptions>
<option name="CONTINUATION_INDENT_SIZE" value="4" />
<option name="USE_RELATIVE_INDENTS" value="false" />
</indentOptions>
<arrangement>
<rules>

View File

@ -4,18 +4,70 @@
<artifactId>build-resources</artifactId>
<version>10.0.0-SNAPSHOT</version>
<name>Jetty :: Build Resources</name>
<packaging>jar</packaging>
<build>
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
</resource>
<resource>
<directory>${project.basedir}/../</directory>
<includes>
<include>LICENSE</include>
<include>NOTICE.txt</include>
</includes>
<targetPath>META-INF</targetPath>
</resource>
</resources>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<!-- No point building javadoc for this project -->
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-remote-resources-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<id>create-shared-resources</id>
<phase>process-resources</phase>
<goals>
<goal>bundle</goal>
</goals>
<configuration>
<resourcesDirectory>${project.build.outputDirectory}</resourcesDirectory>
<includes>
<include>META-INF/LICENSE</include>
<include>META-INF/NOTICE.txt</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<configuration>
<!-- we would prefer not deploy it but we need as it's not discovered as part of reactor
as it's a dependency of a plugin
<skip>true</skip>
-->
</configuration>
</plugin>
</plugins>

View File

@ -14,12 +14,6 @@
<property name="fileExtensions" value="java"/>
<!-- reference to suppressions filter for both eclipse and intellij checkstyle plugins -->
<module name="SuppressionFilter">
<property name="file" value="${checkstyle.suppressions.file}"/>
<property name="optional" value="true"/>
</module>
<!-- Excludes all 'module-info.java' files -->
<!-- See https://checkstyle.org/config_filefilters.html -->
<module name="BeforeExecutionExclusionFileFilter">
@ -33,22 +27,16 @@
</module>
<module name="TreeWalker">
<!--
Eclipse Jetty Specific.
===========================================================================================
-->
<module name="SuppressionCommentFilter">
<property name="offCommentFormat" value="@checkstyle-disable-check : ([\w\|]+)"/>
<property name="onCommentFormat" value="@checkstyle-enable-check : ([\w\|]+)"/>
<property name="checkFormat" value="$1"/>
</module>
<!-- Check abbreviations(consecutive capital letters) length in identifier name -->
<module name="AbbreviationAsWordInName">
<property name="ignoreFinal" value="true"/>
<property name="allowedAbbreviations" value="ALPN, ASCII, AWT, CRLDP, CRLF, FCGI, GZIP, HTTP, HTTPS, ID, IP, ISO8859, JAAS, JDBC, JMXRMI, JNDI, JPMS, JSON, JSTL, LDAP, PROXY, RFC, SPNEGO, URI, URL, UTF8, XML"/>
</module>
<!--
Eclipse Jetty Specific.
===========================================================================================
-->
<!-- Location of Annotations -->
<module name="AnnotationLocation">
@ -90,7 +78,7 @@
<!-- Indentation Rules -->
<module name="Indentation">
<property name="throwsIndent" value="0"/>
<property name="arrayInitIndent" value="8"/>
</module>
<!-- Interface Type Parameter Name -->
@ -215,7 +203,9 @@
</module>
<!-- all switch statements should have "default" label declared -->
<!-- Disabled: Is super noisy
<module name="MissingSwitchDefault"/>
-->
<!-- prevent line wrapping of import / package statements -->
<module name="NoLineWrap"/>
@ -226,9 +216,6 @@
<!-- Filename and Classname match -->
<module name="OuterTypeFilename"/>
<!-- Checks that overload methods are grouped together -->
<module name="OverloadMethodsDeclarationOrder"/>
<!--
Checks based on the Java Language Specification recommendations.
https://docs.oracle.com/javase/specs/jls/se8/html/index.html
@ -284,8 +271,5 @@
<module name="UpperEll"/>
<!-- TODO: look for float / double version of above -->
<!-- Checks the distance between declaration of variable and its first usage -->
<module name="VariableDeclarationUsageDistance"/>
</module>
</module>

View File

@ -1,35 +0,0 @@
<?xml version="1.0"?>
<!DOCTYPE suppressions PUBLIC
"-//Checkstyle//DTD SuppressionFilter Configuration 1.2//EN"
"https://checkstyle.org/dtds/suppressions_1_2.dtd">
<suppressions>
<!-- all /target/ directories -->
<suppress checks=".*" files="[/\\]target[/\\]generated-sources[/\\]" />
<!-- General JUnit Test Cases -->
<suppress checks="AbbreviationAsWordInNameCheck"
files="[/\\]src[/\\]test[/\\]java[/\\]" />
<suppress checks="AvoidEscapedUnicodeCharactersCheck"
files="[/\\]src[/\\]test[/\\]java[/\\]" />
<suppress checks="LocalVariableNameCheck"
files="[/\\]src[/\\]test[/\\]java[/\\]" />
<suppress checks="MethodNameCheck"
files="[/\\]src[/\\]test[/\\]java[/\\]" />
<suppress checks="TypeNameCheck"
files="[/\\]src[/\\]test[/\\]java[/\\]" />
<!-- jetty-jmh specific -->
<suppress checks="AbbreviationAsWordInNameCheck"
files="[/\\]jetty-jmh[/\\]src[/\\]main[/\\]java[/\\]" />
<suppress checks="AvoidEscapedUnicodeCharactersCheck"
files="[/\\]jetty-jmh[/\\]src[/\\]main[/\\]java[/\\]" />
<suppress checks="LocalVariableNameCheck"
files="[/\\]jetty-jmh[/\\]src[/\\]main[/\\]java[/\\]" />
<suppress checks="MethodNameCheck"
files="[/\\]jetty-jmh[/\\]src[/\\]main[/\\]java[/\\]" />
<suppress checks="TypeNameCheck"
files="[/\\]jetty-jmh[/\\]src[/\\]main[/\\]java[/\\]" />
</suppressions>

View File

@ -1,19 +1,19 @@
//
// ========================================================================
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.example.asyncrest;
@ -101,19 +101,19 @@ public class AbstractRestServlet extends HttpServlet
}
}
protected String generateThumbs(Queue<Map<String, String>> results)
protected String generateThumbs(Queue<Map<String, Object>> results)
{
StringBuilder thumbs = new StringBuilder();
for (Map<String, String> m : results)
for (Map<String, Object> m : results)
{
if (!m.containsKey("GalleryURL"))
continue;
thumbs.append("<a href=\"" + m.get("ViewItemURLForNaturalSearch") + "\">");
thumbs.append("<img class='thumb' border='1px' height='25px'" +
" src='" + m.get("GalleryURL") + "'" +
" title='" + m.get("Title") + "'" +
"/>");
thumbs.append("<a href=\"").append(m.get("ViewItemURLForNaturalSearch")).append("\">");
thumbs.append("<img class='thumb' border='1px' height='25px' src='")
.append(m.get("GalleryURL")).append("'")
.append(" title='").append(m.get("Title")).append("'")
.append("/>");
thumbs.append("</a>&nbsp;");
}
return thumbs.toString();

View File

@ -1,19 +1,19 @@
//
// ========================================================================
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.example.asyncrest;
@ -77,17 +77,18 @@ public class AsyncRestServlet extends AbstractRestServlet
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
Long start = System.nanoTime();
long start = System.nanoTime();
// Do we have results yet?
Queue<Map<String, String>> results = (Queue<Map<String, String>>)request.getAttribute(RESULTS_ATTR);
@SuppressWarnings("unchecked")
Queue<Map<String, Object>> results = (Queue<Map<String, Object>>)request.getAttribute(RESULTS_ATTR);
// If no results, this must be the first dispatch, so send the REST request(s)
if (results == null)
{
// define results data structures
final Queue<Map<String, String>> resultsQueue = new ConcurrentLinkedQueue<>();
request.setAttribute(RESULTS_ATTR, results = resultsQueue);
results = new ConcurrentLinkedQueue<>();
request.setAttribute(RESULTS_ATTR, results);
// suspend the request
// This is done before scheduling async handling to avoid race of
@ -100,13 +101,14 @@ public class AsyncRestServlet extends AbstractRestServlet
final AtomicInteger outstanding = new AtomicInteger(keywords.length);
// Send request each keyword
Queue<Map<String, Object>> resultsQueue = results;
for (final String item : keywords)
{
_client.newRequest(restURL(item)).method(HttpMethod.GET).send(
new AsyncRestRequest()
{
@Override
void onAuctionFound(Map<String, String> auction)
void onAuctionFound(Map<String, Object> auction)
{
resultsQueue.add(auction);
}
@ -163,9 +165,9 @@ public class AsyncRestServlet extends AbstractRestServlet
out.close();
}
private abstract class AsyncRestRequest extends Response.Listener.Adapter
private abstract static class AsyncRestRequest extends Response.Listener.Adapter
{
final Utf8StringBuilder _content = new Utf8StringBuilder();
private final Utf8StringBuilder _content = new Utf8StringBuilder();
AsyncRestRequest()
{
@ -182,13 +184,16 @@ public class AsyncRestServlet extends AbstractRestServlet
public void onComplete(Result result)
{
// extract auctions from the results
Map<String, ?> query = (Map<String, ?>)JSON.parse(_content.toString());
@SuppressWarnings("unchecked")
Map<String, Object> query = (Map<String, Object>)new JSON().fromJSON(_content.toString());
Object[] auctions = (Object[])query.get("Item");
if (auctions != null)
{
for (Object o : auctions)
{
onAuctionFound((Map<String, String>)o);
@SuppressWarnings("unchecked")
Map<String, Object> auction = (Map<String, Object>)o;
onAuctionFound(auction);
}
}
onComplete();
@ -196,8 +201,7 @@ public class AsyncRestServlet extends AbstractRestServlet
abstract void onComplete();
abstract void onAuctionFound(Map<String, String> details);
abstract void onAuctionFound(Map<String, Object> details);
}
@Override

View File

@ -1,19 +1,19 @@
//
// ========================================================================
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.example.asyncrest;
@ -28,7 +28,6 @@ import java.util.LinkedList;
import java.util.Map;
import java.util.Queue;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@ -45,7 +44,7 @@ public class SerialRestServlet extends AbstractRestServlet
final long start = System.nanoTime();
String[] keywords = sanitize(request.getParameter(ITEMS_PARAM)).split(",");
Queue<Map<String, String>> results = new LinkedList<Map<String, String>>();
Queue<Map<String, Object>> results = new LinkedList<>();
// make all requests serially
for (String itemName : keywords)
@ -55,13 +54,16 @@ public class SerialRestServlet extends AbstractRestServlet
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.setRequestMethod("GET");
Map query = (Map)JSON.parse(new BufferedReader(new InputStreamReader(connection.getInputStream())));
@SuppressWarnings("unchecked")
Map<String, Object> query = (Map<String, Object>)new JSON().fromJSON(new BufferedReader(new InputStreamReader(connection.getInputStream())));
Object[] auctions = (Object[])query.get("Item");
if (auctions != null)
{
for (Object o : auctions)
{
results.add((Map)o);
@SuppressWarnings("unchecked")
Map<String, Object> auction = (Map<String, Object>)o;
results.add(auction);
}
}
}
@ -91,10 +93,6 @@ public class SerialRestServlet extends AbstractRestServlet
out.close();
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{

View File

@ -1,19 +1,19 @@
//
// ========================================================================
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.example.asyncrest;

View File

@ -16,6 +16,15 @@
</build>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-slf4j-impl</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.example-async-rest</groupId>
<artifactId>example-async-rest-jar</artifactId>

View File

@ -15,6 +15,15 @@
<bundle-symbolic-name>${project.groupId}.embedded</bundle-symbolic-name>
</properties>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-slf4j-impl</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-util-ajax</artifactId>
@ -52,7 +61,7 @@
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>javax-websocket-server</artifactId>
<artifactId>websocket-javax-server</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
@ -62,7 +71,7 @@
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>jetty-websocket-server</artifactId>
<artifactId>websocket-jetty-server</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
@ -132,7 +141,32 @@
<dependency>
<groupId>org.eclipse.jetty.toolchain</groupId>
<artifactId>jetty-test-helper</artifactId>
<!-- scope>test</scope-->
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-jetty-client</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-distribution</artifactId>
<version>${project.version}</version>
<type>tar.gz</type>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<useManifestOnlyJar>false</useManifestOnlyJar>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -1,19 +1,19 @@
//
// ========================================================================
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.embedded;
@ -22,7 +22,6 @@ import java.io.IOException;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.servlet.AsyncContext;
import javax.servlet.ReadListener;
import javax.servlet.ServletException;
import javax.servlet.ServletInputStream;
import javax.servlet.ServletOutputStream;
import javax.servlet.WriteListener;
@ -35,7 +34,7 @@ public class AsyncEchoServlet extends HttpServlet
private static final long serialVersionUID = 1L;
@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
protected void service(HttpServletRequest request, HttpServletResponse response) throws IOException
{
AsyncContext asyncContext = request.startAsync(request, response);
asyncContext.setTimeout(0);

View File

@ -1,25 +1,27 @@
//
// ========================================================================
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.embedded;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Collections;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@ -45,12 +47,28 @@ public class DumpServlet extends HttpServlet
out.println("pathInfo=" + request.getPathInfo());
out.println("session=" + request.getSession(true).getId());
ServletContext servletContext = getServletContext();
String r = request.getParameter("resource");
if (r != null)
{
out.println("resource(" + r + ")=" + getServletContext().getResource(r));
out.println("resource(" + r + ")=" + servletContext.getResource(r));
}
Collections.list(request.getAttributeNames())
.stream()
.filter((name) -> name.startsWith("X-"))
.sorted()
.forEach((name) ->
out.println("request.attribute[" + name + "]=" + request.getAttribute(name)));
Collections.list(servletContext.getAttributeNames())
.stream()
.filter((name) -> name.startsWith("X-"))
.sorted()
.forEach((name) ->
out.println("servletContext.attribute[" + name + "]=" + servletContext.getAttribute(name)));
out.println("</pre>");
}
}

View File

@ -1,19 +1,19 @@
//
// ========================================================================
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.embedded;
@ -28,12 +28,12 @@ import org.eclipse.jetty.servlet.ServletContextHandler;
public class ExampleServer
{
public static void main(String[] args) throws Exception
public static Server createServer(int port)
{
Server server = new Server();
ServerConnector connector = new ServerConnector(server);
connector.setPort(8080);
connector.setPort(port);
server.setConnectors(new Connector[]{connector});
ServletContextHandler context = new ServletContextHandler();
@ -45,6 +45,13 @@ public class ExampleServer
handlers.setHandlers(new Handler[]{context, new DefaultHandler()});
server.setHandler(handlers);
return server;
}
public static void main(String[] args) throws Exception
{
int port = ExampleUtil.getPort(args, "jetty.http.port", 8080);
Server server = createServer(port);
server.start();
server.join();
}

View File

@ -1,38 +1,48 @@
//
// ========================================================================
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.embedded;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.xml.XmlConfiguration;
/**
* Configures and Starts a Jetty server from an XML declaration.
* <p>
* See <a href="https://raw.githubusercontent.com/eclipse/jetty.project/master/examples/embedded/src/main/resources/exampleserver.xml">exampleserver.xml</a>
* </p>
*/
public class ExampleServerXml
{
public static void main(String[] args) throws Exception
public static Server createServer(int port) throws Exception
{
// Find Jetty XML (in classpath) that configures and starts Server.
// See src/main/resources/exampleserver.xml
Resource serverXml = Resource.newSystemResource("exampleserver.xml");
XmlConfiguration.main(serverXml.getFile().getAbsolutePath());
XmlConfiguration xml = new XmlConfiguration(serverXml);
xml.getProperties().put("http.port", Integer.toString(port));
Server server = (Server)xml.configure();
return server;
}
public static void main(String[] args) throws Exception
{
int port = ExampleUtil.getPort(args, "jetty.http.port", 8080);
Server server = createServer(port);
server.start();
server.join();
}
}

View File

@ -0,0 +1,86 @@
//
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.embedded;
import org.eclipse.jetty.util.StringUtil;
public class ExampleUtil
{
/**
* Get a port, possibly configured from Command line or System property.
*
* @param args the command line arguments
* @param propertyName the property name
* @param defValue the default value
* @return the configured port
*/
public static int getPort(String[] args, String propertyName, int defValue)
{
for (String arg : args)
{
if (arg.startsWith(propertyName + "="))
{
String value = arg.substring(propertyName.length() + 2);
int port = toInt(value);
if (isValidPort(port))
return port;
}
}
String value = System.getProperty(propertyName);
int port = toInt(value);
if (isValidPort(port))
return port;
return defValue;
}
/**
* Test if port is in the valid range to be used.
*
* @param port the port to test
* @return true if valid
*/
private static boolean isValidPort(int port)
{
return (port >= 0) && (port <= 65535);
}
/**
* Parse an int, ignoring any {@link NumberFormatException}
*
* @param value the string value to parse
* @return the int (if parsed), or -1 if not parsed.
*/
private static int toInt(String value)
{
if (StringUtil.isBlank(value))
return -1;
try
{
return Integer.parseInt(value);
}
catch (NumberFormatException ignored)
{
// ignored
return -1;
}
}
}

View File

@ -1,19 +1,19 @@
//
// ========================================================================
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.embedded;
@ -58,17 +58,24 @@ import org.eclipse.jetty.util.resource.Resource;
*/
public class FastFileServer
{
public static void main(String[] args) throws Exception
public static Server createServer(int port, File resourceBase)
{
Server server = new Server(8080);
Server server = new Server(port);
HandlerList handlers = new HandlerList();
handlers.setHandlers(new Handler[]{
new FastFileHandler(new File(System.getProperty("user.dir"))),
new FastFileHandler(resourceBase),
new DefaultHandler()
});
server.setHandler(handlers);
return server;
}
public static void main(String[] args) throws Exception
{
int port = ExampleUtil.getPort(args, "jetty.http.port", 8080);
File directory = new File(System.getProperty("user.dir"));
Server server = createServer(port, directory);
server.start();
server.join();
}

View File

@ -1,28 +1,33 @@
//
// ========================================================================
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.embedded;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.DefaultHandler;
import org.eclipse.jetty.server.handler.HandlerList;
import org.eclipse.jetty.server.handler.ResourceHandler;
import org.eclipse.jetty.util.resource.PathResource;
import org.eclipse.jetty.util.resource.Resource;
/**
* Simple Jetty FileServer.
@ -30,12 +35,12 @@ import org.eclipse.jetty.server.handler.ResourceHandler;
*/
public class FileServer
{
public static void main(String[] args) throws Exception
public static Server createServer(int port, Resource baseResource) throws Exception
{
// Create a basic Jetty server object that will listen on port 8080. Note that if you set this to port 0
// then a randomly available port will be assigned that you can either look in the logs for the port,
// or programmatically obtain it for use in test cases.
final Server server = new Server(8080);
Server server = new Server(port);
// Create the ResourceHandler. It is the object that will actually handle the request for a given file. It is
// a Jetty Handler object so it is suitable for chaining with other handlers as you will see in other examples.
@ -45,13 +50,24 @@ public class FileServer
// In this example it is the current directory but it can be configured to anything that the jvm has access to.
resourceHandler.setDirectoriesListed(true);
resourceHandler.setWelcomeFiles(new String[]{"index.html"});
resourceHandler.setResourceBase(".");
resourceHandler.setBaseResource(baseResource);
// Add the ResourceHandler to the server.
HandlerList handlers = new HandlerList();
handlers.setHandlers(new Handler[]{resourceHandler, new DefaultHandler()});
server.setHandler(handlers);
return server;
}
public static void main(String[] args) throws Exception
{
int port = ExampleUtil.getPort(args, "jetty.http.port", 8080);
Path userDir = Paths.get(System.getProperty("user.dir"));
PathResource pathResource = new PathResource(userDir);
Server server = createServer(port, pathResource);
// Start things up! By using the server.join() the server thread will join with the current thread.
// See "http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/Thread.html#join()" for more details.
server.start();

View File

@ -1,23 +1,26 @@
//
// ========================================================================
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.embedded;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.xml.XmlConfiguration;
@ -28,17 +31,25 @@ import org.eclipse.jetty.xml.XmlConfiguration;
* This server is identical to {@link FileServer}, except that it is configured
* via an {@link XmlConfiguration} config file that does the identical work.
* </p>
* <p>
* See <a href="https://raw.githubusercontent.com/eclipse/jetty.project/master/examples/embedded/src/main/resources/fileserver.xml">fileserver.xml</a>
* </p>
*/
public class FileServerXml
{
public static void main(String[] args) throws Exception
public static Server createServer(int port, Path baseResource) throws Exception
{
// Find Jetty XML (in classpath) that configures and starts Server.
// See src/main/resources/fileserver.xml
Resource fileServerXml = Resource.newSystemResource("fileserver.xml");
XmlConfiguration configuration = new XmlConfiguration(fileServerXml);
Server server = (Server)configuration.configure();
configuration.getProperties().put("http.port", Integer.toString(port));
configuration.getProperties().put("fileserver.baseresource", baseResource.toAbsolutePath().toString());
return (Server)configuration.configure();
}
public static void main(String[] args) throws Exception
{
int port = ExampleUtil.getPort(args, "jetty.http.port", 8080);
Path userDir = Paths.get(System.getProperty("user.dir"));
Server server = createServer(port, userDir);
server.start();
server.join();
}

View File

@ -1,19 +1,19 @@
//
// ========================================================================
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.embedded;

View File

@ -1,19 +1,19 @@
//
// ========================================================================
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.embedded;

View File

@ -1,19 +1,19 @@
//
// ========================================================================
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.embedded;

View File

@ -1,19 +1,19 @@
//
// ========================================================================
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.embedded;
@ -51,7 +51,8 @@ public class HelloWorld extends AbstractHandler
public static void main(String[] args) throws Exception
{
Server server = new Server(8080);
int port = ExampleUtil.getPort(args, "jetty.http.port", 8080);
Server server = new Server(port);
server.setHandler(new HelloWorld());
server.start();

View File

@ -1,26 +1,29 @@
//
// ========================================================================
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.embedded;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Date;
import java.util.EnumSet;
@ -56,12 +59,15 @@ import org.eclipse.jetty.servlet.DefaultServlet;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.servlets.PushCacheFilter;
import org.eclipse.jetty.util.resource.PathResource;
import org.eclipse.jetty.util.ssl.SslContextFactory;
public class Http2Server
{
public static void main(String... args) throws Exception
{
int port = ExampleUtil.getPort(args, "jetty.http.port", 8080);
int securePort = ExampleUtil.getPort(args, "jetty.https.port", 8443);
Server server = new Server();
MBeanContainer mbContainer = new MBeanContainer(
@ -69,10 +75,11 @@ public class Http2Server
server.addBean(mbContainer);
ServletContextHandler context = new ServletContextHandler(server, "/", ServletContextHandler.SESSIONS);
String docroot = "src/main/resources/docroot";
if (!new File(docroot).exists())
docroot = "examples/embedded/src/main/resources/docroot";
context.setResourceBase(docroot);
Path docroot = Paths.get("src/main/resources/docroot");
if (!Files.exists(docroot))
throw new FileNotFoundException(docroot.toString());
context.setBaseResource(new PathResource(docroot));
context.addFilter(PushCacheFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
// context.addFilter(PushSessionCacheFilter.class,"/*",EnumSet.of(DispatcherType.REQUEST));
context.addFilter(PushedTilesFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
@ -83,23 +90,22 @@ public class Http2Server
// HTTP Configuration
HttpConfiguration httpConfig = new HttpConfiguration();
httpConfig.setSecureScheme("https");
httpConfig.setSecurePort(8443);
httpConfig.setSecurePort(securePort);
httpConfig.setSendXPoweredBy(true);
httpConfig.setSendServerVersion(true);
// HTTP Connector
ServerConnector http = new ServerConnector(server, new HttpConnectionFactory(httpConfig), new HTTP2CServerConnectionFactory(httpConfig));
http.setPort(8080);
http.setPort(port);
server.addConnector(http);
// SSL Context Factory for HTTPS and HTTP/2
String jettyDistro = System.getProperty("jetty.distro", "../../jetty-distribution/target/distribution");
if (!new File(jettyDistro).exists())
jettyDistro = "jetty-distribution/target/distribution";
Path keystorePath = Paths.get("src/main/resources/etc/keystore.p12").toAbsolutePath();
if (!Files.exists(keystorePath))
throw new FileNotFoundException(keystorePath.toString());
SslContextFactory.Server sslContextFactory = new SslContextFactory.Server();
sslContextFactory.setKeyStorePath(jettyDistro + "/demo-base/etc/keystore");
sslContextFactory.setKeyStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4");
sslContextFactory.setKeyManagerPassword("OBF:1u2u1wml1z7s1z7a1wnl1u2g");
sslContextFactory.setKeyStorePath(keystorePath.toString());
sslContextFactory.setKeyStorePassword("storepwd");
sslContextFactory.setCipherComparator(HTTP2Cipher.COMPARATOR);
// sslContextFactory.setProvider("Conscrypt");
@ -119,7 +125,7 @@ public class Http2Server
// HTTP/2 Connector
ServerConnector http2Connector =
new ServerConnector(server, ssl, alpn, h2, new HttpConnectionFactory(httpsConfig));
http2Connector.setPort(8443);
http2Connector.setPort(securePort);
server.addConnector(http2Connector);
server.start();

View File

@ -1,24 +1,28 @@
//
// ========================================================================
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.embedded;
import org.eclipse.jetty.server.Handler;
import java.io.FileNotFoundException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.DefaultHandler;
import org.eclipse.jetty.server.handler.HandlerList;
@ -28,24 +32,36 @@ import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.util.resource.Resource;
/**
*
* Example of serving content from a JAR file.
* The JAR file in this example does not belong to any Classpath.
*/
public class JarServer
{
public static void main(String[] args) throws Exception
public static Server createServer(int port) throws Exception
{
final Server server = new Server(8080);
Server server = new Server(port);
Path jarFile = Paths.get("src/main/other/content.jar");
if (!Files.exists(jarFile))
throw new FileNotFoundException(jarFile.toString());
ServletContextHandler context = new ServletContextHandler();
Resource.setDefaultUseCaches(true);
Resource base = Resource.newResource("jar:file:src/main/resources/content.jar!/");
Resource base = Resource.newResource("jar:" + jarFile.toAbsolutePath().toUri().toASCIIString() + "!/");
context.setBaseResource(base);
context.addServlet(new ServletHolder(new DefaultServlet()), "/");
HandlerList handlers = new HandlerList();
handlers.setHandlers(new Handler[]{context, new DefaultHandler()});
handlers.addHandler(context);
handlers.addHandler(new DefaultHandler());
server.setHandler(handlers);
return server;
}
public static void main(String[] args) throws Exception
{
int port = ExampleUtil.getPort(args, "jetty.http.port", 8080);
Server server = createServer(port);
server.start();
server.join();
}

View File

@ -1,29 +1,30 @@
//
// ========================================================================
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.embedded;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* A utility test class to locate a Jetty Distribution for testing purposes by searching:
@ -35,71 +36,104 @@ import org.eclipse.jetty.util.log.Logger;
*/
public class JettyDistribution
{
private static final Logger LOG = Log.getLogger(JettyDistribution.class);
private static final Logger LOG = LoggerFactory.getLogger(JettyDistribution.class);
public static final Path DISTRIBUTION;
static
{
Path distro = asJettyDistribution(System.getProperty("jetty.home"));
LOG.debug("JettyDistribution(prop(jetty.home)) = " + distro);
if (distro == null)
{
distro = asJettyDistribution(System.getenv().get("JETTY_HOME"));
LOG.debug("JettyDistribution(env(JETTY_HOME)) = " + distro);
}
if (distro == null)
{
try
{
Path working = new File(".").getAbsoluteFile().getCanonicalFile().toPath();
Path working = Paths.get(System.getProperty("user.dir"));
LOG.debug("JettyDistribution(prop(user.dir)) = " + working);
while (distro == null && working != null)
{
distro = asJettyDistribution(working.resolve("jetty-distribution/target/distribution").toString());
working = working.getParent();
}
LOG.debug("JettyDistribution(working.resolve(...)) = " + distro);
}
catch (Throwable th)
{
LOG.warn(th);
LOG.warn("Unable to resolve Jetty Distribution location", th);
}
}
if (distro == null)
{
LOG.info("JettyDistribution() FAILURE: NOT FOUND");
}
else
{
LOG.debug("JettyDistribution() FOUND = " + distro);
}
DISTRIBUTION = distro;
}
private static Path asJettyDistribution(String test)
private static Path asJettyDistribution(String jettyHome)
{
try
{
if (StringUtil.isBlank(test))
if (jettyHome == null)
{
LOG.info("asJettyDistribution {} is blank", test);
return null;
}
File dir = new File(test);
if (!dir.exists() || !dir.isDirectory())
if (StringUtil.isBlank(jettyHome))
{
LOG.info("asJettyDistribution {} is not a directory", test);
LOG.debug("asJettyDistribution {} is blank", jettyHome);
return null;
}
File demoBase = new File(dir, "demo-base");
if (!demoBase.exists() || !demoBase.isDirectory())
Path dir = Paths.get(jettyHome);
if (!Files.exists(dir))
{
LOG.info("asJettyDistribution {} has no demo-base", test);
LOG.debug("asJettyDistribution {} does not exist", jettyHome);
return null;
}
LOG.info("asJettyDistribution {}", dir);
return dir.getAbsoluteFile().getCanonicalFile().toPath();
if (!Files.isDirectory(dir))
{
LOG.debug("asJettyDistribution {} is not a directory", jettyHome);
return null;
}
Path demoBase = dir.resolve("demo-base");
if (!Files.exists(demoBase) || !Files.isDirectory(demoBase))
{
LOG.debug("asJettyDistribution {} has no demo-base", jettyHome);
return null;
}
LOG.debug("asJettyDistribution {}", dir);
return dir.toAbsolutePath();
}
catch (Exception e)
{
LOG.ignore(e);
LOG.trace("IGNORED", e);
}
return null;
}
public static Path get()
{
if (DISTRIBUTION == null)
throw new RuntimeException("jetty-distribution not found");
return DISTRIBUTION;
}
public static Path resolve(String path)
{
return DISTRIBUTION.resolve(path);
return get().resolve(path);
}
public static void main(String... arg)

View File

@ -1,29 +1,33 @@
//
// ========================================================================
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.embedded;
import java.io.File;
import java.io.FileNotFoundException;
import java.lang.management.ManagementFactory;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.eclipse.jetty.annotations.AnnotationConfiguration;
import org.eclipse.jetty.deploy.DeploymentManager;
import org.eclipse.jetty.deploy.PropertiesConfigurationManager;
import org.eclipse.jetty.deploy.bindings.DebugListenerBinding;
import org.eclipse.jetty.deploy.providers.WebAppProvider;
import org.eclipse.jetty.http.HttpVersion;
import org.eclipse.jetty.jmx.MBeanContainer;
@ -35,6 +39,7 @@ import org.eclipse.jetty.rewrite.handler.ValidUrlRule;
import org.eclipse.jetty.security.HashLoginService;
import org.eclipse.jetty.server.AsyncRequestLogWriter;
import org.eclipse.jetty.server.CustomRequestLog;
import org.eclipse.jetty.server.DebugListener;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.HttpConfiguration;
import org.eclipse.jetty.server.HttpConnectionFactory;
@ -59,21 +64,21 @@ import org.eclipse.jetty.webapp.Configurations;
*/
public class LikeJettyXml
{
public static void main(String[] args) throws Exception
public static Server createServer(int port, int securePort, boolean addDebugListener) throws Exception
{
// Path to as-built jetty-distribution directory
String jettyHomeBuild = JettyDistribution.DISTRIBUTION.toString();
Path jettyHomeBuild = JettyDistribution.get();
// Find jetty home and base directories
String homePath = System.getProperty("jetty.home", jettyHomeBuild);
File homeDir = new File(homePath);
String homePath = System.getProperty("jetty.home", jettyHomeBuild.toString());
Path homeDir = Paths.get(homePath);
String basePath = System.getProperty("jetty.base", homeDir + "/demo-base");
File baseDir = new File(basePath);
String basePath = System.getProperty("jetty.base", homeDir.resolve("demo-base").toString());
Path baseDir = Paths.get(basePath);
// Configure jetty.home and jetty.base system properties
String jettyHome = homeDir.getAbsolutePath();
String jettyBase = baseDir.getAbsolutePath();
String jettyHome = homeDir.toAbsolutePath().toString();
String jettyBase = baseDir.toAbsolutePath().toString();
System.setProperty("jetty.home", jettyHome);
System.setProperty("jetty.base", jettyBase);
@ -91,7 +96,7 @@ public class LikeJettyXml
// HTTP Configuration
HttpConfiguration httpConfig = new HttpConfiguration();
httpConfig.setSecureScheme("https");
httpConfig.setSecurePort(8443);
httpConfig.setSecurePort(securePort);
httpConfig.setOutputBufferSize(32768);
httpConfig.setRequestHeaderSize(8192);
httpConfig.setResponseHeaderSize(8192);
@ -105,11 +110,6 @@ public class LikeJettyXml
handlers.setHandlers(new Handler[]{contexts, new DefaultHandler()});
server.setHandler(handlers);
// Extra options
server.setDumpAfterStart(true);
server.setDumpBeforeStop(false);
server.setStopAtShutdown(true);
// === jetty-jmx.xml ===
MBeanContainer mbContainer = new MBeanContainer(
ManagementFactory.getPlatformMBeanServer());
@ -118,24 +118,20 @@ public class LikeJettyXml
// === jetty-http.xml ===
ServerConnector http = new ServerConnector(server,
new HttpConnectionFactory(httpConfig));
http.setPort(8080);
http.setPort(port);
http.setIdleTimeout(30000);
server.addConnector(http);
// === jetty-https.xml ===
// SSL Context Factory
Path keystorePath = Paths.get("src/main/resources/etc/keystore.p12").toAbsolutePath();
if (!Files.exists(keystorePath))
throw new FileNotFoundException(keystorePath.toString());
SslContextFactory.Server sslContextFactory = new SslContextFactory.Server();
sslContextFactory.setKeyStorePath(jettyHome + "/../../../jetty-server/src/test/config/etc/keystore");
sslContextFactory.setKeyStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4");
sslContextFactory.setKeyManagerPassword("OBF:1u2u1wml1z7s1z7a1wnl1u2g");
sslContextFactory.setTrustStorePath(jettyHome + "/../../../jetty-server/src/test/config/etc/keystore");
sslContextFactory.setTrustStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4");
sslContextFactory.setExcludeCipherSuites("SSL_RSA_WITH_DES_CBC_SHA",
"SSL_DHE_RSA_WITH_DES_CBC_SHA", "SSL_DHE_DSS_WITH_DES_CBC_SHA",
"SSL_RSA_EXPORT_WITH_RC4_40_MD5",
"SSL_RSA_EXPORT_WITH_DES40_CBC_SHA",
"SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA",
"SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA");
sslContextFactory.setKeyStorePath(keystorePath.toString());
sslContextFactory.setKeyStorePassword("storepwd");
sslContextFactory.setTrustStorePath(keystorePath.toString());
sslContextFactory.setTrustStorePassword("storepwd");
// SSL HTTP Configuration
HttpConfiguration httpsConfig = new HttpConfiguration(httpConfig);
@ -145,14 +141,17 @@ public class LikeJettyXml
ServerConnector sslConnector = new ServerConnector(server,
new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()),
new HttpConnectionFactory(httpsConfig));
sslConnector.setPort(8443);
sslConnector.setPort(securePort);
server.addConnector(sslConnector);
// === jetty-deploy.xml ===
DeploymentManager deployer = new DeploymentManager();
//DebugListener debug = new DebugListener(System.out,true,true,true);
// server.addBean(debug);
// deployer.addLifeCycleBinding(new DebugListenerBinding(debug));
if (addDebugListener)
{
DebugListener debug = new DebugListener(System.err, true, true, true);
server.addBean(debug);
deployer.addLifeCycleBinding(new DebugListenerBinding(debug));
}
deployer.setContexts(contexts);
deployer.setContextAttribute(
"org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern",
@ -208,6 +207,20 @@ public class LikeJettyXml
login.setHotReload(false);
server.addBean(login);
return server;
}
public static void main(String[] args) throws Exception
{
int port = ExampleUtil.getPort(args, "jetty.http.port", 8080);
int securePort = ExampleUtil.getPort(args, "jetty.https.port", 8443);
Server server = createServer(port, securePort, true);
// Extra options
server.setDumpAfterStart(true);
server.setDumpBeforeStop(false);
server.setStopAtShutdown(true);
// Start the server
server.start();
server.join();

View File

@ -1,25 +1,27 @@
//
// ========================================================================
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.embedded;
import java.io.File;
import java.io.FileNotFoundException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.eclipse.jetty.http.HttpVersion;
import org.eclipse.jetty.server.Connector;
@ -36,23 +38,13 @@ import org.eclipse.jetty.util.ssl.SslContextFactory;
*/
public class ManyConnectors
{
public static void main(String[] args) throws Exception
public static Server createServer(int plainPort, int securePort) throws Exception
{
// Since this example shows off SSL configuration, we need a keystore
// with the appropriate key. These lookup of jetty.home is purely a hack
// to get access to a keystore that we use in many unit tests and should
// probably be a direct path to your own keystore.
String jettyDistKeystore = "../../jetty-distribution/target/distribution/demo-base/etc/test-keystore";
String keystorePath = System.getProperty("example.keystore", jettyDistKeystore);
File keystoreFile = new File(keystorePath);
if (!keystoreFile.exists())
{
keystorePath = "jetty-distribution/target/distribution/demo-base/etc/keystore";
keystoreFile = new File(keystorePath);
if (!keystoreFile.exists())
throw new FileNotFoundException(keystoreFile.getAbsolutePath());
}
// with the appropriate key.
Path keystorePath = Paths.get("src/main/resources/etc/keystore.p12").toAbsolutePath();
if (!Files.exists(keystorePath))
throw new FileNotFoundException(keystorePath.toString());
// Create a basic jetty server object without declaring the port. Since
// we are configuring connectors directly we'll be setting ports on
@ -67,7 +59,7 @@ public class ManyConnectors
// done. The port for secured communication is also set here.
HttpConfiguration httpConfig = new HttpConfiguration();
httpConfig.setSecureScheme("https");
httpConfig.setSecurePort(8443);
httpConfig.setSecurePort(securePort);
httpConfig.setOutputBufferSize(32768);
// HTTP connector
@ -77,7 +69,7 @@ public class ManyConnectors
// configure an idle timeout.
ServerConnector http = new ServerConnector(server,
new HttpConnectionFactory(httpConfig));
http.setPort(8080);
http.setPort(plainPort);
http.setIdleTimeout(30000);
// SSL Context Factory for HTTPS
@ -88,9 +80,8 @@ public class ManyConnectors
// keystore to be used.
SslContextFactory.Server sslContextFactory = new SslContextFactory.Server();
sslContextFactory.setKeyStorePath(keystoreFile.getAbsolutePath());
sslContextFactory.setKeyStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4");
sslContextFactory.setKeyManagerPassword("OBF:1u2u1wml1z7s1z7a1wnl1u2g");
sslContextFactory.setKeyStorePath(keystorePath.toString());
sslContextFactory.setKeyStorePassword("storepwd");
// OPTIONAL: Un-comment the following to use Conscrypt for SSL instead of
// the native JSSE implementation.
@ -118,7 +109,7 @@ public class ManyConnectors
ServerConnector https = new ServerConnector(server,
new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()),
new HttpConnectionFactory(httpsConfig));
https.setPort(8443);
https.setPort(securePort);
https.setIdleTimeout(500000);
// Here you see the server having multiple connectors registered with
@ -132,7 +123,14 @@ public class ManyConnectors
// Set a handler
server.setHandler(new HelloHandler());
return server;
}
public static void main(String[] args) throws Exception
{
int port = ExampleUtil.getPort(args, "jetty.http.port", 8080);
int securePort = ExampleUtil.getPort(args, "jetty.https.port", 8443);
Server server = createServer(port, securePort);
// Start the server
server.start();
server.dumpStdErr();

View File

@ -1,56 +1,59 @@
//
// ========================================================================
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.embedded;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
public class ManyContexts
{
public static void main(String[] args) throws Exception
public static Server createServer(int port)
{
final Server server = new Server(8080);
Server server = new Server(port);
ContextHandler context = new ContextHandler("/");
context.setContextPath("/");
context.setHandler(new HelloHandler("Root Hello"));
ContextHandler contextFR = new ContextHandler("/fr");
contextFR.setHandler(new HelloHandler("Bonjoir"));
contextFR.setHandler(new HelloHandler("Bonjour"));
ContextHandler contextIT = new ContextHandler("/it");
contextIT.setHandler(new HelloHandler("Bongiorno"));
contextIT.setHandler(new HelloHandler("Buongiorno"));
ContextHandler contextV = new ContextHandler("/");
contextV.setVirtualHosts(new String[]{"127.0.0.2"});
contextV.setHandler(new HelloHandler("Virtual Hello"));
ContextHandlerCollection contexts = new ContextHandlerCollection();
contexts.setHandlers(new Handler[]{
context, contextFR, contextIT,
contextV
});
ContextHandlerCollection contexts = new ContextHandlerCollection(
context, contextFR, contextIT, contextV
);
server.setHandler(contexts);
return server;
}
public static void main(String[] args) throws Exception
{
int port = ExampleUtil.getPort(args, "jetty.http.port", 8080);
Server server = createServer(port);
server.start();
server.dumpStdErr();
server.join();

View File

@ -1,19 +1,19 @@
//
// ========================================================================
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.embedded;
@ -30,6 +30,8 @@ import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
import org.eclipse.jetty.server.handler.DefaultHandler;
import org.eclipse.jetty.server.handler.HandlerCollection;
import org.eclipse.jetty.server.handler.HandlerList;
@ -81,7 +83,7 @@ public class ManyHandlers
if (!params.isEmpty())
{
response.setContentType("text/plain");
response.getWriter().println(JSON.toString(params));
response.getWriter().println(new JSON().toJSON(params));
baseRequest.setHandled(true);
}
}
@ -99,20 +101,23 @@ public class ManyHandlers
HttpServletResponse response) throws IOException,
ServletException
{
request.setAttribute("welcome", "Hello");
response.setHeader("X-Welcome", "Greetings from WelcomeWrapHandler");
super.handle(target, baseRequest, request, response);
}
}
public static void main(String[] args) throws Exception
public static Server createServer(int port) throws IOException
{
final Server server = new Server(8080);
Server server = new Server(port);
// create the handlers
final Handler param = new ParamHandler();
final HandlerWrapper wrapper = new WelcomeWrapHandler();
final Handler hello = new HelloHandler();
final Handler dft = new DefaultHandler();
Handler param = new ParamHandler();
HandlerWrapper wrapper = new WelcomeWrapHandler();
Handler hello = new HelloHandler();
GzipHandler gzipHandler = new GzipHandler();
gzipHandler.setMinGzipSize(10);
gzipHandler.addIncludedMimeTypes("text/plain");
gzipHandler.addIncludedMimeTypes("text/html");
// configure request logging
File requestLogFile = File.createTempFile("demo", "log");
@ -120,16 +125,47 @@ public class ManyHandlers
server.setRequestLog(ncsaLog);
// create the handler collections
HandlerCollection handlers = new HandlerCollection();
HandlerList list = new HandlerList();
HandlerList handlers = new HandlerList();
// link them all together
// wrap contexts around specific handlers
wrapper.setHandler(hello);
list.setHandlers(new Handler[]{param, new GzipHandler()});
handlers.setHandlers(new Handler[]{list, dft});
ContextHandler helloContext = new ContextHandler("/hello");
helloContext.setHandler(wrapper);
ContextHandler paramContext = new ContextHandler("/params");
paramContext.setHandler(param);
ContextHandlerCollection contexts = new ContextHandlerCollection(helloContext, paramContext);
// Wrap Contexts with GZIP
gzipHandler.setHandler(contexts);
// Set the top level Handler List
handlers.addHandler(gzipHandler);
handlers.addHandler(new DefaultHandler());
server.setHandler(handlers);
/* At this point you have the following handler hierarchy.
*
* Server.handler:
* HandlerList
* \- GzipHandler
* | \- ContextHandlerCollection
* | \- ContextHandler ("/hello")
* | | \- WelcomeWrapHandler
* | | \- HelloHandler
* | \- ContextHandler ("/params")
* | \- ParamHandler
* \- DefaultHandler
*/
return server;
}
public static void main(String[] args) throws Exception
{
int port = ExampleUtil.getPort(args, "jetty.http.port", 8080);
Server server = createServer(port);
server.start();
server.join();
}

View File

@ -1,19 +1,19 @@
//
// ========================================================================
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.embedded;
@ -29,9 +29,9 @@ import org.eclipse.jetty.servlet.ServletHolder;
public class ManyServletContexts
{
public static void main(String[] args) throws Exception
public static Server createServer(int port)
{
Server server = new Server(8080);
Server server = new Server(port);
// Setup JMX
MBeanContainer mbContainer = new MBeanContainer(
@ -48,7 +48,7 @@ public class ManyServletContexts
// Add servlets to root context
root.addServlet(new ServletHolder(new HelloServlet("Hello")), "/");
root.addServlet(new ServletHolder(new HelloServlet("Ciao")), "/it/*");
root.addServlet(new ServletHolder(new HelloServlet("Bonjoir")), "/fr/*");
root.addServlet(new ServletHolder(new HelloServlet("Bonjour")), "/fr/*");
// Configure context "/other" for servlets
ServletContextHandler other = new ServletContextHandler(contexts,
@ -57,6 +57,13 @@ public class ManyServletContexts
other.addServlet(DefaultServlet.class.getCanonicalName(), "/");
other.addServlet(new ServletHolder(new HelloServlet("YO!")), "*.yo");
return server;
}
public static void main(String[] args) throws Exception
{
int port = ExampleUtil.getPort(args, "jetty.http.port", 8080);
Server server = createServer(port);
server.start();
server.dumpStdErr();
server.join();

View File

@ -1,25 +1,24 @@
//
// ========================================================================
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.embedded;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@ -29,13 +28,13 @@ import org.eclipse.jetty.servlet.ServletHandler;
public class MinimalServlets
{
public static void main(String[] args) throws Exception
public static Server createServer(int port)
{
// Create a basic jetty server object that will listen on port 8080.
// Note that if you set this to port 0 then a randomly available port
// will be assigned that you can either look in the logs for the port,
// or programmatically obtain it for use in test cases.
Server server = new Server(8080);
Server server = new Server(port);
// The ServletHandler is a dead simple way to create a context handler
// that is backed by an instance of a Servlet.
@ -51,13 +50,20 @@ public class MinimalServlets
// through a web.xml @WebServlet annotation, or anything similar.
handler.addServletWithMapping(HelloServlet.class, "/*");
return server;
}
public static void main(String[] args) throws Exception
{
// Create a basic jetty server object that will listen on port 8080.
int port = ExampleUtil.getPort(args, "jetty.http.port", 8080);
Server server = createServer(port);
// Start things up!
server.start();
// The use of server.join() the will make the current thread join and
// wait until the server is done executing.
// See
// http://docs.oracle.com/javase/7/docs/api/java/lang/Thread.html#join()
// wait until the server thread is done executing.
server.join();
}
@ -66,11 +72,11 @@ public class MinimalServlets
{
@Override
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException,
IOException
HttpServletResponse response) throws IOException
{
response.setContentType("text/html");
response.setStatus(HttpServletResponse.SC_OK);
response.setContentType("text/html");
response.setCharacterEncoding("utf-8");
response.getWriter().println("<h1>Hello from HelloServlet</h1>");
}
}

View File

@ -1,19 +1,19 @@
//
// ========================================================================
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.embedded;
@ -26,7 +26,7 @@ import org.eclipse.jetty.server.ServerConnector;
*/
public class OneConnector
{
public static void main(String[] args) throws Exception
public static Server createServer(int port) throws Exception
{
// The Server
Server server = new Server();
@ -34,7 +34,7 @@ public class OneConnector
// HTTP connector
ServerConnector http = new ServerConnector(server);
http.setHost("localhost");
http.setPort(8080);
http.setPort(port);
http.setIdleTimeout(30000);
// Set the connector
@ -42,6 +42,13 @@ public class OneConnector
// Set a handler
server.setHandler(new HelloHandler());
return server;
}
public static void main(String[] args) throws Exception
{
int port = ExampleUtil.getPort(args, "jetty.http.port", 8080);
Server server = createServer(port);
// Start the server
server.start();

View File

@ -1,19 +1,19 @@
//
// ========================================================================
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.embedded;
@ -23,9 +23,9 @@ import org.eclipse.jetty.server.handler.ContextHandler;
public class OneContext
{
public static void main(String[] args) throws Exception
public static Server createServer(int port)
{
Server server = new Server(8080);
Server server = new Server(port);
// Add a single handler on context "/hello"
ContextHandler context = new ContextHandler();
@ -35,6 +35,13 @@ public class OneContext
// Can be accessed using http://localhost:8080/hello
server.setHandler(context);
return server;
}
public static void main(String[] args) throws Exception
{
int port = ExampleUtil.getPort(args, "jetty.http.port", 8080);
Server server = createServer(port);
// Start the server
server.start();

View File

@ -1,19 +1,19 @@
//
// ========================================================================
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.embedded;
@ -22,11 +22,17 @@ import org.eclipse.jetty.server.Server;
public class OneHandler
{
public static Server createServer(int port)
{
Server server = new Server(port);
server.setHandler(new HelloHandler());
return server;
}
public static void main(String[] args) throws Exception
{
Server server = new Server(8080);
server.setHandler(new HelloHandler());
int port = ExampleUtil.getPort(args, "jetty.http.port", 8080);
Server server = createServer(port);
server.start();
server.join();
}

View File

@ -1,26 +1,27 @@
//
// ========================================================================
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.embedded;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.EnumSet;
import javax.servlet.DispatcherType;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
@ -31,38 +32,59 @@ import javax.servlet.ServletRequest;
import javax.servlet.ServletRequestEvent;
import javax.servlet.ServletRequestListener;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.DefaultServlet;
import org.eclipse.jetty.servlet.ListenerHolder;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.util.resource.PathResource;
import org.eclipse.jetty.util.resource.Resource;
import static javax.servlet.DispatcherType.ASYNC;
import static javax.servlet.DispatcherType.REQUEST;
public class OneServletContext
{
public static void main(String[] args) throws Exception
public static Server createServer(int port, Resource baseResource)
{
Server server = new Server(8080);
Server server = new Server(port);
ServletContextHandler context = new ServletContextHandler(
ServletContextHandler.SESSIONS);
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/");
context.setResourceBase(System.getProperty("java.io.tmpdir"));
context.setBaseResource(baseResource);
server.setHandler(context);
// Add dump servlet
context.addServlet(
context.addServlet(DumpServlet.class, "/dump/*"),
"*.dump");
// add hello servlet
context.addServlet(HelloServlet.class, "/hello/*");
// Add dump servlet on multiple url-patterns
ServletHolder debugHolder = new ServletHolder("debug", DumpServlet.class);
context.addServlet(debugHolder, "/dump/*");
context.addServlet(debugHolder, "*.dump");
// add default servlet (for error handling and static resources)
context.addServlet(DefaultServlet.class, "/");
context.addFilter(TestFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
context.addFilter(TestFilter.class, "/test", EnumSet.of(DispatcherType.REQUEST, DispatcherType.ASYNC));
context.addFilter(TestFilter.class, "*.test", EnumSet.of(DispatcherType.REQUEST, DispatcherType.INCLUDE, DispatcherType.FORWARD));
// sprinkle in a few filters to demonstrate behaviors
context.addFilter(TestFilter.class, "/test/*", EnumSet.of(REQUEST));
context.addFilter(TestFilter.class, "*.test", EnumSet.of(REQUEST, ASYNC));
// and a few listeners to show other ways of working with servlets
context.getServletHandler().addListener(new ListenerHolder(InitListener.class));
context.getServletHandler().addListener(new ListenerHolder(RequestListener.class));
return server;
}
public static void main(String[] args) throws Exception
{
int port = ExampleUtil.getPort(args, "jetty.http.port", 8080);
Path tempDir = Paths.get(System.getProperty("java.io.tmpdir"));
Server server = createServer(port, new PathResource(tempDir));
server.start();
server.dumpStdErr();
server.join();
@ -71,14 +93,18 @@ public class OneServletContext
public static class TestFilter implements Filter
{
@Override
public void init(FilterConfig filterConfig) throws ServletException
public void init(FilterConfig filterConfig)
{
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
{
if (response instanceof HttpServletResponse)
{
HttpServletResponse httpServletResponse = (HttpServletResponse)response;
httpServletResponse.setHeader("X-TestFilter", "true");
}
chain.doFilter(request, response);
}
@ -94,6 +120,7 @@ public class OneServletContext
@Override
public void contextInitialized(ServletContextEvent sce)
{
sce.getServletContext().setAttribute("X-Init", "true");
}
@Override
@ -105,15 +132,14 @@ public class OneServletContext
public static class RequestListener implements ServletRequestListener
{
@Override
public void requestDestroyed(ServletRequestEvent sre)
public void requestInitialized(ServletRequestEvent sre)
{
sre.getServletRequest().setAttribute("X-ReqListener", "true");
}
@Override
public void requestInitialized(ServletRequestEvent sre)
public void requestDestroyed(ServletRequestEvent sre)
{
}
}
}

View File

@ -1,19 +1,19 @@
//
// ========================================================================
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.embedded;
@ -28,9 +28,10 @@ import org.eclipse.jetty.servlet.ServletContextHandler;
public class OneServletContextJmxStats
{
public static void main(String[] args) throws Exception
public static Server createServer(int port)
{
Server server = new Server(8080);
Server server = new Server(port);
// Add JMX tracking to Server
server.addBean(new MBeanContainer(ManagementFactory
.getPlatformMBeanServer()));
@ -45,6 +46,13 @@ public class OneServletContextJmxStats
// Add Connector Statistics tracking to all connectors
ServerConnectionStatistics.addToAllConnectors(server);
return server;
}
public static void main(String[] args) throws Exception
{
int port = ExampleUtil.getPort(args, "jetty.http.port", 8080);
Server server = createServer(port);
server.start();
server.join();

View File

@ -1,41 +1,46 @@
//
// ========================================================================
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.embedded;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.session.DefaultSessionCache;
import org.eclipse.jetty.server.session.NullSessionDataStore;
import org.eclipse.jetty.server.session.SessionCache;
import org.eclipse.jetty.server.session.SessionHandler;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.util.resource.PathResource;
import org.eclipse.jetty.util.resource.Resource;
public class OneServletContextWithSession
{
public static void main(String[] args) throws Exception
public static Server createServer(int port, Resource baseResource)
{
Server server = new Server(8080);
Server server = new Server(port);
// Create a ServletContext, with a session handler enabled.
ServletContextHandler context = new ServletContextHandler(
ServletContextHandler.SESSIONS);
context.setContextPath("/");
context.setResourceBase(System.getProperty("java.io.tmpdir"));
context.setBaseResource(baseResource);
server.setHandler(context);
// Access the SessionHandler from the context.
@ -55,6 +60,15 @@ public class OneServletContextWithSession
// Servlet to read/set the greeting stored in the session.
// Can be accessed using http://localhost:8080/hello
context.addServlet(HelloSessionServlet.class, "/");
return server;
}
public static void main(String[] args) throws Exception
{
int port = ExampleUtil.getPort(args, "jetty.http.port", 8080);
Path dir = Paths.get(System.getProperty("user.dir"));
PathResource baseResource = new PathResource(dir);
Server server = createServer(port, baseResource);
server.start();
server.dumpStdErr();

View File

@ -1,45 +1,38 @@
//
// ========================================================================
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.embedded;
import java.io.File;
import java.lang.management.ManagementFactory;
import org.eclipse.jetty.jmx.MBeanContainer;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.webapp.Configurations;
import org.eclipse.jetty.webapp.WebAppContext;
public class OneWebApp
{
public static void main(String[] args) throws Exception
public static Server createServer(int port)
{
// Create a basic jetty server object that will listen on port 8080.
// Note that if you set this to port 0 then a randomly available port
// will be assigned that you can either look in the logs for the port,
// or programmatically obtain it for use in test cases.
Server server = new Server(8080);
// Setup JMX
MBeanContainer mbContainer = new MBeanContainer(
ManagementFactory.getPlatformMBeanServer());
server.addBean(mbContainer);
Server server = new Server(port);
// The WebAppContext is the entity that controls the environment in
// which a web application lives and breathes. In this example the
@ -56,6 +49,13 @@ public class OneWebApp
// A WebAppContext is a ContextHandler as well so it needs to be set to
// the server so it is aware of where to send the appropriate requests.
server.setHandler(webapp);
return server;
}
public static void main(String[] args) throws Exception
{
int port = ExampleUtil.getPort(args, "jetty.http.port", 8080);
Server server = createServer(port);
Configurations.setServerDefault(server);
@ -66,7 +66,6 @@ public class OneWebApp
// The use of server.join() the will make the current thread join and
// wait until the server is done executing.
// See http://docs.oracle.com/javase/7/docs/api/java/lang/Thread.html#join()
server.join();
}
}

View File

@ -1,66 +1,62 @@
//
// ========================================================================
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.embedded;
import java.io.File;
import java.lang.management.ManagementFactory;
import java.io.FileNotFoundException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import org.eclipse.jetty.annotations.AnnotationConfiguration;
import org.eclipse.jetty.jmx.MBeanContainer;
import org.eclipse.jetty.security.HashLoginService;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.util.resource.PathResource;
import org.eclipse.jetty.webapp.WebAppContext;
public class OneWebAppWithJsp
{
public static void main(String[] args) throws Exception
public static Server createServer(int port) throws FileNotFoundException
{
// Create a basic jetty server object that will listen on port 8080.
// Note that if you set this to port 0 then
// a randomly available port will be assigned that you can either look
// in the logs for the port,
// or programmatically obtain it for use in test cases.
Server server = new Server(8080);
// Setup JMX
MBeanContainer mbContainer = new MBeanContainer(
ManagementFactory.getPlatformMBeanServer());
server.addBean(mbContainer);
Server server = new Server(port);
// The WebAppContext is the entity that controls the environment in
// which a web application lives and
// breathes. In this example the context path is being set to "/" so it
// which a web application lives and breathes.
// In this example the context path is being set to "/" so it
// is suitable for serving root context
// requests and then we see it setting the location of the war. A whole
// host of other configurations are
// requests and then we see it setting the location of the war.
// A whole host of other configurations are
// available, ranging from configuring to support annotation scanning in
// the webapp (through
// PlusConfiguration) to choosing where the webapp will unpack itself.
// the webapp (through PlusConfiguration), to choosing where
// the webapp will unpack itself.
WebAppContext webapp = new WebAppContext();
webapp.setContextPath("/");
File warFile = new File(
"jetty-distribution/target/distribution/demo-base/webapps/test.war");
if (!warFile.exists())
Path warFile = JettyDistribution.resolve("demo-base/webapps/test.war");
if (!Files.exists(warFile))
{
throw new RuntimeException("Unable to find WAR File: " + warFile.getAbsolutePath());
throw new FileNotFoundException(warFile.toString());
}
webapp.setWar(warFile.getAbsolutePath());
webapp.setWarResource(new PathResource(warFile));
webapp.setExtractWAR(true);
// This webapp will use jsps and jstl. We need to enable the
@ -89,19 +85,32 @@ public class OneWebAppWithJsp
// its own we register it as a bean with the Jetty server object so it
// can be started and stopped according to the lifecycle of the server
// itself.
String realmResourceName = "etc/realm.properties";
ClassLoader classLoader = OneWebAppWithJsp.class.getClassLoader();
URL realmProps = classLoader.getResource(realmResourceName);
if (realmProps == null)
throw new FileNotFoundException("Unable to find " + realmResourceName);
HashLoginService loginService = new HashLoginService();
loginService.setName("Test Realm");
loginService.setConfig("examples/embedded/src/test/resources/realm.properties");
loginService.setConfig(realmProps.toExternalForm());
server.addBean(loginService);
// Start things up!
return server;
}
public static void main(String[] args) throws Exception
{
int port = ExampleUtil.getPort(args, "jetty.http.port", 8080);
Server server = createServer(port);
// Start things up!
server.start();
server.dumpStdErr();
// The use of server.join() the will make the current thread join and
// wait until the server is done executing.
// See http://docs.oracle.com/javase/7/docs/api/java/lang/Thread.html#join()
server.join();
}
}

View File

@ -1,19 +1,19 @@
//
// ========================================================================
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.embedded;
@ -27,11 +27,13 @@ import org.eclipse.jetty.servlet.ServletHolder;
public class ProxyServer
{
public static void main(String[] args) throws Exception
public static Server createServer(int port)
{
Server server = new Server();
// Establish listening connector
ServerConnector connector = new ServerConnector(server);
connector.setPort(8888);
connector.setPort(port);
server.addConnector(connector);
// Setup proxy handler to handle CONNECT methods
@ -45,6 +47,15 @@ public class ProxyServer
proxyServlet.setInitParameter("blackList", "www.eclipse.org");
context.addServlet(proxyServlet, "/*");
return server;
}
public static void main(String[] args) throws Exception
{
int port = ExampleUtil.getPort(args, "jetty.http.port", 8080);
Server server = createServer(port);
server.start();
server.join();
}
}

View File

@ -1,44 +1,46 @@
//
// ========================================================================
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.embedded;
import java.util.Arrays;
import org.eclipse.jetty.rewrite.RewriteCustomizer;
import org.eclipse.jetty.rewrite.handler.CompactPathRule;
import org.eclipse.jetty.rewrite.handler.RewriteRegexRule;
import org.eclipse.jetty.server.HttpConfiguration;
import org.eclipse.jetty.server.HttpConnectionFactory;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletContextHandler;
public class RewriteServer
{
public static void main(String[] args) throws Exception
public static Server createServer(int port)
{
Server server = new Server(8080);
HttpConfiguration config = server.getConnectors()[0].getConnectionFactory(HttpConnectionFactory.class).getHttpConfiguration();
Server server = new Server(port);
RewriteCustomizer rewrite = new RewriteCustomizer();
config.addCustomizer(rewrite);
rewrite.addRule(new CompactPathRule());
rewrite.addRule(new RewriteRegexRule("(.*)foo(.*)", "$1FOO$2"));
Arrays.stream(server.getConnectors())
.forEach((connector) -> connector.getConnectionFactory(HttpConnectionFactory.class)
.getHttpConfiguration().addCustomizer(rewrite));
ServletContextHandler context = new ServletContextHandler(
ServletContextHandler.SESSIONS);
context.setContextPath("/");
@ -46,6 +48,14 @@ public class RewriteServer
context.addServlet(DumpServlet.class, "/*");
return server;
}
public static void main(String[] args) throws Exception
{
int port = ExampleUtil.getPort(args, "jetty.http.port", 8080);
Server server = createServer(port);
server.start();
server.join();
}

View File

@ -1,23 +1,25 @@
//
// ========================================================================
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.embedded;
import java.io.FileNotFoundException;
import java.net.URL;
import java.util.Collections;
import org.eclipse.jetty.security.ConstraintMapping;
@ -30,13 +32,13 @@ import org.eclipse.jetty.util.security.Constraint;
public class SecuredHelloHandler
{
public static void main(String[] args) throws Exception
public static Server createServer(int port) throws FileNotFoundException
{
// Create a basic jetty server object that will listen on port 8080.
// Note that if you set this to port 0 then a randomly available port
// will be assigned that you can either look in the logs for the port,
// or programmatically obtain it for use in test cases.
Server server = new Server(8080);
Server server = new Server(port);
// Since this example is for our test webapp, we need to setup a
// LoginService so this shows how to create a very simple hashmap based
@ -46,8 +48,14 @@ public class SecuredHelloHandler
// started and stopped according to the lifecycle of the server itself.
// In this example the name can be whatever you like since we are not
// dealing with webapp realms.
String realmResourceName = "etc/realm.properties";
ClassLoader classLoader = SecuredHelloHandler.class.getClassLoader();
URL realmProps = classLoader.getResource(realmResourceName);
if (realmProps == null)
throw new FileNotFoundException("Unable to find " + realmResourceName);
LoginService loginService = new HashLoginService("MyRealm",
"src/test/resources/realm.properties");
realmProps.toExternalForm());
server.addBean(loginService);
// A security handler is a jetty handler that secures content behind a
@ -68,7 +76,7 @@ public class SecuredHelloHandler
constraint.setRoles(new String[]{"user", "admin"});
// Binds a url pattern with the previously created constraint. The roles
// for this constraing mapping are mined from the Constraint itself
// for this constraint mapping are mined from the Constraint itself
// although methods exist to declare and bind roles separately as well.
ConstraintMapping mapping = new ConstraintMapping();
mapping.setPathSpec("/*");
@ -92,13 +100,19 @@ public class SecuredHelloHandler
// chain the hello handler into the security handler
security.setHandler(hh);
return server;
}
public static void main(String[] args) throws Exception
{
int port = ExampleUtil.getPort(args, "jetty.http.port", 8080);
Server server = createServer(port);
// Start things up!
server.start();
// The use of server.join() the will make the current thread join and
// wait until the server is done executing.
// See
// http://docs.oracle.com/javase/7/docs/api/java/lang/Thread.html#join()
server.join();
}
}

View File

@ -1,24 +1,27 @@
//
// ========================================================================
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.embedded;
import java.io.File;
import java.io.FileNotFoundException;
import java.net.URL;
import javax.naming.NamingException;
import org.eclipse.jetty.annotations.AnnotationConfiguration;
import org.eclipse.jetty.plus.jndi.EnvEntry;
@ -36,10 +39,10 @@ import org.eclipse.jetty.webapp.WebAppContext;
*/
public class ServerWithAnnotations
{
public static final void main(String[] args) throws Exception
public static Server createServer(int port) throws NamingException, FileNotFoundException
{
// Create the server
final Server server = new Server(8080);
Server server = new Server(port);
// Create a WebApp
WebAppContext webapp = new WebAppContext();
@ -60,7 +63,7 @@ public class ServerWithAnnotations
new Transaction(new com.acme.MockUserTransaction());
// Define an env entry with webapp scope.
// THIS ENTRY IS OVERRIDEN BY THE ENTRY IN jetty-env.xml
// THIS ENTRY IS OVERRIDDEN BY THE ENTRY IN jetty-env.xml
new EnvEntry(webapp, "maxAmount", 100d, true);
// Register a mock DataSource scoped to the webapp
@ -70,10 +73,23 @@ public class ServerWithAnnotations
server.addBean(new NamingDump());
// Configure a LoginService
String realmResourceName = "etc/realm.properties";
ClassLoader classLoader = ServerWithAnnotations.class.getClassLoader();
URL realmProps = classLoader.getResource(realmResourceName);
if (realmProps == null)
throw new FileNotFoundException("Unable to find " + realmResourceName);
HashLoginService loginService = new HashLoginService();
loginService.setName("Test Realm");
loginService.setConfig("examples/embedded/src/test/resources/realm.properties");
loginService.setConfig(realmProps.toExternalForm());
server.addBean(loginService);
return server;
}
public static void main(String[] args) throws Exception
{
int port = ExampleUtil.getPort(args, "jetty.http.port", 8080);
Server server = createServer(port);
server.start();
server.dumpStdErr();

View File

@ -1,24 +1,25 @@
//
// ========================================================================
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.embedded;
import java.lang.management.ManagementFactory;
import java.net.MalformedURLException;
import javax.management.remote.JMXServiceURL;
import org.eclipse.jetty.jmx.ConnectorServer;
@ -26,17 +27,16 @@ import org.eclipse.jetty.jmx.MBeanContainer;
import org.eclipse.jetty.server.Server;
/**
* The simplest possible Jetty server.
* A Jetty Server with JMX enabled for remote connections
*/
public class ServerWithJMX
{
public static void main(String[] args) throws Exception
public static Server createServer(int port) throws MalformedURLException
{
// === jetty-jmx.xml ===
Server server = new Server(port);
MBeanContainer mbContainer = new MBeanContainer(
ManagementFactory.getPlatformMBeanServer());
Server server = new Server(8080);
server.addBean(mbContainer);
ConnectorServer jmx = new ConnectorServer(
@ -48,6 +48,14 @@ public class ServerWithJMX
"org.eclipse.jetty.jmx:name=rmiconnectorserver");
server.addBean(jmx);
return server;
}
public static void main(String[] args) throws Exception
{
int port = ExampleUtil.getPort(args, "jetty.http.port", 8080);
Server server = createServer(port);
server.start();
server.dumpStdErr();
server.join();

View File

@ -1,29 +1,31 @@
//
// ========================================================================
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.embedded;
import java.io.File;
import java.nio.file.Path;
import java.util.Properties;
import javax.naming.NamingException;
import org.eclipse.jetty.plus.webapp.EnvConfiguration;
import org.eclipse.jetty.plus.webapp.PlusConfiguration;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.util.resource.PathResource;
import org.eclipse.jetty.webapp.WebAppContext;
/**
@ -31,18 +33,16 @@ import org.eclipse.jetty.webapp.WebAppContext;
*/
public class ServerWithJNDI
{
public static void main(String[] args) throws Exception
public static Server createServer(int port) throws NamingException
{
// Create the server
Server server = new Server(8080);
Server server = new Server(port);
// Create a WebApp
WebAppContext webapp = new WebAppContext();
webapp.setContextPath("/");
File warFile = new File(
"../../jetty-distribution/target/distribution/demo-base/webapps/test-jndi.war");
webapp.setWar(warFile.getAbsolutePath());
Path testJndiWar = JettyDistribution.resolve("demo-base/webapps/test-jndi.war");
webapp.setWarResource(new PathResource(testJndiWar));
server.setHandler(webapp);
// Enable parsing of jndi-related parts of web.xml and jetty-env.xml
@ -74,7 +74,7 @@ public class ServerWithJNDI
// Note that the last arg of "true" means that this definition for
// "wiggle" would override an entry of the
// same name in web.xml
new org.eclipse.jetty.plus.jndi.EnvEntry(webapp, "wiggle", 100D, true);
new org.eclipse.jetty.plus.jndi.EnvEntry(webapp, "wiggle", 100d, true);
// Register a reference to a mail service scoped to the webapp.
// This must be linked to the webapp by an entry in web.xml:
@ -84,7 +84,8 @@ public class ServerWithJNDI
// <res-auth>Container</res-auth>
// </resource-ref>
// At runtime the webapp accesses this as java:comp/env/mail/Session
org.eclipse.jetty.jndi.factories.MailSessionReference mailref = new org.eclipse.jetty.jndi.factories.MailSessionReference();
org.eclipse.jetty.jndi.factories.MailSessionReference mailref =
new org.eclipse.jetty.jndi.factories.MailSessionReference();
mailref.setUser("CHANGE-ME");
mailref.setPassword("CHANGE-ME");
Properties props = new Properties();
@ -106,6 +107,13 @@ public class ServerWithJNDI
// java:comp/env/jdbc/mydatasource
new org.eclipse.jetty.plus.jndi.Resource(
webapp, "jdbc/mydatasource", new com.acme.MockDataSource());
return server;
}
public static void main(String[] args) throws Exception
{
int port = ExampleUtil.getPort(args, "jetty.http.port", 8080);
Server server = createServer(port);
server.start();
server.join();

View File

@ -1,19 +1,19 @@
//
// ========================================================================
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.embedded;
@ -25,11 +25,20 @@ import org.eclipse.jetty.server.Server;
*/
public class SimplestServer
{
public static Server createServer(int port)
{
Server server = new Server(port);
// This has a connector listening on port specified
// and no handlers, meaning all requests will result
// in a 404 response
return server;
}
public static void main(String[] args) throws Exception
{
Server server = new Server(8080);
int port = ExampleUtil.getPort(args, "jetty.http.port", 8080);
Server server = createServer(port);
server.start();
server.dumpStdErr();
server.join();
}
}

View File

@ -1,33 +1,31 @@
//
// ========================================================================
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.embedded;
import java.io.File;
import java.nio.file.Paths;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
import org.eclipse.jetty.server.handler.ResourceHandler;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.eclipse.jetty.util.resource.PathResource;
import org.eclipse.jetty.util.resource.Resource;
/**
@ -37,59 +35,68 @@ import org.eclipse.jetty.util.resource.Resource;
*/
public class SplitFileServer
{
public static void main(String[] args) throws Exception
public static Server createServer(int port, Resource baseResource0, Resource baseResource1)
{
// Create the Server object and a corresponding ServerConnector and then
// set the port for the connector. In this example the server will
// listen on port 8090. If you set this to port 0 then when the server
// listen on port 8080. If you set this to port 0 then when the server
// has been started you can called connector.getLocalPort() to
// programmatically get the port the server started on.
Server server = new Server();
ServerConnector connector = new ServerConnector(server);
connector.setPort(8090);
server.setConnectors(new Connector[]{connector});
connector.setPort(port);
server.addConnector(connector);
// Create a Context Handler and ResourceHandler. The ContextHandler is
// getting set to "/" path but this could be anything you like for
// builing out your url. Note how we are setting the ResourceBase using
// building out your url. Note how we are setting the ResourceBase using
// our jetty maven testing utilities to get the proper resource
// directory, you needn't use these, you simply need to supply the paths
// you are looking to serve content from.
ResourceHandler rh0 = new ResourceHandler();
rh0.setDirectoriesListed(false);
ContextHandler context0 = new ContextHandler();
context0.setContextPath("/");
File dir0 = MavenTestingUtils.getTestResourceDir("dir0");
context0.setBaseResource(Resource.newResource(dir0));
context0.setBaseResource(baseResource0);
context0.setHandler(rh0);
// Rinse and repeat the previous item, only specifying a different
// resource base.
ResourceHandler rh1 = new ResourceHandler();
rh1.setDirectoriesListed(false);
ContextHandler context1 = new ContextHandler();
context1.setContextPath("/");
File dir1 = MavenTestingUtils.getTestResourceDir("dir1");
context1.setBaseResource(Resource.newResource(dir1));
context1.setBaseResource(baseResource1);
context1.setHandler(rh1);
// Create a ContextHandlerCollection and set the context handlers to it.
// This will let jetty process urls against the declared contexts in
// order to match up content.
ContextHandlerCollection contexts = new ContextHandlerCollection();
contexts.setHandlers(new Handler[]{context0, context1});
ContextHandlerCollection contexts = new ContextHandlerCollection(
context0, context1
);
server.setHandler(contexts);
return server;
}
// Start things up!
server.start();
public static void main(String[] args) throws Exception
{
int port = ExampleUtil.getPort(args, "jetty.http.port", 8080);
Resource resource0 = new PathResource(Paths.get("src/test/resources/dir0"));
Resource resource1 = new PathResource(Paths.get("src/test/resources/dir1"));
Server server = createServer(port, resource0, resource1);
// Dump the server state
System.out.println(server.dump());
server.setDumpAfterStart(true);
// Start things up!
server.start();
// The use of server.join() the will make the current thread join and
// wait until the server is done executing.
// See http://docs.oracle.com/javase/7/docs/api/java/lang/Thread.html#join()
server.join();
}
}

View File

@ -1,19 +1,19 @@
//
// ========================================================================
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.embedded;
@ -26,7 +26,7 @@ import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.DefaultHandler;
import org.eclipse.jetty.server.handler.HandlerList;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.websocket.javax.server.JavaxWebSocketServletContainerInitializer;
import org.eclipse.jetty.websocket.javax.server.config.JavaxWebSocketServletContainerInitializer;
/**
* Example of setting up a javax.websocket server with Jetty embedded
@ -46,25 +46,37 @@ public class WebSocketJsrServer
}
}
public static void main(String[] args) throws Exception
public static Server createServer(int port)
{
final Server server = new Server(8080);
Server server = new Server(port);
HandlerList handlers = new HandlerList();
ServletContextHandler contextHandler = new ServletContextHandler(
ServletContextHandler.SESSIONS);
contextHandler.setContextPath("/");
handlers.addHandler(contextHandler);
ServletContextHandler context = new ServletContextHandler();
context.setContextPath("/");
handlers.addHandler(context);
// Enable javax.websocket configuration for the context
JavaxWebSocketServletContainerInitializer.configure(context,
(servletContext, serverContainer) ->
{
// Add your websocket to the javax.websocket.server.ServerContainer
serverContainer.addEndpoint(EchoJsrSocket.class);
}
);
handlers.addHandler(new DefaultHandler());
server.setHandler(handlers);
// Enable javax.websocket configuration for the context
JavaxWebSocketServletContainerInitializer.configure(contextHandler, (context, container) ->
container.addEndpoint(EchoJsrSocket.class));
return server;
}
public static void main(String[] args) throws Exception
{
int port = ExampleUtil.getPort(args, "jetty.http.port", 8080);
Server server = createServer(port);
server.start();
contextHandler.dumpStdErr();
server.join();
}
}

View File

@ -1,32 +1,32 @@
//
// ========================================================================
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.embedded;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.api.WriteCallback;
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage;
import org.eclipse.jetty.websocket.api.annotations.WebSocket;
import org.eclipse.jetty.websocket.server.JettyWebSocketServlet;
import org.eclipse.jetty.websocket.server.JettyWebSocketServletFactory;
import org.eclipse.jetty.websocket.server.config.JettyWebSocketServletContainerInitializer;
/**
* Example of setting up a Jetty WebSocket server
@ -61,20 +61,29 @@ public class WebSocketServer
}
}
public static void main(String[] args) throws Exception
public static Server createServer(int port)
{
Server server = new Server(8080);
Server server = new Server(port);
ServletContextHandler context = new ServletContextHandler(
ServletContextHandler.SESSIONS);
ServletContextHandler context = new ServletContextHandler();
context.setContextPath("/");
server.setHandler(context);
// Add the echo socket servlet to the /echo path map
context.addServlet(new ServletHolder(EchoServlet.class), "/echo");
context.addServlet(EchoServlet.class, "/echo");
// Configure context to support WebSocket
JettyWebSocketServletContainerInitializer.configure(context, null);
return server;
}
public static void main(String[] args) throws Exception
{
int port = ExampleUtil.getPort(args, "jetty.http.port", 8080);
Server server = createServer(port);
server.start();
context.dumpStdErr();
server.join();
}
}

Binary file not shown.

View File

@ -0,0 +1,20 @@
#
# This file defines users passwords and roles for a HashUserRealm
#
# The format is
# <username>: <password>[,<rolename> ...]
#
# Passwords may be clear text, obfuscated or checksummed. The class
# org.eclipse.jetty.util.security.Password should be used to generate obfuscated
# passwords or password checksums
#
# If DIGEST Authentication is used, the password must be in a recoverable
# format, either plain text or OBF:.
#
jetty:MD5:164c88b302622e17050af52c89945d44,user
admin:CRYPT:adpexzg3FUZAk,server-administrator,content-administrator,admin,user
other:OBF:1xmk1w261u9r1w1c1xmq,user
plain:plain,user
user:password,user
# This entry is for digest auth. The credential is a MD5 hash of username:realmname:password
digest:MD5:6e120743ad67abfbc385bc2bb754e297,user

View File

@ -8,7 +8,9 @@
<Item>
<New class="org.eclipse.jetty.server.ServerConnector">
<Arg><Ref refid="ExampleServer"/></Arg>
<Set name="port">8080</Set>
<Set name="port">
<Property name="http.port" default="8080" />
</Set>
</New>
</Item>
</Array>

View File

@ -7,7 +7,9 @@
<Arg>
<New class="org.eclipse.jetty.server.ServerConnector">
<Arg><Ref refid="FileServer"/></Arg>
<Set name="port">8080</Set>
<Set name="port">
<Property name="http.port" default="8080" />
</Set>
</New>
</Arg>
</Call>
@ -22,7 +24,9 @@
<Set name="welcomeFiles">
<Array type="String"><Item>index.html</Item></Array>
</Set>
<Set name="resourceBase">.</Set>
<Set name="resourceBase">
<Property name="fileserver.baseresource" default="." />
</Set>
</New>
</Item>
<Item>

View File

@ -1,4 +1,4 @@
#org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.JavaUtilLog
## Jetty Logging using jetty-slf4j-impl
#org.eclipse.jetty.util.log.javautil.PROPERTIES=java-util-logging.properties
#org.eclipse.jetty.util.log.SOURCE=true
#org.eclipse.jetty.LEVEL=INFO

View File

@ -0,0 +1,64 @@
//
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.embedded;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.client.http.HttpClientTransportOverHTTP;
import org.eclipse.jetty.io.ClientConnector;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
public abstract class AbstractEmbeddedTest
{
public HttpClient client;
@BeforeEach
public void startClient() throws Exception
{
SslContextFactory.Client sslContextFactory = new SslContextFactory.Client();
sslContextFactory.setTrustAll(true);
ClientConnector clientConnector = new ClientConnector();
clientConnector.setSelectors(1);
clientConnector.setSslContextFactory(sslContextFactory);
QueuedThreadPool clientThreads = new QueuedThreadPool();
clientThreads.setName("client");
clientConnector.setExecutor(clientThreads);
client = new HttpClient(new HttpClientTransportOverHTTP(clientConnector));
client.start();
}
@AfterEach
public void stopClient() throws Exception
{
client.stop();
}
protected void dumpResponseHeaders(ContentResponse response)
{
System.out.printf("%s %s %s%n", response.getVersion(), response.getStatus(), response.getReason());
System.out.println(response.getHeaders());
}
}

View File

@ -0,0 +1,90 @@
//
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.embedded;
import java.net.URI;
import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.client.util.StringContentProvider;
import org.eclipse.jetty.http.HttpMethod;
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.server.Server;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;
public class ExampleServerTest extends AbstractEmbeddedTest
{
private Server server;
@BeforeEach
public void startServer() throws Exception
{
server = ExampleServer.createServer(0);
server.start();
}
@AfterEach
public void stopServer() throws Exception
{
server.stop();
}
@Test
public void testGetHello() throws Exception
{
URI uri = server.getURI().resolve("/hello");
ContentResponse response = client.newRequest(uri)
.method(HttpMethod.GET)
.send();
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
// dumpResponseHeaders(response);
// test response content
String responseBody = response.getContentAsString();
assertThat("Response Content", responseBody, containsString("Hello"));
}
@Test
public void testGetEcho() throws Exception
{
URI uri = server.getURI().resolve("/echo/a/greeting");
String postBody = "Greetings from " + ExampleServerTest.class;
ContentResponse response = client.newRequest(uri)
.method(HttpMethod.POST)
.content(new StringContentProvider(postBody))
.send();
// Check the response status code
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
// dumpResponseHeaders(response);
// test response content
String responseBody = response.getContentAsString();
assertThat("Response Content", responseBody, containsString(postBody));
}
}

View File

@ -0,0 +1,67 @@
//
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.embedded;
import java.net.URI;
import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.http.HttpMethod;
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.server.Server;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;
public class ExampleServerXmlTest extends AbstractEmbeddedTest
{
private Server server;
@BeforeEach
public void startServer() throws Exception
{
server = ExampleServerXml.createServer(0);
server.start();
}
@AfterEach
public void stopServer() throws Exception
{
server.stop();
}
@Test
public void testGetHello() throws Exception
{
URI uri = server.getURI().resolve("/hello");
ContentResponse response = client.newRequest(uri)
.method(HttpMethod.GET)
.send();
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
// dumpResponseHeaders(response);
// test response content
String responseBody = response.getContentAsString();
assertThat("Response Content", responseBody, containsString("Hello"));
}
}

View File

@ -0,0 +1,92 @@
//
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.embedded;
import java.io.BufferedWriter;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.http.HttpFields;
import org.eclipse.jetty.http.HttpMethod;
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDir;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
@ExtendWith(WorkDirExtension.class)
public class FastFileServerTest extends AbstractEmbeddedTest
{
private static final String TEXT_CONTENT = "I am an old man and I have known a great " +
"many troubles, but most of them never happened. - Mark Twain";
public WorkDir workDir;
private Server server;
@BeforeEach
public void startServer() throws Exception
{
Path baseDir = workDir.getEmptyPathDir();
Path textFile = baseDir.resolve("simple.txt");
try (BufferedWriter writer = Files.newBufferedWriter(textFile, UTF_8))
{
writer.write(TEXT_CONTENT);
}
server = FastFileServer.createServer(0, baseDir.toFile());
server.start();
}
@AfterEach
public void stopServer() throws Exception
{
server.stop();
}
@Test
public void testGetSimpleText() throws Exception
{
URI uri = server.getURI().resolve("/simple.txt");
ContentResponse response = client.newRequest(uri)
.method(HttpMethod.GET)
.send();
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
// dumpResponseHeaders(response);
HttpFields responseHeaders = response.getHeaders();
assertThat("Content-Type", responseHeaders.get("Content-Type"), is("text/plain"));
assertThat("Content-Length", responseHeaders.getLongField("Content-Length"),
is((long)TEXT_CONTENT.length()));
// test response content
String responseBody = response.getContentAsString();
assertThat("Response body", responseBody, is(TEXT_CONTENT));
}
}

View File

@ -0,0 +1,93 @@
//
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.embedded;
import java.io.BufferedWriter;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.http.HttpFields;
import org.eclipse.jetty.http.HttpMethod;
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDir;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension;
import org.eclipse.jetty.util.resource.PathResource;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
@ExtendWith(WorkDirExtension.class)
public class FileServerTest extends AbstractEmbeddedTest
{
private static final String TEXT_CONTENT = "I am an old man and I have known a great " +
"many troubles, but most of them never happened. - Mark Twain";
public WorkDir workDir;
private Server server;
@BeforeEach
public void startServer() throws Exception
{
Path baseDir = workDir.getEmptyPathDir();
Path textFile = baseDir.resolve("simple.txt");
try (BufferedWriter writer = Files.newBufferedWriter(textFile, UTF_8))
{
writer.write(TEXT_CONTENT);
}
server = FileServer.createServer(0, new PathResource(baseDir));
server.start();
}
@AfterEach
public void stopServer() throws Exception
{
server.stop();
}
@Test
public void testGetSimpleText() throws Exception
{
URI uri = server.getURI().resolve("/simple.txt");
ContentResponse response = client.newRequest(uri)
.method(HttpMethod.GET)
.send();
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
// dumpResponseHeaders(response);
HttpFields responseHeaders = response.getHeaders();
assertThat("Content-Type", responseHeaders.get("Content-Type"), is("text/plain"));
assertThat("Content-Length", responseHeaders.getLongField("Content-Length"),
is((long)TEXT_CONTENT.length()));
// test response content
String responseBody = response.getContentAsString();
assertThat("Response body", responseBody, is(TEXT_CONTENT));
}
}

View File

@ -0,0 +1,92 @@
//
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.embedded;
import java.io.BufferedWriter;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.http.HttpFields;
import org.eclipse.jetty.http.HttpMethod;
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDir;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
@ExtendWith(WorkDirExtension.class)
public class FileServerXmlTest extends AbstractEmbeddedTest
{
private static final String TEXT_CONTENT = "I am an old man and I have known a great " +
"many troubles, but most of them never happened. - Mark Twain";
public WorkDir workDir;
private Server server;
@BeforeEach
public void startServer() throws Exception
{
Path baseDir = workDir.getEmptyPathDir();
Path textFile = baseDir.resolve("simple.txt");
try (BufferedWriter writer = Files.newBufferedWriter(textFile, UTF_8))
{
writer.write(TEXT_CONTENT);
}
server = FileServerXml.createServer(0, baseDir);
server.start();
}
@AfterEach
public void stopServer() throws Exception
{
server.stop();
}
@Test
public void testGetSimpleText() throws Exception
{
URI uri = server.getURI().resolve("/simple.txt");
ContentResponse response = client.newRequest(uri)
.method(HttpMethod.GET)
.send();
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
// dumpResponseHeaders(response);
HttpFields responseHeaders = response.getHeaders();
assertThat("Content-Type", responseHeaders.get("Content-Type"), is("text/plain"));
assertThat("Content-Length", responseHeaders.getLongField("Content-Length"),
is((long)TEXT_CONTENT.length()));
// test response content
String responseBody = response.getContentAsString();
assertThat("Response body", responseBody, is(TEXT_CONTENT));
}
}

View File

@ -0,0 +1,83 @@
//
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.embedded;
import java.net.URI;
import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.http.HttpMethod;
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.server.Server;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;
public class JarServerTest extends AbstractEmbeddedTest
{
private Server server;
@BeforeEach
public void startServer() throws Exception
{
server = JarServer.createServer(0);
server.start();
}
@AfterEach
public void stopServer() throws Exception
{
server.stop();
}
@Test
public void testGetDir0Test0() throws Exception
{
URI uri = server.getURI().resolve("/dir0/test0.txt");
ContentResponse response = client.newRequest(uri)
.method(HttpMethod.GET)
.send();
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
// dumpResponseHeaders(response);
// test response content
String responseBody = response.getContentAsString();
assertThat("Response Content", responseBody, containsString("test0"));
}
@Test
public void testGetDir1Test1() throws Exception
{
URI uri = server.getURI().resolve("/dir1/test1.txt");
ContentResponse response = client.newRequest(uri)
.method(HttpMethod.GET)
.send();
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
// dumpResponseHeaders(response);
// test response content
String responseBody = response.getContentAsString();
assertThat("Response Content", responseBody, containsString("test1"));
}
}

View File

@ -0,0 +1,97 @@
//
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.embedded;
import java.net.URI;
import java.util.Map;
import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.http.HttpMethod;
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.util.component.LifeCycle;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
public class LikeJettyXmlTest extends AbstractEmbeddedTest
{
private Server server;
private URI serverPlainUri;
private URI serverSslUri;
@BeforeEach
public void startServer() throws Exception
{
assumeTrue(JettyDistribution.DISTRIBUTION != null, "jetty-distribution not found");
server = LikeJettyXml.createServer(0, 0, false);
server.start();
Map<String, Integer> ports = ServerUtil.fixDynamicPortConfigurations(server);
// Establish base URI's that use "localhost" to prevent tripping over
// the "REMOTE ACCESS" warnings in demo-base
serverPlainUri = URI.create("http://localhost:" + ports.get("plain") + "/");
serverSslUri = URI.create("https://localhost:" + ports.get("secure") + "/");
}
@AfterEach
public void stopServer() throws Exception
{
LifeCycle.stop(server);
}
@Test
public void testGetTest() throws Exception
{
URI uri = serverPlainUri.resolve("/test/");
ContentResponse response = client.newRequest(uri)
.method(HttpMethod.GET)
.send();
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
// dumpResponseHeaders(response);
// test response content
String responseBody = response.getContentAsString();
assertThat("Response Content", responseBody, containsString("Hello"));
}
@Test
public void testGetTestSsl() throws Exception
{
URI uri = serverSslUri.resolve("/test/");
ContentResponse response = client.newRequest(uri)
.method(HttpMethod.GET)
.send();
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
// dumpResponseHeaders(response);
// test response content
String responseBody = response.getContentAsString();
assertThat("Response Content", responseBody, containsString("Hello"));
}
}

View File

@ -0,0 +1,95 @@
//
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.embedded;
import java.net.URI;
import java.util.Map;
import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.http.HttpMethod;
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.server.Server;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;
public class ManyConnectorsTest extends AbstractEmbeddedTest
{
private Server server;
private URI serverPlainUri;
private URI serverSslUri;
@BeforeEach
public void startServer() throws Exception
{
server = ManyConnectors.createServer(0, 0);
server.start();
Map<String, Integer> ports = ServerUtil.fixDynamicPortConfigurations(server);
// Establish base URI's that use "localhost" to prevent tripping over
// the "REMOTE ACCESS" warnings in demo-base
serverPlainUri = URI.create("http://localhost:" + ports.get("plain") + "/");
serverSslUri = URI.create("https://localhost:" + ports.get("secure") + "/");
}
@AfterEach
public void stopServer() throws Exception
{
server.stop();
}
@Test
public void testPlainGetHello() throws Exception
{
URI uri = serverPlainUri.resolve("/hello");
ContentResponse response = client.newRequest(uri)
.method(HttpMethod.GET)
.send();
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
// dumpResponseHeaders(response);
// test response content
String responseBody = response.getContentAsString();
assertThat("Response Content", responseBody, containsString("Hello"));
}
@Test
public void testSecureGetHello() throws Exception
{
URI uri = serverSslUri.resolve("/hello");
ContentResponse response = client.newRequest(uri)
.method(HttpMethod.GET)
.send();
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
// dumpResponseHeaders(response);
// test response content
String responseBody = response.getContentAsString();
assertThat("Response Content", responseBody, containsString("Hello"));
}
}

View File

@ -0,0 +1,117 @@
//
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.embedded;
import java.net.URI;
import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.http.HttpMethod;
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.server.Server;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;
public class ManyContextsTest extends AbstractEmbeddedTest
{
private Server server;
@BeforeEach
public void startServer() throws Exception
{
server = ManyContexts.createServer(0);
server.start();
}
@AfterEach
public void stopServer() throws Exception
{
server.stop();
}
@Test
public void testGetRootHello() throws Exception
{
URI uri = server.getURI().resolve("/");
ContentResponse response = client.newRequest(uri)
.method(HttpMethod.GET)
.send();
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
// dumpResponseHeaders(response);
// test response content
String responseBody = response.getContentAsString();
assertThat("Response Content", responseBody, containsString("Root Hello"));
}
@Test
public void testGetFrenchHello() throws Exception
{
URI uri = server.getURI().resolve("/fr");
ContentResponse response = client.newRequest(uri)
.method(HttpMethod.GET)
.send();
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
// dumpResponseHeaders(response);
// test response content
String responseBody = response.getContentAsString();
assertThat("Response Content", responseBody, containsString("Bonjour"));
}
@Test
public void testGetItalianGoodMorning() throws Exception
{
URI uri = server.getURI().resolve("/it");
ContentResponse response = client.newRequest(uri)
.method(HttpMethod.GET)
.send();
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
// dumpResponseHeaders(response);
// test response content
String responseBody = response.getContentAsString();
assertThat("Response Content", responseBody, containsString("Buongiorno"));
}
@Test
public void testGetVirtualHostHello() throws Exception
{
int port = server.getURI().getPort();
URI uri = URI.create("http://127.0.0.2:" + port + "/");
ContentResponse response = client.newRequest(uri)
.method(HttpMethod.GET)
.send();
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
// dumpResponseHeaders(response);
// test response content
String responseBody = response.getContentAsString();
assertThat("Response Content", responseBody, containsString("Virtual Hello"));
}
}

View File

@ -0,0 +1,106 @@
//
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.embedded;
import java.net.URI;
import java.util.Map;
import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.http.HttpMethod;
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.util.ajax.JSON;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;
public class ManyHandlersTest extends AbstractEmbeddedTest
{
private Server server;
@BeforeEach
public void startServer() throws Exception
{
server = ManyHandlers.createServer(0);
server.start();
}
@AfterEach
public void stopServer() throws Exception
{
server.stop();
}
@Test
public void testGetParams() throws Exception
{
URI uri = server.getURI().resolve("/params?a=b&foo=bar");
ContentResponse response = client.newRequest(uri)
.method(HttpMethod.GET)
.header(HttpHeader.ACCEPT_ENCODING, "gzip")
.send();
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
// dumpResponseHeaders(response);
// test gzip
// Test that Gzip was used to produce the response
String contentEncoding = response.getHeaders().get(HttpHeader.CONTENT_ENCODING);
assertThat("Content-Encoding", contentEncoding, containsString("gzip"));
// test response content
String responseBody = response.getContentAsString();
Object jsonObj = new JSON().fromJSON(responseBody);
@SuppressWarnings("unchecked")
Map<String, Object> jsonMap = (Map<String, Object>)jsonObj;
assertThat("Response JSON keys.size", jsonMap.keySet().size(), is(2));
}
@Test
public void testGetHello() throws Exception
{
URI uri = server.getURI().resolve("/hello");
ContentResponse response = client.newRequest(uri)
.method(HttpMethod.GET)
.header(HttpHeader.ACCEPT_ENCODING, "gzip")
.send();
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
// dumpResponseHeaders(response);
// test gzip
// Test that Gzip was used to produce the response
String contentEncoding = response.getHeaders().get(HttpHeader.CONTENT_ENCODING);
assertThat("Content-Encoding", contentEncoding, containsString("gzip"));
// test expected header from wrapper
String welcome = response.getHeaders().get("X-Welcome");
assertThat("X-Welcome header", welcome, containsString("Greetings from WelcomeWrapHandler"));
// test response content
String responseBody = response.getContentAsString();
assertThat("Response Content", responseBody, containsString("Hello"));
}
}

View File

@ -0,0 +1,115 @@
//
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.embedded;
import java.net.URI;
import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.http.HttpMethod;
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.server.Server;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;
public class ManyServletContextsTest extends AbstractEmbeddedTest
{
private Server server;
@BeforeEach
public void startServer() throws Exception
{
server = ManyServletContexts.createServer(0);
server.start();
}
@AfterEach
public void stopServer() throws Exception
{
server.stop();
}
@Test
public void testGetHello() throws Exception
{
URI uri = server.getURI().resolve("/hello");
ContentResponse response = client.newRequest(uri)
.method(HttpMethod.GET)
.send();
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
// dumpResponseHeaders(response);
// test response content
String responseBody = response.getContentAsString();
assertThat("Response Content", responseBody, containsString("Hello"));
}
@Test
public void testGetItalianHello() throws Exception
{
URI uri = server.getURI().resolve("/it/hello");
ContentResponse response = client.newRequest(uri)
.method(HttpMethod.GET)
.send();
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
// dumpResponseHeaders(response);
// test response content
String responseBody = response.getContentAsString();
assertThat("Response Content", responseBody, containsString("Ciao"));
}
@Test
public void testGetFrenchHello() throws Exception
{
URI uri = server.getURI().resolve("/fr/hello");
ContentResponse response = client.newRequest(uri)
.method(HttpMethod.GET)
.send();
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
// dumpResponseHeaders(response);
// test response content
String responseBody = response.getContentAsString();
assertThat("Response Content", responseBody, containsString("Bonjour"));
}
@Test
public void testGetOtherYo() throws Exception
{
URI uri = server.getURI().resolve("/other/hello.yo");
ContentResponse response = client.newRequest(uri)
.method(HttpMethod.GET)
.send();
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
// dumpResponseHeaders(response);
// test response content
String responseBody = response.getContentAsString();
assertThat("Response Content", responseBody, containsString("YO!"));
}
}

View File

@ -0,0 +1,67 @@
//
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.embedded;
import java.net.URI;
import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.http.HttpMethod;
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.server.Server;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;
public class MinimalServletsTest extends AbstractEmbeddedTest
{
private Server server;
@BeforeEach
public void startServer() throws Exception
{
server = MinimalServlets.createServer(0);
server.start();
}
@AfterEach
public void stopServer() throws Exception
{
server.stop();
}
@Test
public void testGetHello() throws Exception
{
URI uri = server.getURI().resolve("/hello");
ContentResponse response = client.newRequest(uri)
.method(HttpMethod.GET)
.send();
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
// dumpResponseHeaders(response);
// test response content
String responseBody = response.getContentAsString();
assertThat("Response Content", responseBody, containsString("Hello"));
}
}

View File

@ -0,0 +1,67 @@
//
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.embedded;
import java.net.URI;
import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.http.HttpMethod;
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.server.Server;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;
public class OneConnectorTest extends AbstractEmbeddedTest
{
private Server server;
@BeforeEach
public void startServer() throws Exception
{
server = OneConnector.createServer(0);
server.start();
}
@AfterEach
public void stopServer() throws Exception
{
server.stop();
}
@Test
public void testGetHello() throws Exception
{
URI uri = server.getURI().resolve("/hello");
ContentResponse response = client.newRequest(uri)
.method(HttpMethod.GET)
.send();
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
// dumpResponseHeaders(response);
// test response content
String responseBody = response.getContentAsString();
assertThat("Response Content", responseBody, containsString("Hello"));
}
}

View File

@ -0,0 +1,67 @@
//
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.embedded;
import java.net.URI;
import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.http.HttpMethod;
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.server.Server;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;
public class OneContextTest extends AbstractEmbeddedTest
{
private Server server;
@BeforeEach
public void startServer() throws Exception
{
server = OneContext.createServer(0);
server.start();
}
@AfterEach
public void stopServer() throws Exception
{
server.stop();
}
@Test
public void testGetHello() throws Exception
{
URI uri = server.getURI().resolve("/hello");
ContentResponse response = client.newRequest(uri)
.method(HttpMethod.GET)
.send();
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
// dumpResponseHeaders(response);
// test response content
String responseBody = response.getContentAsString();
assertThat("Response Content", responseBody, containsString("Hello"));
}
}

View File

@ -0,0 +1,67 @@
//
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.embedded;
import java.net.URI;
import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.http.HttpMethod;
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.server.Server;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;
public class OneHandlerTest extends AbstractEmbeddedTest
{
private Server server;
@BeforeEach
public void startServer() throws Exception
{
server = OneHandler.createServer(0);
server.start();
}
@AfterEach
public void stopServer() throws Exception
{
server.stop();
}
@Test
public void testGetHello() throws Exception
{
URI uri = server.getURI().resolve("/hello");
ContentResponse response = client.newRequest(uri)
.method(HttpMethod.GET)
.send();
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
// dumpResponseHeaders(response);
// test response content
String responseBody = response.getContentAsString();
assertThat("Response Content", responseBody, containsString("Hello"));
}
}

View File

@ -0,0 +1,101 @@
//
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.embedded;
import java.net.URI;
import java.util.Set;
import javax.management.MBeanServer;
import javax.management.ObjectInstance;
import javax.management.ObjectName;
import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.http.HttpMethod;
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.io.ConnectionStatistics;
import org.eclipse.jetty.jmx.MBeanContainer;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.opentest4j.AssertionFailedError;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
@ExtendWith(WorkDirExtension.class)
public class OneServletContextJmxStatsTest extends AbstractEmbeddedTest
{
private Server server;
@BeforeEach
public void startServer() throws Exception
{
server = OneServletContextJmxStats.createServer(0);
server.start();
}
@AfterEach
public void stopServer() throws Exception
{
server.stop();
}
@Test
public void testGetDumpViaPathInfo() throws Exception
{
URI uri = server.getURI().resolve("/dump/something");
ContentResponse response = client.newRequest(uri)
.method(HttpMethod.GET)
.send();
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
// dumpResponseHeaders(response);
// test response content
String responseBody = response.getContentAsString();
assertThat("Response Content", responseBody,
allOf(
containsString("DumpServlet"),
containsString("servletPath=/dump"),
containsString("pathInfo=/something")
)
);
}
@Test
public void testJmxConnectStatsPresent() throws Exception
{
MBeanContainer mbeanContainer = server.getBean(MBeanContainer.class);
MBeanServer mbeanServer = mbeanContainer.getMBeanServer();
String domain = ConnectionStatistics.class.getPackage().getName();
Set<ObjectName> mbeanNames = mbeanServer.queryNames(ObjectName.getInstance(domain + ":type=connectionstatistics,*"), null);
ObjectName connStatsName = mbeanNames.stream().findFirst().orElseThrow(AssertionFailedError::new);
ObjectInstance mbeanConnStats = mbeanServer.getObjectInstance(connStatsName);
Number connections = (Number)mbeanServer.getAttribute(connStatsName, "connections");
assertThat("stats[connections]", connections, is(notNullValue()));
assertThat("stats[connections]", connections.longValue(), greaterThanOrEqualTo(0L));
}
}

View File

@ -0,0 +1,158 @@
//
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.embedded;
import java.io.BufferedWriter;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.http.HttpMethod;
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDir;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension;
import org.eclipse.jetty.util.resource.PathResource;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;
@ExtendWith(WorkDirExtension.class)
public class OneServletContextTest extends AbstractEmbeddedTest
{
private static final String TEXT_CONTENT = "The secret of getting ahead is getting started. - Mark Twain";
public WorkDir workDir;
private Server server;
@BeforeEach
public void startServer() throws Exception
{
Path baseDir = workDir.getEmptyPathDir();
Path textFile = baseDir.resolve("simple.txt");
try (BufferedWriter writer = Files.newBufferedWriter(textFile, UTF_8))
{
writer.write(TEXT_CONTENT);
}
server = OneServletContext.createServer(0, new PathResource(baseDir));
server.start();
}
@AfterEach
public void stopServer() throws Exception
{
server.stop();
}
@Test
public void testGetHello() throws Exception
{
URI uri = server.getURI().resolve("/hello/there");
ContentResponse response = client.newRequest(uri)
.method(HttpMethod.GET)
.send();
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
// dumpResponseHeaders(response);
// test response content
String responseBody = response.getContentAsString();
assertThat("Response Content", responseBody, containsString("Hello"));
}
@Test
public void testGetDumpViaPathInfo() throws Exception
{
URI uri = server.getURI().resolve("/dump/something");
ContentResponse response = client.newRequest(uri)
.method(HttpMethod.GET)
.send();
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
// dumpResponseHeaders(response);
// test response content
String responseBody = response.getContentAsString();
assertThat("Response Content", responseBody,
allOf(
containsString("DumpServlet"),
containsString("servletPath=/dump"),
containsString("pathInfo=/something")
)
);
}
@Test
public void testGetDumpSuffix() throws Exception
{
URI uri = server.getURI().resolve("/another.dump");
ContentResponse response = client.newRequest(uri)
.method(HttpMethod.GET)
.send();
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
// dumpResponseHeaders(response);
// test response content
String responseBody = response.getContentAsString();
assertThat("Response Content", responseBody,
allOf(
containsString("DumpServlet"),
containsString("servletPath=/another.dump"),
containsString("pathInfo=null")
)
);
}
@Test
public void testGetTestDumpSuffix() throws Exception
{
URI uri = server.getURI().resolve("/test/another.dump");
ContentResponse response = client.newRequest(uri)
.method(HttpMethod.GET)
.send();
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
// dumpResponseHeaders(response);
String filterResponseHeader = response.getHeaders().get("X-TestFilter");
assertThat("X-TestFilter header", filterResponseHeader, is("true"));
// test response content
String responseBody = response.getContentAsString();
assertThat("Response Content", responseBody,
allOf(
containsString("DumpServlet"),
containsString("servletPath=/test/another.dump"),
containsString("pathInfo=null"),
containsString("request.attribute[X-ReqListener]=true"),
containsString("servletContext.attribute[X-Init]=true")
)
);
}
}

View File

@ -0,0 +1,95 @@
//
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.embedded;
import java.io.BufferedWriter;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.http.HttpMethod;
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDir;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension;
import org.eclipse.jetty.util.resource.PathResource;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;
@ExtendWith(WorkDirExtension.class)
public class OneServletContextWithSessionTest extends AbstractEmbeddedTest
{
private static final String TEXT_CONTENT = "Do the right thing. It will gratify some people and astonish the rest. - Mark Twain";
public WorkDir workDir;
private Server server;
@BeforeEach
public void startServer() throws Exception
{
Path baseDir = workDir.getEmptyPathDir();
Path textFile = baseDir.resolve("simple.txt");
try (BufferedWriter writer = Files.newBufferedWriter(textFile, UTF_8))
{
writer.write(TEXT_CONTENT);
}
server = OneServletContextWithSession.createServer(0, new PathResource(baseDir));
server.start();
}
@AfterEach
public void stopServer() throws Exception
{
server.stop();
}
@Test
public void testGetHello() throws Exception
{
URI uri = server.getURI().resolve("/");
ContentResponse response = client.newRequest(uri)
.method(HttpMethod.GET)
.send();
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
// dumpResponseHeaders(response);
String setCookieValue = response.getHeaders().get(HttpHeader.SET_COOKIE);
assertThat("Set-Cookie value", setCookieValue, containsString("JSESSIONID="));
// test response content
String responseBody = response.getContentAsString();
assertThat("Response Content", responseBody,
allOf(
containsString("session.getId() = "),
containsString("session.isNew() = true")
)
);
}
}

Some files were not shown because too many files have changed in this diff Show More