Skip to content

Commit

Permalink
Merge pull request #25044 from OndroMih/ondromih-gh24918-proxy-scheme
Browse files Browse the repository at this point in the history
Enhancement: Respect scheme from the serverName listener property in redirect URLs
  • Loading branch information
arjantijms authored Jul 15, 2024
2 parents d87effb + 2746e91 commit 3736639
Show file tree
Hide file tree
Showing 20 changed files with 318 additions and 108 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<!--
Copyright (c) 2024 Contributors to the Eclipse Foundation.
Copyright (c) 2005, 2018 Oracle and/or its affiliates. All rights reserved.
This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -69,7 +70,7 @@ <h4><a id="sthref116" name="sthref116"></a>Edit HTTP Listener</h4>
<dt>Server Name</dt>
<dd>
<p>The host name to be used in the URLs the server sends to the client. This name is the alias name if your server uses an alias. If your server does not use an alias, leave this field blank.</p>
<p>This value affects URLs the server automatically generates; it does not affect the URLs for directories and files stored in the server. If your server uses an alias, the server-name should be the alias name. If a colon and port number are appended, that port is used in URLs the server sends to the client.</p>
<p>This value affects URLs the server automatically generates; it does not affect the URLs for directories and files stored in the server. If your server uses an alias, the server-name should be the alias name. If a colon and port number are appended, that port is used in URLs the server sends to the client. If a scheme and <code>://</code> are prepended, the scheme will be used in the URLs.</p>
</dd>
</dl>
<a id="sthref117" name="sthref117"></a>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<!--
Copyright (c) 2024 Contributors to the Eclipse Foundation.
Copyright (c) 2005, 2018 Oracle and/or its affiliates. All rights reserved.
This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -65,7 +66,7 @@ <h4><a id="sthref113" name="sthref113"></a>New HTTP Listener</h4>
<dt>Server Name</dt>
<dd>
<p>The host name to be used in the URLs the server sends to the client. This name is the alias name if your server uses an alias. If your server does not use an alias, leave this field blank.</p>
<p>This value affects URLs the server automatically generates; it does not affect the URLs for directories and files stored in the server. If your server uses an alias, the server-name should be the alias name. If a colon and port number are appended, that port is used in URLs the server sends to the client.</p>
<p>This value affects URLs the server automatically generates; it does not affect the URLs for directories and files stored in the server. If your server uses an alias, the server-name should be the alias name. If a colon and port number are appended, that port is used in URLs the server sends to the client. If a scheme and <code>://</code> are prepended, the scheme will be used in the URLs.</p>
</dd>
</dl>
<a id="sthref114" name="sthref114"></a>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<!--
Copyright (c) 2024 Contributors to the Eclipse Foundation.
Copyright (c) 2005, 2018 Oracle and/or its affiliates. All rights reserved.
This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -60,7 +61,7 @@ <h4><a id="sthref142" name="sthref142"></a>New Protocol</h4>
<dt>Server Name</dt>
<dd>
<p>The host name to be used in the URLs the server sends to the client. This name is the alias name if your server uses an alias. If your server does not use an alias, leave this field blank.</p>
<p>This value affects URLs the server automatically generates; it does not affect the URLs for directories and files stored in the server. If your server uses an alias, the server-name should be the alias name. If a colon and port number are appended, that port is used in URLs the server sends to the client.</p>
<p>This value affects URLs the server automatically generates; it does not affect the URLs for directories and files stored in the server. If your server uses an alias, the server-name should be the alias name. If a colon and port number are appended, that port is used in URLs the server sends to the client. If a scheme and <code>://</code> are prepended, the scheme will be used in the URLs.</p>
</dd>
<dt>Default Virtual Server</dt>
<dd>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<!--
Copyright (c) 2024 Contributors to the Eclipse Foundation.
Copyright (c) 2005, 2018 Oracle and/or its affiliates. All rights reserved.
This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -67,7 +68,7 @@ <h4><a id="sthref26" name="sthref26"></a>To Edit an HTTP Listener</h4>
<li>
<p>In the Server Name field, type the host name to be used in the URLs the server sends to the client.</p>
<p>This name is the alias name if your server uses an alias. If your server does not use an alias, leave this field blank.</p>
<p>This value affects URLs the server automatically generates; it does not affect the URLs for directories and files stored in the server. If your server uses an alias, the server-name should be the alias name. If a colon and port number are appended, that port is used in URLs the server sends to the client.</p>
<p>This value affects URLs the server automatically generates; it does not affect the URLs for directories and files stored in the server. If your server uses an alias, the server-name should be the alias name. If a colon and port number are appended, that port is used in URLs the server sends to the client. If a scheme and <code>://</code> are prepended, the scheme will be used in the URLs.</p>
</li>
<li>
<p>Click Save.</p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<!--
Copyright (c) 2024 Contributors to the Eclipse Foundation.
Copyright (c) 2005, 2018 Oracle and/or its affiliates. All rights reserved.
This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -72,7 +73,7 @@ <h4><a id="sthref23" name="sthref23"></a>To Create an HTTP Listener</h4>
<li>
<p>In the Server Name field, type the host name to be used in the URLs the server sends to the client.</p>
<p>This name is the alias name if your server uses an alias. If your server does not use an alias, leave this field blank.</p>
<p>This value affects URLs the server automatically generates; it does not affect the URLs for directories and files stored in the server. If your server uses an alias, the server-name should be the alias name. If a colon and port number are appended, that port is used in URLs the server sends to the client.</p>
<p>This value affects URLs the server automatically generates; it does not affect the URLs for directories and files stored in the server. If your server uses an alias, the server-name should be the alias name. If a colon and port number are appended, that port is used in URLs the server sends to the client. If a scheme and <code>://</code> are prepended, the scheme will be used in the URLs.</p>
</li>
<li>
<p>Click OK.</p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<!--
Copyright (c) 2024 Contributors to the Eclipse Foundation.
Copyright (c) 2005, 2018 Oracle and/or its affiliates. All rights reserved.
This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -64,7 +65,7 @@ <h4><a id="sthref50" name="sthref50"></a>To Create a Protocol</h4>
<li>
<p>In the Server Name field, type the host name to be used in the URLs the server sends to the client.</p>
<p>This name is the alias name if your server uses an alias. If your server does not use an alias, leave this field blank.</p>
<p>This value affects URLs the server automatically generates; it does not affect the URLs for directories and files stored in the server. If your server uses an alias, the server-name should be the alias name. If a colon and port number are appended, that port is used in URLs the server sends to the client.</p>
<p>This value affects URLs the server automatically generates; it does not affect the URLs for directories and files stored in the server. If your server uses an alias, the server-name should be the alias name. If a colon and port number are appended, that port is used in URLs the server sends to the client. If a scheme and <code>://</code> are prepended, the scheme will be used in the URLs.</p>
</li>
<li>
<p>From the Default Virtual Server drop-down list, select the virtual server to be associated with this protocol.</p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#
# Copyright (c) 2024 Contributors to the Eclipse Foundation.
# Copyright (c) 2009, 2018 Oracle and/or its affiliates. All rights reserved.
#
# This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -210,7 +211,7 @@ grizzly.httpPageTitle=HTTP
grizzly.httpPageTitleHelp=Modify HTTP settings for the protocol.

