Bladeren bron

http cookie冲突问题

MaxKey 4 jaren geleden
bovenliggende
commit
2691e49957

+ 31 - 21
maxkey-core/src/main/java/org/maxkey/web/WebContext.java

@@ -35,6 +35,8 @@ import org.maxkey.domain.UserInfo;
 import org.maxkey.util.DateUtils;
 import org.maxkey.util.StringGenerator;
 import org.maxkey.web.message.Message;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.context.ApplicationContext;
 import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
 import org.springframework.security.core.Authentication;
@@ -52,7 +54,9 @@ import org.springframework.web.servlet.support.RequestContextUtils;
  * @since 1.5
  */
 public final class WebContext {
-
+    
+    final static Logger _logger = LoggerFactory.getLogger(WebContext.class);
+    
     public static Properties properties;
      
     /**
@@ -192,33 +196,39 @@ public final class WebContext {
     }
 
     /**
-     * get Http Context full Path,if port equals 80 is omitted.
+     * get Http Context full Path.
      * 
-     * @return String eg:http://192.168.1.20:9080/webcontext or
-     *         http://www.website.com/webcontext
+     * @return String HttpContextPath
      */
     public static String getHttpContextPath() {
         HttpServletRequest httpServletRequest = WebContext.getRequest();
+        return getHttpContextPath(httpServletRequest);
+    }
+    
+    /**
+     * get Http Context full Path,if port equals 80 or 443 is omitted.
+     * 
+     * @return String eg:http://192.168.1.20:9080/webcontext or
+     *         http://www.website.com/webcontext
+     */
+    public static String getHttpContextPath(HttpServletRequest httpServletRequest) {
         ApplicationConfig applicationConfig = (
                 ApplicationConfig) WebContext.getBean("applicationConfig");
-
-        if (applicationConfig.getServerPrefix() != null 
-                && !applicationConfig.getServerPrefix().equals("")) {
-            return applicationConfig.getServerPrefix();
-        } else {
-            String httpContextPath = 
-                    httpServletRequest.getScheme() + "://" + applicationConfig.getDomainName();
-            int port = httpServletRequest.getServerPort();
-            if (port == 443 && httpServletRequest.getScheme().equalsIgnoreCase("https")) {
-                //
-            } else if (port == 80 && httpServletRequest.getScheme().equalsIgnoreCase("http")) {
-                //
-            } else {
-                httpContextPath += ":" + port;
-            }
-            httpContextPath += httpServletRequest.getContextPath() + "";
-            return httpContextPath;
+        
+        _logger.trace("Config ServerPrefix " + applicationConfig.getServerPrefix());
+        _logger.trace("Config DomainName " + applicationConfig.getDomainName());
+        _logger.trace("ServerName " + httpServletRequest.getServerName());
+        
+        String scheme = httpServletRequest.getScheme().toLowerCase();
+        String httpContextPath = scheme + "://"+httpServletRequest.getServerName();
+        int port = httpServletRequest.getServerPort();
+        if(!(port==80 || port==443)){
+            httpContextPath    +=  ":"+port;
         }
+        httpContextPath += httpServletRequest.getContextPath() + "";
+        
+        _logger.trace("httpContextPath " + httpContextPath);
+        return httpContextPath;
 
     }
 

+ 4 - 19
maxkey-core/src/main/java/org/maxkey/web/tag/BasePathTagDirective.java

@@ -22,6 +22,7 @@ import java.util.Map;
 
 import javax.servlet.http.HttpServletRequest;
 
+import org.maxkey.web.WebContext;
 import org.springframework.beans.factory.annotation.Autowired;
 
 import freemarker.core.Environment;
@@ -33,38 +34,22 @@ import freemarker.template.TemplateModel;
 /**
  * <@basePath/>
    *  获取请求地址及应用上下文标签
- * get Http Context full Path,if port equals 80 443 is omitted
- * @return String
- * eg:http://192.168.1.20:9080/webcontext or http://www.website.com/webcontext
  * @author Crystal.Sea
  *
  */
 
 @FreemarkerTag("basePath")
 public class BasePathTagDirective implements TemplateDirectiveModel {
+    
 	@Autowired
     private HttpServletRequest request;
 	
-	private String basePath = null;
-
 	@Override
 	public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
 			throws TemplateException, IOException {
-		if(basePath==null) {
-			basePath = request.getScheme()+"://"+request.getServerName();
-			int port=request.getServerPort();
-			if(port==443 && request.getScheme().equalsIgnoreCase("https")){
-				
-			}else if(port==80 && request.getScheme().equalsIgnoreCase("http")){
-				
-			}else{
-				basePath	+=	":"+port;
-			}
-			basePath += request.getContextPath()+"";
-		}
-		env.getOut().append(basePath);
+	    
+		env.getOut().append(WebContext.getHttpContextPath(request));
 		
-
 	}
 
 }

+ 3 - 5
maxkey-core/src/main/java/org/maxkey/web/tag/BaseTagDirective.java

@@ -40,16 +40,14 @@ import freemarker.template.TemplateModel;
 public class BaseTagDirective implements TemplateDirectiveModel {
 	@Autowired
     private HttpServletRequest request;
-	
-	private static String base = null;
 
 	@Override
 	public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
 			throws TemplateException, IOException {
 		//String url = params.get(URL).toString();
-		if(base==null) {
-			base=request.getContextPath();
-		}
+
+		String  base=request.getContextPath();
+		
 		env.getOut().append(base);