Skip to content
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
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Copy link
Contributor

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?

*
* @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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No indent.
s/exits/exists/

* 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still feels like a job of a ResourceFactory. Why is this needed?

* </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);
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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");
}

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>
Loading
Loading