=== modified file 'dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FredController.java' --- dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FredController.java 2012-12-10 13:53:34 +0000 +++ dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FredController.java 2012-12-28 11:28:02 +0000 @@ -27,6 +27,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import org.hisp.dhis.web.webapi.v1.utils.ContextUtils; import org.springframework.http.MediaType; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.stereotype.Controller; @@ -34,21 +35,25 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; +import javax.servlet.http.HttpServletRequest; + import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo; /** * @author Morten Olav Hansen */ -@Controller( value = "fred-controller-" + FredController.PREFIX ) -@RequestMapping( value = FredController.PREFIX ) -@PreAuthorize( "hasRole('M_dhis-web-api-fred') or hasRole('ALL')" ) +@Controller(value = "fred-controller-" + FredController.PREFIX) +@RequestMapping(value = FredController.PREFIX) +@PreAuthorize("hasRole('M_dhis-web-api-fred') or hasRole('ALL')") public class FredController { public static final String PREFIX = "v1"; - @RequestMapping( value = "", method = RequestMethod.GET, produces = { MediaType.TEXT_HTML_VALUE, MediaType.TEXT_XML_VALUE } ) - public String home( Model model ) + @RequestMapping(value = "", method = RequestMethod.GET, produces = { MediaType.TEXT_HTML_VALUE, MediaType.TEXT_XML_VALUE }) + public String home( Model model, HttpServletRequest request ) { + ContextUtils.populateContextPath( model, request ); + model.addAttribute( "baseUrl", linkTo( FredController.class ).toString() ); model.addAttribute( "pageName", "home" ); model.addAttribute( "page", FredController.PREFIX + "/index.vm" ); === added file 'dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/utils/ContextUtils.java' --- dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/utils/ContextUtils.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/utils/ContextUtils.java 2012-12-28 11:28:02 +0000 @@ -0,0 +1,35 @@ +package org.hisp.dhis.web.webapi.v1.utils; + +import org.springframework.ui.Model; +import org.springframework.web.servlet.support.ServletUriComponentsBuilder; +import org.springframework.web.util.UriComponents; + +import javax.servlet.http.HttpServletRequest; + +/** + * @author Morten Olav Hansen + */ +public class ContextUtils +{ + public static 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 ); + } +} === modified file 'dhis-2/dhis-web/dhis-web-api-fred/src/main/webapp/WEB-INF/api-fred-velocity/v1/layout.vm' --- dhis-2/dhis-web/dhis-web-api-fred/src/main/webapp/WEB-INF/api-fred-velocity/v1/layout.vm 2012-12-09 09:26:56 +0000 +++ dhis-2/dhis-web/dhis-web-api-fred/src/main/webapp/WEB-INF/api-fred-velocity/v1/layout.vm 2012-12-28 11:28:02 +0000 @@ -6,16 +6,18 @@ FRED Facility API v1.0 (DHIS2) - - - - + + + + + - + +