]> source.dussan.org Git - archiva.git/commitdiff
service to retrieve baseUrl
authorOlivier Lamy <olamy@apache.org>
Tue, 14 Feb 2012 22:59:13 +0000 (22:59 +0000)
committerOlivier Lamy <olamy@apache.org>
Tue, 14 Feb 2012 22:59:13 +0000 (22:59 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1244257 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-webapp-js/src/main/java/org/apache/archiva/webapp/ui/services/api/DefaultRuntimeInfoService.java
archiva-modules/archiva-web/archiva-webapp-js/src/main/java/org/apache/archiva/webapp/ui/services/model/ApplicationRuntimeInfo.java

index 44c9d11144e265495121dcc5cc9f9253ac600098..c3f02aaec04ebc406e75b7ec876014eda3238ff0 100644 (file)
@@ -25,6 +25,8 @@ import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Service;
 
 import javax.inject.Inject;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.core.Context;
 
 /**
  * @author Olivier Lamy
@@ -38,6 +40,9 @@ public class DefaultRuntimeInfoService
 
     private ArchivaRuntimeInfo archivaRuntimeInfo;
 
+    @Context
+    protected HttpServletRequest httpServletRequest;
+
     @Inject
     public DefaultRuntimeInfoService( ArchivaRuntimeInfo archivaRuntimeInfo )
     {
@@ -51,9 +56,17 @@ public class DefaultRuntimeInfoService
         applicationRuntimeInfo.setBuildNumber( this.archivaRuntimeInfo.getBuildNumber() );
         applicationRuntimeInfo.setTimestamp( this.archivaRuntimeInfo.getTimestamp() );
         applicationRuntimeInfo.setVersion( this.archivaRuntimeInfo.getVersion() );
+        applicationRuntimeInfo.setBaseUrl( getBaseUrl( httpServletRequest ) );
         return applicationRuntimeInfo;
     }
 
+    protected String getBaseUrl( HttpServletRequest req )
+    {
+        return req.getScheme() + "://" + req.getServerName() + ( req.getServerPort() == 80
+            ? ""
+            : ":" + req.getServerPort() ) + req.getContextPath();
+    }
+
     public Boolean logMissingI18n( String key )
     {
         i18nLogger.info( "missing i18n key : '{}'", key );
index e6794bd352c4de757431482a37ef556f42769a2e..351bc6182dd92040f6533a6cb184546d46889aa5 100644 (file)
@@ -42,6 +42,8 @@ public class ApplicationRuntimeInfo
 
     private boolean logMissingI18n;
 
+    private String baseUrl;
+
 
     public ApplicationRuntimeInfo()
     {
@@ -124,6 +126,16 @@ public class ApplicationRuntimeInfo
         this.logMissingI18n = logMissingI18n;
     }
 
+    public String getBaseUrl()
+    {
+        return baseUrl;
+    }
+
+    public void setBaseUrl( String baseUrl )
+    {
+        this.baseUrl = baseUrl;
+    }
+
     @Override
     public String toString()
     {
@@ -136,6 +148,7 @@ public class ApplicationRuntimeInfo
         sb.append( ", timestamp=" ).append( timestamp );
         sb.append( ", copyrightRange='" ).append( copyrightRange ).append( '\'' );
         sb.append( ", logMissingI18n=" ).append( logMissingI18n );
+        sb.append( ", baseUrl='" ).append( baseUrl ).append( '\'' );
         sb.append( '}' );
         return sb.toString();
     }