Skip to content

Commit

Permalink
Issue #12000 - use URIUtil::toURI instead of URI::create in MavenWebA…
Browse files Browse the repository at this point in the history
…ppContext
  • Loading branch information
joakime committed Jul 3, 2024
1 parent 05a0498 commit 2ecbaa6
Show file tree
Hide file tree
Showing 22 changed files with 526 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1892,15 +1892,18 @@ else if (scheme.equalsIgnoreCase("file"))
}

/**
* <p>Convert a String into a URI suitable for use as a Resource.</p>
* <p>Convert a String into a URI in a sane way.</p>
*
* @param resource If the string starts with one of the ALLOWED_SCHEMES, then it is assumed to be a
* representation of a {@link URI}, otherwise it is treated as a {@link Path}.
* <p>
* This exits to take an end user provided String and make a usable URI out of it.
* It is capable of dealing with paths that have spaces, windows slashes, windows UNC references,
* relative paths, absolute paths, and much more.
* </p>
*
* @param resource If the string starts with a recognized scheme, then it is assumed to be a representation
* of a {@link URI}, otherwise it is treated as a {@link Path} (which is then converted to a URI)
* @return The {@link URI} form of the resource.
* @deprecated This method is currently resolving relative paths against the current directory, which is a mechanism
* that should be implemented by a {@link ResourceFactory}. All calls to this method need to be reviewed.
*/
@Deprecated(since = "12.0.8")
public static URI toURI(String resource)
{
Objects.requireNonNull(resource);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1086,6 +1086,7 @@ public static Stream<Arguments> toURICases()
else
{
// URI (and unix) format (relative)
args.add(Arguments.of("/path/that has spaces/foo.jar", "file:///path/that%20has%20spaces/foo.jar"));
args.add(Arguments.of("/path/to/foo.jar", "file:///path/to/foo.jar"));
args.add(Arguments.of("/path/to/bogus.txt", "file:///path/to/bogus.txt"));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invoker.goals = test -e
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.eclipse.jetty.ee10.its.jetty-start-mojo-it</groupId>
<artifactId>jetty-simple-project</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>

<artifactId>jetty-simple-base</artifactId>
<packaging>jar</packaging>

<name>EE10 :: Simple :: Base</name>

<dependencies>
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.toolchain</groupId>
<artifactId>jetty-perf-helper</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// ========================================================================
// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.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.its.jetty_start_mojo_it;

@SuppressWarnings("serial")
public class Counter implements java.io.Serializable
{
int counter = 0;
String last;

public int getCount()
{
counter++;
return counter;
}

public void setLast(String uri)
{
last = uri;
}

public String getLast()
{
return last;
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// ========================================================================
// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.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.its.jetty_start_mojo_it;

import java.io.IOException;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

/**
*
*/
@WebServlet("/hello")
public class HelloServlet
extends HttpServlet
{

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
String who = req.getParameter("name");

resp.getWriter().write("Hello " + (who == null ? "unknown" : who));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// ========================================================================
// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.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.its.jetty_start_mojo_it;

import java.io.IOException;

import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

public class PingServlet
extends HttpServlet
{

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
String who = req.getParameter("name");

resp.getWriter().write("pong " + (who == null ? "unknown" : who));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>

<web-fragment
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-fragment_3_1.xsd"
version="3.1">

<name>FragmentA</name>

<ordering>
<after><others/></after>
</ordering>

<servlet>
<servlet-name>Ping</servlet-name>
<servlet-class>org.eclipse.jetty.its.jetty_start_mojo_it.PingServlet</servlet-class>
<init-param>
<param-name>extra1</param-name><param-value>123</param-value>
</init-param>
<init-param>
<param-name>extra2</param-name><param-value>345</param-value>
</init-param>
</servlet>

<servlet-mapping>
<servlet-name>Ping</servlet-name>
<url-pattern>/ping</url-pattern>
</servlet-mapping>


</web-fragment>
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.eclipse.jetty.ee10.its.jetty-start-mojo-it</groupId>
<artifactId>jetty-simple-project</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>

<artifactId>jetty-simple-webapp</artifactId>
<packaging>war</packaging>

<name>EE10 :: Simple :: WebApp</name>

<properties>
<jetty.port.file>${project.build.directory}/jetty-start-port.txt</jetty.port.file>
</properties>

<dependencies>

<dependency>
<groupId>org.eclipse.jetty.ee10.its.jetty-start-mojo-it</groupId>
<artifactId>jetty-simple-base</artifactId>
</dependency>

<dependency>
<groupId>org.eclipse.jetty.ee10</groupId>
<artifactId>jetty-ee10-servlet</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.eclipse.jetty.ee10</groupId>
<artifactId>jetty-ee10-maven-plugin</artifactId>
<classifier>tests</classifier>
<type>test-jar</type>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-client</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

<build>

<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>IntegrationTest*.java</include>
</includes>
<systemPropertyVariables>
<jetty.port.file>${jetty.port.file}</jetty.port.file>
<context.path>/setbycontextxml</context.path>
<pingServlet>true</pingServlet>
<helloServlet>true</helloServlet>
<contentCheck>Counter accessed 1 times.</contentCheck>
<pathToCheck>/jsp/bean1.jsp</pathToCheck>
<maven.it.name>${project.groupId}:${project.artifactId}</maven.it.name>
</systemPropertyVariables>
<dependenciesToScan>
<dependency>org.eclipse.jetty.ee10:jetty-ee10-maven-plugin</dependency>
</dependenciesToScan>
</configuration>
</plugin>
<plugin>
<groupId>org.eclipse.jetty.ee10</groupId>
<artifactId>jetty-ee10-maven-plugin</artifactId>
<executions>
<execution>
<id>start-jetty</id>
<phase>test-compile</phase>
<goals>
<goal>start</goal>
</goals>
<configuration>
<contextXml>${basedir}/src/config/context.xml</contextXml>
<systemProperties>
<jetty.port.file>${jetty.port.file}</jetty.port.file>
<jetty.deployMode>EMBED</jetty.deployMode>
</systemProperties>
<jettyXmls>
<jettyXml>${basedir}/src/config/jetty.xml</jettyXml>
</jettyXmls>
<loginServices>
<loginService implementation="org.eclipse.jetty.security.HashLoginService">
<name>Test Realm</name>
<config implementation="org.eclipse.jetty.maven.MavenResource">
<resourceAsString>${basedir}/src/config/realm.properties</resourceAsString>
</config>
</loginService>
</loginServices>
<webApp>
<jettyEnvXml>${basedir}/src/config/jetty-env.xml</jettyEnvXml>
<resourceBases>
<resourceBase>${basedir}/src/main/webapp</resourceBase>
</resourceBases>
</webApp>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">

<Configure class="org.eclipse.jetty.ee10.webapp.WebAppContext">

<Set name="contextPath">/setbycontextxml</Set>

</Configure>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://eclipse.dev/jetty/configure_10_0.dtd">
<Configure id='wac' class="org.eclipse.jetty.ee10.webapp.WebAppContext">

<!-- Add an EnvEntry only valid for this webapp -->
<New id="foo" class="org.eclipse.jetty.plus.jndi.EnvEntry">
<Arg><Ref refid='wac'/></Arg>
<Arg>fooBoolean</Arg>
<Arg type="java.lang.Double">100</Arg>
<Arg type="boolean">true</Arg>
</New>
</Configure>
Loading

0 comments on commit 2ecbaa6

Please sign in to comment.