Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
6fc87764
Commit
6fc87764
authored
Sep 18, 2016
by
Phillip Webb
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #6919 from eddumelendez/gh-6904
* pr/6919: Add contextPath LocalHostUriTemplateHandler URIs
parents
7299976d
bc55b6e0
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
22 additions
and
5 deletions
+22
-5
JerseyAutoConfigurationCustomFilterContextPathTests.java
.../JerseyAutoConfigurationCustomFilterContextPathTests.java
+1
-1
JerseyAutoConfigurationCustomServletContextPathTests.java
...JerseyAutoConfigurationCustomServletContextPathTests.java
+1
-1
LocalHostUriTemplateHandler.java
...ork/boot/test/web/client/LocalHostUriTemplateHandler.java
+10
-3
LocalHostUriTemplateHandlerTests.java
...oot/test/web/client/LocalHostUriTemplateHandlerTests.java
+10
-0
No files found.
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomFilterContextPathTests.java
View file @
6fc87764
...
...
@@ -64,7 +64,7 @@ public class JerseyAutoConfigurationCustomFilterContextPathTests {
@Test
public
void
contextLoads
()
{
ResponseEntity
<
String
>
entity
=
this
.
restTemplate
.
getForEntity
(
"/
app/
rest/hello"
,
ResponseEntity
<
String
>
entity
=
this
.
restTemplate
.
getForEntity
(
"/rest/hello"
,
String
.
class
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
}
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomServletContextPathTests.java
View file @
6fc87764
...
...
@@ -64,7 +64,7 @@ public class JerseyAutoConfigurationCustomServletContextPathTests {
@Test
public
void
contextLoads
()
{
ResponseEntity
<
String
>
entity
=
this
.
restTemplate
.
getForEntity
(
"/
app/
rest/hello"
,
ResponseEntity
<
String
>
entity
=
this
.
restTemplate
.
getForEntity
(
"/rest/hello"
,
String
.
class
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
}
...
...
spring-boot-test/src/main/java/org/springframework/boot/test/web/client/LocalHostUriTemplateHandler.java
View file @
6fc87764
...
...
@@ -16,6 +16,7 @@
package
org
.
springframework
.
boot
.
test
.
web
.
client
;
import
org.springframework.boot.bind.RelaxedPropertyResolver
;
import
org.springframework.boot.web.client.RootUriTemplateHandler
;
import
org.springframework.core.env.Environment
;
import
org.springframework.util.Assert
;
...
...
@@ -28,6 +29,7 @@ import org.springframework.web.util.UriTemplateHandler;
*
* @author Phillip Webb
* @author Andy Wilkinson
* @author Eddú Meléndez
* @since 1.4.0
*/
public
class
LocalHostUriTemplateHandler
extends
RootUriTemplateHandler
{
...
...
@@ -36,9 +38,11 @@ public class LocalHostUriTemplateHandler extends RootUriTemplateHandler {
private
final
String
scheme
;
private
RelaxedPropertyResolver
serverPropertyResolver
;
/**
* Create a new {@code LocalHostUriTemplateHandler} that will generate {@code http}
* URIs using the given {@code environment} to determine the port.
* URIs using the given {@code environment} to determine the
context path and
port.
* @param environment the environment used to determine the port
*/
public
LocalHostUriTemplateHandler
(
Environment
environment
)
{
...
...
@@ -47,7 +51,8 @@ public class LocalHostUriTemplateHandler extends RootUriTemplateHandler {
/**
* Create a new {@code LocalHostUriTemplateHandler} that will generate URIs with the
* given {@code scheme} and use the given {@code environment} to determine the port.
* given {@code scheme} and use the given {@code environment} to determine the
* context-path and port.
* @param environment the environment used to determine the port
* @param scheme the scheme of the root uri
* @since 1.4.1
...
...
@@ -58,12 +63,14 @@ public class LocalHostUriTemplateHandler extends RootUriTemplateHandler {
Assert
.
notNull
(
scheme
,
"Scheme must not be null"
);
this
.
environment
=
environment
;
this
.
scheme
=
scheme
;
this
.
serverPropertyResolver
=
new
RelaxedPropertyResolver
(
environment
,
"server."
);
}
@Override
public
String
getRootUri
()
{
String
port
=
this
.
environment
.
getProperty
(
"local.server.port"
,
"8080"
);
return
this
.
scheme
+
"://localhost:"
+
port
;
String
contextPath
=
this
.
serverPropertyResolver
.
getProperty
(
"context-path"
,
""
);
return
this
.
scheme
+
"://localhost:"
+
port
+
contextPath
;
}
}
spring-boot-test/src/test/java/org/springframework/boot/test/web/client/LocalHostUriTemplateHandlerTests.java
View file @
6fc87764
...
...
@@ -29,6 +29,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Phillip Webb
* @author Andy Wilkinson
* @author Eddú Meléndez
*/
public
class
LocalHostUriTemplateHandlerTests
{
...
...
@@ -74,4 +75,13 @@ public class LocalHostUriTemplateHandlerTests {
assertThat
(
handler
.
getRootUri
()).
isEqualTo
(
"https://localhost:8080"
);
}
@Test
public
void
getRootUriShouldUseContextPath
()
throws
Exception
{
MockEnvironment
environment
=
new
MockEnvironment
();
environment
.
setProperty
(
"server.contextPath"
,
"/foo"
);
LocalHostUriTemplateHandler
handler
=
new
LocalHostUriTemplateHandler
(
environment
);
assertThat
(
handler
.
getRootUri
()).
isEqualTo
(
"http://localhost:8080/foo"
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment