-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue #12000 - use URIUtil::toURI instead of URI::create in MavenWebAppContext #12001
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1892,24 +1892,27 @@ 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}. | ||
* @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. | ||
* <p> | ||
* This exits to take an end user provided String and make a usable URI out of it. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No indent. |
||
* It is capable of dealing with paths that have spaces, windows slashes, windows UNC references, | ||
* relative paths, absolute paths, and much more. | ||
Comment on lines
+1899
to
+1900
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This still feels like a job of a |
||
* </p> | ||
* | ||
* @param reference If the reference 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 input string. | ||
*/ | ||
@Deprecated(since = "12.0.8") | ||
public static URI toURI(String resource) | ||
public static URI toURI(String reference) | ||
{ | ||
Objects.requireNonNull(resource); | ||
Objects.requireNonNull(reference); | ||
|
||
if (URIUtil.hasScheme(resource)) | ||
if (URIUtil.hasScheme(reference)) | ||
{ | ||
try | ||
{ | ||
URI uri = new URI(resource); | ||
URI uri = new URI(reference); | ||
|
||
if (ResourceFactory.isSupported(uri)) | ||
return correctURI(uri); | ||
|
@@ -1920,7 +1923,7 @@ public static URI toURI(String resource) | |
// Input is a possible Windows path disguised as a URI "D:/path/to/resource.txt". | ||
try | ||
{ | ||
return toURI(Paths.get(resource).toUri().toASCIIString()); | ||
return toURI(Path.of(reference).toUri().toASCIIString()); | ||
} | ||
catch (InvalidPathException x) | ||
{ | ||
|
@@ -1946,7 +1949,7 @@ public static URI toURI(String resource) | |
// Treat it as a Path, as that's all we have left to investigate. | ||
try | ||
{ | ||
return toURI(Paths.get(resource).toUri().toASCIIString()); | ||
return toURI(Path.of(reference).toUri().toASCIIString()); | ||
} | ||
catch (InvalidPathException x) | ||
{ | ||
|
@@ -1957,7 +1960,7 @@ public static URI toURI(String resource) | |
// a URI or a File Path. The cause is usually due to bad input (eg: | ||
// characters that are not supported by file system) | ||
if (LOG.isDebugEnabled()) | ||
LOG.debug("Input string cannot be converted to URI \"{}\"", resource); | ||
LOG.debug("Input string cannot be converted to URI \"{}\"", reference); | ||
throw new IllegalArgumentException("Cannot be converted to URI"); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start with spaces mojo-it/invoker.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
invoker.goals = test -e |
39 changes: 39 additions & 0 deletions
39
.../jetty-ee10-maven-plugin/src/it/jetty-start with spaces mojo-it/jetty-simple-base/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
38 changes: 38 additions & 0 deletions
38
...it/jetty-simple-base/src/main/java/org/eclipse/jetty/its/jetty_start_mojo_it/Counter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
|
40 changes: 40 additions & 0 deletions
40
...tty-simple-base/src/main/java/org/eclipse/jetty/its/jetty_start_mojo_it/HelloServlet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...etty-simple-base/src/main/java/org/eclipse/jetty/its/jetty_start_mojo_it/PingServlet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...-start with spaces mojo-it/jetty-simple-base/src/main/resources/META-INF/web-fragment.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you need to say it better than "in a sane way". what does that mean?