dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #20497
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9372: support x-forwarded-proto
------------------------------------------------------------
revno: 9372
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2012-12-19 15:41:00 +0100
message:
support x-forwarded-proto
modified:
dhis-2/dhis-web/dhis-web-mobile/src/main/java/org/hisp/dhis/web/mobile/controller/MobileController.java
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-web/dhis-web-mobile/src/main/java/org/hisp/dhis/web/mobile/controller/MobileController.java'
--- dhis-2/dhis-web/dhis-web-mobile/src/main/java/org/hisp/dhis/web/mobile/controller/MobileController.java 2012-12-19 11:22:35 +0000
+++ dhis-2/dhis-web/dhis-web-mobile/src/main/java/org/hisp/dhis/web/mobile/controller/MobileController.java 2012-12-19 14:41:00 +0000
@@ -62,8 +62,7 @@
@RequestMapping(value = "/index")
public String index( Model model, HttpServletRequest request )
{
- UriComponents contextPath = ServletUriComponentsBuilder.fromContextPath( request ).build();
- model.addAttribute( "contextPath", contextPath.toString() );
+ populateContextPath( model, request );
model.addAttribute( "page", "index.vm" );
return "base";
@@ -72,8 +71,7 @@
@RequestMapping(value = "/messages")
public String messages( Model model, HttpServletRequest request )
{
- UriComponents contextPath = ServletUriComponentsBuilder.fromContextPath( request ).build();
- model.addAttribute( "contextPath", contextPath.toString() );
+ populateContextPath( model, request );
model.addAttribute( "page", "messages.vm" );
return "base";
@@ -82,8 +80,7 @@
@RequestMapping(value = "/messages/new-message")
public String newMessage( Model model, HttpServletRequest request )
{
- UriComponents contextPath = ServletUriComponentsBuilder.fromContextPath( request ).build();
- model.addAttribute( "contextPath", contextPath.toString() );
+ populateContextPath( model, request );
model.addAttribute( "page", "new-message.vm" );
return "base";
@@ -92,8 +89,7 @@
@RequestMapping(value = "/messages/{uid}")
public String message( @PathVariable("uid") String uid, Model model, HttpServletRequest request )
{
- UriComponents contextPath = ServletUriComponentsBuilder.fromContextPath( request ).build();
- model.addAttribute( "contextPath", contextPath.toString() );
+ populateContextPath( model, request );
model.addAttribute( "page", "message.vm" );
model.addAttribute( "messageId", uid );
@@ -103,8 +99,7 @@
@RequestMapping(value = "/interpretations")
public String interpretations( Model model, HttpServletRequest request )
{
- UriComponents contextPath = ServletUriComponentsBuilder.fromContextPath( request ).build();
- model.addAttribute( "contextPath", contextPath.toString() );
+ populateContextPath( model, request );
model.addAttribute( "page", "interpretations.vm" );
return "base";
@@ -113,8 +108,7 @@
@RequestMapping(value = "/user-account")
public String settings( Model model, HttpServletRequest request )
{
- UriComponents contextPath = ServletUriComponentsBuilder.fromContextPath( request ).build();
- model.addAttribute( "contextPath", contextPath.toString() );
+ populateContextPath( model, request );
model.addAttribute( "page", "user-account.vm" );
return "base";
@@ -124,8 +118,7 @@
@RequestMapping(value = "/data-entry")
public String dataEntry( Model model, HttpServletRequest request )
{
- UriComponents contextPath = ServletUriComponentsBuilder.fromContextPath( request ).build();
- model.addAttribute( "contextPath", contextPath.toString() );
+ populateContextPath( model, request );
model.addAttribute( "page", "data-entry.vm" );
return "base";
@@ -138,4 +131,26 @@
InputStream inputStream = new ClassPathResource( "dhis-mobile-manifest.appcache" ).getInputStream();
IOUtils.copy( inputStream, response.getOutputStream() );
}
+
+ private void populateContextPath( Model model, HttpServletRequest request )
+ {
+ UriComponents contextPath = ServletUriComponentsBuilder.fromContextPath( request ).build();
+
+ String contextPathString = contextPath.toString();
+ String xForwardedProto = request.getHeader( "X-Forwarded-Proto" );
+
+ if ( xForwardedProto != null )
+ {
+ if ( contextPathString.contains( "http://" ) && xForwardedProto.equalsIgnoreCase( "https" ) )
+ {
+ contextPathString = contextPathString.replace( "http://", "https://" );
+ }
+ else if ( contextPathString.contains( "https://" ) && xForwardedProto.equalsIgnoreCase( "http" ) )
+ {
+ contextPathString = contextPathString.replace( "https://", "http://" );
+ }
+ }
+
+ model.addAttribute( "contextPath", contextPathString );
+ }
}