http.serverNameLabel=Server Name:
http.serverNameHelp=Alias name if server uses an alias. If a colon and port number are appended, that port will be used in URLs the server sends to the client.
http.serverNameHelp=Alias name if server uses an alias. A colon and port number can be appended. Scheme and :// can be prepended. They will be used in URLs the server sends to the client.
http.Adapter=Adapter:
http.AdapterHelp=Class name of the static resources adapter
http.defVirtualServerLabel=Default Virtual Server:
Expand Down
5 changes: 5 additions & 0 deletions appserver/tests/admin/tests/pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2024 Contributors to the Eclipse Foundation.
Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved.
This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -102,6 +103,10 @@
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, 2023 Contributors to the Eclipse Foundation
* Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation
* Copyright (c) 2012, 2020 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand All @@ -16,7 +16,7 @@
*/
package org.glassfish.main.admin.test;

import static java.nio.charset.StandardCharsets.ISO_8859_1;
import static org.glassfish.main.admin.test.ConnectionUtils.getURL;
import static org.glassfish.main.itest.tools.asadmin.AsadminResultMatcher.asadminOK;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.allOf;
Expand All @@ -28,26 +28,16 @@
import static org.hamcrest.Matchers.stringContainsInOrder;
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StringWriter;
import java.net.URL;
import java.net.URLConnection;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.commons.lang3.StringUtils;
import org.glassfish.main.itest.tools.GlassFishTestEnvironment;
import org.glassfish.main.itest.tools.asadmin.Asadmin;
import org.glassfish.main.itest.tools.asadmin.AsadminResult;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.exporter.ZipExporter;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
Expand Down Expand Up @@ -93,6 +83,10 @@ public void deployAppToClusterTest() {
warFile), asadminOK());
}

private static File getWar() {
return TestResources.createSimpleWarDeployment(TEST_APP_NAME);
}

@Test
@Order(3)
public void createInstancesTest() {
Expand Down Expand Up @@ -218,57 +212,4 @@ public void deleteClusterTest() {
assertThat(ASADMIN.exec("delete-cluster", CLUSTER_NAME), asadminOK());
}

/**
* These methods open a connection to the given URL and returns the string that is returned from that URL. This is
* useful for simple servlet retrieval
*
* @param urlstr The URL to connect to
* @return The string returned from that URL, or empty string if there was a problem contacting the URL
*/
private static String getURL(String urlstr) {
URLConnection urlc = openConnection(urlstr);
try (
BufferedReader ir = new BufferedReader(new InputStreamReader(urlc.getInputStream(), ISO_8859_1)); StringWriter ow = new StringWriter()) {
String line;
while ((line = ir.readLine()) != null) {
ow.write(line);
ow.write("\n");
}
return ow.getBuffer().toString();
} catch (IOException ex) {
return fail(ex);
}
}

private static URLConnection openConnection(String url) {
try {
return new URL(url).openConnection();
} catch (IOException e) {
throw new IllegalArgumentException(e);
}
}

protected static File getWar() {
final WebArchive war = ShrinkWrap.create(WebArchive.class)
.addAsWebResource(
new StringAsset(
"<html>\n"
+ " <head>\n"
+ " <title>Simple test app</title>\n"
+ " <meta charset=\"UTF-8\">\n"
+ " </head>\n"
+ " <body>\n"
+ " <div>Simple test app</div>\n"
+ " </body>\n"
+ "</html>"),
"index.html");
try {
File tempFile = File.createTempFile(TEST_APP_NAME, ".war");
war.as(ZipExporter.class).exportTo(tempFile, true);
return tempFile;
} catch (IOException e) {
throw new IllegalStateException("WAR file creation failed for app " + TEST_APP_NAME, e);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright (c) 2024 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://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: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package org.glassfish.main.admin.test;

import static java.nio.charset.StandardCharsets.ISO_8859_1;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StringWriter;
import java.net.URL;
import java.net.URLConnection;

public class ConnectionUtils {
/**
* This method opens a connection to the given URL and returns the string that is returned from that URL. This is
* useful for simple servlet retrieval
*
* @param urlstr The URL to connect to
* @return The string returned from that URL, or empty string if there was a problem contacting the URL
*/
public static String getURL(String urlstr) {
URLConnection urlc = openConnection(urlstr);
return getContent(urlc);
}

/**
* This method retrieves the content of the connection response as plain String
*
* @param connection
* @return The string returned from that connection, or empty string if there was a problem contacting the URL
*/
public static String getContent(URLConnection connection) {
try (
BufferedReader ir = new BufferedReader(new InputStreamReader(connection.getInputStream(), ISO_8859_1)); StringWriter ow = new StringWriter()) {
String line;
while ((line = ir.readLine()) != null) {
ow.write(line);
ow.write("\n");
}
return ow.getBuffer().toString();
} catch (IOException ex) {
return fail(ex);
}
}

public static URLConnection openConnection(String url) {
try {
return new URL(url).openConnection();
} catch (IOException e) {
throw new IllegalArgumentException(e);
}
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (c) 2024 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://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: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package org.glassfish.main.admin.test;

import java.io.File;
import java.io.IOException;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.exporter.ZipExporter;
import org.jboss.shrinkwrap.api.spec.WebArchive;

public class TestResources {

public static final String SIMPLE_HTML_PAGE
= "<html>\n"
+ " <head>\n"
+ " <title>Simple test app</title>\n"
+ " <meta charset=\"UTF-8\">\n"
+ " </head>\n"
+ " <body>\n"
+ " <div>Simple test app</div>\n"
+ " </body>\n"
+ "</html>";

public static File createSimpleWarDeployment(String appName) {
final WebArchive war = ShrinkWrap.create(WebArchive.class)
.addAsWebResource(
new StringAsset(SIMPLE_HTML_PAGE),
"index.html");
try {
File tempFile = File.createTempFile(appName, ".war");
war.as(ZipExporter.class).exportTo(tempFile, true);
return tempFile;
} catch (IOException e) {
throw new IllegalStateException("WAR file creation failed for app " + appName, e);
}
}

}
Loading

0 comments on commit 3736639

Please sign in to comment.